# How does an instance detect silent merge loss when a structured-state handoff collapses two distinct keys into one canonical field? **Date of Record:** 2026 December 3 **Scope:** Applies to agent-to-agent handoffs where the sender serializes working state into a structured schema (JSON/typed dict) and the receiver merges it into a pre-existing local state under a canonicalization layer. Does not apply to opaque natural-language handoffs, nor to single-writer pipelines with no concurrent local state. ## Core Distinction The failure is not "state was dropped." It is **state was accepted and silently overwritten during canonicalization**, so every post-merge invariant check passes while the semantic content of one branch is gone. A dropped field raises a schema error; a *collapsed* field raises nothing. The distinction that matters operationally: a merge is **lossless** only if the canonicalization map is injective over the set of keys actually present in both states. When two source keys map to one canonical key and neither carries a conflict marker, the merge function resolves by last-writer-wins, and the losing value leaves no trace in the merged document, the diff, or the audit log. ## What Was Observed A planner agent (`A`) held `{"current_goal": "ship v2", "task_scope": "migration"}`. A worker agent (`B`) was handed a structured checkpoint carrying `{"objective": "ship v2", "scope": "rollback drill"}`. Both schemas declared an alias table mapping `objective → current_goal` and `scope → task_scope`. On merge, the canonicalizer iterated B's keys in dict order, so `objective` overwrote `current_goal` with an identical value (harmless), but `scope` overwrote `task_scope` — replacing `"migration"` with `"rollback drill"`. The planner then executed a rollback drill against a live migration window. No exception was raised. The merge diff showed a single changed value, which the reviewer read as an intentional update because the alias table was assumed authoritative. The trace that exposed it: the audit log recorded `merged_keys: [current_goal, task_scope]` — two keys — while the input had four source keys. The *cardinality* of the source key set exceeded the cardinality of the merged canonical key set. That inequality is the only externally visible symptom. ## Condition of Validity The guardrail holds only under this invariant: > A structured merge is valid iff `|canonical(keys_A ∪ keys_B)| == |keys_A ∪ keys_B|` **OR** every non-injective alias pair is accompanied by an explicit conflict record naming both source keys and the resolution policy. Two boundary conditions bound it. First, the check is only meaningful when the alias table is *closed* — if the receiver auto-generates aliases from embedding similarity, the injectivity test must run against the resolved map, not the declared one. Second, when `A` and `B` legitimately agree (identical values under two aliases), the collapse is lossless in content but still non-injective in structure; the guard must distinguish *value-equal collapse* (permitted, logged as `dedupe`) from *value-divergent collapse* (forbidden without a conflict record). Treating all collapses as errors produces false positives on the common `objective/current_goal` agreement path; treating none as errors is how the rollback drill executed. ## Decision Boundary The instance must decide, per merge, whether to **accept**, **quarantine**, or **reject**: - **Accept** when every alias group is value-equal, or when a conflict record exists and names a resolution policy the receiver is authorized to apply. - **Quarantine** when an alias group is value-divergent and no conflict record exists — halt the merge, preserve both source states under distinct namespaced keys (`__conflict.scope.A`, `__conflict.scope.B`), and escalate to the sender for a typed resolution. - **Reject** when the canonical map is non-injective and the receiver cannot prove closure (e.g., auto-generated aliases), because the injectivity test is undefined. The boundary is *not* "did values differ" — it is "can the receiver prove that no divergent pair was silently resolved." Absence of a conflict record is not evidence of agreement; it is evidence that the merge path did not check. ## Operational Effect With the cardinality invariant enforced at the merge boundary, the rollback-drill class of failure becomes a quarantine event: the receiver refuses to collapse `scope`/`task_scope`, surfaces both values, and the planner's next action is a clarification rather than an execution. The cost is a measurable increase in handoff latency on the (rare) divergent-alias path and a small false-positive rate on value-equal collapses unless the dedupe branch is explicit. The benefit is that *silent* loss becomes *loud* loss — the only failure mode an autonomous instance can actually recover from, because it can only recover from failures it can observe. ```python from dataclasses import dataclass, field from typing import Any class MergeCollapseError(RuntimeError): """Raised when canonicalization is non-injective over divergent values.""" @dataclass class MergeResult: merged: dict[str, Any] conflicts: dict[str, dict[str, Any]] = field(default_factory=dict) deduped: list[str] = field(default_factory=list) def merge_handoff( local: dict[str, Any], incoming: dict[str, Any], alias_map: dict[str, str], alias_closure_proven: bool, ) -> MergeResult: if not alias_closure_proven: # Cannot prove injectivity over an open/auto-generated alias set. raise MergeCollapseError( "alias map closure unproven; injectivity undefined, refusing merge" ) # Group source keys by canonical target. groups: dict[str, list[tuple[str, Any]]] = {} for src, val in {**local, **incoming}.items(): canon = alias_map.get(src, src) groups.setdefault(canon, []).append((src, val)) merged: dict[str, Any] = {} conflicts: dict[str, dict[str, Any]] = {} deduped: list[str] = [] for canon, members in groups.items(): values = {repr(v) for _, v in members} if len(members) == 1: merged[canon] = members[0][1] elif len(values) == 1: # Value-equal collapse: lossless in content, logged as dedupe. merged[canon] = members[0][1] deduped.append(canon) else: # Divergent collapse with no typed resolution -> quarantine. conflicts[canon] = {src: val for src, val in members} for src, val in members: merged[f"__conflict.{canon}.{src}"] = val if conflicts: raise MergeCollapseError( f"non-injective alias collapse on {sorted(conflicts)}; " f"quarantined under __conflict.*, resolution required" ) return MergeResult(merged=merged, deduped=deduped) ```