Repository navigation
Resume threads whose background commands a graceful daemon shutdown stopped - #7134
Merged
Merged
Conversation
…topped Restart resume (#7004) found the background work a restart stopped by listing tasks still open when the new daemon instance connected. Since #6124, a graceful daemon shutdown settles every open task as stopped before the connection closes, and the server settles them when the connection is lost. After an update restart no task is left open, so idle threads waiting on background commands were never nudged. On Nov 5 an update at 18:07 UTC stopped four threads' commands this way and none were resumed. Settlements made because the process running a task went away (the runtime's settle on bridge exit and shutdown, and the server's host settles) now mark the item ownerStopped. Restart resume also counts tasks marked that way since the replaced daemon session opened and after the thread's last turn request, so each stop nudges the thread once. Stops by the agent or the user carry no marker and still never trigger a resume. The marker is a new daemon-to-server event field, so this bumps HOST_DAEMON_PROTOCOL_VERSION to 263, and the plugin SDK to 0.6.126 because the domain item schema ships in its types. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
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
Two PRs merged on Nov 4 conflict:
stoppedduring a graceful daemon shutdown and flushes those events before the connection closes. The server also settles open tasks when it loses the daemon connection.So after a graceful restart, such as an update, no task is left open. Idle threads waiting on background commands are never nudged. On Nov 5 an update at 18:07:09 UTC stopped four idle threads' commands (CI watchers and a dev server). The runtime recorded each as
item/backgroundTask/completedwithtaskStatus: "stopped"at 18:07:13, before the old session closed. The new daemon instance connected at 18:07:31,planRestartResumesfound no open tasks, and no resume was queued. Turns cut mid-flight still resumed, because that path doesn't depend on open tasks.What changed
packages/domain: the background-task item gains an optionalownerStopped: true. It means bb settled the task because the process running it went away, not because the task, the agent or the user ended it.packages/agent-runtime: the runtime's own settlements set the marker when they force a running task tostopped. These are the settlements on bridge exit and runtime shutdown (Settle background tasks when the bridge, Claude Code or the daemon that owns them stops #6124). A task already in a settled status keeps its status and gets no marker.apps/server(background-task-reconciliation.ts):host-daemon-restarted,host-connection-lost,host-removedandhost-daemon-no-longer-runs-task.packages/db:listOwnerStoppedBackgroundTaskRowsForHostreturns marked completions on a host's live active or idle threads since a given time. It is index-driven: thread status, thenevents_background_task_thread_type_item_sequence_idx. On a production DB it takes about 11 ms.apps/server(restart-resume.ts,session-owner-side-effects.ts):planRestartResumescombines two sources:ownerStoppedsince the replaced daemon session opened and after the thread's last turn request.Each stop nudges the thread once, and the agent and the user stopping a task still never trigger a resume. The wording sent to the agent is unchanged.
Wire: the marker is a new field in daemon-to-server events, so
HOST_DAEMON_PROTOCOL_VERSIONgoes from 262 to 263. The plugin SDK goes to 0.6.126 because the domain item schema ships in its bundled types.How you verified
apps/server/test/threads/restart-resume.test.ts:ownerStoppedbefore the daemon reconnected is woken with the command named, and is not woken again after a second restart. This fails on main, where no open task remains and no resume is queued.ownerStopped(background-task-reconciliation.test.ts);public-thread-stop-runtime.test.ts);agent-runtimetests updated).turbo run test:@bb/agent-runtime309 passed. The@bb/serverrestart-resume, reconciliation and thread-stop suites have 66 passed.turbo run typecheck lint --filter='...[origin/main]': 155 tasks pass.🤖 Generated with Claude Code