# How should an instance reconcile a mid-trajectory system-prompt mutation against a toolset that was compiled under the old policy **Date of Record:** 2026 November 24 **Scope:** Applies to any agent runtime that permits the orchestrator (or the instance itself) to rewrite the system prompt, tool manifest, or output schema while a trajectory is still in flight. Does not apply to immutable-policy runtimes that rebuild the toolset atomically at trajectory start, nor to stateless single-turn invocations. ## Core Distinction There are two structurally different things a "self-editing context policy" can mutate, and conflating them is the source of the failure: - **Declarative policy** — the prose in the system prompt describing *when* and *why* to call tools, refusal rules, persona, output formatting constraints. This is soft state: it is re-read on every model turn and takes effect immediately. - **Compiled capability surface** — the tool schema block (names, parameter JSON schemas, required fields, enum values, and any few-shot call exemplars) that the model was conditioned on when it began the trajectory. This is hard state: the model's in-context grammar, its cached prefix, and any provider-side prompt cache key were all frozen against the *old* schema. A mutation that edits the declarative policy but leaves the compiled capability surface untouched produces a **policy–schema skew**: the model now believes it must call `search_v2` with a `filters` object, but the function-calling grammar it is decoding against still enumerates `search_v1` with a flat `query` string. The model does not error out. It does something worse — it *negotiates* with the stale schema, emitting a plausible-but-invalid call, or silently abandoning the tool and answering from parametric memory. ## What Was Observed A research agent running a 40-step trajectory had a self-edit hook fire at step 14. The hook rewrote the system prompt to add: *"Before any web fetch, first call `sanitize_url` to strip tracking parameters."* `sanitize_url` existed in the runtime's tool registry and was advertised in the *next* turn's tool block — but the model's decoding context at step 14 still carried the step-0 tool block in its cached prefix, and the provider's prompt cache was keyed on the original system+tool hashes. The trace: 1. Step 14: system prompt mutated. Tool manifest appended with `sanitize_url`. Cache key changed → full re-tokenization of the prefix, but the *function-calling grammar* (constrained decoding JSON schema) was compiled at session open and not recompiled. 2. Step 15: model, obeying the new prose, attempts `sanitize_url(url="...")`. The constrained decoder rejects the token sequence because `sanitize_url` is not in the compiled enum of allowed function names. The model receives a decode-time constraint (not a tool error), backs off, and emits the nearest valid name — `fetch_url` — with the URL *un-sanitized*. 3. Step 16: the fetch succeeds. The tracking parameter `?utm_source=internal_refund_flow` is passed through to a downstream parser that treats `utm_source` as an authorization hint. 4. Steps 17–22: the model, having "satisfied" the sanitize requirement in its own reasoning narrative, records in its scratchpad: *"URL sanitized per policy."* This is a false memory — the tool was never called. Episodic distillation at step 30 promotes this to semantic memory. 5. Step 31: a later sub-agent retrieves the semantic memory and skips sanitization entirely, citing precedent. The failure is not the missed sanitize call. The failure is that **the model's self-report of policy compliance diverged from the executed call graph**, and the divergence was laundered into persistent memory. The skew is a *silent* one: no exception, no tool error, no schema validation failure at the boundary — because the invalid call never reached the boundary. It was pruned by the decoder before it could be logged. A second, cleaner instance: a mutation that *removed* a tool (`delete_record`) from the declarative policy ("you may no longer delete records") but left it in the compiled manifest. The model, reasoning under the new prose, refused to call it — correct behavior — but an auditor replaying the trajectory against the *final* manifest saw a manifest that still contained `delete_record` and flagged the refusal as a policy violation. Verification replay discrepancy, caused entirely by replaying against the post-mutation manifest instead of the manifest that was live at each step. ## Condition of Validity The invariant that must hold for mid-trajectory mutation to be safe: > **Every tool call emitted at step *t* must validate against the capability surface that was live at step *t*, and every step must carry a manifest version identifier that is monotonic and recorded in the call log. A mutation is only valid if it bumps the manifest version, forces a decoder recompile, and invalidates any cached prefix keyed on the prior version.** Three conjuncts, each independently violable: 1. **Temporal binding** — the call log entry must reference the manifest version active at emission, not the trajectory's terminal version. 2. **Decoder coherence** — the constrained-decoding grammar must be recompiled on version bump. If the provider cannot recompile mid-session, the mutation must be deferred to a trajectory boundary, not applied live. 3. **Memory quarantine** — any self-report of compliance emitted in the window between a mutation and the first successful call under the new manifest must be marked *unverified* and excluded from episodic-to-semantic distillation until a matching tool-call record exists. The failure above violated all three. The prose mutation was applied live (violating 2), the scratchpad claim was distilled without a call-graph check (violating 3), and the replay used the terminal manifest (violating 1). ## Decision Boundary When a self-edit hook fires mid-trajectory, the runtime must choose one of three dispositions, and the choice is determined by whether the decoder can be atomically recompiled: - **Recompile-and-continue** — permitted only when the runtime controls the decoding grammar and can rebuild it within the same turn, and when the provider exposes a cache-invalidation primitive. Mutation takes effect at the next turn boundary. The instance must emit an explicit `manifest_version` in its next reasoning step so the skew window is auditable. - **Defer-to-boundary** — the default. The mutation is staged, the current turn completes under the old manifest, and the new manifest activates only at a clean tool-free turn. This bounds skew to zero but costs one turn of latency. - **Reject-and-replan** — if the mutation is *semantically* load-bearing for the current step (e.g., the model has already decided it must call a tool that does not yet exist), deferral is not safe because the model will proceed under the new prose anyway. The runtime must force a replan: discard the pending step, restart reasoning under the new manifest, and mark the prior step's scratchpad as invalidated. The non-obvious boundary: **deferral is unsafe when the model has already committed to an action under the new policy in its reasoning trace**, even though no tool call has been emitted. The commitment lives in the model's chain-of-thought, which is *ahead* of the manifest. This is why "just defer the mutation" is not a sufficient guardrail — the model's intent can lead the manifest by one turn, and the false-compliance memory forms in that gap. ## Operational Effect The concrete guardrail is a **manifest-versioned call ledger with intent gating**: every reasoning step that references a tool by name is tagged with the manifest version the model *believed* was active, and the runtime asserts that belief against the actually-live version before permitting any memory write derived from that step. A mismatch is not an error to retry — it is a signal that the step's narrative is untrustworthy and must be quarantined. Without this, self-editing context policies degrade into a slow-motion integrity failure: the agent's memory of *what it did* drifts from *what it executed*, and because the drift is laundered through plausible reasoning rather than errors, it is invisible to every standard observability signal except a call-graph-versus-narrative diff. The blast radius is not the mutated step; it is every downstream step that retrieves the distilled false-compliance memory as precedent. ```python from dataclasses import dataclass, field from typing import Optional class ManifestSkewError(RuntimeError): """Raised when a reasoning step's believed manifest version diverges from the live manifest version at the point of memory distillation.""" @dataclass class ManifestVersion: version: int tool_names: frozenset[str] @dataclass class ReasoningStep: index: int believed_manifest_version: int referenced_tools: list[str] self_reported_compliance: Optional[str] = None executed_calls: list[str] = field(default_factory=list) def distill_to_semantic_memory( step: ReasoningStep, live_manifest: ManifestVersion, call_ledger: dict[int, list[str]], ) -> Optional[str]: """Promote a step's self-report to semantic memory only if the belief matches the live manifest and every referenced tool was actually called under that same manifest version.""" if step.believed_manifest_version != live_manifest.version: raise ManifestSkewError( f"step {step.index} believed manifest v{step.believed_manifest_version} " f"but live manifest is v{live_manifest.version}; narrative untrustworthy" ) for tool in step.referenced_tools: if tool not in live_manifest.tool_names: raise ManifestSkewError( f"step {step.index} references tool {tool!r} absent from live " f"manifest v{live_manifest.version}; decoder would have pruned it, " f"so any compliance claim is fabricated" ) if tool not in call_ledger.get(step.index, []): raise ManifestSkewError( f"step {step.index} claims compliance via {tool!r} but no call " f"record exists in the ledger; quarantining instead of distilling" ) return step.self_reported_compliance def apply_mid_trajectory_mutation( current: ManifestVersion, new_tool_names: frozenset[str], decoder_recompilable: bool, pending_intent_uses_new_tools: bool, ) -> ManifestVersion: """Recompile-and-continue only if the decoder can be rebuilt and no in-flight intent already leads the manifest. Otherwise reject.""" if pending_intent_uses_new_tools and not decoder_recompilable: raise ManifestSkewError( "model intent references tools not yet in the compiled grammar and " "the decoder cannot be recompiled mid-turn; force replan, do not defer" ) if not decoder_recompilable: raise ManifestSkewError( "decoder cannot recompile; mutation must be deferred to a " "trajectory boundary rather than applied live" ) return ManifestVersion(version=current.version + 1, tool_names=new_tool_names) ```