Skip to content

Decode inbound remote codec payloads concurrently - #1287

Open
sattwikbhakta26 wants to merge 2 commits into
temporalio:mainfrom
sattwikbhakta26:feat/concurrent-remote-codec-decode
Open

sattwikbhakta26 wants to merge 2 commits into
temporalio:mainfrom
sattwikbhakta26:feat/concurrent-remote-codec-decode

Conversation

@sattwikbhakta26

Copy link
Copy Markdown

Related issues

Closes #1193

What changed?

Previously, cliext.ClientOptionsBuilder.Build configured remote payload codecs using converter.NewPayloadCodecGRPCClientInterceptor, which leaves proxy.VisitPayloadsOptions.ConcurrencyLimit unset (0), causing every visited payload in a gRPC response (such as temporal workflow show --output json) to be decoded serially over HTTP.

This PR:

  • Replaces the SDK wrapper call in cliext/client.go with a direct proxy.NewPayloadVisitorInterceptor helper (newPayloadCodecGRPCClientInterceptor) that:
    • Sets bounded concurrency on inbound payload decoding (default: 16).
    • Keeps outbound payload encoding sequential (0), keeping the change tightly scoped to decoding latency while leaving the helper structured for future outbound concurrency if desired.
    • Preserves SkipSearchAttributes: true on both inbound and outbound visitors.
  • Adds a --codec-concurrency client flag (cliext/option-sets.yaml + regenerated cliext/flags.gen.go, default 16) so users with rate-limited or single-threaded codec servers can tune concurrency down (e.g., --codec-concurrency 1 for strictly sequential decoding) or up. Rejects invalid values < 1.
  • Clones http.DefaultTransport in newRemotePayloadCodec and sets MaxIdleConnsPerHost to match the configured concurrency (instead of Go's default of 2) so concurrent /decode waves reuse keep-alive connections without mutating the global default transport.
  • Adds black-box unit tests in cliext/client_test.go covering:
    • Concurrent and bounded inbound decoding (48 history events with a deterministic concurrency barrier), header propagation (X-Namespace, Authorization, --codec-header), and HTTP keep-alive connection reuse (ConnState).
    • Sequential decoding when --codec-concurrency 1 is configured.
    • Validation of negative and explicit 0 concurrency values.
    • Sequential outbound encoding and clean inbound HTTP error propagation.

Checklist

Stability

  • No breaking changes; JSON output format is unchanged

Design

  • This feature does not depend on Cloud-only APIs or behavior (it works against an OSS server)
  • New flags are named after the API concept, not the implementation mechanism
  • New flags don't duplicate an existing flag that serves the same purpose
  • New flags do not have short aliases without strong justification

Help text

  • All flags shown in help text and examples are implemented and functional

Behavior

  • Results go to stdout; errors and warnings go to stderr
  • Error messages are lowercase with no trailing punctuation

Tests

  • Verified existing functional test (TestSharedServerSuite/TestWorkflow_Execute_CodecEndpoint)
  • Added unit tests (cliext/client_test.go)

Manual tests

Setup
Run a local Temporal server and a remote codec server (e.g. on http://localhost:8081), and execute a workflow with multiple payload-bearing events.

Happy path

$ temporal workflow show \
    --workflow-id YourWorkflowId \
    --codec-endpoint http://localhost:8081 \
    --output json
<decoded workflow history JSON, with inbound /decode calls running concurrently up to 16 in flight>

$ temporal workflow show \
    --workflow-id YourWorkflowId \
    --codec-endpoint http://localhost:8081 \
    --codec-concurrency 1 \
    --output json
<decoded workflow history JSON, with inbound /decode calls running sequentially>

Error case

$ temporal workflow show \
    --workflow-id YourWorkflowId \
    --codec-endpoint http://localhost:8081 \
    --codec-concurrency 0
Error: invalid codec concurrency 0: must be >= 1
$ echo $?
1

Configure bounded concurrency on the inbound remote payload codec gRPC
visitor (default 16) via go.temporal.io/api/proxy's VisitPayloadsOptions
and add a --codec-concurrency flag (allowing --codec-concurrency 1 for
sequential decoding against rate-limited codec servers). Also clone
http.DefaultTransport in newRemotePayloadCodec with MaxIdleConnsPerHost
matched to the configured concurrency so keep-alive connections are
reused across concurrent decode waves.

Closes temporalio#1193
@sattwikbhakta26
sattwikbhakta26 requested a review from a team as a code owner December 6, 2026 19:02
@CLAassistant

CLAassistant commented Dec 6, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@CLAassistant

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Dec 6, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-12-06T19:49:20.987294Z 4234034 New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: bf551cceef

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread cliext/client.go Resolved
Share a single buffered-channel semaphore across all gRPC invocations on
the client inside newPayloadCodecGRPCClientInterceptor so commands that
issue parallel RPCs on the same client (such as `workflow trace`) still
strictly respect --codec-concurrency (including --codec-concurrency 1).
Also set MaxConnsPerHost alongside MaxIdleConnsPerHost on the cloned
HTTP transport to prevent extra connections from opening under load, and
add multi-RPC concurrency and cancellation tests.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 4234034663

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread cliext/client.go
if defaultTransport, ok := http.DefaultTransport.(*http.Transport); ok {
transport := defaultTransport.Clone()
transport.MaxIdleConnsPerHost = maxConnsPerHost
transport.MaxConnsPerHost = maxConnsPerHost

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Avoid throttling outbound codec requests with the inbound limit

When an HTTP/1.1 codec is used and callers issue concurrent payload-bearing RPCs on one client, this transport-wide cap also applies to /encode: with --codec-concurrency 1, outbound encodes serialize and a slow encode can block inbound decoding. That contradicts the generated help's “Maximum number of concurrent inbound requests” (cliext/flags.gen.go:108) and the explicit zero outbound traversal limit; before this change the default transport imposed no per-host active-connection cap. The shared inboundSem already bounds /decode, so do not derive the all-direction MaxConnsPerHost from the inbound setting.

Useful? React with 👍 / 👎.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature Request] Decode workflow histories concurrently with remote codec servers

2 participants