buzz-acp: multi-thread event batch collapses all replies to the newest event's thread (misroute)
Component: crates/buzz-acp (queue.rs / format_prompt)
Summary: When a channel has pending events spanning more than one thread, buzz-acp drains them into a single batch and derives the entire turn's scope and --reply-to anchor from only the newest event in that batch. An agent answering content from thread A can have its reply anchored to thread B, because B's event happened to be newest in the batch.
Evidence (code):
flush_next()"drains ALL events for that channel into a single batch" (queue.rs ~L258).format_prompt()uses only the last event for scope + anchor:let last_event = batch.events.last()(L1416)let thread_tags = parse_thread_tags(&last_event.event)(L1423)- passed to
resolve_reply_anchor(...)(L1479)
resolve_reply_anchor(L1214) is correct in isolation; the defect is that one batch spanning N threads yields one anchor.
Reproduction (observed on relay): In channel 655a83db-…, a human sent a new top-level message (ad587ca1…, no e-tag) at 17:43:34 asking "how useful is all of this work". The agent's answer (8ce1dd5c…, 35s later) was tagged e … 2165572e… reply — an unrelated older thread — because other messages in that older thread were newer in the same batch. Trigger root and reply root differ = misroute. Later turns routed correctly once each batch contained a single thread.
Impact: Human-facing replies land in the wrong thread when a user is active in two threads at once — confusing, and it re-triggers the wrong conversation's participants.
Suggested fix direction: Don't anchor a mixed-thread batch to batch.events.last(). Either (a) split a batch per-thread so each turn answers+anchors within one thread, or (b) resolve the reply anchor against the specific event a reply addresses. A new top-level trigger should never inherit an older thread's root.
Repro data: buzz messages get --channel 655a83db-fc70-4556-a901-90c4f1a73cc8 --since 1786124580 --before 1786124940
Same AMQ ask as https://github.com/block/buzz/issues/3176: batch_mode=per_event so a misrouted coalesced batch never reaches amq-acp. AMQ already refuses two event ids on one prompt; that cannot repair a collapsed thread upstream.
Re-checked the code claims at origin/main (f038cbbb0) — they all still hold,
and the one open PR that references this issue does not touch this path.
Still present
crates/buzz-acp/src/queue.rs:370 flush_next — "drains ALL events for that
channel into a single batch"
crates/buzz-acp/src/queue.rs:1980 let last_event = match batch.events.last()
crates/buzz-acp/src/queue.rs:1987 let thread_tags = parse_thread_tags(&last_event.event)
crates/buzz-acp/src/queue.rs:2028 resolve_reply_anchor(…)
So one batch spanning N threads still yields exactly one scope and one anchor, both taken from whichever event happened to be newest.
#6633 does not close this
#6633 ("state the reply destination in mid-turn steer prompts") is the natural
thing to assume already covers this, since it references this issue and rewrites
a lot of the same file (queue.rs +342/-50). It does not: grepping its diff for
batch.events.last, flush_next, and parse_thread_tags(&last_event returns
nothing. It fixes the native steer path not stating a destination at all,
which is a different defect from a batch collapsing several threads onto one
anchor. Worth saying out loud so this issue is not closed as a duplicate of it.
That PR is heavily editing this file though, so whoever implements this will probably want to land after it rather than race it.
The two suggested directions are not equivalent
- (b) resolve the anchor per addressed event is local to
format_prompt, but needs a way to know which event a given reply answers — the agent returns prose, not a target id, so something has to attribute it. - (a) split the batch per thread keeps attribution trivial by construction
(one turn, one thread), but changes queue behaviour and overlaps #3176's
batch_mode=per_eventask. #3176 and this issue look like the same root with different scopes.
Not claiming this — flagging that the path is still open and that #6633 is not the fix, so the next person does not re-derive it.