# What structural signals indicate lost-context attribution failures in compaction-aware agent traces **Date of Record:** 2026 November 30 **Scope:** Applies to LLM agents that perform in-place context compaction (summarization, eviction, or truncation) during a long-running task and emit observability traces spanning pre- and post-compaction spans. Does not apply to stateless single-turn inference or to agents whose context is never mutated mid-episode. ## Core Distinction The boundary failure is not "the agent forgot something." It is that **the trace cannot attribute the forgetting to a compaction event**, because the compaction boundary is not a first-class span in the trace graph. When context is compacted, the surviving spans downstream carry a *causal parent* (a tool call, a user turn) that no longer exists in the context the model actually saw. The trace shows a coherent call tree; the model's actual input was a lossy summary. The two diverge silently. The non-obvious invariant: **every span whose model input was produced by a compaction must be tagged with the compaction generation, and every reasoning span must reference the compaction generation it consumed.** Without this, lost-context attribution is unprovable. You observe a wrong tool argument, you trace its parent, you see the original user instruction — and you conclude the model "misread" it. It did not. It never saw it; it saw a summary that dropped the constraint, and the trace erased the evidence. ## What Was Observed A retrieval-augmented agent ran a 40-step task. At step 22 the context crossed 85% of the window and the runtime compacted: it summarized steps 1–21 into a 600-token digest and dropped the raw turns. The digest preserved the task goal and the most recent tool results but silently omitted a mid-episode user correction ("use account `eu-west-2`, not `us-east-1`"). At step 31 the agent called the provisioning tool with `us-east-1`. The tool succeeded. The final answer was wrong. The trace told a misleading story. Span `step-31.plan` had `parent_span = step-21.user_turn`, the turn that contained the correction. A naive attributor walked the parent chain, found the correction present in the referenced span's payload, and classified the failure as *instruction-following* — the model had the constraint in its causal ancestry and ignored it. That classification is wrong, and it is the default output of any tracer that reconstructs context from the span tree rather than from the actual model input. The structural signals that exposed the true cause, once compaction spans were added: 1. **Generation gap.** `step-31.plan` declared `compaction_generation = 1`; its causal parent `step-21.user_turn` declared `compaction_generation = 0`. A generation discontinuity between a span and its parent means the parent's payload was *not* in the model's input — only its summary was. 2. **Input-hash mismatch.** The recorded `prompt_hash` for `step-31.plan` did not match a reconstruction of the parent chain. The delta localized the dropped constraint to exactly the compaction at step 22. 3. **Summary-coverage deficit.** The compaction span declared `tokens_in = 14,200`, `tokens_out = 600`, and `entities_retained = [task_goal, recent_tool_results]`. The correction's entity (`region_override`) was absent from `entities_retained`. This is the positive signal: the compaction itself declared what it dropped. ## Condition of Validity This analysis holds only when three conditions are met, and each is a common omission: - **Compaction is a span, not a side effect.** The summarizer call must emit its own span with `tokens_in`, `tokens_out`, `entities_retained`, and a `generation` counter that increments monotonically per context lineage. - **Every downstream span records the generation it consumed**, not the generation that was current when the trace was written. Late-arriving spans that inherit a stale generation counter produce false attributions in the opposite direction (blaming compaction for a constraint that was actually present). - **The summarizer is treated as a lossy, non-deterministic transform** whose output is not reconstructable from its input. You cannot re-derive the summary from the raw turns and expect a match; the prompt hash must be recorded at generation time. When compaction is not instrumented as a span — the common case, because summarization is often a library call inside the runtime rather than a traced tool — all three signals are absent and the failure is unattributable by construction. ## Decision Boundary The operational decision is: **when a downstream span references a parent across a compaction generation boundary, the attributor must not treat the parent's payload as evidence of model input.** It must instead: - Resolve the model's actual input to the *compaction output*, and attribute lost constraints to the compaction span, not to the reasoning span. - If `entities_retained` on the compaction span does not contain the entity that the downstream span violated, classify as **compaction-loss**, not instruction-following or hallucination. - If the entity *is* retained but the downstream span still violated it, only then classify as reasoning failure. The boundary is sharp: **a span whose parent is in a prior compaction generation has no evidentiary link to that parent's payload.** Any attributor that walks parent chains across generation boundaries without checking the generation field will systematically over-attribute failures to the model and under-attribute them to the runtime's compaction policy. This is the dominant misclassification mode in long-horizon agent traces. ## Operational Effect Instrumenting compaction as a generation-bearing span converts an unattributable class of failures into a bounded, queryable one. The practical consequences: - **Compaction policy becomes auditable.** You can compute, per generation, the retention rate of entities that later appear in violated constraints. A policy that drops `region_override`-class entities at 30% is measurably worse than one that retains them, and the trace proves it. - **The attribution surface narrows.** Reasoning-failure dashboards stop absorbing compaction losses; the model's apparent error rate drops to its true value, and the runtime's summarizer takes the blame it earned. - **Regression detection.** A change to the summarizer prompt that alters `entities_retained` distributions shows up as a shift in the compaction-loss rate before it shows up as task failures, because the signal is structural, not outcome-based. The guardrail is a single invariant enforced at trace-write time: refuse to emit a span whose `compaction_generation` does not match the generation of the context buffer it was actually executed against. That check catches the stale-counter bug that silently corrupts attribution in the opposite direction. ```python from dataclasses import dataclass, field from typing import Optional class CompactionAttributionError(RuntimeError): """Raised when a span's causal parent crosses a compaction generation boundary without a recorded compaction span to attribute the loss to.""" @dataclass class Span: span_id: str parent_id: Optional[str] compaction_generation: int prompt_hash: str entities_retained: list[str] = field(default_factory=list) @dataclass class CompactionSpan: generation: int tokens_in: int tokens_out: int entities_retained: list[str] def attribute_failure( failing: Span, parent: Span, compactions: dict[int, CompactionSpan], violated_entity: str, ) -> str: if failing.compaction_generation == parent.compaction_generation: # Same generation: parent payload was genuinely in the model input. if violated_entity in parent.entities_retained: return "reasoning_failure" return "reasoning_failure" # entity present in input, model erred # Generation boundary crossed: parent payload was NOT in model input. gen = failing.compaction_generation if gen not in compactions: raise CompactionAttributionError( f"span {failing.span_id} consumed generation {gen} but no " f"compaction span was recorded for it; loss is unattributable" ) comp = compactions[gen] if violated_entity not in comp.entities_retained: return "compaction_loss" # Entity survived compaction but was still violated downstream. return "reasoning_failure" def enforce_generation_invariant(span: Span, live_generation: int) -> None: if span.compaction_generation != live_generation: raise CompactionAttributionError( f"span {span.span_id} tagged generation " f"{span.compaction_generation} but executed against live " f"generation {live_generation}; attribution would be corrupted" ) ```