Skip event kinds a Temporal `stream_agent_events()` subscriber does not know, instead of failing the stream

Merged
DO
7d ago
+199-7
  • Part of #13739
  • Part of #14378 (stream attempts: response boundaries, attempt identity and partials)

TemporalDurability.stream_agent_events() decoded every topic item through the AgentStreamEvent discriminated union, so a subscriber running an older Pydantic AI than the workers failed the whole stream on the first event kind it didn't know: for example ModelResponseRejectedEvent (#11939) or the response start and end events that are planned. Subscribers routinely lag workers, since they're often a separate web tier.

This makes the subscriber skip those items instead:

  • The Workflow Stream subscription now yields RawValues, and each item is decoded with the client's payload converter and the same result type as before, so known kinds decode exactly as they did.
  • A ValidationError whose only cause is an unknown tag on the top-level event_kind discriminator (union_tag_invalid at the root location) skips the item and emits a UserWarning, once per kind per subscription, saying to upgrade pydantic-ai in the consumer.
  • Any other error still raises, including a known kind with a bad payload and an unknown tag nested inside a known event (e.g. a part kind).

The decoding moved out of Temporal's subscription generator because an exception raised there ends the generator, so it can't skip and continue. The public signature and return type are unchanged.

New event kinds should only be published to topics once this has been out for a few releases.

Checklist

  • No breaking changes in accordance with the version policy.
  • Any permitted compatibility impact has a label, warning, migration and release note, and an exact API-check waiver if the gate reports it.
  • PR title is fit for the release changelog.

šŸ¤– Generated with Claude Code


Summary by cubic

Makes TemporalDurability.stream_agent_events() subscribers skip event kinds they don't recognize instead of failing the stream, so consumers running an older Pydantic AI than the workers can keep reading events published by newer workers.

  • The subscription now yields raw payloads and decodes each item separately; the public signature and return type are unchanged.
  • Unknown event kinds are skipped with a one-time UserWarning per kind that points at the consumer's code; any other validation error still raises, including a malformed payload on a known kind and an unknown tag nested inside a known event.
  • Known kinds decode exactly as before. Consumers on v2.76 or later skip unknown kinds with a warning to upgrade; docs note this behavior.