Skip to content

feat(agent-vm): minimum spend — delete undemanded capacity, read-only status, opt-in provisioning - #11761

Merged
Git-on-my-level merged 3 commits into
mainfrom
feat/agent-vm-minimum-spend
Aug 17, 2026
Merged

Git-on-my-level merged 3 commits into
mainfrom
feat/agent-vm-minimum-spend

Conversation

@Git-on-my-level

@Git-on-my-level Git-on-my-level commented Aug 17, 2026 •

Copy link
Copy Markdown
Member

Agent VM minimum spend: delete undemanded capacity, read-only status, opt-in provisioning

Implements the code half of the minimum-spend prescription
(docs/superpowers/specs/2026-08-17-agent-vm-minimum-spend-design.md, in this
PR). Operator instruction: aggressive savings, small UX degradation accepted.

Why

Measured on 2026-08-17 (prod agent-proxy logs + billing export):

  • Zero successful agent sessions since Aug 13; 761 sessions / 41 users in
    30 days. Last 24h: 135 attempts from 43 users, none reached a VM.
  • Run rate before the operator's mass-stop: $3,725/week ($2,050 VM +
    $964 disk + $711 IP). After the stop, 1,208 stopped-fleet disks keep
    billing ~$6,040/month
    — stop preserves disks; only delete reclaims them
    (autoDelete).
  • Within an hour of the stop, 10 VMs were RUNNING again via wake-on-open and
    reconciler drift-restarts. Without these changes the stop is a one-shot.

Root allocation error: cost is O(registered users × 24h), demand is
O(concurrent sessions × session length).

What changes

  1. Reconciler: undemanded ⇒ deleted, never stopped-and-kept
    (backend/jobs/agent_vm_reconciler.py, services/agent_vm_lifecycle.py).
    • Stopped VM with no start demand, no session lease, no active boot-image
      migration → identity-fenced delete_instance + owner record marked
      missing (provision can replace immediately; terminal cleanup erases the
      record after the existing grace).
    • Idle RUNNING VM → deleted after AGENT_VM_IDLE_TEARDOWN_SECONDS
      (renamed from AGENT_VM_IDLE_STOP_SECONDS, which no deployment sets;
      default lowered 1h → 30m, floor unchanged at 30m).
    • Drift path repairs-and-restarts only on start demand; a drained
      drifted VM without demand is deleted in the same run (retires the
      stop-rewrite-restart loop resurrecting broken guests ~90×/day).
    • Undemanded RUNNING VM behind recreate_required boot-image drift is
      stopped so the next run deletes it, instead of billing forever behind a
      terminal marker.
    • No unique data is lost: the state disk holds a client-uploaded SQLite
      copy (guest errors Upload omi.db first without it) and the Chrome
      profile is a Docker tmpfs that never persisted.
  2. Wake-on-open retired (services/agent_vm_read.py,
    routers/desktop_agent_vm.py): GET /v2/agent/status and the shared read
    decision are strictly observational — they demote stale ready caches and
    record provider 404s but never queue reconciler start demand.
    AgentVmReadDecision.queue_start is removed. Real wake paths unchanged:
    agent-proxy connect and POST /v1/agent/vm-ensure still call
    request_vm_start.
  3. Provisioning dark by default (routers/desktop_agent_vm.py,
    .github/workflows/desktop_backend_auto_dev.yml): creating a VM (or
    replacing a provider-confirmed missing pointer) requires
    AGENT_VM_PROVISIONING_ENABLED=true. Existing live owners keep the
    idempotent exists path (legacy-principal test included), so released
    desktops hit their existing provision-failed logging and continue. Dev
    auto-deploy sets the flag (dogfood); prod deliberately does not — the
    next prod deploy of this SHA turns new-VM creation off in prod.

Docs updated in the same PR: fleet-reconciler runbook, reaper chart README,
and the prescription spec (targets, quantified UX cost, ranked
operator-vs-code actions, rejected options, sequencing).

UX spent (accepted by the operator)

  • Prod feature is dark for users without a live VM until the flag is set.
    Measured regression today: zero (no user completes a session now; they get
    an honest 503 instead of a broken spinner).
  • Warm start (~60–90s) becomes cold provision (~2–5 min + DB re-upload) after
    ≥30 min idle. Affected population at current demand: ~1 user.
  • App launch / status polling never resurrects a VM; only a real connect does.

Test-rewrite justification (AGENTS.md rule)

test_desktop_status_* (authority tripwire) and the wake-on-open tests assert
the inverted contract. External basis cited in the tests: prod agent-proxy
measurement (135 status-driven restart attempts in 24h, zero successful
sessions) and the 2026-08-17 operator cost directive.

Explicitly NOT in this PR

  • No live GCE/GCS/Cloud Run mutation. Deleting the 1,208-disk stopped fleet,
    promoting to prod, and (optionally) flipping the reaper live are operator
    actions listed in the prescription doc.
  • No machine-type/disk/Spot changes, no omi-agent VM Public IP Exposure & Storage Cost Leak #7326 public-IP removal (now a
    security item, ~$0 cost after teardown), no Cloud Run runtime migration
    (superseded in priority; see prescription).

Verification

Interpreter: backend/.venv (repo test runner env; the older backend/venv
lacks pytest-asyncio and fails at baseline).

  • pytest tests/unit/test_agent_vm_reconciler_job.py -q → 104 passed
  • pytest tests/unit/test_desktop_agent_vm.py tests/unit/test_agent_vm_read_decision.py tests/unit/test_agent_vm_reconciler_authority.py -q → 52 passed
  • Adjacent suites (test_agent_vm_reconciler.py, test_agent_vm_reaper.py,
    test_tools_agent_route_response_shape.py, test_agent_vm_account_cleanup.py,
    …) → 56 passed; second batch (async/protocol/firewall/health/reaped-
    record/deploy-scripts/scheduler) → 83 passed
  • Post-format re-run of the four changed suites → 156 passed
  • scripts/scan_async_blockers.py --dirs routers → 0 findings
  • Pre-existing, unrelated: tests/unit/test_agent_vm_startup.py fails
    identically (21F) on unmodified main in this environment.
  • Not exercised live: reconcile-vs-GCE deletion on a real instance (no live
    mutations allowed in this task); covered by fenced unit tests + dev bake.

Line-Count-Exception: backend/jobs/agent_vm_reconciler.py | 1912 -> 1995 | teardown policy lives beside the drift/idle branches it replaces; splitting the reconciler mid-policy-change would be the unreviewable migration AGENTS.md forbids
Line-Count-Exception: backend/services/agent_vm_lifecycle.py | 2126 -> 2145 | one identity-fenced delete_instance next to the existing fenced delete_replacement it mirrors

Rollout

Dev bake via auto-deploy (reconciler job + desktop-backend), watch:
teardown results in reconciler logs, no deletion of leased VMs, provision 503
absent on dev (flag on). Prod promote is the operator's call and is what
activates dark provisioning + fleet-regrowth prevention in prod.

🤖 Generated with Claude Code

Review in cubic

Git-on-my-level and others added 3 commits August 17, 2026 17:29
…opping

Minimum-spend policy (2026-08-17): a VM and its autoDelete disks may exist
only around session demand. Measured basis: 1,208 stopped-fleet disks bill
~$6,040/month while the feature served zero successful sessions since
Aug 13 (prod agent-proxy logs).

- A stopped VM with no start demand, no session lease, and no active
  boot-image migration is deleted (numeric-instance-ID-fenced) and its owner
  record is marked missing so provisioning can claim a replacement.
- Idle RUNNING VMs are deleted after AGENT_VM_IDLE_TEARDOWN_SECONDS
  (renamed from AGENT_VM_IDLE_STOP_SECONDS; default lowered 1h -> 30m).
- The drift path repairs-and-restarts only on start demand; a drained
  drifted VM without demand is deleted in the same run, retiring the
  stop-rewrite-restart loop on permanently broken guests (~90 resets/day).
- Undemanded RUNNING VMs behind a recreate_required boot-image record are
  stopped so the next run deletes them.
- GceAgentVmClient.delete_instance is the new identity-fenced delete;
  callers must hold the owner lease and observe zero session leases.

State loss is nil by construction: the state disk holds a client-uploaded
SQLite copy (guest errors 'Upload omi.db first' without it) and the Chrome
profile is a tmpfs that never persisted.

Verification: cd backend && .venv pytest
tests/unit/test_agent_vm_reconciler_job.py (104 passed), plus
test_agent_vm_reconciler.py, test_agent_vm_reaper.py,
test_agent_vm_reaped_record_recovery.py in the adjacent-suite run.

Co-Authored-By: Claude Opus 5 <[email protected]>
Wake-on-open retired: GET /v2/agent/status and the shared read decision
never queue reconciler start demand. Measured basis (prod agent-proxy,
trailing 24h): 135 status/poll-driven restart attempts against zero
successful sessions. Real wake paths are unchanged: agent-proxy connect
and POST /v1/agent/vm-ensure still call request_vm_start.

POST /v2/agent/provision is dark by default: creating a VM (or replacing
a provider-confirmed missing pointer) requires
AGENT_VM_PROVISIONING_ENABLED=true. Existing live owners keep the
idempotent exists path, so released desktops degrade to their existing
provision-failed logging. Dev auto-deploy sets the flag for dogfood;
prod deliberately does not.

The authority tripwire now asserts get_agent_status has no
request_vm_start path (contract change cited to the 24h measurement, per
the test-rewrite rule).

Verification: cd backend && .venv pytest
tests/unit/test_desktop_agent_vm.py tests/unit/test_agent_vm_read_decision.py
tests/unit/test_agent_vm_reconciler_authority.py (52 passed);
scripts/scan_async_blockers.py --dirs routers (0 findings).

Co-Authored-By: Claude Opus 5 <[email protected]>
Target steady state, quantified UX cost, ranked operator vs code actions,
rejected options (incl. superseding the Cloud Run session-runtime track in
priority), risks, and sequencing.

Co-Authored-By: Claude Opus 5 <[email protected]>
@mintlify

mintlify Bot commented Aug 17, 2026 •

Copy link
Copy Markdown

Preview deployment for your docs. Learn more about Mintlify Previews.

Project Status Preview Updated (UTC)
omi 🟢 Ready View Preview Aug 17, 2026, 9:42 PM

💡 Tip: Enable Workflows to automatically generate PRs for you.

@Git-on-my-level
Git-on-my-level merged commit 2157329 into main Aug 17, 2026
44 checks passed
@Git-on-my-level
Git-on-my-level deleted the feat/agent-vm-minimum-spend branch August 17, 2026 22:56
Git-on-my-level added a commit that referenced this pull request Aug 18, 2026
… control plane (#11795)

## Retire the cloud Agent VM: tombstone the broker endpoints and delete
the control plane

Analysis of record: **SCA-339** (passive agent surface), **SCA-340**
(migration mechanics), **SCA-341** (constraints/entitlements/privacy).
Operator authorization 2026-08-17: "have the same omp agent open a PR
for the deletion and retirement." Follows merged #11761 (minimum-spend
freeze: opt-in provisioning, read-only status, reconciler deletes
undemanded VMs).

### The measured case

- 1,179 → **48 GCE instances** (1,131 deleted 2026-08-17; the 48 stopped
survivors are deliberately kept pending an export-window decision).
- **~$5,800/mo reclaimed** at the July peak (~$240/mo remains while the
48 stopped instances are held).
- **2,773 lifetime sessions across 106 users; zero successful sessions
since 2026-08-13**; ~0.1% utilization at the July peak (41 distinct
users/30d).

### Why this is route-and-delete, not a rewrite

The VM never defined its own integration tools: `agent_vm/main.py`
fetched tool definitions from `GET /v1/agent/tools` and executed them
via `POST /v1/agent/execute-tool` — the same endpoints the managed
`omi:auto:chat-agent` path uses. **Those two endpoints stay.** Mobile
chat never used a VM (the only mobile door was the default-off
`claudeAgentEnabled` dev flag, removed here); desktop chat runs through
`/v2/chat/completions` + the local agent runtime. Only the per-user GCE
capacity and its control plane die.

### What is lost with no equivalent

- Cloud browser automation (Playwright on the VM).
- Cloud-resident general compute (Bash/workspace on a server filesystem)
for users without the desktop app.
- Ad-hoc cross-table read-only SQL over synced desktop data (per-domain
tools remain).
- Phone access to desktop-synced screen data (screenshot semantic
search, daily recaps from the phone).

Demand for all four was the long tail (peak 41 users/30d, zero sessions
since 2026-08-13).

### Security improvement

The VM path uploaded a **plaintext SQLite replica of desktop data to a
per-user GCE disk**, and the proxy forwarded the user's **Firebase token
over plaintext HTTP** (`ws://<ip>:8080/ws?token=…`) to a box running the
Claude Agent SDK with `permission_mode="bypassPermissions"` and Bash.
Deleting the fleet removes that entire exposure class; managed inference
already runs in the encrypted-at-rest Firestore trust domain every other
Omi feature uses.

### The client contract (the only change that hits every old client at
once)

Old desktop clients (Stable 0.12.144 / Beta 0.12.186) keep calling the
broker until they update, so the two desktop endpoints become
**permanent tombstones**, pinned by contract tests
(`backend/tests/unit/test_desktop_agent_vm.py`):

- `POST /v2/agent/provision` → **410**. Never 401 — `APIClient` has
`signOutOn401: true` and a retirement must not force sign-outs.
- `GET /v2/agent/status` → **200 with a `null` body**. Never `200` +
`status:"provisioning"` without an IP — old clients would poll 75×5s
(~6.25 min).
- `POST /v2/agent/vm/stop-self` → 410 (only the deleted guest image ever
called it).
- `GET/POST /v1/agent/vm-status|vm-ensure|keepalive` → **removed
outright** (zero desktop callers; generated Swift only; mobile callers
removed in this same PR). Recorded in `DELIBERATELY_REMOVED_ENDPOINTS`
in `check_app_client_openapi_compatibility.py` so the app-client
compatibility gate still rejects every *accidental* removal.

**Mobile ordering question, resolved:** deleting the code is not tearing
down the running service. The GKE agent-proxy keeps serving its last
image until the operator decommissions it (runbook below), so builds
with `claudeAgentEnabled=true` are no worse off than today — they are
*already* broken against a fleet with zero running VMs. Removing the
toggle starts the clock on aging them out.

### INV-DATA-1 (named because this touches `app/lib/env/env.dart`)

The invariant's routing table pinned `wss://agent.omi.me/v1/agent/ws` as
canonical Flutter agent routing, `env.dart` threw at startup if prod
didn't match, and `env_test.dart:121,126` asserted it. This PR removes
the retired surface from the routing table, the startup guard, and the
guard tests in the same change — routing authority now covers only the
surfaces that still exist. No other INV-DATA-1 row changes.

### What is deleted

`backend/agent-proxy/` (the GKE WS bridge), `backend/agent_vm/` (guest
image), `backend/jobs/agent_vm_reconciler.py`,
`backend/services/agent_vm_{lifecycle,migration_control,read}.py`,
`backend/routers/desktop_agent_vm.py`'s 900-line broker (replaced by the
~50-line tombstone module), the 15 `backend/scripts/` agent-vm scripts,
the `agent-proxy` / `agent-vm-firewall` / `agent-vm-reaper` charts, both
`gcp_backend_agent_proxy*.yml` workflows, the Agent VM image build +
reconciler deploy + release-pointer promotion steps in
`desktop_backend_{prod,auto_dev}.yml` (plus their `AGENT_VM_*`/`GCE_*`
service env vars, now explicitly `--remove-env-vars`'d), ~20 dead test
files, the 6 agent-vm failure-class JSONs, and the docs/runbooks that
died with it.

**Deliberately kept:** `/v1/agent/tools` + `/v1/agent/execute-tool`
(passive agent tool surface), `agent_vm_account_cleanup.py` and the
account-deletion purge path (48 VMs still hold plaintext user data —
deleting them is a live privacy obligation until the fleet is gone), and
the entire desktop-local agent runtime (`INV-AGENT-*`, `INV-CHAT-1` —
the surface that actually delivers Architect's sold "Automations and
vibe coding"; Windows sells Architect with no cloud VM ever).

### Operator runbook (out of scope for this PR — gcloud work, in order)

1. **Cloud Scheduler:** pause then delete job `agent-vm-reconciler-5m`
(both projects if dev runs one).
2. **Cloud Run:** delete job `agent-vm-reconciler` (it rides the
desktop-backend image; nothing in this PR deploys it anymore).
3. **GKE:** delete the agent-proxy Deployment/Service/Ingress/Helm
release and the reaper CronJob `prod-agent-vm-reaper` (namespace
`prod-omi-backend`), then remove the `agent.omi.me` DNS record.
4. **Firewall:** delete rules `omi-agent-vm-allow-private-8080` and
`omi-agent-vm-deny-public-8080` (target tag `omi-agent-vm`).
5. **IAM:** delete custom roles `omiAgentVmReconciler`,
`omiAgentVmReconcilerOperations`, `omiAgentVmReconcilerSubnetwork`,
`omiAgentVmSelfStop`; delete service accounts `agent-vm-reconciler@`,
`omi-agent-vm-bootstrap@`, `agent-vm-reaper@` and their bindings (incl.
KSA `prod-agent-vm-reaper-sa` Workload Identity binding).
6. **GCS:** delete `gs://$AGENT_GCS_BUCKET/agent-vm/releases/**`
(release pointers/startup manifests).
7. **Compute image family:** delete the `omi-agent` image family.
8. **The 48 stopped instances** (`omi-agent-*`, ~2,400 GB disks):
**irreversible** — decide the export window first. Their workspace files
have no download endpoint; the only export paths are (a) restart an
instance on request and drive a live session, or (b) snapshot the disk
to GCS and hand over a link. Holding them stopped costs ~$240/mo.
9. **Later, scripted (tracked as a follow-up issue):** Firestore sweep
of `users.agentVm.*`, `users/{uid}/agentVmMigrations`,
`account_deletions.late_agent_vm_cleanup`, and the
`agent_vm_reconciler_leases` collection — only after the fleet is empty;
then retire `agent_vm_account_cleanup.py`.

Rollback for steps 1–3 is the prior Cloud Run revision / re-applying the
charts from git history (minutes). The tombstone endpoints themselves
need no rollback — they are additive responses on paths old clients
already tolerate.

### Rollback for this PR

Prior Cloud Run revision of desktop-backend, minutes (env flips are
per-revision). The PR itself reverts cleanly: the deleted surfaces have
no remaining callers.

### Out of scope (tracked as stage-3 issues under the parent)

Desktop client removal of `AgentVMService`/`AgentSyncService` (~1.76k
LOC, rides the desktop release train); the Firestore sweep; the
account-cleanup retirement; the infra teardown above.


<!-- This is an auto-generated description by cubic. -->
<a
href="https://cubic.dev/pr/BasedHardware/omi/pull/11795?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. -->
pull Bot pushed a commit to Mu-L/omi that referenced this pull request Aug 18, 2026
The cloud Agent VM (one GCE e2-small per user running a Claude coding
agent) is retired: 2,773 lifetime sessions across 106 users, zero since
2026-08-13, ~0.1% peak utilization. Its integration toolset was fetched
from /v1/agent/tools + /v1/agent/execute-tool, which the managed
omi:auto:chat-agent path already serves - those endpoints stay.

Server contract for old desktop clients (pinned by contract tests):
- POST /v2/agent/provision -> 410 (never 401: APIClient signOutOn401
  force-signs-out)
- GET /v2/agent/status -> 200 null body (never provisioning-without-IP:
  6.25-min poll loops)
- /v1/agent/{vm-status,vm-ensure,keepalive} removed (zero desktop
  callers; recorded in DELIBERATELY_REMOVED_ENDPOINTS so the app-client
  compatibility gate still rejects accidental removals)

Deleted: agent-proxy WS bridge, agent_vm guest image, reconciler job,
agent_vm_{lifecycle,migration_control,read} services, 15 scripts, 3
charts, both gcp_backend_agent_proxy workflows, agent-vm release +
reconciler deploy steps and env in desktop_backend_{prod,auto_dev},
~20 dead test files, 6 failure classes, mobile claudeAgentEnabled door
(WS client, env constant, Dart agent codegen group), INV-DATA-1
routing row + env startup guard + guard tests, dead docs/runbooks.

Kept: /v1/agent/{tools,execute-tool}, agent_vm_account_cleanup (48
stopped VMs still hold plaintext user data - live privacy obligation),
desktop-local agent runtime (INV-AGENT-*), desktop-backend image smoke
now explicit in both deploy workflows.

Analysis of record: SCA-339/340/341. Follows merged BasedHardware#11761.

Co-authored-by: multica-agent <[email protected]>

This branch was successfully deployed

1 active deployment
staging - docs — f429e62a Deployed Aug 17, 2026 by mintlify[bot]
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.

1 participant