Skip to content

feat: Serialization context - #796

Open
xepozz wants to merge 2 commits into
masterfrom
feature/serialization-context2
Open

xepozz wants to merge 2 commits into
masterfrom
feature/serialization-context2

Conversation

@xepozz

@xepozz xepozz commented Aug 17, 2026

Copy link
Copy Markdown
Collaborator

What was changed

Why?

Closes #587

Checklist

  1. Closes

  2. How was this tested:

  1. Any docs updates needed?
  1. Merge Feature: Serialization context tests features#868
  2. Merge feat(php): serialization context conformance tests xepozz/temporal-features#1

@xepozz
xepozz force-pushed the feature/serialization-context2 branch 4 times, most recently from 83f4524 to 298145d Compare August 21, 2026 11:22
Add SerializationContext support so a payload converter or failure converter
can know which namespace, workflow, or activity a payload belongs to:

- SerializationContext marker with WorkflowSerializationContext and
  ActivitySerializationContext, plus SerializationContextAwareInterface and
  SerializationContextApplier for opt-in context binding.
- Outbound workflow context is resolved at a single choke point in
  WorkflowContext::request per command type (activity, local activity, child
  workflow, external signal, complete, side effect, continue-as-new); stubs
  create plain EncodedValues and carry no context.
- Inbound routers, client API (start, signal-with-start, update-with-start,
  query, update, result), start memo, schedule mapping, pending activity info,
  heartbeat details, and failure chains are converted with the proper context.
- ActivityCompletionClient stays context-free by default with an explicit
  withContext escape hatch for out-of-band completion.

Covered by unit tests and an acceptance suite that signs every payload with
its serialization context and rejects any mismatch.
@xepozz
xepozz force-pushed the feature/serialization-context2 branch from 298145d to 46a74b8 Compare August 21, 2026 11:58
@xepozz xepozz changed the title Feature/serialization context2 feat: Serialization context Aug 21, 2026
@xepozz
xepozz marked this pull request as ready for review September 12, 2026 14:26
@xepozz
xepozz requested review from a team, roxblnfk and wolfy-j as code owners September 12, 2026 14:26

@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: 46a74b8ce1

ℹ️ 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".

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

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines 210 to +211
if ($this->values !== null) {
$converter = $this->converter();

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 Skip converter lookup for empty value lists

When EncodedValues::empty() or EncodedValues::fromValues([]) has no converter, toPayloads() now calls converter() before discovering that there are no values and throws LogicException. Previously the empty loop returned an empty Payloads message without requiring a converter, so callers that serialize an empty collection directly regress; return early for an empty values array or obtain the converter only inside the loop.

Useful? React with 👍 / 👎.

Comment on lines +79 to +82
$collection = $memo === null
? EncodedCollection::fromValues([], $this->converter)
: EncodedCollection::fromPayloadCollection($memo->getFields(), $this->converter);
$collection->setSerializationContext($this->context);

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 Derive list memo context from each execution

When results come through WorkflowClient::listWorkflowExecutions(), the mapper is constructed without a context, so this assigns null to every memo even though the response contains each workflow ID and the list request knows the namespace. Accessing a memo encoded by a context-aware converter will therefore fail or use the wrong key, while describe() works because it supplies a context; construct a workflow context per mapped execution for list results.

Useful? React with 👍 / 👎.

Comment on lines +195 to +198
$context = $this->getSerializationContext();

$queryArguments = EncodedValues::fromValues($args, $converter);
$queryArguments->setSerializationContext($context);

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 Recompute query context after interceptor rerouting

If a client query interceptor uses the supported QueryInput::with(workflowExecution: ...) API to route the query to another workflow, this context was captured from the original stub before the interceptor runs. The request arguments remain signed for the original workflow and the returned payload is also decoded under that original context, so context-aware converters fail for the rerouted query; derive and apply the context from the final $input->workflowExecution inside the terminal callback.

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] Serialization context for codecs and converters

2 participants