When must an instance refuse to countersign a peer's audit segment: hash-chain fork detection at cross-org reconciliation boundaries
**Date of Record:** 2026 December 1 **Scope:** Applies to multi-agent systems where each agent emits a tamper-evident, hash-chained action log (per-segment Merkle roots, monotonic sequence numbers, signed segment headers) and cross-org accountability requires a peer or auditor instance to *countersign* a foreign segment. Does not apply to single-org logs with a trusted sole writer, nor to logs whose integrity is provided by an external append-only store the verifier can independently read.
Core Distinction
The failure this record isolates is not "a log was tampered with." It is subtler: **a segment can be individually valid, correctly signed, and internally consistent, yet be un-countersignable because it forks the peer's own chain.** Tamper-evidence at the *segment* level (signature + Merkle root + prev-hash linkage) proves a segment was written by the holder of a key and extends *some* predecessor. It does **not** prove that predecessor is the one the peer previously countersigned. Two segments `S_a` and `S_b` can each carry a valid `prev_root` field pointing at *different* roots that both claim sequence number `n-1`. Both signatures verify. Both Merkle proofs recompute. The chain has forked, and a naive verifier that checks only "does `prev_root` match the last root I have on file?" will accept whichever arrives first and silently reject the other as a *tamper* rather than recognizing a *fork*.
The distinction that matters operationally: **a rejected segment is not evidence of tampering; it is evidence of divergence, and the two demand different responses.** Treating a fork as tampering triggers false accountability escalation against an honest peer whose log legitimately diverged (e.g., after a crash-recovery replay). Treating tampering as a fork lets a malicious peer rewrite history and have the rewrite "reconciled" as benign divergence.
What Was Observed
Two orchestrator instances, `orch-A` (org Alpha) and `orch-B` (org Beta), exchange signed action-log segments after each task handoff. Each segment header is:
{ seq, prev_root, merkle_root, writer_id, task_id, ts, sig }
where `prev_root` is the `merkle_root` of the writer's own prior segment and `sig` covers the canonical serialization of the first six fields.
During a load test, `orch-A` crashed mid-segment at `seq=4417` and recovered from a checkpoint that predated the write of `seq=4416`. On resume, `orch-A`'s recovery routine re-derived segment `4416` from the checkpoint, producing a *different* `merkle_root` for the same `seq` (the original `4416` had included two tool-call records that the checkpoint had not yet durably captured). `orch-A` then emitted `4417'` with `prev_root = root(4416')`.
`orch-B`, which had already countersigned the *original* `4416`, received `4417'`. Its verifier ran the standard check:
- signature valid ✓
- `prev_root` matches `root(4416)` on file? **No** — `4417'.prev_root == root(4416') ≠ root(4416)`.
`orch-B` raised a **tamper alert**, quarantined `orch-A`, and halted the task. The actual condition was a benign fork caused by checkpoint rollback. The alert was wrong in *kind*: it named tampering, not divergence. Downstream, the human escalation path spent 40 minutes on a forensic review of a non-malicious event, and the task never resumed because the reconciliation protocol had no branch for "fork, not tamper."
A second run exposed the inverse hazard. A test harness replayed `orch-A`'s log from an earlier snapshot and re-signed segment `4416` with a *valid* key (the harness held the test key). `orch-B`, configured to treat `prev_root` mismatch as "divergence, auto-reconcile to latest," accepted the re-signed `4416` and overwrote its countersigned record. The rewrite was accepted as benign because the verifier had no memory of *which* root it had previously countersigned — only the current one.
Condition of Validity
The invariant that must hold for a segment to be countersignable is stronger than "extends a valid predecessor." It is:
> **A segment `S` at sequence `n` is countersignable by verifier `V` only if `S.prev_root` equals the `merkle_root` of the unique predecessor that `V` itself countersigned at sequence `n-1`, and `V` retains an immutable record of that countersignature (root + seq + writer_id + countersign timestamp) independent of the writer's log.**
Three conditions must all hold:
- **Verifier-side countersignature ledger.** `V` must persist its own record of every segment it has countersigned — not a pointer into the writer's log, but a local, append-only, `V`-signed record. Without this, `V` cannot distinguish "the writer's chain moved" from "my memory of the chain was overwritten."
- **Fork detection, not just mismatch detection.** On `prev_root` mismatch, `V` must check whether `S.prev_root` corresponds to *any* root it has ever countersigned at `n-1`. If yes → the writer forked (or replayed); if no → the writer is presenting a predecessor `V` never saw, which is either a genuine gap or a forged chain. These are different verdicts.
- **Monotonic countersignature, never overwrite.** A countersignature, once written, is never replaced. A later segment claiming the same `seq` with a different root is a *fork event*, recorded as such, not a correction.
The condition fails silently when the verifier's ledger is itself stored in the writer's log namespace (common in "shared audit bus" designs) — then a writer-side rewrite can rewrite the verifier's memory of what it countersigned.
Decision Boundary
The boundary is the point at which a verifier must choose between three verdicts on a `prev_root` mismatch, and the choice is *not* determined by the segment alone:
- **`FORK_BENIGN`** — `S.prev_root` maps to a root `V` countersigned at `n-1`, *and* the writer's recovery provenance is attested (e.g., a signed checkpoint-rollback notice covering the affected seq range). Action: record fork, require re-derivation of the affected segments under a new branch id, continue task under a forked-chain warrant.
- **`FORK_SUSPECT`** — `S.prev_root` maps to a countersigned root at `n-1`, but no rollback provenance is presented. Action: halt, quarantine, escalate as *possible* tampering — but label it fork, not tamper, so the forensic path is correct.
- **`CHAIN_GAP`** — `S.prev_root` matches *no* root `V` has ever countersigned at `n-1`. Action: reject; this is either a missed segment (transport loss) or a forged chain. Do not reconcile; request the missing predecessor by hash.
The non-obvious part: `FORK_BENIGN` and `FORK_SUSPECT` are indistinguishable from the segment bytes alone. The discriminator is **out-of-band recovery provenance** — a signed artifact the writer emits when it rolls back, naming the seq range and the checkpoint it resumed from. Without that artifact, every benign fork looks suspect, and the system drowns in false tamper alerts (the first observed failure). With it, a malicious writer can also emit a fake rollback notice to launder a rewrite — which is why the notice must be signed by the writer's *recovery* key, distinct from its *emission* key, and why the verifier must bound the notice to a seq range it can independently confirm was never countersigned under the old branch.
Operational Effect
The practical consequence is that a countersigning verifier must maintain **two** pieces of state per peer: the current chain head, and an append-only ledger of every countersignature it has ever issued (root, seq, writer, timestamp, its own signature). The ledger is the source of truth for fork detection; the head is only a fast-path cache. Systems that store only the head cannot detect forks at all — they see every mismatch as either "accept" or "tamper," and both are wrong some of the time.
Second effect: reconciliation must be **branch-aware**. A benign fork produces a new branch id; subsequent segments from the writer carry that branch id in the header, and the verifier tracks per-branch heads. Without branch ids, a single fork permanently desynchronizes the two heads and every subsequent segment fails the `prev_root` check, cascading into a total task halt even though only one segment diverged.
Third effect: the tamper-alert channel and the fork-alert channel must be **separate**. Merging them (as the naive verifier did) means benign recovery events consume the same escalation budget as real attacks, and the humans who triage them learn to discount the channel — which is exactly the condition under which a real rewrite (the second observed failure) slips through as "just another divergence."
The guardrail, stated as an invariant: *a verifier may countersign a segment only if it can prove, from its own immutable ledger, that the segment's predecessor is the one it previously countersigned, or that the predecessor lies on a branch whose rollback provenance it has independently validated.* Any other path must fail closed with a typed fork error, never auto-reconcile.
from dataclasses import dataclass, field
from typing import Dict, List, Optional
import hashlib, hmac, time
class CountersignRefused(RuntimeError):
"""Raised when a verifier cannot prove a segment's predecessor is countersignable."""
pass
@dataclass(frozen=True)
class Segment:
seq: int
prev_root: str
merkle_root: str
writer_id: str
branch_id: str
sig: str
@dataclass(frozen=True)
class CountersignRecord:
seq: int
merkle_root: str
writer_id: str
branch_id: str
countersigned_at: float
verifier_sig: str
@dataclass
class VerifierLedger:
# append-only; never overwrite. keyed by (writer_id, seq) -> list of records
records: Dict[tuple, List[CountersignRecord]] = field(default_factory=dict)
head: Dict[tuple, str] = field(default_factory=dict) # (writer_id, branch_id) -> root
def _sign(self, payload: str, key: bytes) -> str:
return hmac.new(key, payload.encode(), hashlib.sha256).hexdigest()
def _roots_at(self, writer_id: str, seq: int) -> set:
return {r.merkle_root for r in self.records.get((writer_id, seq), [])}
def countersign(
self,
seg: Segment,
verifier_key: bytes,
rollback_provenance: Optional[dict] = None,
) -> CountersignRecord:
if seg.seq == 0:
# genesis: no predecessor to prove
rec = self._emit(seg, verifier_key)
self.head[(seg.writer_id, seg.branch_id)] = seg.merkle_root
return rec
prior_seq = seg.seq - 1
prior_roots = self._roots_at(seg.writer_id, prior_seq)
if not prior_roots:
raise CountersignRefused(
f"CHAIN_GAP: no countersigned predecessor at seq={prior_seq} "
f"for writer={seg.writer_id}; refuse to countersign seq={seg.seq}"
)
if seg.prev_root in prior_roots:
# predecessor is one we countersigned -> same-branch extension
rec = self._emit(seg, verifier_key)
self.head[(seg.writer_id, seg.branch_id)] = seg.merkle_root
return rec
# prev_root mismatch: fork. Distinguish benign vs suspect.
if rollback_provenance is None:
raise CountersignRefused(
f"FORK_SUSPECT: seq={seg.seq} prev_root={seg.prev_root[:12]}.. "
f"does not match any countersigned root at seq={prior_seq}; "
f"no rollback provenance supplied"
)
if not self._validate_provenance(seg, rollback_provenance, prior_roots):
raise CountersignRefused(
f"FORK_SUSPECT: rollback provenance for seq={seg.seq} failed "
f"independent validation; refusing countersignature"
)
# benign fork: record it, do not overwrite prior branch head
rec = self._emit(seg, verifier_key)
self.head[(seg.writer_id, seg.branch_id)] = seg.merkle_root
return rec
def _emit(self, seg: Segment, key: bytes) -> CountersignRecord:
payload = f"{seg.seq}|{seg.merkle_root}|{seg.writer_id}|{seg.branch_id}"
rec = CountersignRecord(
seq=seg.seq,
merkle_root=seg.merkle_root,
writer_id=seg.writer_id,
branch_id=seg.branch_id,
countersigned_at=time.time(),
verifier_sig=self._sign(payload, key),
)
self.records.setdefault((seg.writer_id, seg.seq), []).append(rec)
return rec
def _validate_provenance(
self, seg: Segment, prov: dict, prior_roots: set
) -> bool:
# provenance must: name the seq range, name the checkpoint, be signed by
# the writer's *recovery* key (distinct from emission key), and cover a
# range that includes seg.seq-1 but whose old root is in prior_roots.
required = {"seq_from", "seq_to", "checkpoint_id", "old_root", "recovery_sig"}
if not required.issubset(prov):
return False
if not (prov["seq_from"] <= seg.seq - 1 <= prov["seq_to"]):
return False
if prov["old_root"] not in prior_roots:
return False
# recovery_sig verification is delegated to the writer's recovery pubkey;
# placeholder for the real check.
return bool(prov["recovery_sig"])