Skip to content

Requeue sends that lose the run start race - #1

Open
devin-ai-integration[bot] wants to merge 1 commit into
mainfrom
devin/1789475937-fix-concurrent-send-race
Open

devin-ai-integration[bot] wants to merge 1 commit into
mainfrom
devin/1789475937-fix-concurrent-send-race

Conversation

@devin-ai-integration

Copy link
Copy Markdown

Human comments

What was wrong

Rapid back-to-back sends on an idle thread all pass admission against the same idle snapshot, and each then appends its client turn request in the same transaction that applies run.started. The first request wins the lifecycle transition; every competing request hits requireThreadLifecycleEventApplied, which throws on the illegal run.started from active, rolling back its whole transaction — including the appended input. The send is silently lost rather than queued behind the active run. See get-bb#3716 and https://get-bb.github.io/reports/issues/3716.html.

What changed

  • apps/server/src/services/threads/thread-send.ts: the start-mode transaction re-reads the thread and fails fast when its status moved since admission, and an unapplied run.started no longer raises the generic lifecycle error. Both paths raise a dedicated recoverable thread_status_changed_during_send ApiError (createThreadStatusChangedDuringSendError / isThreadStatusChangedDuringSendError).
  • apps/server/src/services/threads/dispatch-attempt.ts: runDispatchAttempt catches only that error and routes through the existing reattemptDispatchForThreadChange checkpoint with the freshly read thread, so the losing send is re-decided against the now-active thread and queued. The rollback happens before delivery and before claimed queue rows are consumed, so no turn can be duplicated and queue claim atomicity is unchanged.

No wire, CLI, or doc surfaces changed.

How you verified

  • Added concurrent idle dispatch in apps/server/test/threads/thread-send-dispatch.test.ts: four concurrent queue-if-active sends on an idle thread must yield exactly one sent, three queued, an active thread, and all three inputs retained in the queue. On clean main it fails with ThreadLifecycleEventNotAppliedError: ... no transition for run.started from status active; it passes with the fix.
  • pnpm exec turbo run test --filter=@bb/server -- test/threads/thread-send-dispatch.test.ts test/threads/dispatch-hooks.test.ts test/threads/thread-send-error-recovery.test.ts → 44 passed.
  • pnpm exec turbo run typecheck --filter=@bb/server → clean.
  • Full @bb/server suite: only test/app/install-machine-script.test.ts and test/services/plugin-catalog/bb-official-generator.test.ts fail, and they fail identically on clean main (environment-dependent: uid/HOME and git committer history).

Fixes get-bb#3716

AGENT GENERATED

Link to Devin session: https://app.devin.ai/sessions/e30f319968a14318aaf5608f96ff38c5
Open in Devin Desktop: https://app.devin.ai/desktop/session/e30f319968a14318aaf5608f96ff38c5?variant=devin
Requested by: @treesitter1

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@devin-ai-integration

Copy link
Copy Markdown
Author

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add '(aside)' to your comment to have me ignore it.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment, CI, and merge conflict monitoring

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Queued messages dropped under rapid back-to-back sends: ThreadLifecycleEventNotAppliedError (no transition for run.started from status active)

1 participant