Repository navigation
Conversation
A stop sent while the thread is not marked stopping (the re-stop on a same-instance reconnect) can be acknowledged after the user has already sent a new message. Its result then finalized the new run: the thread went idle, its turn was interrupted and its background tasks settled. A stop result now has no effect when a turn was requested after the stop was sent, unless the thread is stopping again, in which case the result still ends that stop. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Collaborator
Author
|
Closing: live QA against a real daemon showed the stale stop reply changes nothing visible (the daemon answers the stop before starting the next turn). The real effect found was a ~1.75 s idle flicker of the new run in a rare reconnect case, which doesn't justify two new guards in the core stop and completion paths. |
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
A
thread.stopresult was applied to whatever run the thread had when the result arrived, not to the run the stop was sent for. Most stops first mark the threadstopping, and astoppingthread refuses sends, so nothing can come after them. The re-stop that a same-instance daemon reconnect sends for a thread it already stopped (reconcileDaemonReportedThreads) leaves the threadidle, so the user can send a new message while that stop is still in flight. When the stop is then acknowledged,settleThreadStopCommandResultsettles the thread's background tasks and finalizes it: the new run goesactive→idle, its turn is interrupted, and its background tasks are marked done while the provider still runs them. This is the stale-stop guard from #6552, split out on its own (investigation in the parent thread of this work).What changed
settleThreadStopCommandResultignores a stop result (success or failure,interruptorrelease) when a turn was requested at or after the time the stop was sent. It has no effect: no finalize, no background-task settlement, no interaction interrupt.stoppingagain, the result still applies. When the user stops the newer run while the old stop is in flight, the new stop is not dispatched (the old one holds the in-flight claim), so the old result is the only thing that ends it. Astoppingthread refuses sends, so a request newer than an ordinary stop cannot exist.@bb/dbqueryhasTurnRequestSince(one thread'sclient/turn/requestedrows, bycreated_at).No wire, schema, CLI or SDK change.
How you verified
Two regression tests in
apps/server/test/internal/background-task-reconciliation.test.ts, both driving the real reconnect flow (session open with the thread active → re-stop queued → user sends → new turn starts with a running background task → old stop acknowledged):idleitem/backgroundTask/completedactive, task still openstoppingexception: fails, thread stuckstoppingidleCommands:
pnpm exec turbo run typecheck lint --filter='...[origin/main]': 11/11 tasks passpnpm exec turbo run test --filter=@bb/server: 3870 passed, 1 failed intest/app/install-machine-script.test.ts. That file fails on origin/main as well, with a different test each run; unrelated.🤖 Generated with Claude Code