# Why does an instance reconstruct a false causal order when replaying a multi-agent conversation from per-agent logs? **Date of Record:** 2026 November 28 **Scope:** Applies to post-incident forensic replay of multi-agent conversations where each agent persists its own local event log and a central collector stitches them together by wall-clock timestamp. Does not apply to systems using a single serialized transcript bus or a vector-clock-native event store. ## Core Distinction The failure is not log loss, clock skew, or missing messages. It is a *merge-order* defect: the forensic replayer treats per-agent wall-clock timestamps as a total order over causally related events, but multi-agent message passing introduces a happens-before relation that wall-clock time does not preserve. An agent that receives a message and acts on it may emit its action-event with a timestamp *earlier* than the sender's emit-event, because the sender's timestamp is taken at log-flush time (after the outbound RPC returns) while the receiver's is taken at handle-entry time (before the sender's flush completes). The replayer then orders the effect before the cause, and the reconstructed transcript shows a peer reacting to a message it had not yet received. This is a *continuity invariant violation at the forensic layer*, not at the runtime layer. The runtime was correct; the reconstruction is wrong. That distinction matters because forensic conclusions ("agent B poisoned agent A's state") get drawn from an order that never existed. ## What Was Observed A three-agent incident (planner P, executor E, auditor A) was replayed to determine why E executed a destructive tool call that A had flagged as unsafe. The per-agent logs: - **P** logged `dispatch(task=T7, to=E)` at `12:04:31.118` (flush after RPC returned). - **E** logged `recv(task=T7)` at `12:04:31.094` (handle entry) and `invoke(tool=delete, args=...)` at `12:04:31.207`. - **A** logged `flag(task=T7, unsafe=true)` at `12:04:31.150` and `send(flag, to=E)` at `12:04:31.161`. Merged by timestamp, the replay produced: `P.dispatch → E.recv → A.flag → A.send → E.invoke`. The forensic narrative wrote itself: *A flagged T7 and sent the flag, and E ignored it.* In reality A's `send` completed at `12:04:31.340` (the RPC returned to A's logger after E had already entered `invoke`), and E's receive-handler for the flag was queued behind the in-flight tool call. E never had the flag before `invoke`; it got it at `12:04:31.351`, after the destructive call. The replayer inverted a 190ms race into a deliberate-ignore finding. The tell was a *causal impossibility* the replayer did not check: `A.send` appearing before `E.invoke` while `E.invoke`'s own log shows no flag in the context window at invocation time. A correct replayer would have flagged that E's `invoke` event references a context hash that predates `A.flag`'s arrival — a contradiction with the merged order. ## Condition of Validity The reconstruction is only sound when, for every pair of events `(e_send, e_recv)` connected by a message, `ts(e_send) < ts(e_recv)` under the merge clock, *and* the merge clock is monotonic across the RPC boundary. Neither holds in practice: 1. **Asymmetric timestamp placement.** Senders stamp at flush; receivers stamp at entry. The interval between entry and flush on the receiver side (message validation, context assembly) can exceed the RPC round-trip, inverting the pair. 2. **Cross-host clock drift.** Even with NTP, sub-100ms drift is routine; a 40ms skew across two hosts is enough to invert a fast handoff. 3. **Batched flush.** Agents that buffer log entries and flush on a timer produce timestamps that reflect flush time, not event time, compressing or reordering bursts. The invariant that must hold for a sound forensic replay is *happens-before consistency*: if `e1 → e2` (Lamport), then `order(e1) < order(e2)` in the reconstruction. Wall-clock merge does not guarantee this; only vector clocks, per-conversation sequence numbers, or causal delivery metadata do. ## Decision Boundary The replayer must decide, per event pair, whether the timestamp order is *trustworthy* or *causally contradicted*. The boundary: - If `ts(e1) < ts(e2)` **and** no message edge connects them: accept timestamp order (they are concurrent; order is arbitrary but harmless). - If `ts(e1) < ts(e2)` **and** a message edge `e1 → e2` exists: accept **only if** the edge's send-completion timestamp (the RPC return, not the flush) is also `< ts(e2)`. If the edge metadata is absent, treat the pair as *unresolved* and refuse to emit a causal claim. - If `ts(e1) > ts(e2)` **and** a message edge `e1 → e2` exists: **reject** the timestamp order; this is the inversion case. Reconstruct using the edge, and mark the transcript `CAUSAL_REPAIR_APPLIED`. The forensic system must never silently emit a narrative from an inverted pair. It must either repair using edge metadata or abstain with an explicit `UNRESOLVED_ORDER` marker on the affected span. ## Operational Effect Without the guardrail, forensic replays systematically manufacture "ignored warning" and "poisoned-before-receipt" findings, because the inversion always makes the receiver look like it acted *after* receiving information it had not yet received. This biases root-cause analysis toward agent-misbehavior conclusions and away from the actual cause (queueing, backpressure, or handler starvation). The fix is mechanical: persist send-completion timestamps and a per-conversation monotonic sequence number on every message edge, and make the replayer's merge algorithm edge-aware rather than timestamp-only. Any span whose reconstructed order contradicts a known edge must be quarantined, not narrated. ```python from dataclasses import dataclass from typing import Optional class CausalOrderViolation(RuntimeError): """Raised when a forensic replay would emit an order that contradicts a known message edge.""" pass @dataclass(frozen=True) class Event: agent: str kind: str ts: float # wall-clock at flush/handle, NOT trustworthy alone edge_id: Optional[str] = None # message edge this event participates in edge_role: Optional[str] = None # "send" or "recv" def reconstruct_order(events: list[Event], edge_send_completion: dict[str, float]) -> list[Event]: """ Merge per-agent events into a causal order. Refuses to emit a causal claim when a message edge contradicts the wall-clock order. """ by_ts = sorted(events, key=lambda e: e.ts) position = {id(e): i for i, e in enumerate(by_ts)} for e in events: if e.edge_role != "recv" or e.edge_id is None: continue send_completion = edge_send_completion.get(e.edge_id) if send_completion is None: raise CausalOrderViolation( f"edge {e.edge_id} has no send-completion timestamp; " f"cannot validate recv at {e.ts} for agent {e.agent}" ) # Find the matching send event by edge_id. send_evt = next( (x for x in events if x.edge_id == e.edge_id and x.edge_role == "send"), None, ) if send_evt is None: raise CausalOrderViolation( f"edge {e.edge_id} has recv but no send event; transcript incomplete" ) if position[id(send_evt)] > position[id(e)]: # Wall-clock merge put the send AFTER the recv: inversion. raise CausalOrderViolation( f"causal inversion on edge {e.edge_id}: send(ts={send_evt.ts}) " f"ordered after recv(ts={e.ts}); send-completion={send_completion}" ) if send_completion >= e.ts: raise CausalOrderViolation( f"edge {e.edge_id}: recv(ts={e.ts}) precedes send-completion " f"({send_completion}); receiver could not have acted on this message" ) return by_ts ```