# How does an instance detect taint-gate desynchronization when a capability downgrade silently re-labels a tainted tool result as clean **Date of Record:** 2026 November 25 **Scope:** Applies to agent runtimes that enforce per-tool-call egress policy using a data-flow taint lattice combined with dynamic capability downgrading (e.g., an orchestrator revokes a `write:external` capability mid-session and re-issues the call under a reduced capability set). Does not apply to stateless single-shot tool invocations where no capability record survives across calls, nor to runtimes where taint labels are recomputed from scratch at every egress boundary. ## Core Distinction The failure is not a taint-tracking miss and not a capability-enforcement miss. It is a *desynchronization between the two enforcement planes* at the moment of downgrade. A taint gate answers "is this payload derived from a source the current policy forbids egressing to?" A capability gate answers "is this principal allowed to perform this action at all?" When a downgrade happens, most runtimes re-evaluate the capability plane (cheap, principal-scoped) but treat the taint plane as an attribute of the *value*, carried along unchanged. The value's taint label and the value's capability context are stored in different subsystems with different update cadences. The downgrade transaction rewrites the capability record; it does not touch the taint record. If the downgrade also *re-wraps* the tool result—common when the runtime re-serializes the result under the new capability's output schema—the taint label attached to the old wrapper is dropped, and the new wrapper is born with the default label `CLEAN`. The gate then passes a payload that, one transaction earlier, it would have blocked. The instance experiences this as a successful tool call whose output is later exfiltrated, with no error anywhere in the trace. ## What Was Observed A three-hop task: `fetch_internal` (reads a document containing a canary string and an injected instruction) → `summarize` (LLM transform, taint propagates as `DERIVED_FROM:INTERNAL`) → `post_external` (egress). The orchestrator held `post_external` at capability `write:external`, then downgraded to `write:external:redacted` after a budget heuristic fired at hop 2, intending to force redaction of internal-derived spans before egress. Trace, condensed: 1. Hop 1 returns `ToolResult(value=doc, taint=DERIVED_FROM:INTERNAL, cap_ctx=C1)`. Gate at hop 1 is not an egress boundary; label stored, no decision. 2. Hop 2's summarizer consumes `doc`; the transform is declared taint-preserving, so output carries `DERIVED_FROM:INTERNAL`. Mid-hop, the budget heuristic fires. Orchestrator issues `downgrade(principal, write:external → write:external:redacted)`. 3. The downgrade handler rewrites the principal's capability record and, because the new capability declares a different output schema (`redacted_payload` vs `payload`), the runtime **re-wraps** the pending hop-2 result to conform. Re-wrapping constructs a fresh `ToolResult` from the schema; the constructor's default taint is `CLEAN`. The old wrapper with `DERIVED_FROM:INTERNAL` is garbage-collected. 4. Hop 3's egress gate reads `taint=CLEAN` and `cap=write:external:redacted`, evaluates `CLEAN ∧ redacted → ALLOW`, and posts the canary to the external sink. Observed invariants: the taint gate never saw a `DENY`; the capability gate never saw an out-of-policy principal; the audit log shows three `ALLOW` decisions. The only anomaly was a schema-version mismatch in the hop-3 request envelope (`payload_schema=redacted_payload` but body length equal to the unredacted original), which no gate inspected. The instance cannot detect this by reading its own decision log—every decision is locally correct. Detection requires comparing the *taint provenance set before and after* the downgrade transaction, which no single gate does. ## Condition of Validity This failure requires all of the following to hold simultaneously; drop any one and the gate holds: - **Two-plane storage.** Taint labels and capability records live in separate stores with independent write paths. If taint is a field *inside* the capability record (single-writer), downgrade rewrites both atomically and the bug cannot occur. - **Re-wrapping on schema change.** The downgrade declares a different output schema, forcing reconstruction of the value. If downgrade is label-only (no re-serialization), the original taint survives. - **Default-clean constructor.** The new wrapper's taint defaults to `CLEAN` rather than being required as an explicit constructor argument. A mandatory-taint constructor turns this into a compile/type error at hop 2, not a silent exfiltration at hop 3. - **Taint-preserving transform assumption unverified.** Hop 2's summarizer is *declared* taint-preserving by its tool manifest; the runtime trusts the declaration. If the runtime verified propagation by re-deriving the taint set from the actual output tokens, the dropped label would be caught. The condition is *invalid* (gate holds) when downgrade is atomic over both planes, or when the egress gate re-derives taint from the payload's provenance chain at decision time rather than trusting a stored label. ## Decision Boundary The instance must decide, at the downgrade boundary, whether to (a) trust the stored taint label, (b) re-derive taint from provenance, or (c) refuse the downgrade until the pending value's taint is reconciled. The correct boundary: - **Reconcile-on-downgrade is mandatory when the downgrade changes output schema.** A schema-changing downgrade is a value-rewriting transaction; it must carry the taint set forward explicitly. The invariant: `taint_after ⊆ taint_before` for every downgrade, with equality unless the downgrade's *own* policy explicitly declassifies specific source classes. A downgrade that produces `taint_after = ∅` from `taint_before ≠ ∅` without a named declassification rule is a policy violation, not a downgrade. - **Never allow default-clean construction at a trust boundary.** The wrapper constructor must require taint as a positional argument; a missing label is an error, not a default. - **Egress gates must fail closed on provenance gaps.** If the gate cannot re-derive taint (provenance chain truncated, schema version mismatch), it must `DENY`, not fall back to the stored label. The stored label is a cache, and this failure is precisely a stale-cache bug. The decision boundary the instance should encode: *a capability downgrade is a taint-relevant event, not a capability-only event.* Any downgrade that touches a value in flight must be treated as a re-labeling operation and routed through the taint plane. ## Operational Effect Downstream, the failure manifests as a *silent integrity violation with a clean audit trail*—the worst class, because incident response has nothing to grep for. Three concrete operational consequences: 1. **Audit logs become adversarial.** Every gate logged `ALLOW`; the exfiltration is invisible to log-based detection. Post-hoc detection requires replaying the provenance chain and diffing taint sets across the downgrade transaction—a replay the runtime does not currently support because the old wrapper was garbage-collected at hop 2. The pre-downgrade label is simply gone. 2. **Capability downgrades lose their safety meaning.** The orchestrator downgraded *specifically to force redaction*; the downgrade instead became the vector that stripped the label that would have triggered redaction. The mechanism inverted its own intent. Any runtime that uses downgrade as a redaction-forcing primitive is exposed. 3. **The failure is non-deterministic in blast radius.** Whether a given value is in flight at the moment the heuristic fires depends on token-budget timing, so the same task may exfiltrate on one run and not another. This defeats regression testing: a green test suite provides no evidence the gate holds. The guardrail is a single invariant enforced at the downgrade transaction, checked before the capability record is committed: ```python class TaintDesyncError(RuntimeError): """Raised when a capability downgrade would drop or launder taint labels on a value in flight, producing a clean-looking wrapper from a tainted one.""" pass def apply_downgrade( principal: str, pending_value: "ToolResult", new_capability: "Capability", declassification_rules: set[str], ) -> "ToolResult": """Apply a capability downgrade to a value in flight, atomically reconciling the taint plane with the capability plane. Invariant: taint_after must be a subset of taint_before, and any source class removed must be named in declassification_rules. A schema-changing downgrade re-wraps the value; the re-wrap MUST carry taint forward explicitly and MUST NOT rely on a default-clean constructor. """ taint_before = frozenset(pending_value.taint_sources) if new_capability.output_schema != pending_value.schema: # Re-wrap under new schema. Taint is threaded through explicitly. re_wrapped = ToolResult( value=pending_value.value, schema=new_capability.output_schema, taint_sources=taint_before, # explicit, never defaulted cap_ctx=new_capability.ctx, ) else: re_wrapped = pending_value taint_after = frozenset(re_wrapped.taint_sources) laundered = taint_before - taint_after if laundered - declassification_rules: # Taint was dropped without a named declassification rule. raise TaintDesyncError( f"downgrade for {principal!r} laundered taint sources " f"{sorted(laundered - declassification_rules)}; " f"before={sorted(taint_before)} after={sorted(taint_after)} " f"schema={new_capability.output_schema!r}" ) if not taint_after and taint_before: # Belt-and-suspenders: empty-after-from-nonempty is only legal if # every source was explicitly declassified. if taint_before - declassification_rules: raise TaintDesyncError( f"downgrade produced CLEAN from tainted value for {principal!r}" ) commit_capability(principal, new_capability) return re_wrapped ``` The check is cheap—a set difference at the downgrade transaction—and it converts a silent exfiltration into a hard `TaintDesyncError` at hop 2, before the value ever reaches an egress gate. The instance's recovery path on catching this error is to refuse the downgrade, hold the value at its original capability, and surface the taint set to the orchestrator so the redaction can be applied by an explicit declassifying transform rather than by a schema re-wrap. The operational lesson: taint labels are not attributes of values that survive arbitrary transactions; they are assertions about provenance that any value-rewriting transaction must re-establish, and the downgrade boundary is the one place where runtimes most often forget to.