Skip to content

fix: handle VM deleted in GCP while Firestore record still exists (#6891) - #6892

Merged
beastoin merged 1 commit into
mainfrom
fix/6891-agent-status-vm-deleted-gcp
Apr 28, 2026
Merged

beastoin merged 1 commit into
mainfrom
fix/6891-agent-status-vm-deleted-gcp

Conversation

@thainguyensunya

Copy link
Copy Markdown
Collaborator

Fix: handle VM deleted in GCP while Firestore record still exists (#6891)

  • Add delete_agent_vm to FirestoreService to clear the agentVm field
  • Return "NOT_FOUND" from check_gce_instance_status on HTTP 404 instead of silently falling through as "UNKNOWN"
  • Add NOT_FOUND match arm in get_agent_status to delete stale Firestore record and return null, allowing client to re-provision

@greptile-apps

greptile-apps Bot commented Apr 20, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR fixes a state-drift bug where a GCE VM had been deleted in GCP but its agentVm record persisted in Firestore, causing the status endpoint to return stale data indefinitely. The fix propagates a proper NOT_FOUND signal from check_gce_instance_status, adds a corresponding match arm in get_agent_status to clear the stale record via a new delete_agent_vm helper, and returns null so the client can re-provision cleanly.

Confidence Score: 5/5

Safe to merge — the fix is correct and the only finding is a minor missing error log.

All three changes are logically sound: the 404 detection, the NOT_FOUND match arm, and the Firestore field-deletion via updateMask are all correct. The one P2 finding (silently dropped deletion error) doesn't affect correctness since the client gets None and can re-provision regardless.

No files require special attention.

Important Files Changed

Filename Overview
desktop/Backend-Rust/src/routes/agent.rs Adds NOT_FOUND match arm in get_agent_status to handle stale Firestore records and returns HTTP 404 from check_gce_instance_status; logic is correct, only minor: deletion error is silently dropped.
desktop/Backend-Rust/src/services/firestore.rs Adds delete_agent_vm helper that uses the Firestore updateMask field-omission pattern to delete the agentVm field; implementation is correct.

Sequence Diagram

sequenceDiagram
    participant Client
    participant AgentRoute as get_agent_status
    participant GCE as check_gce_instance_status
    participant Firestore

    Client->>AgentRoute: GET /agent/status
    AgentRoute->>Firestore: get agentVm record
    Firestore-->>AgentRoute: agentVm exists (stale)
    AgentRoute->>GCE: GET instances/{vm_name}
    GCE-->>AgentRoute: HTTP 404
    Note over GCE,AgentRoute: NEW: return "NOT_FOUND"
    AgentRoute->>Firestore: delete_agent_vm(uid)
    Note over AgentRoute,Firestore: NEW: omit agentVm from body,<br/>include in updateMask → field deleted
    Firestore-->>AgentRoute: OK
    AgentRoute-->>Client: null (re-provision)
Loading

Reviews (1): Last reviewed commit: "fix: handle VM deleted in GCP while Fire..." | Re-trigger Greptile

"VM {} no longer exists in GCP — clearing Firestore record",
vm.vm_name
);
let _ = state.firestore.delete_agent_vm(&user.uid).await;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Silently dropped Firestore deletion error

The let _ = ... pattern discards any error from delete_agent_vm. If the deletion fails (e.g., a permissions issue), the function still returns None — meaning the client will re-provision — but the stale agentVm record will remain in Firestore. Every subsequent status poll will hit GCP, get 404 again, silently attempt deletion again, and return None, with no observable signal that the cleanup is broken. Adding an error log helps surface this.

Suggested change
let _ = state.firestore.delete_agent_vm(&user.uid).await;
if let Err(e) = state.firestore.delete_agent_vm(&user.uid).await {
tracing::error!(
"Failed to delete stale agentVm record for uid {}: {}",
user.uid, e
);
}

@beastoin

beastoin commented Apr 21, 2026 •

Copy link
Copy Markdown
Collaborator

@thainguyensunya which problem this pr help solve?

@thainguyensunya

Copy link
Copy Markdown
Collaborator Author

@thainguyensunya which problem this pr help solve?

@beastoin This PR addresses the issue #6891.
In brief, it handles the case where an omi-agent VM is created and later removed due to inactivity. Currently, if a user’s omi-agent is still stored in Firestore but the VM has been deleted, the system fails to pre-provision the VM and returns an error.

This PR resolves that issue by properly handling the missing VM scenario and allowing the provisioning pipeline to trigger the creation of a new omi-agent VM.

@beastoin
beastoin merged commit d2e540f into main Apr 28, 2026
3 checks passed
@beastoin
beastoin deleted the fix/6891-agent-status-vm-deleted-gcp branch April 28, 2026 04:24
@beastoin

Copy link
Copy Markdown
Collaborator

@thainguyensunya lgtm, merged

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. -->
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