Honor compatible compactions in Responses continuation
This pull request was posted by Codex Desktop using gpt-6-luna on behalf of David.
Why we make these changes
OpenAI Responses can receive compatible encrypted compactions from other providers, and inline compactions from endpoints that do not share server state. Older response IDs must not cross those boundaries. The shared wire-boundary predicate protects automatic IDs, explicit seeds, and prompt-cache comparisons, while inline compactions remain chainable on endpoints that accept server state. This HTTP fix is now the base of the Responses WebSocket PR. Related: #4414. The split was requested in this maintainer discussion.
New public surface
None.
User-visible behavior
- previous_response_id='resp_before_compaction'
+ previous_response_id omitted; compaction and later messages sent as input
Verification
Endpoint-state boundary regression covers automatic and concrete seeds across compatible encrypted foreign compactions and same-provider inline compactions at shared and non-shared endpoints, plus summary-only, empty, incompatible-provider, and same-provider stateless controls. It reproduces the endpoint defect, and confirms same-endpoint inline continuation remains chainable. The final commit 67299fffcd448cf8115a6f323afcf1bac1f696cb changes only two documentation paragraphs; runtime and regression-test files are unchanged from 01b950c5fc5d4a4058e9d5655bf3d4207cf29227. Focused tests, Pyright, Ruff, and pre-commit passed at the preceding head 01b950c5fc5d4a4058e9d5655bf3d4207cf29227.
Docs navigation passed for source SHA 67299fffcd448cf8115a6f323afcf1bac1f696cb. The pinned documentation preview is built from that same full source SHA.
At current head 67299fffcd448cf8115a6f323afcf1bac1f696cb, full CI run 40997864778 passed on its first attempt. At the preceding head 01b950c5fc5d4a4058e9d5655bf3d4207cf29227, CI run 40989442137 passed on attempt 2 after attempt 1 was cancelled during the Python 3.11 all-extras shard and its coverage job failed; CodSpeed and PR Gates passed there.
What changes for existing users
HTTP defaults are unchanged. Compatible foreign compactions and inline compactions from endpoints without shared server state stop response-ID chaining, so the next request replays the compaction item and later messages. Inline compactions on endpoints that accept server state remain chainable.
PR decisions
2026-10-29 · pre-push review 1 of 3 at d91be2c1e2 · iter -
- Decision: Reserved fresh independent pre-push review.
- Why: Full focused HTTP compaction change from main271deb7ac0; shared predicate and regression matrix.
- Source: https://github.com/pydantic/pydantic-ai/tree/codex/compatible-compaction-continuation
- Session: 01a17f94-09f2-7db1-8461-346e575fb310
2026-10-29 · pre-push review 1 of 3 at d91be2c1e2 · iter -
- Decision: No findings; current at d91be2c1e2b600b3a6b7796fc430c53b6d35c05b.
- Why: Reviewed tree e5d1583ca89590a8015c5f415df98364c2757b6a; full diff271deb7ac0..d91be2c1e2 from policy271deb7ac0.
- Source: https://github.com/pydantic/pydantic-ai/tree/codex/compatible-compaction-continuation
- Session: 01a17f94-09f2-7db1-8461-346e575fb310
2026-10-29 · Preserve same-provider stateful compaction continuation · iter -
- Decision: Apply the shared part predicate only to foreign responses; preserve the existing marker-only boundary for same-provider responses.
- Why: A red regression reproduced dropping the real inline response ID in stateful OpenAI compaction; auto and concrete seeds now retain it.
- Source: https://github.com/pydantic/pydantic-ai/pull/11861#discussion_r4415487130
- Session: 01a17f94-09f2-7db1-8461-346e575fb310
2026-10-29 · pre-push review 2 of 3 at 6c004303a9 · iter -
- Decision: Reserved fresh scoped follow-up review.
- Why: Follow-up d91be2c1e2..6c004303a9 preserves stateful compaction; verify hosted findings4415487130 and4415487674. Policy2ca8794841.
- Source: https://github.com/pydantic/pydantic-ai/pull/11861
- Session: 01a17f94-09f2-7db1-8461-346e575fb310
2026-10-29 · pre-push review 2 of 3 at 6c004303a9 · iter -
- Decision: No findings; current at6c004303a9190300d1e10633ffcc660554b7fd7a.
- Why: Reviewed tree0662c80fa2fde74a6fc8b90e745c72859e44ef48; scoped d91be2c1e2..6c004303a9 plus full branch context; policy2ca8794841.
- Source: https://github.com/pydantic/pydantic-ai/pull/11861
- Session: 01a17f94-09f2-7db1-8461-346e575fb310
2026-10-29 · pre-push review 3 of 3 at30b6a37c80 · iter -
- Decision: Reserved final fresh scoped review on latest Sol after two hosted review rounds.
- Why: Follow-up6c004303a9..30b6a37c80 replaces derived expected values with explicit cases and simplifies mutually exclusive branches; policyc2ac8cc49c.
- Source: https://github.com/pydantic/pydantic-ai/pull/11861
- Session: 01a17f94-09f2-7db1-8461-346e575fb310
2026-10-29 · pre-push review 3 of 3 at30b6a37c80 · iter -
- Decision: No findings; current at30b6a37c8055328ca01c85349635657b98449794.
- Why: Reviewed tree02c06cc90aa170809dcd52aac976c3b23f192ec4; scoped6c004303a9..30b6a37c80 plus full branch context; policyc2ac8cc49c. Local budget exhausted.
- Source: https://github.com/pydantic/pydantic-ai/pull/11861
- Session: 01a17f94-09f2-7db1-8461-346e575fb310
2026-10-29 · Keep explicit compaction cases and narrow their parameters · iter -
- Decision: Use Literal parameter types while retaining the existing explicit per-case request bodies.
- Why: A targeted Pyright probe catches misspelled branch comparisons with Literal but not misspelled pytest parameter values or IDs; a Case dataclass adds structure without new behavioral coverage to this legacy-file regression.
- Source: https://github.com/pydantic/pydantic-ai/pull/11861#discussion_r4416546859
- Session: 01a17f94-09f2-7db1-8461-346e575fb310
2026-10-29 · Retain the shared compaction predicate within the focused fix · iter -
- Decision: Keep adapter-aware trimming and continuation on the existing shared part predicate without changing the shared trim helper contract.
- Why: Both paths already pass identical model declarations to one classifier. The proposed base wrapper requires new callback wiring for shared trimming but fixes no reproduced boundary disagreement; private helper imports follow existing model-module precedent.
- Source: https://github.com/pydantic/pydantic-ai/pull/11861#discussion_r4417003346
- Session: 01a17f94-09f2-7db1-8461-346e575fb310
2026-10-30 · Scope inline compaction chaining by shared server state · iter -
- Decision: Use accepts_server_state for the marker-only inline-compaction branch, retaining its legacy provider_url fallback and Provider.shares_server_state_with overrides.
- Why: The public request regression reproduces reuse of an older local response ID and cache baseline across a compatible encrypted compaction from a non-sharing endpoint with the same provider name.
- Source: https://github.com/pydantic/pydantic-ai/pull/11774
- Session: 01a18a73-e6d4-7783-ad03-3b70e89b0875
- Supersedes: Preserve same-provider stateful compaction continuation
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.