Skip to content

Use declared types for transfer serialization - #1878

Draft
tconley1428 wants to merge 4 commits into
mainfrom
fix/transfer-converter-type-hints
Draft

tconley1428 wants to merge 4 commits into
mainfrom
fix/transfer-converter-type-hints

Conversation

@tconley1428

@tconley1428 tconley1428 commented Sep 16, 2026

Copy link
Copy Markdown
Contributor

Select transfer type converters from declared argument and result types during serialization. When a hint is absent, or the declared type has no registered converter, skip transfer conversion. The runtime type is never used for selection. The hint only selects the converter: conversion still calls the existing to_transfer_type(value) method.

Carry hints through workflow and activity calls, signals, queries, updates, update-with-start, continue-as-new, schedules, and Nexus calls. Generated System Nexus calls obtain their input hints from registered operation definitions for now; temporalio/nexgen#194 tracks generating operation objects instead. Add encode_with_type_hints and to_payloads_with_type_hints, which scope hints in a private ContextVar and invoke existing encode(values) / to_payloads(values) overrides with the original sequence unchanged. Preserve RawValue passthrough.

Bind hints to the original sequence so unrelated nested conversions cannot use them. Hide the context before invoking transfer and inner payload converters, restore it in finally, and expire it for child tasks that outlive the originating call. Custom overrides must forward the original sequence to retain hints; rebuilt sequences receive no transfer conversion unless hints are supplied again.

Validation:

  • poe format and poe lint passed, including Pyright, mypy, basedpyright, and docstyle.
  • 177 tests passed using poe test -s -n 4 tests/test_serialization_type_hints.py tests/test_converter.py tests/test_serialization_context.py tests/nexus/test_temporal_system_nexus.py tests/worker/test_interceptor.py tests/worker/test_update_with_start.py tests/contrib/pydantic/test_pydantic.py tests/test_extstore.py.

New tests cover declared/runtime disagreement, absence of hints or registered converters, generic selection, old-signature overrides, sequence identity, nested and concurrent serialization, error/cancellation cleanup, context expiration in child tasks, raw payloads, and end-to-end input/result conversion.

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.

1 participant