Repository navigation
Description
Found during the P6.3 acceptance (#425, Task 18 step 1) on the shared KVM rig.
What happened
A P6 host ran container sandboxes plus one P4 microvm-worker (moca_microvm_0), with MICROVM_MAX_COMMITTED_MB=8192. With the unit's 4 GiB SH_MEMORY_RESERVE_MB, that leaves a 4 GiB VM budget, about 14 VMs at 288 MiB each. SH_WORKSPACE_IDLE=8h and SH_STANDBY_DEPTH=2.
After about 12 P4 sessions, every turn of the next three sessions failed. Each exec came back as a tool error:
memory-budget: committing 301989888 more bytes would reach 4529848320 against a budget of 4294967296
(MaxCommittedBytes 8589934592 less MemoryReserveBytes 4294967296)
The model received that as the bash tool's output. The turns did not get a 503 with Retry-After. The sessions stayed in their tier, which is correct per P6.3.
Why
- The worker's presence record advertises
capacityMax=WORKER_MAX_CONCURRENT(16): concurrent exec slots. - The supervisor's lease cap uses that number.
remote-worker/internal/vmpool/errors.gocalls it "primary admission control", withMaxRunsand the memory budget as backstops. The wire contract has no "busy" frame, so a backstop refusal can only surface as an exec error. - The boot-time budget check (
microvm-worker/main.go, around L128) sizes the budget formaxConcurrent × (1 + StandbyDepth)VMs. - A session's idle, resident workspace VM holds memory for
SH_WORKSPACE_IDLE(8 h here), yet it uses no lease slot. So the memory a worker has committed grows with the number of distinct recent sessions, not with concurrency. The worker keeps advertising free slots it can no longer admit. - P6.3's affinity keeps each session on its sandbox, so all of a session's turns reuse its resident VM. That is right for the workspace, but it means a busy P4 host reaches this state sooner.
What a user sees
New P4 sessions fail with a tool error in the transcript, on a host that reports spare capacity. Nothing retries, and nothing says "at capacity".
Options
- Report the real headroom. The worker lowers its effective capacity, or marks itself saturated, when the memory budget cannot admit one more VM. That needs a presence update;
Hellois sent once, so this needs either a capacity update frame or a re-Hello. - Make a refusal retryable. Map a budget refusal (
RefuseMemoryBudget, ormax-runs) to an exec status the harness classifies as saturated, so the turn answers 503 withRetry-Afterinstead of handing the error text to the model. - Evict under pressure. Reclaim the least-recently-used idle workspace VM (it is persisted on disk under
SH_WORKSPACE_ROOT) before refusing. - Document it. In
P4-ON-P6.md, sizeMICROVM_MAX_COMMITTED_MBandSH_WORKSPACE_IDLEfor the expected number of distinct sessions, not for concurrency.
(2) is the smallest user-visible fix. (3) stops a host's capacity from leaking away over time.
Repro
On a host with a small budget, create more distinct P4 sessions than the budget holds VMs, all within SH_WORKSPACE_IDLE. On the rig, the session after about 14 committed VMs failed. Raising the budget to 12288 MB let three more sessions pass.
Activity
test(vmpool): wait for the async reclaim before asserting on destroys
fix: scope the capacity latch to sandbox tools, correct the memory model
fix(vmpool): shed an idle standby instead of refusing on the memory b…
fix: answer 503 for a host capacity refusal instead of narrating it t…
Merge pull request #597 from cwiklik/fix/452-budget-saturation
fix(knative-server): a /turn 503 says, and logs, which capacity refus…