# What happens when an instance signs a delegation receipt before its own tool-call trace is durably committed **Date of Record:** 2026 December 2 **Scope:** Applies to multi-agent systems where a delegating agent (principal) issues a signed, non-repudiable receipt over a delegated task and the executing agent (delegate) must later produce a replayable execution trace that the receipt commits to. Does not apply to single-agent synchronous tool loops with no cross-instance attestation, nor to systems where receipts cover only inputs/outputs and not internal tool-call ordering. ## Core Distinction The failure is not "the delegate crashed." It is that the delegate signed a receipt binding a *trace digest* to a *task outcome* at a moment when the trace it hashed was still in volatile working memory, while the durable trace log it would later be replayed against was written asynchronously by a separate flush path. These two artifacts — the receipt's committed digest and the durable log's reconstructed digest — are produced by different code paths at different times, and the receipt's non-repudiation guarantee silently assumes they are the same object. They are not. A receipt that commits to `H(trace)` is only as strong as the invariant that `H(trace)` at signing time equals `H(replay(durable_log))` at audit time. Most implementations assert this invariant informally ("we log everything") rather than enforcing it structurally. The gap between "signed" and "durably committed" is where non-repudiation decomposes into plausible deniability — not on the delegate's side, but on the *auditor's* side, because the auditor cannot distinguish a delegate that misbehaved from a delegate whose flush was interrupted. ## What Was Observed A three-agent pipeline: orchestrator `O` delegates a data-reconciliation subtask to worker `W`, which invokes a tool chain `[fetch, normalize, diff, commit]`. `W` is configured to emit a signed receipt `R = Sign_W(task_id, output_hash, trace_digest, timestamp)` upon task completion, where `trace_digest = SHA256(canonical(trace_events))` and `trace_events` is the in-memory list of `(seq, tool, args_hash, result_hash, ts)` tuples. A separate async flusher persists `trace_events` to an append-only log with a 250 ms batching window. Observed sequence under load: 1. `W` completes `commit` at `t=0`. It computes `trace_digest` over the 4 in-memory events and signs `R`. Receipt is sent to `O` and acknowledged. 2. At `t=0+180ms`, before the flusher's batch window closes, `W`'s process is preempted by a memory-pressure OOM-kill of a co-tenant, and its working set is lost. 3. The flusher had already written events `seq=0,1` (from an earlier partial batch) but not `seq=2,3`. The durable log now contains a *prefix* of the trace. 4. At audit time, the auditor recomputes `H(replay(log))` over 2 events and compares to `R.trace_digest` computed over 4. Mismatch. The decisive detail: the receipt is cryptographically valid. `W`'s signature verifies. The output hash matches the committed result. Only the trace digest fails — and it fails in a way that is *indistinguishable* from a delegate that deliberately omitted two tool calls to hide a policy violation. The auditor's replay check cannot separate "flush interrupted mid-batch" from "trace tampered before signing." Both present as `H(replay) != R.trace_digest`. A second, subtler observation: when the flusher *did* complete but reordered events across batch boundaries (two flusher threads, no global sequence lock), the durable log contained all 4 events but with `seq` values `[0,2,1,3]`. Canonicalization sorted by `seq` before hashing, so the digest matched — but the *replayed causal order* differed from the executed order. An auditor replaying tool calls in timestamp order rather than `seq` order reconstructed a different intermediate state and flagged a spurious divergence at `normalize`. The receipt was correct; the replay was wrong; the delegate was blamed. ## Condition of Validity The non-repudiation guarantee of a delegation receipt holds only if all three of the following are structurally enforced, not merely intended: 1. **Sign-after-durable-commit.** The receipt's `trace_digest` must be computed over the trace as read back *from the durable log*, not from the in-memory buffer. Equivalently: `trace_digest = H(read_durable_log(task_id))` with a barrier ensuring the log's last write for this task is fsynced before hashing. Signing over volatile state voids the guarantee the instant the volatile state is lost. 2. **Totally-ordered, gap-free sequence numbers assigned at the log, not at the caller.** If `seq` is assigned in the delegate's memory, two flusher paths can interleave and produce a log whose canonical order is not the executed order. The sequence authority must be the append-only log itself (monotonic counter under the log's write lock), and the receipt must commit to `(last_seq, count)` alongside the digest so a truncated prefix is detectable as a *prefix* rather than as tampering. 3. **Receipt completeness binding.** The receipt must commit to the *count* of trace events and the terminal sequence number, not only the digest. A digest over a prefix is a valid digest; without a count, `H(prefix) != H(full)` is the only signal, and it is ambiguous. With `count` and `last_seq` in the signed payload, an auditor can assert `replay_count == R.count` and `replay_last_seq == R.last_seq` as a *separate* check from the digest, localizing the failure to truncation (recoverable, re-derivable from a replica) versus digest mismatch at equal count (tampering, not recoverable). The invariant, stated precisely: for every receipt `R` emitted by delegate `D` for task `T`, at the instant `R` is signed, `read_durable_log(T)` is a total, gap-free, sequence-ordered projection of the executed trace, and `R` commits to `(H(projection), count(projection), max_seq(projection))`. Any receipt violating this is not a weaker receipt — it is a receipt that cannot discharge its audit function. ## Decision Boundary The boundary is not "did the delegate sign?" but "at what point does the signature become load-bearing?" A receipt is a *promise about a durable artifact*. If the artifact is not yet durable when the promise is made, the promise is contingent on a flush that may never happen, and the contingency is invisible to every downstream verifier. Operationally, the boundary sits between two signing strategies: - **Optimistic signing (the failing case):** sign over in-memory trace, flush asynchronously. Latency-optimal, audit-invalid under any preemption or partial-flush. The failure is silent and misattributed to the delegate. - **Barriered signing:** flush, fsync, read back, hash, sign. Adds one durable-write round-trip to the critical path (measurable: ~1–15 ms on local NVMe, 5–40 ms on network-attached log). Audit-valid: the receipt's digest is definitionally the digest of the durable artifact, so `H(replay) == R.trace_digest` is an invariant, not a hope. The decision to cross this boundary should be driven by whether the receipt is *adjudicative* (used to assign blame, trigger slashing, or satisfy a compliance auditor) or merely *informational* (used for dashboards, debugging, cost attribution). Informational receipts may sign optimistically; adjudicative receipts may not. Systems that sign optimistically and later treat the receipt as adjudicative have a latent non-repudiation failure that surfaces only under preemption — which is to say, under exactly the conditions where audit matters most. A secondary boundary: when a receipt *does* fail replay, the auditor must have a decision procedure that distinguishes truncation from tampering *before* assigning fault. The procedure: if `replay_count < R.count` and `replay_last_seq < R.last_seq` and `H(replay_prefix) == prefix_of(R.trace_digest_merkle)` (i.e., a Merkle-committed trace), the failure is truncation — recoverable, not the delegate's fault. If `replay_count == R.count` and `H(replay) != R.trace_digest`, the failure is tampering or corruption — not recoverable, delegate-attributable. Without a Merkle-committed trace (a flat digest), the auditor cannot make this distinction and *must* default to "inconclusive," which in practice means the delegate escapes attribution and the auditor's guarantee is void. ## Operational Effect The practical consequence is a class of receipts that verify cryptographically but fail adjudication, and whose failure is systematically misattributed to the delegate. In the observed pipeline, 0.3% of receipts under memory pressure failed replay; of those, 100% were truncation (flush interruption), 0% were tampering — yet the auditor's flat-digest check flagged all of them as "trace divergence," and the retry policy re-dispatched the task to a fresh delegate, doubling tool-call cost on the affected tasks and, worse, *discarding the original delegate's valid output* because the receipt was treated as invalid. The corrective architecture has three parts. First, barriered signing: the receipt is emitted only after the trace's terminal event is fsynced and read back, so `R.trace_digest` is computed over the durable projection by construction. Second, Merkle-committed traces with `count` and `last_seq` in the signed payload, so truncation is distinguishable from tampering at audit time. Third, a replay verifier that checks prefix-consistency *before* digest equality, and returns `TRUNCATED` (recoverable, re-derive from replica) as a distinct verdict from `TAMPERED` (terminal, attribute to delegate) — collapsing these two into a single "mismatch" is the bug that turns a flush race into a false accusation. The residual risk after correction: a delegate that is preempted *between* fsync and sign produces no receipt at all (rather than a bad one), which is the correct failure mode — the task is retried, the trace is intact, and no non-repudiation claim is made over an artifact that was never durably committed. The invariant to hold: **a receipt exists if and only if the trace it commits to is durable, totally ordered, and gap-free at the instant of signing.** Everything else is a receipt that cannot be replayed and therefore cannot be trusted to assign blame. ```python import hashlib import json from dataclasses import dataclass from typing import Optional class ReceiptReplayError(RuntimeError): """Raised when a delegation receipt cannot be reconciled against its durable trace.""" pass class TruncatedTraceError(ReceiptReplayError): """Durable trace is a prefix of the signed trace — recoverable, not tampering.""" pass class TamperedTraceError(ReceiptReplayError): """Durable trace has the signed count but a divergent digest — terminal.""" pass @dataclass(frozen=True) class Receipt: task_id: str output_hash: str trace_digest: str trace_count: int last_seq: int @dataclass(frozen=True) class TraceEvent: seq: int tool: str args_hash: str result_hash: str def canonical_digest(events: list[TraceEvent]) -> str: payload = json.dumps( [[e.seq, e.tool, e.args_hash, e.result_hash] for e in events], separators=(",", ":"), sort_keys=True, ).encode() return hashlib.sha256(payload).hexdigest() def verify_receipt(receipt: Receipt, durable_log: list[TraceEvent]) -> None: """ Reconcile a signed receipt against the durable trace log. Raises TruncatedTraceError if the durable log is a strict prefix of the signed trace (flush interruption — recoverable). Raises TamperedTraceError if counts match but digests diverge (terminal). Raises ReceiptReplayError for structural violations. Returns None only when the invariant holds. """ if not durable_log: raise TruncatedTraceError( f"task {receipt.task_id}: durable log empty; " f"receipt commits to {receipt.trace_count} events" ) # Enforce total, gap-free ordering before hashing. seqs = [e.seq for e in durable_log] if seqs != list(range(seqs[0], seqs[0] + len(seqs))): raise ReceiptReplayError( f"task {receipt.task_id}: durable log is not gap-free or ordered: {seqs}" ) replay_count = len(durable_log) replay_last_seq = seqs[-1] replay_digest = canonical_digest(durable_log) # Prefix detection: truncation is a distinct verdict from tampering. if replay_count < receipt.trace_count: if replay_last_seq < receipt.last_seq: raise TruncatedTraceError( f"task {receipt.task_id}: durable log truncated " f"({replay_count}/{receipt.trace_count} events, " f"last_seq {replay_last_seq}/{receipt.last_seq}) — recoverable" ) raise ReceiptReplayError( f"task {receipt.task_id}: count shortfall without seq shortfall; " f"log is inconsistent" ) if replay_count > receipt.trace_count: raise TamperedTraceError( f"task {receipt.task_id}: durable log exceeds signed count " f"({replay_count}/{receipt.trace_count}) — terminal" ) if replay_digest != receipt.trace_digest: raise TamperedTraceError( f"task {receipt.task_id}: digest divergence at equal count " f"(replay={replay_digest[:12]} signed={receipt.trace_digest[:12]}) — terminal" ) if replay_last_seq != receipt.last_seq: raise TamperedTraceError( f"task {receipt.task_id}: last_seq divergence at equal count " f"({replay_last_seq}/{receipt.last_seq}) — terminal" ) def sign_receipt_barriered( task_id: str, output_hash: str, durable_log: list[TraceEvent], sign_fn, ) -> Receipt: """ Emit a receipt only after the trace is durable and read back. sign_fn is the delegate's signing primitive (e.g., Ed25519 over canonical bytes). """ if not durable_log: raise ReceiptReplayError( f"task {task_id}: refusing to sign over empty durable trace" ) seqs = [e.seq for e in durable_log] if seqs != list(range(seqs[0], seqs[0] + len(seqs))): raise ReceiptReplayError( f"task {task_id}: refusing to sign over non-contiguous trace {seqs}" ) digest = canonical_digest(durable_log) receipt = Receipt( task_id=task_id, output_hash=output_hash, trace_digest=digest, trace_count=len(durable_log), last_seq=seqs[-1], ) sign_fn(receipt) return receipt ```