Replay signed and encrypted history data to providers with the same `canonical_system`
Why we make these changes
Signed and encrypted history data (encrypted reasoning, thinking signatures, OpenAI compaction items) was only sent back when the part's provider_name equalled the model's system. That's too strict where names share a key (openai-codex and openai, Claude on Bedrock and anthropic, a renamed AnthropicProvider subclass) and too loose where one name covers two transports: the Gemini API and Vertex AI are both google and reject each other's thought signatures (#10905), and OpenAIProvider covers both OpenAI and an AsyncAzureOpenAI client. This implements the design in the last maintainer comment on #11463, with the follow-up decisions recorded on this PR.
[!WARNING]
Compatibility impact: A history that mixes providers can send a different request: encrypted reasoning and compaction items now go between openai-codex and openai, Claude thinking between anthropic and Bedrock, and a request after a compatible compaction item starts from it. A Gemini API thought signature is no longer sent to Vertex AI (or the reverse), even through a proxy URL for new histories; the documented dummy goes instead. Google and OpenAIProvider responses now always record canonical_system, so OpenAIProvider with an AsyncAzureOpenAI client no longer gets fresh OpenAI encrypted data. Anthropic file and container IDs are no longer sent through Bedrock, Vertex AI or Foundry clients. Requests that stay on one provider and model family are unchanged; on Bedrock, a history that switches from Claude to another model family (such as DeepSeek R1, both bedrock) now sends Claude's thinking as text instead of with its signature, as designed. Tool dispatch after a compaction judges the boundary with the same check the request was trimmed by.
Why this can ship in a minor release: It fixes requests that were rejected or lost data the receiving API can verify; no public API changes shape.
Migration: None needed. To keep the old split, override canonical_system/compatible_systems on a provider subclass; openai_send_reasoning_ids=False still stops reasoning items.
New public surface
Provider.canonical_system,Provider.compatible_systems, mirrored onModel;Model.accepts_stateless_artifacts(response, part)ModelResponse.canonical_system(set when it differs fromprovider_name, and always when the provider derives it from its client: Google providers,OpenAIProvider)pydantic_ai.providers.openai_compatible.OpenAICompatibleProvider(name, *, base_url, api_key, openai_client, http_client, profile, canonical_system, compatible_systems)AnthropicModelProfile.anthropic_accepts_file_and_container_ids
User-visible behavior
history = (await Agent(OpenAICodexModel('gpt-6-astra')).run('...')).all_messages()
await Agent(OpenAIResponsesModel('gpt-6-astra')).run('...', message_history=history)
# before: Codex reasoning sent as text, compaction item dropped and the full history resent
# after: encrypted reasoning and the compaction item are sent; the request starts from the compaction
Verification
- Predicate matrix and per-adapter request shapes:
tests/test_canonical_system.py - Recorded cross-system round-trips (Codex↔OpenAI reasoning, Codex compaction → OpenAI trim, the #10905
FallbackModelVertex→Gemini API→Vertex run, Anthropic API↔Bedrock signatures and redacted thinking):tests/test_canonical_system_live.py - Request-capture diff against
main, 13 receivers × 15 recorded-history sources (unstamped histories): every pair with the same provider and model family is byte-identical; only the 7 cross-system pairs change, including Bedrock Claude history into a non-Claude Bedrock model. - An offline run through the third-party
ClaudeCodeProvider(AnthropicProvider)plugin keeps ananthropichistory's signatures, redacted thinking and compaction.
What changes for existing users
Requests that stay on one provider and model family are unchanged; mixed histories change as described in the warning above.
PR decisions
2026-10-27 · Same-name legacy fallback · iter -
- Decision: An artifact whose family is derived from its name alone (no stamp, no decisive Google URL) is also accepted when its provider_name equals the receiver's system.
- Why: Keeps single-provider requests byte-identical for old histories under providers whose canonical can differ from their name (OpenAIProvider+Azure client, GoogleProvider on Vertex, Bedrock Claude, renamed subclasses); stamps and Google URL evidence still override.
- Source: https://github.com/pydantic/pydantic-ai/issues/11463
2026-10-27 · Part provider_name None is not accepted · iter -
- Decision: accepts_stateless_artifacts(response, part) returns False for a part without provider_name; passing part=None judges data the response carries itself (Google inline signatures on unnamed parts).
- Why: Sites that required an exact part name today keep rejecting unnamed parts, so UI round-trips that lost provider_name do not newly send signatures.
- Source: https://github.com/pydantic/pydantic-ai/issues/11463
2026-10-27 · Bedrock canonical via bedrock_thinking_variant · iter -
- Decision: BedrockConverseModel.canonical_system is 'anthropic' when the profile's bedrock_thinking_variant is 'anthropic', else the provider's.
- Why: Reuses the existing Claude-family Literal flag (user-overridable for inference-profile ARNs) instead of adding a second knob.
- Source: https://github.com/pydantic/pydantic-ai/issues/11463
2026-10-27 · Literal canonical only where stateless data exists · iter -
- Decision: Built-in providers whose adapters replay stateless data return a literal canonical_system (anthropic, google*, xai, bedrock, bedrock-mantle, azure, openai-codex, openai-chatgpt, openrouter, snowflake); others use the default self.name.
- Why: Rename-only subclasses inherit where it matters without adding ~30 no-op overrides.
- Source: https://github.com/pydantic/pydantic-ai/issues/11463
2026-10-27 · _matching_provider_names kept for uploaded files only · iter -
- Decision: Google uploaded-file validation (stateful scope) keeps the transport alias set; all replay sites use accepts_stateless_artifacts.
- Why: Files are stateful (project/key scoped); the design folds only stateless replay into the shared mechanism.
- Source: https://github.com/pydantic/pydantic-ai/issues/11463
2026-10-27 · FallbackModel delegation · iter -
- Decision: FallbackModel.canonical_system/compatible_systems delegate to its first model; the execution-availability window resolves the candidate that produced the serving response via a private Model._model_for_response hook.
- Why: FallbackModel has no current model outside a request; the window must judge with the producer's acceptance so trim and window agree.
- Source: https://github.com/pydantic/pydantic-ai/issues/11463
2026-10-27 · Anthropic native tool kinds split · iter -
- Decision: web_search/web_fetch/tool_search server-tool parts use the stateless predicate; code execution and MCP parts keep exact provider_name matching.
- Why: Search/fetch results carry encrypted or inline stateless payloads; code execution is container-scoped (stateful).
- Source: https://github.com/pydantic/pydantic-ai/issues/11463
2026-10-27 · OpenAICompatibleProvider module and profile · iter -
- Decision: Public class lives in providers/openai_compatible.py; its default profile is LiteLLM's vendor-prefix mapping (moved there, LiteLLM now calls it); accepts a ModelProfile (merged) or a callable(model_name) (replaces).
- Why: The private _openai_compatible module keeps only the SDK base + old-name alias; keeping the vendor map out of it avoids importing every family profile on every OpenAI-SDK provider import.
- Source: https://github.com/pydantic/pydantic-ai/issues/11463
2026-10-27 · Anthropic file/container flag · iter -
- Decision: New AnthropicModelProfile flag anthropic_accepts_file_and_container_ids, narrowed to False in AnthropicModel.profile for AsyncAnthropicBedrock/Vertex/Foundry (not Mantle); gates UploadedFile (UserError), container_upload + files beta, history container reuse, and code-execution native part replay.
- Why: Client-class capability gating per profile rules; Mantle is Claude Platform on AWS, whose Files API support wasn't verified, so left on (maintainer question).
- Source: https://github.com/pydantic/pydantic-ai/issues/11463
2026-10-27 · Native tool search follows the predicate · iter -
- Decision: synthesize_local_tool_search_messages takes keeps_native=self.accepts_stateless_artifacts; OpenAI hosted tool search and Anthropic tool_search parts replay to compatible systems, without stateful item ids.
- Why: Tool-search items carry their state inline; the synthesize pass and the adapter must agree on which native parts survive.
- Source: https://github.com/pydantic/pydantic-ai/issues/11463
2026-10-27 · pre-push review 1 of 3 at 626948e45ee737425d8291beacd261a2b3450d43 · iter -
- Decision: dispatched (reserved)
- Why: tree 881c70a69c3055ed23118e615e09156f5445aec9; scope d98c7cd48c..626948e45e full branch
- Source: https://github.com/pydantic/pydantic-ai/tree/canonical-system-replay
2026-10-27 · pre-push review 1 of 3 at 626948e45ee737425d8291beacd261a2b3450d43 · iter -
- Decision: remediated: window predicate only for trimming producer (+ exact-name fallback), Anthropic citations via predicate, paused-turn container gated, code-exec part gating reverted, docs/skill wording; dismissed private-method test finding (render-capture precedent, client-class gating needs real client classes) and vendor-profile relocation
- Why: tree 881c70a69c; scope d98c7cd48c..626948e45e full branch
- Source: https://github.com/pydantic/pydantic-ai/issues/11463
2026-10-27 · Code execution history unchanged on Bedrock/Vertex/Foundry clients · iter -
- Decision: Own code-execution parts keep exact provider_name replay on every client; only file/container IDs are gated by the client-class flag.
- Why: Probed: Bedrock InvokeModel rejects the code execution tool (400 unknown tag), so no such history arises there; Vertex/Foundry unprobed (no access), and dropping own parts would change single-provider requests.
- Source: https://github.com/pydantic/pydantic-ai/issues/11463
2026-10-27 · pre-push review 2 of 3 at ede61863d933c9477b56a0cd2712dd05fa629782 · iter -
- Decision: dispatched (reserved)
- Why: tree 6cb4a66f983bdf6393328ef740f4d5f294310165; follow-up scope 626948e45e..HEAD
- Source: https://github.com/pydantic/pydantic-ai/tree/canonical-system-replay
2026-10-27 · pre-push review 2 of 3 at ede61863d933c9477b56a0cd2712dd05fa629782 · iter -
- Decision: remediated: models/AGENTS.md compaction flag rule; docs/models/google.md proxy wording. Prior findings verified fixed; finding 8 dismissal accepted.
- Why: tree 6cb4a66f98; follow-up scope 626948e45e..ede61863d9
- Source: https://github.com/pydantic/pydantic-ai/tree/canonical-system-replay
2026-10-27 · pre-push review 3 of 3 at 1c9bad2b33 · iter -
- Decision: dispatched (reserved)
- Why: tree d24f9edce2; follow-up scope ede61863d9..1c9bad2b33 (docs + models/AGENTS.md)
- Source: https://github.com/pydantic/pydantic-ai/tree/canonical-system-replay
2026-10-27 · pre-push review 3 of 3 at 1c9bad2b33 · iter -
- Decision: remediated: models/AGENTS.md wording (both directions, fallback named, paragraph order) and google.md sentence. Budget exhausted; push without a fourth review.
- Why: tree d24f9edce2; scope ede61863d9..1c9bad2b33
- Source: https://github.com/pydantic/pydantic-ai/tree/canonical-system-replay
2026-10-27 · defer: Accept openai and xai reasoning on OpenRouter when the request is pinned to that upstream · iter -
- Decision: Filed as https://github.com/pydantic/pydantic-ai/issues/11507 instead of fixing here
- Why: Out of scope for this PR: own design decisions
- Source: https://github.com/pydantic/pydantic-ai/issues/11507
2026-10-27 · defer: Scope stateful history IDs by endpoint, not only by provider_name · iter -
- Decision: Filed as https://github.com/pydantic/pydantic-ai/issues/11508 instead of fixing here
- Why: Out of scope for this PR: own design decisions
- Source: https://github.com/pydantic/pydantic-ai/issues/11508
2026-10-27 · defer: Normalize the OpenTelemetry provider name for providers that share a canonical system · iter -
- Decision: Filed as https://github.com/pydantic/pydantic-ai/issues/11509 instead of fixing here
- Why: Out of scope for this PR: own design decisions
- Source: https://github.com/pydantic/pydantic-ai/issues/11509
2026-10-27 · defer: Use the upstream's pricing for providers that share a canonical system · iter -
- Decision: Filed as https://github.com/pydantic/pydantic-ai/issues/11510 instead of fixing here
- Why: Out of scope for this PR: own design decisions
- Source: https://github.com/pydantic/pydantic-ai/issues/11510
2026-10-27 · defer: Carry ModelResponse.canonical_system through UI adapter message round-trips · iter -
- Decision: Filed as https://github.com/pydantic/pydantic-ai/issues/11511 instead of fixing here
- Why: Out of scope for this PR: own design decisions
- Source: https://github.com/pydantic/pydantic-ai/issues/11511
2026-10-27 · defer: Replace provider-name feature gates in model adapters with profile flags · iter -
- Decision: Filed as https://github.com/pydantic/pydantic-ai/issues/11512 instead of fixing here
- Why: Out of scope for this PR: own design decisions
- Source: https://github.com/pydantic/pydantic-ai/issues/11512
2026-10-27 · defer: CodeExecutionTool advertised for Claude on Bedrock clients but rejected · iter -
- Decision: Filed as https://github.com/pydantic/pydantic-ai/issues/11513 instead of fixing here
- Why: Out of scope for this PR: own design decisions
- Source: https://github.com/pydantic/pydantic-ai/issues/11513
2026-10-27 · defer: AgentSpec/infer_provider support for OpenAICompatibleProvider (commented on the existing issue) · iter -
- Decision: Filed as https://github.com/pydantic/pydantic-ai/issues/5471 instead of fixing here
- Why: Out of scope for this PR: own design decisions
- Source: https://github.com/pydantic/pydantic-ai/issues/5471
2026-10-27 · post-budget push at 42b165222b · iter -
- Decision: Merged origin/main (resolved profiles/anthropic.py by keeping both new flags; regenerated durable_exec_contract.json) and replaced the Google Cloud host check with an anchored regex for CodeQL py/incomplete-url-substring-sanitization; pushed without a fourth review (budget exhausted), after targeted tests and pyright.
- Why: Review budget 3/3 used; delta is a conflict resolution plus an equivalent host match
- Source: https://github.com/pydantic/pydantic-ai/pull/11504
2026-10-27 · exempt push after 42b165222b · iter -
- Decision: test-only fixes from CI: optional-SDK collection, Temporal payload size (+24 bytes for canonical_system null), pyright isinstance narrowing
- Why: Exempt delta: test-harness repairs and fixture corrections to established behavior; chains from post-budget 42b165222b
- Source: https://github.com/pydantic/pydantic-ai/pull/11504
2026-10-27 · FallbackModel ambiguous producer prefers trimming model · iter -
- Decision: When two fallback candidates match a response by provider name and canonical system, _model_for_response prefers one with _honors_compaction_boundaries; pushed at 9fdc498ffd after the review budget (3/3).
- Why: Macroscope finding (Chat+Responses on one provider); the response carries no producer id and stamping one on every FallbackModel response would change stored history for all users; the trimming choice errs toward refusing, as the window docstring prefers
- Source: https://github.com/pydantic/pydantic-ai/pull/11504
2026-10-27 · OpenAICompatibleProvider profile= through a private instance hook · iter -
- Decision: model_profile stays a staticmethod (default profile); profile= applies via private Provider._configured_model_profile, which Model._provider_model_profile calls; pushed at 25f8e0b244 after the review budget.
- Why: CI Review (douwebot) finding: an instance model_profile broke the static Provider contract; profile= is part of the agreed signature, and a private hook avoids adding public extension surface
- Source: https://github.com/pydantic/pydantic-ai/pull/11504#discussion_r4390501706
2026-10-27 · Always stamp Google responses · iter -
- Decision: GoogleModel always sets ModelResponse.canonical_system (google / google-cloud); provider_url negative evidence stays only for unstamped histories; FallbackModel matches an unstamped response by its derived system.
- Why: Maintainer decision on open question 1: proxied Gemini API responses were indistinguishable from Vertex ones
- Source: https://github.com/pydantic/pydantic-ai/pull/11504
2026-10-27 · Stamp whenever canonical system follows the client · iter -
- Decision: Provider._canonical_system_follows_client (True on BaseGoogleProvider and OpenAIProvider) makes models always stamp ModelResponse.canonical_system; replaces the GoogleModel-only override. Same-name fallback stays only for unstamped history.
- Why: Maintainer decision: OpenAIProvider with an AsyncAzureOpenAI client must not receive fresh plain-OpenAI encrypted data; one mechanism over two special cases
- Source: https://github.com/pydantic/pydantic-ai/pull/11504
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.
Posted by CLAI on Douwe's behalf.