Repository navigation
fix: make queued-message dispatch atomic and composable - #2884
Merged
Merged
Conversation
Automatic grouped claims required every member to match the same sweep trigger, so groups mixing plugin and timer waits could never become eligible. Compose per-member plugin or due-time eligibility while retaining the immediate whole-group claim.
Automatic turn-start sends omitted an eligibility callback, so callback presence let a clean group member pull a failed sibling into a claim. Require explicit-send intent at the shared claim boundary so only Send now can admit failures.
ymichael
deleted the
bb/investigate-queued-message-bugs-thr_uawcey4qag
branch
September 2, 2026 00:21
This was referenced Sep 2, 2026
ymichael
added a commit
that referenced
this pull request
Sep 2, 2026
## Human comments ## What was wrong #2884 centralized atomic queue admission, whole-group eligibility, failed-row exclusion, and manual-Stop policy, but automatic dispatch orchestration was still split across lifecycle events, timer and plugin walkers, wait-release handlers, and recovery. Those callers independently chose candidate rows, pacing, coalescing, and failure behavior. In particular, the `turn-started` path captured queued row IDs and only logged terminal failures, while other drains persisted them, and plugin recheck coalescing used process-global state rather than server-instance state. The manual-Stop pause also classified ordinary queued rows as only unwaited or `thread-busy`. A user message parked while a turn was starting uses `turn-starting`, so an automatic drain could claim that older row after Stop and unexpectedly restart the thread. The initial coordinator migration also grouped idle, scheduled, and orphan recovery under one periodic job guard and expanded plugin removal into one deferred task per affected thread. A slow idle pass could therefore suppress due-schedule recovery on overlapping ticks, while removing a plugin could create an unbounded burst of deferred queue work. ## What changed - Replaced the old `queue-drains` module and automatic-send entry points with one queued-message dispatch coordinator whose interface accepts typed wake-up facts. - Migrated thread lifecycle, turn events, workspace readiness, provisioning settlement, interaction settlement, host reconnect, plugin recheck/removal, message creation, and periodic recovery to that interface. - Moved candidate discovery, wait release, per-thread dispatch coalescing, requeue pacing, automatic eligibility, claims, timeout treatment, persistent failure handling, and orphaned-plugin recovery behind the coordinator seam. - Kept lifecycle wake-ups immediate even after a recent requeue while timer and plugin sweeps retain their anti-spin cooldown. - Kept periodic idle, due-scheduled, and orphaned-plugin recovery as independently guarded typed wakes, so an overlapping tick can deliver due work while an earlier idle pass is still running. - Kept plugin-unregister release and dispatch as one sequential coordinator batch instead of one deferred task per affected thread. - Scoped plugin-recheck request coalescing to each server instance. - Kept explicit “Send now” separate behind an explicit-send-only interface. - Classified `turn-starting` user rows as ordinary for manual-Stop pause policy, while keeping explicit Send now as the deliberate override. There is no host-daemon wire, database schema, CLI, SDK, migration, or documentation contract change. ## How you verified - Added regressions for terminal failure persistence on `turn-started`, lifecycle wake-ups during the requeue cooldown, per-server request coalescing, and orphaned plugin waits. - Added a public HTTP/session-event regression covering steer during startup, manual Stop, a late `turn/started`, a later queued message, automatic `thread-ready` dispatch, and explicit Send now. It failed before the predicate fix and passed after it. - Added an overlapping-periodic-tick regression that blocks idle recovery and proves due scheduled work gets the next dispatch opportunity. It failed before independent guards and passed after. - Added a plugin-unregister regression covering multiple affected threads. It failed with two deferred tasks before the batch fix and passed with one afterward while draining both rows. - Final focused Turbo queue/lifecycle matrix: 69/69 server tests passed. - `@bb/server` Turbo typecheck and build passed. - Full server suite before the review follow-up: 2,134 passed. The ten unrelated `install-machine-script` cases failed both in the full run and alone because this host has `/tmp/package.json` with `"type": "module"`, which makes their extensionless CommonJS fixture fail with `ReferenceError: require is not defined`. - Changed-file formatting and `git diff --check` passed. Follow-up to #2884. > AGENT GENERATED
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Human comments
What was wrong
Queued-message readiness was decided independently by startup events, idle sweeps, plugin/timer drains, failed-row handling, and manual Stop handling. Each fix could pass alone while their predicates disagreed when composed: a settled
turn-startingrow could be discovered but rejected, a failed grouped sibling could ride with a healthy row, and a stale runtime event or in-flight hook could cross a manual Stop. Startup admission also trusted a stale active thread after it changed to error, which could strand a row or changesteersemantics.What changed
thread-busy, andturn-startingwaits.sendNow/optional-callback claim API with an explicitautomaticversusexplicit-sendpolicy.INpredicate for idle-drainable wait kinds.This supersedes #2866 and #2867 and includes the failed-group and Stop-boundary follow-ups. There is no host-daemon wire, schema, CLI, SDK, migration, or documentation contract change.
How you verified
steermodes.install-machine-scripttests failed because their fake host daemon did not connect.pnpm exec turbo run typecheck --filter=@bb/server --filter=@bb/dbpassed.pnpm exec turbo run build --filter=@bb/serverpassed.git diff --checkpassed.