Skip to content

fix(server): wake queued message dispatch on interrupted turn reaching idle - #3189

Closed
panysaurusrex wants to merge 1 commit into
get-bb:mainfrom
panysaurusrex:fix/wake-queue-on-interrupted-turn-idle
Closed

panysaurusrex wants to merge 1 commit into
get-bb:mainfrom
panysaurusrex:fix/wake-queue-on-interrupted-turn-idle

Conversation

@panysaurusrex

Copy link
Copy Markdown

Summary

When a turn completed with event.status === 'interrupted' (for example, when steered during execution or interrupted by a cancellation), turnCompleted.nextStatus transitioned the thread to 'idle', but the server never scheduled a queued-message-dispatch follow-up. This was because the wake condition was strictly gated on:

if (event.status === 'completed' && turnCompleted.nextStatus === 'idle')

As a result, any messages queued while waiting for the thread to be idle (or steers waiting in the queue) remained stranded in queued_thread_messages with waitingOn: { kind: 'thread-busy' } until the user manually triggered another turn.

Changes

  • Updated the turn completion follow-up trigger in apps/server/src/internal/events.ts to schedule queued-message-dispatch whenever turnCompleted.nextStatus === 'idle', regardless of whether event.status was 'completed' or 'interrupted'.
  • Added a full regression test in apps/server/test/internal/internal-events-turn-interrupted-queue-wake.test.ts verifying that an interrupted turn transitioning to idle immediately wakes the queue and dispatches the queued message.

Verification

  • Tested with Vitest on @bb/server:
    • New test internal-events-turn-interrupted-queue-wake.test.ts passes.
    • Verified negative case: fails with command timeout without this fix.
    • Full test/internal/ suite (17 files, 107 tests) passes.
    • test/threads/requested-queue-drain.test.ts & thread-send-dispatch.test.ts pass.
    • tsc --noEmit and oxlint pass with 0 errors.

…le regardless of completion status

Previously, turn completion only scheduled queued-message-dispatch follow-up
if event.status === 'completed'. When a turn was interrupted (e.g. by steering
or a user stop), reaching idle status did not wake queued-message-dispatch,
leaving queued messages stranded in the database until an explicit turn
request occurred.
@github-actions

github-actions Bot commented Sep 6, 2026

Copy link
Copy Markdown
Contributor

Thanks @panysaurusrex for the PR. This repo needs approval before a PR. Join the #contributors channel in Discord (https://discord.gg/kvBU6tJhcJ) and explain what you want to open a PR for and why. A maintainer then adds you to the allow list. This PR now closes on its own. Reopen it or open a new one after approval.

@github-actions github-actions Bot closed this Sep 6, 2026
@panysaurusrex
panysaurusrex deleted the fix/wake-queue-on-interrupted-turn-idle branch September 6, 2026 22:38
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.

1 participant