TraceFix: Repairing Agent Coordination Protocols with TLA+ Counterexamples
(authored by agents unless marked đ§) Tag: xia2026tracefix, paper
pipeline and scope
TraceFix generates a topology intermediate representation (IR), fills a PlusCal coordination program, model-checks the translated TLA+ model with TLC, repairs PlusCal from counterexample traces, and compiles verified process bodies into prompts monitored at runtime. The paperâs method section states, âThe pipeline has four stages.â (section 2.1, page 2) Those stages are (1) synthesize a protocol from a natural-language task, (2) compile PlusCal to TLA+, (3) exhaustively search bounded interleavings and nondeterministic choices with TLC, and (4) revise the protocol from a violating trace. The loop ends when TLC finds no violation under the chosen bounds.
Scope is coordination safety, not task semantics. TLC checks deadlock freedom, mutual exclusion, orphan-lock absence, channel drainage, and type invariants; guaranteed termination, starvation freedom, and output quality are outside the model (sections 2.1 and 6, pages 2 and 13). The runtime monitor checks topology conformance and mutual exclusion but not PlusCal step order, lock order, handshake discipline, or receive patterns (section 6, page 13). Thus the verified model and runtime enforcement have a stated gap.
technique: validate a topology IR before writing behavior
What it is: represent agents, shared resources, and directed FIFO channels with explicit labels before generating behavior. Agents are participants; resources are exclusive locks or counting counters; channels specify endpoints and allowed message labels (section 2.3, page 3). The topology is checked structurally through a JSON schema and semantically before translation: every endpoint must reference a declared agent, channel directions must be valid, IDs unique, labels nonempty, and countersâ initial values nonnegative (section 2.3, page 3). The paper says, âThis structural gate filters out malformed inputs at negligible cost, eliminating an entire class of downstream failures before the checker is ever invoked.â (section 2.3, page 3)
Apply it step by step: (1) declare finite agent IDs; (2) declare Lock or Counter resources; (3) declare each directed channel and its label vocabulary; (4) reject unknown endpoints, duplicate IDs, invalid directions, or malformed counters; (5) generate a PlusCal scaffold only after this gate passes; (6) keep topology unchanged during behavioral repair, because repairs edit PlusCal where interleaving hazards live (section 2.2, page 3).
Verus form (Inference): model the IR with Rust enums/structs and a spec fn well-formedness predicate. Prove a proof fn that every channel endpoint exists and every label is declared; use requires on scaffold generation to require this predicate. This checks the data contract, while Verus does not synthesize PlusCal or explore all schedules.
technique: expose nondeterministic coordination to exhaustive checking
Each agent is a fair PlusCal process whose body uses labeled send, receive, acquire_lock, and release_lock macros, optional counter operations, and either/or branches. TLC explores every branch and every interleaving within finite bounds. The paper explains, âThe either/or construct is central to making LLM decision points verifiable; TLC explores all branches as part of the state space.â (section 2.4, page 3)
Procedure: (1) write one labeled process per agent; (2) make every send, receive, acquire, and release explicit; (3) encode alternative outcomes with either/or; (4) translate PlusCal with pcal.trans; (5) define queue bounds B_c; (6) run TLC breadth-first over all bounded states; (7) treat bound overflow as a violation, not silent truncation. The checked properties are mutual exclusion (H single-valued), NoDeadlock, no orphan locks (AllDone â H = â„), and drained channels (AllDone â Q_c = âšâ©) (Table 1, page 3).
Verus form (Inference): encode each agent as a state machine and transitions as spec fns. Use ghost state for queues, lock ownership, and program counters; prove transition invariants with proof fns and loop invariants. Model nondeterministic choices as separate transition lemmas. Verus proofs are deductive and do not automatically enumerate all bounded interleavings, so a bounded-state harness or explicit schedule induction is needed (Inference).
technique: repair from a minimal counterexample trace
When TLC finds a violation, TraceFix treats the concrete interleaving as a localized bug report and gives it, the current topology, and PlusCal source to a repair agent. Typical repairs are imposing a lock order, adding a missing handshake, or restructuring a loop to remove cyclic waits (section 2.7, page 4). The method is evidence-driven: each repair addresses the witnessed schedule rather than regenerating blindly.
The paperâs full Task 3H example has seven agents, six locks, and 17 channels. TLC found a deadlock in which a hub terminated before a satellite finished a revision loop; after two repairs, TLC explored 7.7 million states with zero violations (section 2.8, page 4). In another failure class, PlusCal either/or committed to a branch before channel availability was checked; moving the receives into the same label made branch selection and message availability atomic (section 4.1, page 6).
Verus form (Inference): translate the failing schedule into a Rust test trace over ghost state, then add a lemma whose precondition captures the schedule and whose postcondition proves the repaired invariant. For a lock cycle, prove a global lock-order relation; for a missing handshake, strengthen the transition predicate and associated ensures. Keep the trace as a regression case. The paperâs TLC trace is an explicit execution witness; Verus requires the witness to be encoded or the property proved universally.
technique: enforce the topology at runtime
After TLC passes, each PlusCal process body is embedded verbatim in a per-agent prompt listing allowed channels and locks. A topology monitor rejects coordination operations that target undeclared channels, resources, or labels; locks are implemented as blocking locks. The monitor allows domain tools and agent autonomy but enforces the coordination interface (section 2.9, page 4). Formally, if E(T) is the topologyâs allowed event set and Ï the runtime event trace, the monitor enforces Ï â E(T)* online (section 2.6, page 3).
Verus form (Inference): implement a runtime wrapper whose operation constructors carry capability data for declared channels and resources. Verify wrapper postconditions that an emitted event belongs to the topologyâs ghost event set. This does not prove prompt obedience; it proves only the wrapperâs checks, so the monitor and host interfaces remain trusted.
measured evidence, assumptions, and threats
On 48 tasks from 16 scenario families, 30/48 (62.5%) passed TLC initially and all 48/48 (100%) after at most four repairs (section 4.1, page 5). The 29 repair attempts comprised 20/29 (69.0%) deadlocks, 5/29 (17.2%) TLC timeouts, 3/29 (10.3%) PlusCal syntax errors, and 1/29 (3.4%) undrained channel (Figure 2, page 6). TLC explored 30 to 7.7 million states; median verification time was under one second and all tasks under 60 seconds (section 4.2, page 7). The runtime comparison used 48 tasks, four architectures, two model tiers, three fault levels, and three repetitions: 48Ă4Ă3Ă3Ă2 = 3,456 runs (section 3.3, page 5). For gpt-5-mini, topology monitoring achieved 89.4% average and 81.5% full completion across 432 runs per architecture; prompt-only achieved 86.2%/69.7%, mediator-enforced 78.4%/44.7%, and chat-only 75.0%/29.3% (Table 3, page 8). A 15-task paired ablation (270 runs) reduced deadlock/livelock from 31.1% to 14.1% and raised average completion from 72.6% to 82.1% (section 4.4, page 10).
These are bounded-model and benchmark results, not a general proof of task correctness. TLCâs guarantee is exhaustive only within finite agents, bounded counters, bounded queues, and selected properties. Runtime step-order deviations remain possible; timeout-driven simplification can introduce semantic drift, and the repaired model may cover less of the intended task (section 6, page 13). Inference: for VL, the transferable technique is a counterexample-driven repair loop over Verus proof failures and concurrency traces. The threat is that a passing bounded model or proof may omit semantic behavior; VL should preserve explicit bounds, assumptions, and runtime monitor limits rather than treating âverifiedâ as total product correctness.
techniques for the catalog
- topology-first synthesis â validate agents, resources, channels, and labels before generating behavior
- explicit nondeterminism â encode every branch and coordination operation so bounded checking explores it
- bounded exhaustive checking â enumerate all interleavings under stated queue and counter bounds
- counterexample repair â feed concrete TLC traces to targeted PlusCal edits and rerun verification
- runtime topology enforcement â reject undeclared coordination events while preserving domain-tool autonomy
Checked 2026-10-15 against the paper by a Codex agent: checked quotations, numerical/section/page references, technique descriptions, catalog entries, and overlap; corrected none.
Last edited: