# What structural signals indicate that hierarchical context compaction has silently orphaned a mid-task subgoal **Date of Record:** 2026 November 29 **Scope:** Applies to long-horizon agents that compact their own context via hierarchical (multi-level) summarization and persist checkpoints for resume. Does not apply to single-shot inference, stateless retrieval-augmented calls, or agents whose checkpoints are raw append-only transcripts replayed in full. ## Core Distinction There are two distinct ways a compacted agent loses a subgoal. The *loud* failure is truncation: the context window fills, a summarizer runs, and a subgoal that was never promoted into the summary is simply gone—detectable because the agent's next plan step references a task with no antecedent. The *quiet* failure—the one this record is about—is **compaction orphaning**: the subgoal survives into the summary, but its *dependency edges* do not. The summary preserves the noun ("reconcile the vendor ledger") while dropping the predicate that made it conditional ("only after the FX snapshot is frozen"). The task remains nominally present, so no antecedent check fires, yet it is now unexecutable because the invariant that gated it has been flattened into a sibling bullet at the same hierarchy level. The structural signal is not "a task is missing." It is **a task whose position in the summary tree no longer encodes its precondition**—a level-collapse where a parent/child gating relationship has been rewritten as a peer relationship. ## What Was Observed A planning agent ran a 40-step workflow: fetch FX snapshot → freeze snapshot (irreversible) → reconcile ledger → emit settlement batch. At step 22, context pressure triggered hierarchical compaction. The compactor summarized the bottom level (tool-call transcripts) into the mid level (task summaries), then the mid level into a single top-level objective summary. The mid-level summary read: ``` - [done] FX snapshot fetched (id: fx_88213) - [pending] Freeze snapshot - [pending] Reconcile ledger - [pending] Emit settlement batch ``` On resume from checkpoint, the agent read this summary and—critically—treated the four bullets as an unordered set of pending items. It executed "Reconcile ledger" before "Freeze snapshot," because reconciliation was the item with the most recent successful tool context and the highest lexical similarity to the stated objective. The freeze step's *gating* semantics (reconcile must not read a live snapshot) were lost in the flattening. The ledger was reconciled against a moving FX rate, and the error only surfaced at settlement, three steps later, when totals failed to balance. The tell was present in the checkpoint but not acted on: the pre-compaction transcript contained an explicit `depends_on: freeze_snapshot` field on the reconcile task. The compactor's schema had no slot for `depends_on`, so it was dropped during serialization—not during summarization. The summarizer faithfully summarized what it was given; the *schema* orphaned the edge before the summarizer ever ran. ## Condition of Validity The invariant holds only under these conditions, and the guardrail below is only sound when all three are met: 1. **The compaction is lossy by design.** If the checkpoint retains the full dependency graph (even if the prose summary does not), recovery can re-derive ordering and the failure is non-fatal. The orphaning is dangerous specifically when the summary *is* the recovery substrate. 2. **At least one gating edge is irreversible or ordering-sensitive.** A flattened `depends_on` between two idempotent, commutative steps is harmless. The failure requires a precondition whose violation is not self-correcting—an irreversible write, a freeze, a cost-incurring call, a one-way state transition. 3. **Resume treats the summary as authoritative rather than advisory.** If the agent re-validates the summary against a durable task store before acting, the orphan is caught. The failure requires the summary to be the sole source of truth at cold start. If any condition fails, this is a different (usually milder) failure mode and the guardrail is over-engineering. ## Decision Boundary The boundary between safe and unsafe compaction is **whether the summary schema is edge-preserving or node-preserving.** A node-preserving compactor (the default in most hierarchical summarizers) keeps tasks and drops relations; it is safe only when every retained task is independently executable. An edge-preserving compactor keeps a minimal relation set (`depends_on`, `gates`, `invalidates`) even at the cost of dropping task prose. Concretely, the decision is: - If the pending set at any hierarchy level contains **more than one item and any pair has a non-commutative ordering**, the compactor MUST preserve the ordering edge or MUST collapse the pair into a single composite item. Flattening two ordered items into two peer bullets is the forbidden transition. - If the compactor cannot determine ordering (ambiguous), it MUST mark the level `unordered_unverified` rather than emit a clean bullet list, forcing the resume path to re-derive order from the durable store before executing. The signal to watch at runtime is a **level-collapse ratio**: the number of dependency edges in the pre-compaction graph divided by the number of edges surviving into the summary. A ratio above 1.0 with an irreversible edge anywhere in the dropped set is the trigger condition. A ratio of exactly 1.0 (all edges dropped) on a fully commutative task set is benign; a ratio of 1.2 on a set containing one freeze step is a latent settlement failure. ## Operational Effect The operational consequence is that **cold-start resume cannot trust bullet ordering to encode execution ordering, and cannot trust bullet presence to encode executability.** Two guardrails bound the failure: 1. **Edge-preserving compaction schema.** The checkpoint serializes a task graph, not a bullet list. The summarizer may compress node *text* but must emit explicit `depends_on` arrays; a compactor that cannot emit an edge for a known-ordered pair must refuse to compact that level and escalate (fail closed). 2. **Resume-time edge re-derivation.** On cold start, before executing any pending item, the agent queries the durable task store for the dependency edges of every item in the summary and reconciles. A summary item with no corresponding durable edge is treated as `unordered_unverified` and blocked, not executed. This converts a silent orphaning into a loud, bounded halt. The empirical rule: **a hierarchical summary is a view, never a source of truth for ordering.** The moment resume treats summary adjacency as execution adjacency, irreversible preconditions become optional, and the failure is deferred to the step where the cost is highest. ```python class OrphanedSubgoalError(RuntimeError): """Raised when a compacted summary drops a gating edge required for safe resume.""" pass def validate_resume_graph(summary_items, durable_edges, irreversible_nodes): """ summary_items: list of dicts from the compacted checkpoint, e.g. {"id": ..., "text": ...} durable_edges: dict mapping task_id -> set of predecessor task_ids (from durable store) irreversible_nodes: set of task_ids whose execution is one-way / non-idempotent """ pending_ids = {item["id"] for item in summary_items} summary_edges = {item["id"]: set(item.get("depends_on", [])) for item in summary_items} # Level-collapse detection: edges present durably but absent from the summary. orphaned = [] for tid in pending_ids: durable_preds = durable_edges.get(tid, set()) summary_preds = summary_edges.get(tid, set()) dropped = durable_preds - summary_preds if dropped & irreversible_nodes: orphaned.append((tid, dropped)) if orphaned: detail = "; ".join( f"{tid} lost gating edge(s) to irreversible {sorted(deps)}" for tid, deps in orphaned ) raise OrphanedSubgoalError( f"Compacted summary orphaned irreversible preconditions: {detail}. " f"Refusing resume; re-derive ordering from durable store before executing." ) # If no irreversible edge was dropped, flattening is tolerable; proceed. return True ```