Repository navigation
Resume an active provider machine whose daemon is gone - #6160
Closed
alexandre-vl wants to merge 1 commit into
Closed
alexandre-vl wants to merge 1 commit into
alexandre-vl wants to merge 1 commit into
Conversation
A provider machine whose daemon died while its lifecycle phase stayed active was never repaired: resume returned early for active machines, the lifecycle sweep only resumed suspended ones, and a follow-up parked on a host-offline wait that only a reconnect releases. Core now calls the provider's resume for such a machine once its daemon has gone unheard for the 30-second reconnect grace while a thread runs there or a message waits for it: from dispatch, from the lifecycle sweep, and from an explicit resume request. A failed attempt keeps the machine active with the error and retries after a minute, and bb machine resume reports that failure instead of printing success.
alexandre-vl
added a commit
to alexandre-vl/bb
that referenced
this pull request
Oct 23, 2026
…e whose daemon is gone (get-bb#6160)
Contributor
|
This is an automated message. We have closed this pull request because it has been open for more than two weeks. |
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
When the daemon of a provider-managed machine dies while core still records the machine as
active, nothing ever repairs it:resumeMachineWithIntentreturns early for every phase exceptsuspended,suspendingandresuming(provider-orchestration.ts).suspendedAtis set and a follow-up waits on it (provider-orchestration.ts).host-offlinewait with no schedule (dispatch-attempt.ts). Only a daemon reconnect releases it.This happened on a berth sandbox: earlyoom sent SIGTERM to the daemon, its launcher exited 0, and the thread stayed
waiting-for-hostwith its message queued until someone restarted the daemon by hand.#6159 makes the launcher restart a daemon after such a kill. This PR is the server-side recovery for every case the launcher cannot cover: the launcher itself stopped, or a daemon that exited for any other reason on a machine with no service manager.
What changed
When a machine needs it (
apps/server/src/services/machines/provider-orchestration.ts):activeMachineNeedsResume(deps, hostId)is true for a machine that meets all of these:resume;active, with no connected daemon;HOST_RECONNECT_GRACE_MS(30 s) ago;suspendRetryAt;host-offlinequeued message, or anactive,startingorstoppingthread. The thread check ismachineHasRunningThreads, new inpackages/db/src/data/machines.ts.The 30 s is measured from
lastSeenAt, which heartbeats refresh every 5 s, so it also covers a daemon that died while the server was down.How it is repaired:
resumeMachine(deps, hostId, { includeActive: true })runs the provider's existingresumefor such a machine.resumecontract already requires reusing compute that still runs.resumeends with runs the installer's--start, which returns as soon as a daemon answers.Who asks for it:
host-offlinenow requests machine readiness (dispatch-attempt.ts);ensureHostSessionReadyForWork(queued-message-dispatch.ts);POST /hosts/:id/resumeandbb machine resume, which did nothing for an active machine before.Failures:
activewithMachine resume failed: …and retries after 60 s. A suspended machine keeps its 10 s retry.bb machine resumeexits 1 with that message instead of printing that the machine resumed. Its description now covers an active machine whose daemon is gone.Docs:
packages/templates/src/templates/bb-guide-machines.md;plugins/bb-guide/skills/bb-plugin-authoring/references/backend-machines.md;resumedeclaration comment inpackages/plugin-sdk/src/machine-provider.ts;bb.experimental_machinesand "Machine enrollment and bootstrap" entries indocs/api_to_audit.md. They gain a stabilization criterion: resuming an active machine must reuse its running compute, and must not restore an older snapshot over compute that is still there.Compatibility:
HOST_DAEMON_PROTOCOL_VERSIONstays 251.@get-bb/plugin-sdk0.6.73 is not on npm yet, so the version guard passes without a bump. If 0.6.73 ships first, this needsnode scripts/bump-plugin-sdk.mjs --patch.For review
Machine resume failed: …message until the next successful resume (machine-status.ts). Until the retry time passes, a suspend of it is refused, for up to 60 s, becausemaintainMachinecheckssuspendRetryAt. Clearing both when the daemon reconnects would be a small follow-up.plugins/environment-modal-sandbox/providers/modal/backend.ts). Hence the new stabilization criterion.How you verified
New tests, each failing on
1e80ca7b4and passing here:apps/server/test/services/machines/lifecycle-recovery.test.ts, 6 cases:resume;activeuntil its retry time, then retries.apps/server/test/public/public-thread-offline-followup.test.ts: a follow-up sent after the grace resumes the machine and dispatchesturn.submit. With only the dispatch trigger removed, it fails again (Tests 1 failed | 3 passed (4)), so it exercises dispatch, not the sweep.apps/server/test/threads/machine-lifecycle.test.ts, 2 cases: the resume route resumes an active machine only when its daemon is gone.apps/cli/src/__tests__/command-output/machine.test.ts:bb machine resumeexits 1 with the failure message.Failures on
1e80ca7b4:Totals:
1e80ca7b4Tests 5 failed | 20 passed (25)Tests 25 passed (25)Tests 1 failed | 23 passed (24)Tests 24 passed (24)Commands:
pnpm exec turbo run typecheck --filter=@bb/server --filter=@bb/cli --filter=@bb/db --filter=@get-bb/plugin-sdk --filter=@bb/templates: 11/11 tasks pass.pnpm exec turbo run testwith the same filters, plus--filter=bb-plugin-bb-guide --filter=bb-plugin-plugin-api-docs: 16/16 tasks pass;@bb/serverhas 3684 passed and 1 skipped.node packages/plugin-sdk/scripts/check-npm-version-guard.mjs: pass.Not run live: a real provider machine whose daemon dies.