Repository navigation
fix(backend): enable agent-vm reaper to stop idle disk cost leak - #10390
Conversation
Co-authored-by: Cursor <[email protected]>
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 1c32ffbbc0
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
Co-authored-by: Cursor <[email protected]>
- Remove RUNNING VM reaping entirely: agent-proxy keeps active sessions RUNNING via /ping keep-alive, and the reaper has no heartbeat signal to safely distinguish a long-lived session from an abandoned one. Reaping RUNNING VMs by creation age alone would delete VMs underneath active sessions. - Return exit code 1 when live deletes fail so the CronJob's restartPolicy: OnFailure retries instead of silently reporting success. - Replace module-scope sys.modules mutation in tests with a pytest fixture to avoid polluting the shared pytest process. Verification: BACKEND_UNIT_TEST_FILE_LIST=tests/unit/test_agent_vm_reaper.py bash test.sh — 10 passed.
8d16fe7 to
659de24
Compare
Monitor run — review feedback addressedAddressed all 3 Codex review threads:
Verification: Note: Backend unit suite failure on this PR is the pre-existing |
kodjima33
left a comment
There was a problem hiding this comment.
agent-vm reaper — approved; not auto-merged (740 lines exceeds scoped bug-fix gate)
Co-authored-by: Cursor <[email protected]>
- Remove RUNNING VM reaping entirely: agent-proxy keeps active sessions RUNNING via /ping keep-alive, and the reaper has no heartbeat signal to safely distinguish a long-lived session from an abandoned one. Reaping RUNNING VMs by creation age alone would delete VMs underneath active sessions. - Return exit code 1 when live deletes fail so the CronJob's restartPolicy: OnFailure retries instead of silently reporting success. - Replace module-scope sys.modules mutation in tests with a pytest fixture to avoid polluting the shared pytest process. Verification: BACKEND_UNIT_TEST_FILE_LIST=tests/unit/test_agent_vm_reaper.py bash test.sh — 10 passed.
659de24 to
f9ec905
Compare
|
Monitor run — rebased onto current main Rebased this branch onto the latest The remaining CI failures (Backend unit suite, Public Developer API contract) are pre-existing
The PR's own test ( |
Co-authored-by: Cursor <[email protected]>
- Remove RUNNING VM reaping entirely: agent-proxy keeps active sessions RUNNING via /ping keep-alive, and the reaper has no heartbeat signal to safely distinguish a long-lived session from an abandoned one. Reaping RUNNING VMs by creation age alone would delete VMs underneath active sessions. - Return exit code 1 when live deletes fail so the CronJob's restartPolicy: OnFailure retries instead of silently reporting success. - Replace module-scope sys.modules mutation in tests with a pytest fixture to avoid polluting the shared pytest process. Verification: BACKEND_UNIT_TEST_FILE_LIST=tests/unit/test_agent_vm_reaper.py bash test.sh — 10 passed.
f9ec905 to
9bf0c06
Compare
|
Monitor run — rebased onto current main (09ce8a7) Rebased this branch onto the latest The two failing CI checks are pre-existing
|
Co-authored-by: Cursor <[email protected]>
- Remove RUNNING VM reaping entirely: agent-proxy keeps active sessions RUNNING via /ping keep-alive, and the reaper has no heartbeat signal to safely distinguish a long-lived session from an abandoned one. Reaping RUNNING VMs by creation age alone would delete VMs underneath active sessions. - Return exit code 1 when live deletes fail so the CronJob's restartPolicy: OnFailure retries instead of silently reporting success. - Replace module-scope sys.modules mutation in tests with a pytest fixture to avoid polluting the shared pytest process. Verification: BACKEND_UNIT_TEST_FILE_LIST=tests/unit/test_agent_vm_reaper.py bash test.sh — 10 passed.
9bf0c06 to
1d2463d
Compare
|
Monitor run — rebased onto current main; OpenAPI contract now green Rebased this branch onto the latest
|
The existing CronJob was never deployed (no GSA, no prod CronJob). Stop ≠ delete, so TERMINATED omi-agent VMs keep ~50 GB pd-balanced disks. Add a dry-run-first apply path, 12h terminated grace, and selection tests. Failure-Class: new Co-authored-by: Cursor <[email protected]>
Co-authored-by: Cursor <[email protected]>
- Remove RUNNING VM reaping entirely: agent-proxy keeps active sessions RUNNING via /ping keep-alive, and the reaper has no heartbeat signal to safely distinguish a long-lived session from an abandoned one. Reaping RUNNING VMs by creation age alone would delete VMs underneath active sessions. - Return exit code 1 when live deletes fail so the CronJob's restartPolicy: OnFailure retries instead of silently reporting success. - Replace module-scope sys.modules mutation in tests with a pytest fixture to avoid polluting the shared pytest process. Verification: BACKEND_UNIT_TEST_FILE_LIST=tests/unit/test_agent_vm_reaper.py bash test.sh — 10 passed.
1d2463d to
1b492ed
Compare
|
Rebased onto latest All checks green. |
…vidence Co-authored-by: Cursor <[email protected]>
…edHardware#10390) ## Summary Fixes the **cost half** of BasedHardware#7326: stopped `omi-agent-*` VMs keep billing ~50 GB `pd-balanced` boot disks because `autoDelete: true` only fires on instance **delete**, not stop. **Approach:** enable/fix the existing `backend/charts/agent-vm-reaper` CronJob (it was written but never deployed — no GSA, no CronJob in `prod-omi-backend`). Prefer reusing that machinery over new systems. - Extract selection/delete into `backend/scripts/agent_vm_reaper.py` (dry-run default; live gated) - Add refuse-by-default `backend/scripts/apply-agent-vm-reaper.sh` (creates GSA + WI + ConfigMap + CronJob) - TERMINATED grace: `lastStopTimestamp` ≥ **12h** (preserves same-day `start_stopped_vm` resume; after delete, status `NOT_FOUND` → clear Firestore → client re-provisions + DB upload) - RUNNING older than **2d** still reaped as abandoned - Checked-in CronJob default `DRY_RUN=true` so bare apply is log-only **Not in this PR:** public NAT removal / firewall cutover (phase-1 health-auth PR / BasedHardware#9261 lane). No network changes. ## Live evidence (2026-07-23, project `based-hardware`) | Metric | Value | |--------|-------| | Fleet | ~183 TERMINATED + ~104 RUNNING `omi-agent-*` | | Disk | 50 GB `pd-balanced` each | | Idle disk burn | ~183 × $5 ≈ **~$915/mo** | | Prod CronJob | **missing** (`kubectl -n prod-omi-backend get cronjob` — no reaper) | | GSA `agent-vm-reaper@…` | **NOT_FOUND** | | Node default SA | `roles/compute.viewer` only — dedicated WI SA required | Dry-run of this PR's script (`python3 backend/scripts/agent_vm_reaper.py --dry-run`): - **137** reapable now (85 TERMINATED ≥12h + 52 RUNNING ≥2d) - Immediate idle-disk savings from those TERMINATED ≈ **~$425/mo** - Remaining TERMINATED age into the 12h window → full idle-disk fleet bounded toward ~$0 beyond grace; steady-state savings ≈ **~$800–915/mo** once LIVE, plus abandoned RUNNING compute ## Manual steps after merge (required — no CD for this chart) ```bash # 1) Install IAM + CronJob in dry-run (log-only) AGENT_VM_REAPER_APPLY=1 bash backend/scripts/apply-agent-vm-reaper.sh # 2) Manual job + inspect logs kubectl -n prod-omi-backend create job --from=cronjob/prod-agent-vm-reaper agent-vm-reaper-manual-$(date +%s) kubectl -n prod-omi-backend logs job/<job-name> # 3) Enable deletes AGENT_VM_REAPER_APPLY=1 AGENT_VM_REAPER_LIVE=1 bash backend/scripts/apply-agent-vm-reaper.sh ``` Local inventory only (no mutation): `python3 backend/scripts/agent_vm_reaper.py --dry-run` ## Test plan - [x] `python3 -m pytest backend/tests/unit/test_agent_vm_reaper.py -v` → 9 passed (selection, dry-run, refuse gates, manifest defaults) - [x] `bash backend/scripts/apply-agent-vm-reaper.sh` without gate → REFUSED exit 1 - [x] Live dry-run against GCP inventory → 137 targets logged, zero deletes - [ ] After merge: apply dry-run CronJob, review logs, then LIVE=1 - [ ] Confirm TERMINATED count drops over ~24h; disks deleted with instances ## Relationship - **BasedHardware#7326** — progresses **cost** half only (partial). Full close still needs private networking / remove public NAT (deferred; depends on proxy routing + peer/move VMs). - **Health-auth / superseding BasedHardware#9261** — separate PR; this change does not touch agent-proxy, NAT, or firewall. Failure-Class: new <!-- This is an auto-generated description by cubic. --> <a href="https://cubic.dev/pr/BasedHardware/omi/pull/10390?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. -->
Summary
Fixes the cost half of #7326: stopped
omi-agent-*VMs keep billing ~50 GBpd-balancedboot disks becauseautoDelete: trueonly fires on instance delete, not stop.Approach: enable/fix the existing
backend/charts/agent-vm-reaperCronJob (it was written but never deployed — no GSA, no CronJob inprod-omi-backend). Prefer reusing that machinery over new systems.backend/scripts/agent_vm_reaper.py(dry-run default; live gated)backend/scripts/apply-agent-vm-reaper.sh(creates GSA + WI + ConfigMap + CronJob)lastStopTimestamp≥ 12h (preserves same-daystart_stopped_vmresume; after delete, statusNOT_FOUND→ clear Firestore → client re-provisions + DB upload)DRY_RUN=trueso bare apply is log-onlyNot in this PR: public NAT removal / firewall cutover (phase-1 health-auth PR / #9261 lane). No network changes.
Live evidence (2026-07-23, project
based-hardware)omi-agent-*pd-balancedeach183 × $5 ≈ **$915/mo**kubectl -n prod-omi-backend get cronjob— no reaper)agent-vm-reaper@…roles/compute.vieweronly — dedicated WI SA requiredDry-run of this PR's script (
python3 backend/scripts/agent_vm_reaper.py --dry-run):$0 beyond grace; steady-state savings ≈ **$800–915/mo** once LIVE, plus abandoned RUNNING computeManual steps after merge (required — no CD for this chart)
Local inventory only (no mutation):
python3 backend/scripts/agent_vm_reaper.py --dry-runTest plan
python3 -m pytest backend/tests/unit/test_agent_vm_reaper.py -v→ 9 passed (selection, dry-run, refuse gates, manifest defaults)bash backend/scripts/apply-agent-vm-reaper.shwithout gate → REFUSED exit 1Relationship
Failure-Class: new