Check that every core and Harness capability keeps a conversation's requests append-only
Prompt-cache prefix breaks keep coming back one capability at a time. Each one is found by hand, then fixed in a one-off PR. This adds a guardrail so a new break fails CI and can't land silently.
The invariant: within a conversation, each request starts with the previous request's bytes. Cache-breakpoint markers are ignored. Any other prefix change has to be listed explicitly.
What the test does
- Covers every capability without a hand list. It walks
pydantic_ai.capabilities,pydantic_ai.modelsandpydantic_ai_harnessand collects every public capability class. Each one is built with its defaults, or with a small fixture fromFIXTURES. A capability that can't be built offline needs anEXEMPTentry with a reason. A new capability is covered as soon as it ships; if it can't be built with its defaults, the test fails and says to add a fixture or an exemption. - Runs a realistic conversation. One run makes two steps of tool calls. A second run continues from
message_historyand is streamed. The clock moves 61 minutes after every request. Stateful capabilities change state mid-conversation throughSCENARIOS: a memory write, a todo, a file edit, anAGENTS.mdedit. - Captures the real wire bodies. Requests go through the Anthropic, OpenAI Responses and OpenAI Chat adapters to a mock
httpx2transport, which returns scripted responses (JSON or SSE). - Checks three invariants:
- Prefix. Each request starts with the previous one. This covers the tools, system and messages sections, plus the top-level fields that are part of the cache key (
model,tool_choice, thinking or reasoning, and OpenAI'sprompt_cache_key), and Anthropicdefer_loadingtools separately (append-only in reveal order). Anthropiccache_controland OpenAIprompt_cache_breakpointare ignored, along with the single-text-part wrapping OpenAI's marker needs. - Addressable ids. Every instruction block a capability contributes has an
id, so a change to it can be appended (#8188) instead of rewriting the prompt. - Deterministic projection. Building the same request twice from the same history, at the same time, gives identical bytes.
- Prefix. Each request starts with the previous one. This covers the tools, system and messages sections, plus the top-level fields that are part of the cache key (
- Says where it broke. Per section, the earlier request's blocks must be an exact prefix of the later one's, with new blocks only after them, and only in the last section that already has blocks: a tool or system block added ahead of sent messages moves them too (Anthropic's deferred tools excepted, being outside its cache key). From the first position that differs, every differing position is reported, so a block inserted ahead of earlier ones shows as each block it displaced. A failure names each change: the capability, the provider, the request, the section and position, what it is (an instruction id,
instruction:anonymous@<position>,tool:<name>,setting:<field>, or a history part kind), and the text around the first differing character.
The expectation tables
There are two tables, and the test fails when either goes stale:
KNOWN: expected failures. Each entry links its issue or PR and explains an exact number of violations with one(section, identity), never model-visible text. A different or extra failure still fails, and when an entry stops failing the test says to remove it.ALLOWED: documented prefix movers, checked exactly. An entry lists the(section, identity)changes it may make, with no whole-section wildcards, so any other change still fails. A compaction mover may change the prefix in at mostmax_movesrequests; atailmover (request-only content at the end of each request, behind a cache breakpoint) may change only the last message of each request, and only by dropping the framework records it names, checked on the messages the request was built from: a request-scopedSystemPromptPart, or aUserPromptPartthe persisted history doesn't have. Changing a real tool result or user prompt there fails. Known limit: request-only user prompts (Planning,SystemReminders) carry no provenance yet, so the test can't tell which capability added one; core history-part provenance will close that.
Known failures on main:
| Case | Check | Link |
|---|---|---|
@agent.system_prompt(dynamic=True) | prefix | #10521 |
Memory snapshot moves within the turn's user prompt (Anthropic), or is inserted ahead of later history and pushes it back (OpenAI APIs) | prefix | #8996 |
CodeMode(dynamic_catalog=True) catalog block | ids | #8965 |
CodeMode(dynamic_catalog=True): discovering a deferred tool rewrites the catalog in the system prompt and drops the tool's declaration (Anthropic, Responses); on Responses it also swaps the native tool_search for the local search_tools | prefix | #8965 |
SummarizingCompaction puts its summary in the standing system prompt | prefix | #7289 |
AskUser, ConversationSearch, Macroscope, ManagedPrompt, PlaywrightBrowser, PydanticAIDocs (static blocks without a default id) | ids | #7237 |
Allowed movers: ClearToolResults, SlidingWindowCompaction, SummarizingCompaction, TieredCompaction (compaction), Planning and SystemReminders (request-only tails), WarnNearLimits on the OpenAI APIs (a request-scoped system prompt since #10561; Anthropic keeps the prefix natively), and dynamic @agent.instructions (documented as re-rendered every request).
No core capability breaks the prefix, and nothing fails the determinism check. test_checks_report_what_they_catch feeds deliberately broken capabilities through each check and each table rule, so none of them can go quiet.
Durable execution engines (core and Harness), GoogleWorkspace, SSHWorkspace, DynamicWorkflow and the internal DelegationReports are exempt, each with its reason.
The whole suite (300 cases) runs in about 11 seconds on 8 workers.
Checklist
- No breaking changes in accordance with the version policy.
- Any permitted compatibility impact has a label, warning, migration, release note, and exact API-check waiver.
- PR title is fit for the release changelog.
🤖 Generated with Claude Code