Skip to content

Recheck thread status before committing dispatch - #3718

Merged
SawyerHood merged 2 commits into
mainfrom
slopcop/issue-3716
Sep 15, 2026
Merged

SawyerHood merged 2 commits into
mainfrom
slopcop/issue-3716

Conversation

@bb-slop-cop

@bb-slop-cop bb-slop-cop Bot commented Sep 15, 2026 •

Copy link
Copy Markdown
Contributor

Human comments

What was wrong

Concurrent sends could pass idle admission together. After one activated the thread, competing sends attempted an illegal lifecycle transition and lost their input. The transaction status recheck prevents that race, but initially also rejected reprovision's own transition to starting, leaving no persisted provisioning request to advance. Reproduction report.

What changed

Recheck thread status inside the request transaction before appending input or consuming claimed queue rows. If another send changed the status, retry admission so queue-mode input waits behind the winning send.

For reprovision, run admission before the run.preparing transition within the transaction that persists the request and provisioning context. Publish the status notification after success. Rejected admission leaves the thread and its events unchanged. Retain the concurrent queue-send regression and add a rejected-reprovision regression. No public API or daemon wire changes.

How you verified

  • Original PR head reproduced all four server CI failures: three queued reprovision requests returned 409, and retry never issued its environment command.
  • New rejected-reprovision test failed on the original implementation and passes with the fix; it checks idle status, unchanged events, absent provisioning context, and no status notification.
  • All 146 tests passed using pnpm exec turbo run test --filter=@bb/server --concurrency=4 -- test/threads/thread-turn-dispatch.test.ts test/threads/thread-send-dispatch.test.ts test/public/public-thread-data.test.ts test/threads/thread-provisioning-recovery.test.ts test/threads/dispatch-hooks.test.ts test/threads/thread-send-error-recovery.test.ts --maxWorkers=4.
  • Full integration suite: 82 tests passed, including both delayed-start-ack reprovision cases and unarchive environment recovery.
  • Server and integration typechecks passed through Turbo; formatting and git diff --check passed.
  • Full local server run passed 2,701 tests. The two local watcher failures also reproduced with the original implementation; the two provider fixture tests passed with the normal test environment.
  • Final-head CI is green on 0f7c68d4e6d188c3aa4bc7018ac89e8ada2fe9cd: full server and integration suites, all app and package tests, build/typecheck/lint, and Linux/macOS package smoke passed. All 14 applicable PR checks passed; two conditional checks were skipped.

Fixes #3716

AGENT GENERATED

@SawyerHood
SawyerHood merged commit 79568e9 into main Sep 15, 2026
16 checks passed
@SawyerHood
SawyerHood deleted the slopcop/issue-3716 branch September 15, 2026 17:16
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