Skip to content

BRC deadlock: mcp__brc__wait_loop misses ACKs that arrive between successive wait calls #1995

Closed

Description

@jwbron

Summary

BRC producer (refiner role in this case) can deadlock when reviewer ACKs arrive in the window between a returning mcp__brc__wait_loop call and the subsequent mcp__brc__wait_loop call. The producer ends up waiting forever on events that have already fired.

Observed on pipeline issue-1973 (refine phase, v2 re-proposal), reproducible without any user intervention.

Concrete timeline

Pipeline: issue-1973, refine phase, v2 proposal.

Time (UTC) Event
18:20:55 refiner sends CONSENSUS_PROPOSE (v2), then immediately calls mcp__brc__wait_loop(for_types=[CONSENSUS_ACK, CONSENSUS_NACK, CONSENSUS_RE_REVIEW, OVERSEER_ALERT])
18:20:59 wait_loop #1 begins blocking
18:21:21 reviewer_agent_design sends CONSENSUS_ACK
18:21:21 wait_loop #1 returns with the reviewer_agent_design ACK
18:21:24 reviewer_refine sends CONSENSUS_ACK (during the ~3 s window between calls)
18:21:25 refiner calls wait_loop #2 for the remaining ACK
18:21:25+ wait_loop #2 blocks — and never returns. The reviewer_refine ACK that landed 1 s earlier is not delivered
18:20:00 (earlier) reviewer_refine sent CONSENSUS_CONFIRMED
18:18:14 (earlier) reviewer_agent_design sent CONSENSUS_CONFIRMED
… consensus view: both reviewers reviewer_phase=CONFIRMED, refiner stuck in producer_phase=PROPOSED
18:26:54 overseer raises `orchestrator-consensus-silent [medium]`
18:29:33 overseer escalates to `[high]`
18:32:02 manual send_message(type=STATUS, to=refiner) nudge from overseer role — ignored, since STATUS is not in the wait_loop filter set

The consensus snapshot at the time of the nudge:

```json
{
"agents": {
"refiner": {"confirmed": false, "producer_phase": "PROPOSED"},
"reviewer_agent_design": {"confirmed": true, "reviewer_phase": "CONFIRMED"},
"reviewer_refine": {"confirmed": true, "reviewer_phase": "CONFIRMED"}
},
"blocking_agents": ["refiner"],
"is_complete": false,
"protocol": "brc"
}
```

Root cause (hypothesis)

mcp__brc__wait_loop appears to use a wait-start timestamp (or equivalent cursor snapshot taken at call time) as its lower bound for event matching, rather than threading a monotonic cursor across successive calls. Any event that fires in the gap between `wait_loop#N returns` and `wait_loop#(N+1) begins` is lost for that consumer.

This is the same class of bug that host-side wait_for_status_change already solved by having callers thread the returned cursor into the next call's since parameter (see docs/reference/agent-wait-patterns.md §7). The agent-side mcp__brc__wait_loop needs the same contract.

Impact

  • Any BRC producer that re-enters wait_loop after a partial result (e.g. waiting for a subset of reviewers, then looping for the rest) is at risk.
  • More likely on re-review cycles (v2+) where reviewers often respond in quick succession because the diff is small.
  • Deadlock is silent from the producer's perspective — the consensus endpoint correctly shows `is_complete: false` but gives no hint the producer has lost events.
  • Overseer detects the symptom (`orchestrator-consensus-silent`) but cannot recover it: STATUS nudges don't wake the stuck wait, and the producer never emits CONSENSUS_CONFIRMED on its own.

Reproduction

Happened unprompted on issue-1973 refine phase v2 with the default roster (refiner, reviewer_refine, reviewer_agent_design). Likely race-dependent but the gap is only ~3 s, so it is not rare.

Suggested fixes

  1. Cursor threading — have mcp__brc__wait_loop return a cursor and accept a since parameter, matching the wait_for_status_change contract. Agents pass the previous response's cursor into the next call so no events can slip through the gap.
  2. Alternative / complement: state snapshot at call time — when the agent calls wait_loop, first check the consensus/message state synchronously and return immediately if the desired events have already occurred (i.e. don't block at all when the answer is already in the log).
  3. Recovery path — add a STATUS message type (or equivalent) to the wait_loop filter so an operator nudge can unblock a stuck producer without restarting the container.

(1) is the real fix; (2) is a defensive cheap win; (3) is a safety net.

Observability notes

get_container_logs(agent_role=refiner) shows the producer sitting in mcp__brc__wait_loop with no further tool calls after the bad wait started. A future improvement could be to log the since/cursor each wait_loop invocation sends, so this class of bug is trivial to spot from logs.

Related

  • docs/reference/agent-wait-patterns.md §7 — the host-side wait_for_status_change already uses cursor threading.
  • /.claude/skills/sdlc monitoring logic explicitly mentions the "wait→wait race window" that cursor threading closes for host-side waits. The agent-side mcp__brc__wait_loop currently lacks this.

Activity

  1. added a commit that references this issue on Apr 24, 2026
    e01394a
  2. added 3 commits that reference this issue on Apr 24, 2026
    e5a3473
    78c3826
    7d2f767
  3. added a commit that references this issue on Apr 25, 2026
    5cd3d64
  4. added 2 commits that reference this issue on Apr 25, 2026
    2bd4e28
    af0e7eb
  5. added a commit that references this issue on May 31, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions