Add bounded scale-to-zero leases - #366
Open
tnsardesai wants to merge 5 commits into
Open
Conversation
tnsardesai
commented
Sep 3, 2026
tnsardesai
commented
Sep 3, 2026
tnsardesai
commented
Sep 3, 2026
tnsardesai
marked this pull request as ready for review
September 3, 2026 22:21
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Want higher recall? High effort reviews run extra passes and find more bugs. A team admin can switch effort levels in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit ce21b43. Configure here.
sjmiller609
approved these changes
Sep 4, 2026
sjmiller609
left a comment
Contributor
There was a problem hiding this comment.
- server/lib/scaletozero/scaletozero.go:71-75 — Considering returning an error if called in Hypeman instead of succeeding.
- server/openapi.yaml:1647-1698 — consider if we should delete the "release" endpoint, since we could just renew the lease with a shorter duration? Seems subjective though, so whatever you prefer is good (e.g. just set TTL to 1s or 0s versus DELETE)
- note: I checked on the clock jumping concern and I think there isn't one because this uses relative monotonic timing
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.

problem
A handler that streams a large response can finish once the final bytes are accepted by the guest TCP send buffer, before those bytes have reached metro-api. Releasing the request-scoped scale-to-zero hold at that point can suspend the VM with response bytes still queued.
Metro-api needs a crash-safe way to hold scale-to-zero disabled until the guest response has been fully read. The existing disable/enable pin is intentionally a permanent boolean used by lifecycle management, so reusing it for individual responses would let one response release another caller's pin and could leave a VM pinned forever if metro-api exits.
change
PUT/DELETE /scaletozero/leases/{lease_id}endpointsExisting
/scaletozero/disableand/scaletozero/enablebehavior is unchanged.tests
make oapi-generatego build ./...go vet ./...go test -race ./lib/scaletozero ./cmd/api/apigo test ./lib/scaletozero -run '^TestDebouncedControllerLeaseRenewalSurvivesStaleExpiry$' -count=50go test ./lib/scaletozero -run '^TestDebouncedControllerLeaseDefaultsExpiryScheduler$' -count=50go test -race $(go list ./... | grep -v '/e2e$')(all changed packages passed; one unrelatedlib/devtoolsproxyChromium temp-directory cleanup raced once)go test -race ./lib/devtoolsproxy(retry passed)rollout
Release this in browser images before relying on bounded leases from metro-api. The metro-api change treats a 404/405 as an older image and retains its independent stall-wake watchdog during the image rollout.
Note
Medium Risk
Changes when VMs can scale to zero (infrastructure lifecycle) but the API is additive, TTL-bounded, and existing disable/enable pin behavior is unchanged.
Overview
Adds bounded scale-to-zero leases so callers (e.g. metro-api) can keep a VM awake for a limited time after a streaming response ends, without using the permanent pin or request refcount.
New
PUT/DELETE /scaletozero/leases/{lease_id}endpoints validate lease IDs andttl_seconds(1–300), delegate toAcquireLease/ReleaseLeaseon the existing scale-to-zero controller, and map lease-cap exhaustion to 409. OpenAPI client/server and telemetry operation categories are regenerated.DebouncedControllernow tracks named leases with timers (renew on repeat ID), a 1024-lease cap, and treats active leases like pins/refcounts when deciding re-enable; cooldown re-enable failures are logged instead of silently ignored.Reviewed by Cursor Bugbot for commit 8d0b726. Bugbot is set up for automated code reviews on this repo. Configure here.