Skip to content

Stop the open turn when a start refusal fails the run - #6924

Closed
ymichael wants to merge 2 commits into
mainfrom
bb/stop-open-turn-on-start-refusal-error-thr_iuf6kaf35m
Closed

ymichael wants to merge 2 commits into
mainfrom
bb/stop-open-turn-on-start-refusal-error-thr_iuf6kaf35m

Conversation

@ymichael

@ymichael ymichael commented Nov 3, 2026

Copy link
Copy Markdown
Collaborator

Human comments

What was wrong

When the daemon refused a turn start with any error other than competing_turn while a provider turn was open, settleThreadCommandFailure in apps/server/src/services/threads/thread-lifecycle.ts moved the thread to error. It never checked for an open turn, so bb left the turn open and sent the daemon no stop. The provider kept working behind a thread showing error. This is item 6 from the investigation of #6552's stop fixes against main. #6727, #6728, #6736 and #6870 didn't touch this path, and the repro still failed on current main.

What changed

  • settleThreadCommandFailure: when a start refusal (thread.start, or turn.submit in start mode) fails the run, bb records any open turn as turn/completed with status interrupted in the same transaction. After the commit, it sends thread.stop with intent interrupt, using the existing dispatcher and thread.stop in-flight guard.
  • The "turn completed: interrupted" write moves out of applyActiveTurnInterruptionInTransaction into a helper that both paths use.
  • This adapts Settle every turn input and every started turn #6552's version, which was written against the input ledger that has since been dropped. Settle every turn input and every started turn #6552 also stopped the turn on refused steers, which would kill a healthy live turn. This PR deliberately limits the stop to start refusals. A refused steer still fails the run as it does today, with the turn left open and no stop sent. Fixing that ("does not fail a live run when its steer is refused") is a separate, later PR.
  • No wire, protocol, CLI or doc changes.

What a user sees differently

  • The open turn now ends as interrupted instead of looking like it's still running under an error badge.
  • The provider actually stops working.
  • When the stop settles, the thread stays in error. If the thread has never been stopped before, a stopped marker may appear in the timeline, and queued messages get a chance to send, as after any stop.
  • If the daemon later reports the turn finished, nothing changes, because a thread in error ignores a late "stop settled".

How you verified

The existing test "still fails the run for other refusals while a root turn is stored" in apps/server/test/threads/thread-send-dispatch.test.ts already set up this case but only checked for error. It is renamed to "fails the run and stops the open root turn for other refusals" and now also checks that the turn is closed and an interrupt thread.stop was queued.

Check main this PR
Investigation repro test, copied onto current main Fails: { openTurn: 'turn-unrequested', stopSent: false } Passes
Regression test in thread-send-dispatch.test.ts Fails: expected 'turn-unrequested' to be null Passes
Refused-steer repro (behavior must not change) error, turn open, no stop Same
pnpm exec turbo run typecheck lint --filter='...[origin/main]' — Passes
pnpm exec turbo run test --filter=@bb/server — 3869 passed, 1 skipped

@bb/server has no lint script, so I also ran oxlint and prettier on the changed files; neither reports anything in this diff.

🤖 Generated with Claude Code

AGENT GENERATED

When the daemon refused a turn start with anything other than
competing_turn while a provider turn was open, bb set the thread to
error but left the turn open and never told the daemon to stop it, so
the provider kept working behind an errored thread.

Settling that failure now records the open turn as interrupted and
dispatches thread.stop to the daemon. Steer refusals are unchanged.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Closing the open turn on the server and then receiving the provider's
own interrupted completion stored two turn/completed events. The second
one was treated as an unexplained interruption, so a child thread's
parent notice changed from failed to interrupted.

Mark the turn stopped before sending the stop, as a normal stop does,
and let the provider's completion close the turn. If the stop settles
without one, closing the errored thread's open turn is now done when
the stop is finalized.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@ymichael

ymichael commented Nov 3, 2026

Copy link
Copy Markdown
Collaborator Author

Closing: live QA with real Claude Code found no real trigger. Background-task wakes do open unrequested turns, but in 12 timed races no start was refused with anything other than competing_turn (already handled on main). The bug only reproduced with an injected daemon fault.

@ymichael ymichael closed this Nov 3, 2026
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