Skip to content

Let a stranded machine finish removal without on-machine cleanup - #5859

Merged
ymichael merged 6 commits into
get-bb:mainfrom
salemsayed:fix/remove-unreachable-machine
Oct 20, 2026
Merged

ymichael merged 6 commits into
get-bb:mainfrom
salemsayed:fix/remove-unreachable-machine

Conversation

@salemsayed

Copy link
Copy Markdown
Contributor

Human comments

What was wrong

Removing a persistent provider machine whose computer is already gone never finishes. sweepProviderMachine (apps/server/src/services/machines/provider-orchestration.ts) first tears down every environment on the host, and provider-owned environment teardown runs on the host daemon. With the daemon gone each teardown fails with "Host is not connected", the host is set to teardownStatus: "failed", and the sweep retries every 60 s forever. retry-cleanup only re-runs the same teardown and the delete route has no other path, so the machine stays at "Cleanup failed · Host is not connected" in Settings → Machines with no way to finish. Seen on a real manual-provider machine whose server had been deleted before its bb removal.

What changed

  • Server: POST /hosts/:id/force-remove → forceMachineRemoval. Accepted only for a machine in removing whose teardown failed, that is disconnected, persistent, and still has environments blocking removal (409 machine_cleanup_not_failed / machine_connected / machine_cleanup_not_blocked otherwise). It waits for in-flight machine sweeps/removals and environment operations, marks the host's environments destroyed without running their teardown on the machine (markHostEnvironmentsDestroyed, as the ephemeral path does) and emits experimental_environment.removed for each, then runs the normal removal: the provider's remove, key revocation and destroyed. A provider remove failure leaves the machine retryable with retry-cleanup.
  • Race fix: environment teardown failure writes (runRemove) no longer overwrite an environment already marked removed, so a teardown that was in flight when its machine was forgotten cannot leave a destroyed row retrying forever against a destroyed host.
  • SDK hosts.experimental_forceRemove, CLI bb machine force-remove <id-or-name> [--yes], and the app: the existing Remove machine dialog (row menu and machine page) switches to "Remove without cleanup" with an explanation for a stranded machine. The thread banner for cleanup-failed machines mentions it.
  • Docs: bb guide machines template (command table and acceptance rules), CLI command index, plugin-authoring machine/SDK references, docs/api_to_audit.md, plugin API surfaces.
  • A separate route rather than bb machine remove --force: the preconditions differ, and a force flag on a healthy machine would silently skip cleanup on a reachable computer.
  • No daemon wire changes; HOST_DAEMON_PROTOCOL_VERSION unchanged.

How you verified

  • New apps/server/test/services/machines/force-removal.test.ts: a stranded machine stays stuck after retry-cleanup and is destroyed by force removal (environments destroyed, provider remove called once, environment.removed emitted, no further teardown attempts); refusals before failure and while connected; public route 409/200/404; a late in-flight teardown failure keeps the environment removed (fails without the runRemove guard); provider remove failing after the skip stays retryable; a suspended stranded machine is removed without resuming. Machine-credential 403 matrix, CLI, SDK type list and both UI dialog entry points covered.
  • pnpm exec turbo run typecheck lint for server, cli, app, sdk, server-contract, templates, bb-guide and plugin-api-docs; tests for server (machines, hosts, environments, environment providers, public host management), cli, sdk, templates, bb-guide, plugin-api-docs and the two app machine views; oxfmt --check.
  • End to end: this branch's server, network-isolated, on a copy of the real stuck database. bb machine retry-cleanup left the machine at removing/failed "Host is not connected"; force-remove on the server machine was refused with 409; force-remove on the stranded one removed it (host destroyed, all 280 of its environments destroyed/removed, other machines untouched); a second call reported the machine not found.

AGENT GENERATED

@ymichael
ymichael force-pushed the fix/remove-unreachable-machine branch from e7549e3 to 37105f4 Compare October 20, 2026 20:10
@ymichael
ymichael merged commit f539d22 into get-bb:main Oct 20, 2026
46 checks passed
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.

2 participants