Repository navigation
Resume daemon-restarted threads with persisted provider sessions - #2296
bradhallett wants to merge 1 commit into
Conversation
|
cc @ymichael — re-review ping; no feedback since this opened. The one product decision flagged in the description, restated so it's easy to rule on: #1592 asks that a daemon restart "pick the thread up again automatically". This PR makes restarted threads cleanly resumable — the persisted provider session re-attaches on the next Gates: server suite green (single documented pre-existing env failure), mutation-checked, no wire changes. |
…-bb#1592) When a restarted daemon re-registers, active threads used to get a synthetic turn/completed + system/error (\"Thread interrupted because the host daemon disconnected\" / \"Please retry the thread to continue.\") and land in error, even though a persisted provider session (ACP/Codex) survives the restart and re-attaches through thread/resume on the next dispatch. Runs with a persisted provider thread id now settle like a user stop — turn/completed (interrupted) + system/thread/interrupted, no synthetic system/error — and land idle via stop.requested/stop.settled, which keeps them resumable by the next turn.submit and the queued-message auto-send sweep. Runs with no provider session to re-attach keep the failure interruption. The same-instance reconnect and disconnect-grace paths are unchanged.
e0f830a to
c20bec6
Compare
RebaseRebased onto Conflicts in all 3 files, resolved as:
No behavioral change vs the previous head; no duplicate logic on Gates
cc @ymichael — re-review ping; the diff-vs-main is now just the settlement logic + its tests.
|
|
This is an automated message. We have closed this pull request because it has been open for more than two weeks. |
What was wrong
When a daemon re-registers with a new instance id,
handleHostSessionOpenedunconditionally failed every active thread on that host before reconciliation could look at it: a syntheticturn/completed(interrupted), asystem/error("Thread interrupted because the host daemon disconnected" / "Please retry the thread to continue."), andrun.failedlanding the thread inerror(base fff3ae8:session-owner-side-effects.tscallingthread-lifecycle.ts). That is a lie for any run whose provider session survives the restart: ACP and Codex sessions persist on the host and re-attach throughthread/resumeon the next dispatch. #1592 asks for exactly this — overnight work dying on every daemon restart with a "please retry" prompt instead of continuing.What changed
apps/server/src/services/threads/background-task-reconciliation.ts: newsettleDaemonRestartedThreadRunsForResume, the daemon-restart counterpart of the dangling-task backstop. Active threads on the host that have a persisted provider thread id settle like a user stop —turn/completed(interrupted) plussystem/thread/interrupted(reasonhost-daemon-restarted), no syntheticsystem/error— and landidleviastop.requested/stop.settled. Runs with no provider session (e.g. athread.startthat never established one) are left active and keep the existing failure interruption; there is nothing to re-attach.apps/server/src/internal/session-owner-side-effects.ts: the replacement-instance branch calls the resume settlement before the interruption sweep, which then only sees the non-resumable runs.settleDanglingBackgroundTasksand the same-instance reconnect / disconnect-grace / host-removed paths are unchanged.HOST_DAEMON_PROTOCOL_VERSIONuntouched); no CLI or doc surface affected.Deviations from the issue's ask, flagged for maintainers:
turn.submit, and the existing queued-message auto-send sweep continues threads that had work queued — no manual retry, no misleading error. It does not automatically re-submit the interrupted turn's stored input: that duplicates the user message in the provider transcript and is a product decision (happy to implement if you want it).turn/completed(interrupted) record, same as a user stop. Leaving the turn open would misroute subsequent sends as steers to a turn no live runtime owns.How you verified
Extended
apps/server/test/internal/background-task-reconciliation.test.ts:"resumes active turns whose provider session survives a daemon restart" — drives
handleDaemonSocketClosedthen/internal/session/openwith a new instance id and asserts the thread landsidlewith exactly[turn/completed, system/thread/interrupted]and nosystem/error. On base fff3ae8 the same scenario produceserrorplus the syntheticsystem/error, so this test fails before the change."interrupts active runs with no provider session to re-attach when a different daemon instance registers" — guards the nothing-to-re-attach case: still
errorwith the failure interruption.The existing same-instance-reconnect and disconnect-grace tests are untouched and still cover their paths.
Locally:
pnpm exec turbo run test --filter=@bb/server— 1923 tests, 1922passing; the single failure (
test/app/install-machine-script.test.ts)reproduces identically on a pristine
maincheckout atfff3ae8(environmental, pre-existing). Mutation check: reverting only the
session-owner-side-effects.tswiring makes the resume test fail (1failed / 11 passed) and pass with the call restored.
pnpm exec turbo run typecheck lint --filter=@bb/servergreen;pnpm exec oxfmt --checkgreen on all three touched files.Fixes #1592