fix(cloud): durably retry observed destroy cleanup
Follow-up to #15359. Observed provider-side destruction can finish the database transition while model-plane revocation or per-machine home-volume deletion fails. This makes those external cleanup steps durable and independently retryable, including across account deletion.
The repair also validates the closed cleanup shape, keeps the retry queue bounded/fair, and transfers terminal cleanup to a standalone outbox before account rows are removed.
Evidence:
- Before: explicit destroy cleanup failures were logged and then forgotten; account deletion could remove the only retry marker.
- After:
bun test --isolate tests/vm-workflows.test.ts— 79 pass, 80 database-gated skips, 0 failures. bun run typecheck— pass.- Independent exact-head review — clean.
- Canonical autoreview and cmux policy gate — clean.
— Mochi
Need help on this PR? Tag @codesmith-bot with what you need. Autofix is disabled.
Summary by cubic
Follow-up to #15359. Makes provider-observed destroy cleanup durable and independently retryable. Previously, when a VM was observed destroyed, model-plane revocation and home-volume deletion could fail and be logged and forgotten; account deletion could also remove the only retry marker. Cleanup steps now persist in an outbox and retry with a bounded, fair queue.
- The status read, access preflight, and stats read now finish the destroy transition themselves, including revoking model-plane tokens and recording the
vm.destroyedevent; the status is derived in a shared path so a provider 404 means the same thing everywhere. - Persists pending model-plane revoke and home-volume delete steps in
cloud_vm_observed_destroy_cleanups. - Transfers terminal cleanup to the outbox before account rows are removed, so account deletion can no longer lose the retry marker.
- Validates the closed cleanup shape via a check constraint and adds a partial index for efficient retry scans.
- Providers without legacy
deleteHomeVolumesupport now report failure instead of silently succeeding. - Migration runner executes each migration in its own transaction so the concurrent index can be created on PlanetScale, and retries when a concurrent index is left invalid.
Summary by CodeRabbit
- Bug Fixes
- VMs confirmed as destroyed by their provider are now retired promptly, even when they have an attached home volume.
- Cleanup of VM credentials and exclusively owned home volumes can be retried independently if it cannot be completed immediately.
- Missing provider VMs are handled consistently during status checks, and successful status updates are reflected in usage records.
- Cleanup is no longer reported as successful when the provider does not support deleting a home volume.