Repository navigation
fix(backend): clear the agentVm record when its GCE instance is gone (reaped VM strands agent chat) - #10694
Merged
Conversation
The agent-vm reaper deletes aged TERMINATED omi-agent-* instances but leaves
users/{uid}.agentVm saying "ready" with the deleted VM's IP. Both Python
readers folded the GCE 404 into "UNKNOWN": _ensure_vm_running fell into its
"STAGING, etc. — let it be" branch and returned the stale record, so
agent-proxy dialed a dead address and waited out the full 120s health timeout
before answering "Agent VM is not responding", and POST /v1/agent/vm-ensure
answered "ready". Nothing repaired the record, and the desktop provision
endpoint reports "exists" while it is present, so the user's agent chat stayed
broken on every later attempt. 20 distinct users hit this in prod on
2026-07-25..26 (repeat attempts per user).
Report 404 as NOT_FOUND (distinct from "could not tell") and, only for that
status, delete the record — the same resume contract GET /v2/agent/status
already implements on the desktop Rust path. UNKNOWN still leaves a live VM's
record untouched.
Verified: real WS route through the agent-proxy FastAPI app with GCE returning
404 — before: 120.1s to close, 41 probes of the dead IP, "Agent VM is not
responding", record untouched; after: 0.02s, 1 probe, error + record cleared.
Regression tests fail on the pre-fix code (4/6) and pass after; 63 tests green
across the agent VM / agent-proxy / route-shape suites.
Failure-Class: FC-agent-vm-stop-retains-disk
Git-on-my-level
added a commit
that referenced
this pull request
Aug 4, 2026
…ks (#11029) ## Summary - Make the durable `account_deletions/{uid}` marker a single fail-closed admission policy across Firebase, developer/MCP keys, OAuth issuance, HTTP/WebSocket entry points, Agent proxy sessions, and Agent VM provisioning. Completed and unknown markers remain fenced so an old token cannot revive a deleted UID. - Make deletion admission atomic at `pending`, revoke UID-bearing API/OAuth credentials, delete the account's GCE Agent VM before its Firestore pointer disappears, and transactionally fence late proxy/VM writes so in-flight work cannot recreate owner data. - Make accepted macOS cleanup durable across restart, drain owner-bound VM/sync work before deleting storage, remove the legacy anonymous fallback, upload a consistent SQLite snapshot with cancellable compression and bounded retries, and preserve typed startup errors in Flutter. Repeated delete requests during `pending`/`running` intentionally receive typed `403 account_deletion_in_progress` responses without marker rollback or requeue. The deletion fence is preserved. Canonical project: [BasedHardware Project #15](https://github.com/orgs/BasedHardware/projects/15) ## Sanitized incident evidence - A delete confirmation preceded a later same-provider sign-in/onboarding sequence by nine days. - The deleted UID's user document and GCE instance were gone, while its durable deletion marker completed after retried queue acceleration failures. - No verified event proves old server memory reads after deletion. This PR treats legacy local-database migration, still-valid old credentials, and late owner-scoped work as identity-isolation risks; typed readiness failures remain timeout-class evidence rather than proof of server data disclosure. Related lineage: #10444, #7696, #9632, #10597, #9821, #6891, #6892, #10600, and #10694. ## Failure class Failure-Class: none This is an audit-driven hardening sweep across durable deletion admission, credential revocation, local owner-data disposal, and Agent VM/proxy lifecycle safety. The reusable prevention surfaces are the shared fail-closed policy, transactional admission/CAS writers, the durable local cleanup journal, the effective-owner generation fence, and behavioral regression tests. ## Product invariants affected - INV-AUTH-1 — preserves the exclusive effective-owner transition, clears accepted-deletion storage before credential/session publication, blocks every credential family after durable admission, and rejects late owner-bound Agent VM continuations. - INV-CHAT-1 — drains Agent VM/sync work at the existing owner transition, transactionally fences late proxy message/session writes, and preserves typed startup failures without changing canonical transcript ownership. ## Changed paths - `.github/scripts/product_file_line_count_ratchet_baseline/backend-database.json` - `.github/scripts/product_file_line_count_ratchet_baseline/backend-routers.json` - `.github/scripts/product_file_line_count_ratchet_baseline/desktop-swift-root.json` - `app/lib/services/agent_chat_service.dart` - `app/test/services/agent_chat_service_test.dart` - `backend/agent-proxy/Dockerfile` - `backend/agent-proxy/main.py` - `backend/database/account_deletion_projection_fence.py` - `backend/database/mcp_oauth.py` - `backend/database/users.py` - `backend/dependencies.py` - `backend/routers/apps.py` - `backend/routers/desktop_agent_vm.py` - `backend/routers/mcp_sse.py` - `backend/routers/oauth.py` - `backend/routers/transcribe.py` - `backend/services/users/account_deletion.py` - `backend/testing/e2e/test_account_deletion_cloud_tasks.py` - `backend/tests/services/users/test_account_deletion.py` - `backend/tests/unit/test_account_deletion_auth_fence.py` - `backend/tests/unit/test_agent_proxy_async_boundaries.py` - `backend/tests/unit/test_agent_proxy_startup_client_gone.py` - `backend/tests/unit/test_byok_security.py` - `backend/tests/unit/test_dependency_async_boundaries.py` - `backend/tests/unit/test_desktop_agent_vm.py` - `backend/tests/unit/test_mcp_api_key_auth_context.py` - `backend/tests/unit/test_mcp_oauth.py` - `backend/tests/unit/test_oauth_token_async_boundaries.py` - `backend/utils/account_deletion_access.py` - `backend/utils/other/endpoints.py` - `desktop/macos/Desktop/Sources/AgentSyncService.swift` - `desktop/macos/Desktop/Sources/AgentVMService.swift` - `desktop/macos/Desktop/Sources/AuthService.swift` - `desktop/macos/Desktop/Sources/Chat/RuntimeOwnerIdentity.swift` - `desktop/macos/Desktop/Sources/DefaultsKey.swift` - `desktop/macos/Desktop/Sources/DesktopAutomationBridge.swift` - `desktop/macos/Desktop/Sources/MainWindow/Pages/Settings/Components/SettingsContentView+SettingsUpdates.swift` - `desktop/macos/Desktop/Sources/Rewind/Core/RewindDatabase+AccountDeletion.swift` - `desktop/macos/Desktop/Tests/AgentSyncBatchQueryTests.swift` - `desktop/macos/Desktop/Tests/AgentVMLifecycleFenceTests.swift` - `desktop/macos/Desktop/Tests/AuthSessionCoordinatorTests.swift` - `desktop/macos/Desktop/Tests/OnboardingPersistenceClearingTests.swift` - `desktop/macos/Desktop/Tests/RewindDatabaseLifecycleTests.swift` - `desktop/macos/changelog/unreleased/20260802-account-deletion-local-data.json` - `desktop/macos/e2e/flows/logout.yaml` ## Verification - Focused backend deletion/auth/proxy/VM suite: `194 passed`. - Hermetic Cloud Tasks deletion suite: `5 passed`; repeated pending/running requests are asserted as typed `403` without requeue. - Focused macOS deletion, owner-fence, snapshot, and sync suite: `32 tests`, `0 failures`. - Focused Flutter Agent Chat suite: `2 passed`. - Follow-up MCP OAuth consent suite: `37 passed`. - Follow-up macOS cleanup/bridge compile suite: `17 tests`, `0 failures`. - Python runtime sources compile cleanly; pinned Python/Dart/Swift formatters and `git diff --check` are clean. - Required CI-lane PR-body preflight: `34 checks passed` in `108.01s`. Backend Hermetic Merge Gate: in scope because backend runtime and hermetic contract code changed. ## Limitations - No production Firebase/Auth, Firestore, Cloud Tasks, GCE, deployment, release, or customer-data mutation was performed. - Same-provider recreation is covered hermetically at the UID/auth boundary; no live Google sign-in was attempted. - Agent readiness and teardown are covered through backend state-machine, proxy protocol, owner-generation, snapshot/upload, credential cleanup, and stale-pointer tests; no live GCE VM was provisioned. <!-- This is an auto-generated description by cubic. --> <a href="https://cubic.dev/pr/BasedHardware/omi/pull/11029?utm_source=github" target="_blank" rel="noopener noreferrer" data-no-image-dialog="true"><picture><source media="(prefers-color-scheme: dark)" srcset="https://www.cubic.dev/buttons/review-in-cubic-dark.svg"><source media="(prefers-color-scheme: light)" srcset="https://www.cubic.dev/buttons/review-in-cubic-light.svg"><img alt="Review in cubic" src="https://www.cubic.dev/buttons/review-in-cubic-dark.svg"></picture></a> <!-- End of auto-generated description by cubic. -->
undivisible
pushed a commit
to undivisible/omi
that referenced
this pull request
Sep 29, 2026
…asedHardware#10694) The agent-vm reaper deletes aged TERMINATED omi-agent-* instances but leaves users/{uid}.agentVm saying "ready" with the deleted VM's IP. Both Python readers folded the GCE 404 into "UNKNOWN": _ensure_vm_running fell into its "STAGING, etc. — let it be" branch and returned the stale record, so agent-proxy dialed a dead address and waited out the full 120s health timeout before answering "Agent VM is not responding", and POST /v1/agent/vm-ensure answered "ready". Nothing repaired the record, and the desktop provision endpoint reports "exists" while it is present, so the user's agent chat stayed broken on every later attempt. 20 distinct users hit this in prod on 2026-07-25..26 (repeat attempts per user). Report 404 as NOT_FOUND (distinct from "could not tell") and, only for that status, delete the record — the same resume contract GET /v2/agent/status already implements on the desktop Rust path. UNKNOWN still leaves a live VM's record untouched. Verified: real WS route through the agent-proxy FastAPI app with GCE returning 404 — before: 120.1s to close, 41 probes of the dead IP, "Agent VM is not responding", record untouched; after: 0.02s, 1 probe, error + record cleared. Regression tests fail on the pre-fix code (4/6) and pass after; 63 tests green across the agent VM / agent-proxy / route-shape suites. Failure-Class: FC-agent-vm-stop-retains-disk
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.
Bug (live prod)
backend/scripts/agent_vm_reaper.py(CronJob) deletes aged TERMINATEDomi-agent-*instances to stop boot-disk billing, but it leavesusers/{uid}.agentVmsayingstatus: readywith the deleted VM's IP. Both Python readers folded the GCE404into"UNKNOWN":agent-proxy_ensure_vm_running→if gce_status not in ("TERMINATED", "STOPPED"): return vm # STAGING, etc. — let it be→ returns the stale record →agent_wsthen polls the dead IP for the full_wait_for_vm_healthy120s window and answers{"type":"error","message":"Agent VM is not responding"}.POST /v1/agent/vm-ensure→ falls through and answers{"has_vm": true, "status": "ready"}.Nothing repairs the record, and
POST /v2/agent/provisionreportsexistswhile it is present, so agent chat stays broken on every later attempt. Prod evidence (based-hardware, 2026-07-25..26): 20 distinct users whoseagentVmpoints at a GCE instance that returns 404 (e.g.omi-agent-5yc7omh3ffbg— 20 lookups,omi-agent-pkqlgn652iaf— 19), plus the matching unhandled ASGIWebSocketDisconnectwhen the user gives up before the 120s wait ends (main.py:432, 12:41:10Z).Fix
Report a 404 as
NOT_FOUND— distinct fromUNKNOWN("could not tell") — and, only for that status, delete theagentVmrecord so a client can provision a replacement. This is the resume contractGET /v2/agent/statusalready implements on the desktop Rust path (desktop/macos/Backend-Rust/src/routes/agent.rs), now extended to the two Python readers.UNKNOWNkeeps the existing leave-it-alone behavior, so a transient GCE error can never delete a live VM's record.agent-proxy/main.py:_check_gce_statusreturnsNOT_FOUNDon 404;_ensure_vm_runningclears the record and fails fast;_start_vm_and_waitraisesVmNotFoundErroron 404 so the non-readyrestart path clears it too.routers/agent_tools.py:vm-ensurereturns{"has_vm": false}and clears the record.database/users.py:delete_agent_vm(uid).What I tested
Real WS route through the agent-proxy FastAPI app (
TestClient.websocket_connect("/v1/agent/ws"), only Firebase/Firestore/GCE-HTTP edges faked, GCE instance GET → 404):Agent VM is not respondingFailed to start agent VMagentVmdeletedRegression tests —
backend/tests/unit/test_agent_vm_reaped_record_recovery.py(6 behavioral tests through the module seams): 4 fail on the pre-fix code (git stashof the three source files), all 6 pass after. Two of them assert the negative case — anUNKNOWN(500) status must leave the record intact.Suites run (
pytest):test_agent_vm_reaped_record_recovery.py,test_agent_proxy_async_boundaries.py,test_agent_vm_async.py,test_agent_vm_reaper.py,test_tools_agent_route_response_shape.py,test_scan_async_blockers.py→ 63 passed.black --line-length 120 --skip-string-normalizationclean.Product invariants affected: none (
scripts/pr-preflight --suggest).This is the stated resume contract of
FC-agent-vm-stop-retains-disk("keep the client NOT_FOUND → re-provision pathas the resume contract after delete") — the contract the Python readers never implemented. The new regression test is
recorded as that class's
canonical_prevention_artifact.Failure-Class: FC-agent-vm-stop-retains-disk
🤖 automated by hourly watchdog — tested and merged