Skip to content

docs(sbx): lease spec v0.2 and ADR-0048 revision after E17a - #718

Merged
pdettori merged 8 commits into
rossoctl:mainfrom
pdettori:docs/sbx-lease-e17a-revision
Nov 12, 2026
Merged

pdettori merged 8 commits into
rossoctl:mainfrom
pdettori:docs/sbx-lease-e17a-revision

Conversation

@pdettori

@pdettori pdettori commented Nov 12, 2026 •

Copy link
Copy Markdown
Member

Summary

Revises the SBX lease-mode design (SBX0.3, #698, ADR-0048) after E17a, the pre-build experiment in rossoctl/moca-experiments (e17/, PR rossoctl/moca-experiments#21). E17a's predictions are sealed (2026-11-12).

E17a ran the E15 resident patch (a stand-in for the lease, with a 300 s idle timeout) against per-Exec on a synthetic cache-heavy Python session, at N = 1 on the E15 metal host:

Command class Per-Exec Warm lease Gain
Short (grep, sed on project files) 53 ms 6 ms 89%
import numpy, pandas, scipy, sklearn 755 ms 454 ms 40%
grep -r over the venv (realistic turns) 1960 ms 2000 ms −2%
analyze.py (CSV parse + KMeans) 15.6 s 14.4 s 8%
pytest 61.2 s 61.0 s 0%

Findings:

  • Per-Exec VMs already read the workspace through the host page cache.
  • A lease guest keeps a file set warm only if it lives through a whole agent turn.
  • Every lease VM filled its 1024 MiB cgroup after one heavy command. The guest had freed most of that memory, but nothing returned it to the host, so the measured charge equalled the full charge.
  • A full lease cgroup also leaves no room for the host to cache that VM's workspace. When the lease ends, the next VM reads the workspace from disk: about 2 s against 390 ms.

Changes

  • Lease spec v0.2:
    • level 1 re-scoped to short and import-bound commands, plus capacity at mid duty (E15: 128 against 80);
    • free-page reporting in v1 for lease VMs (§6);
    • page-cache headroom in each lease VM's cgroup: memory.max = PerVMBytes + SH_LEASE_PAGECACHE_MB, default 256 MiB (§6);
    • the idle timeout is set together with the memory model, with the 300 s default re-examined in E17b (§4);
    • the sealed E17 criteria replace the §10 proposals;
    • new open items: Firecracker free-page reporting support (blocks plan 3), and an E17 extension to size level 2's latency case;
    • a new §17 with the findings.
  • ADR-0048: a "Revision 2026-11-12: E17a" section. It replaces decision 7, narrows decision 14, keeps decision 3 pending E17b, points decision 13 at the sealed criteria, and adds decisions 18 (cgroup headroom) and 19 (size level 2 before its security review).

Docs only. E17a is complete: at pycache N = 128 the gains are short 0.91, import 0.42, grep 0.01, so criterion 2 misses at both N, as predicted. Criterion 1 holds (E15 metal, reused: 128 against 80). Report: rossoctl/moca-experiments e17/results/E17A-REPORT.md (PR #21). The plans 2–5 build decision is open.

Assisted-By: Claude Code

E17a (moca-experiments e17/, predictions sealed 2026-11-12) found a warm
lease guest saves 89% on short commands and 40% on a stack import, but
0-8% on long compute, and nothing on a venv grep in realistic turns:
per-Exec already reads through the host page cache, and every lease VM
filled its 1024 MiB cgroup after one heavy command.

- level 1 re-scoped to short/import-bound commands and mid-duty capacity
- free-page reporting moves into v1 (replaces decision 7)
- lease VM cgroups get page-cache headroom (new decision 18)
- idle timeout and memory model set together; 300 s re-examined in E17b
- level 2 is the latency case; size it with an E17 extension (decision 19)
- §17 records the E17a findings

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Paolo Dettori <[email protected]>
@pdettori pdettori added the ready-for-ai-review Request automated AI code review from clawgenti label Nov 12, 2026

@ingpaolodettori-dev ingpaolodettori-dev left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Summary

Docs-only revision of the SBX0.3 lease spec (v0.2) and ADR-0048 after E17a. It adds free-page reporting to v1, a page-cache headroom in lease cgroups, narrows level 1, points §10 at the sealed criteria, and adds §17 with the findings. The reasoning follows from the data, and the ADR decisions it replaces or narrows (3, 7, 13, 14) match the numbering on main. The code references hold on main dd0ce71: writeMemoryMax is at cgroup.go:366, and runningCommittedLocked is at budget.go:418-425. The main gap is that the new cgroup-headroom decision doesn't say how it fits the worker's reusable cgroup pool (inline).

The PR is still a draft: the pycache N = 128 rung is pending and will be added to §17. This approval covers the text at cf93f67.

Author: pdettori (MEMBER — maintainer)
Areas reviewed: Docs (spec + ADR), cross-checked against remote-worker/internal/vmpool on main
Agent/IDE config (.claude/.vscode): none
Commits: 1 commit, all signed-off: yes
CI status: passing (all 16 checks; k8s-kind-e2e did not run on this head)

`memory.current`, so the measured charge above follows the working set. Free page _hinting_ and a
deflate-on-OOM policy are not needed. Check before plan 3: the pinned Firecracker version's balloon
API and the guest kernel's `CONFIG_PAGE_REPORTING` (§16).
- **Page-cache headroom in the lease cgroup (v0.2).** Each VM's cgroup has `memory.max` =

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

suggestion: Per-VM cgroups aren't created per VM any more. cgroupPool (vmpool/cgroup_pool.go) keeps a free list of reused cgroups, all written once with the same memMax. Its safety argument is that a reused cgroup inherits ~1 MiB of charge. A lease cgroup with PerVMBytes + SH_LEASE_PAGECACHE_MB breaks both assumptions. (a) It needs its own free list, or a memory.max rewrite on acquire and a reset on release. (b) Host page cache charged to it stays charged to the cgroup after the VM exits, so returning it to the shared list would hand a per-Exec VM up to ~256 MiB of inherited charge under a PerVMBytes bound. Worth a sentence here, and a line in the plan that builds it.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Agreed, and checked against cgroup_pool.go on main. Fixed in 9c23b32 (§6, "Not from the cgroup pool"): lease cgroups are never taken from or returned to the pool. The worker creates one per lease and removes it when the lease ends, so no per-Exec VM can inherit its page-cache charge. Leases are few and long-lived, so that costs one mkdir/rmdir per lease. The plan that builds lease VMs (plan 3) carries it, with a test that a per-Exec VM after a lease starts with the pool's usual ~1 MiB. The ADR's decision 18 says the same.

ends reads from disk: in E17a a grep in such a VM took about 2 s, where a per-`Exec` VM, whose short
life left the host cache in place, took 390 ms (§17). Lease VMs get `memory.max` =
`PerVMBytes` + `SH_LEASE_PAGECACHE_MB` (default 256 MiB). The measured charge counts it when used
(`memory.current`), so it costs admission only what the host actually caches. Free-page reporting

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

suggestion: "Costs admission only what the host actually caches" understates it slightly: the lease charge is memory.current × SH_LEASE_HEADROOM (1.25, line 336). A full lease VM with full headroom is therefore charged about 1.25 × (PerVMBytes + 256 MiB) ≈ 1.6 GiB at 1 GiB guests, above a per-Exec VM's PerVMBytes. That's fine, since reclaim covers it, but state the upper bound so the §6 headroom target (SH_LEASE_RECLAIM_FREE_MB) is sized against it.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Right, fixed in 9c23b32. §6 now states the bound, 1.25 × (PerVMBytes + SH_LEASE_PAGECACHE_MB): about 1.6 GiB at 1 GiB guests and about 680 MiB at 256 MiB guests. SH_LEASE_RECLAIM_FREE_MB's default is now 2 × PerVMBytes + max(2 GiB, 2 × (bound − SH_LEASE_START_MB)), about 4.9 GiB at 1 GiB guests and 2.6 GiB at 256 MiB guests. That also covers two busy lease VMs growing from their start estimate to the bound between samples, which reclaim cannot catch.


- **Per-`Exec` already gets a warm cache from the host.** A per-`Exec` VM reads the workspace through
the host page cache, so its second grep took 390 ms against 2.2 s for the first touch of a fresh
workspace. A warm lease guest took 115 ms. The lease's cache gain is that difference, not the cold

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

nit: The back-to-back numbers differ between sections. §1.1 (line 59) says 388 → 112 ms, while §17 says 390 ms and 115 ms here (the §17 table and the ADR also use 390 ms). Pick one source (median of which run?) and use it in both places.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Fixed in 9c23b32. One source now: the medians of the 20-call class probes in the E17 calibration (per-Exec 388 ms, warm lease 112 ms), used in §1.1, §6, §17 and the ADR.

…both N)

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Paolo Dettori <[email protected]>
… one number source)

- lease cgroups are created per lease and never pooled: a reused cgroup
  would hand a per-Exec VM the lease's leftover page-cache charge
- state the lease charge bound, 1.25 x (PerVMBytes + SH_LEASE_PAGECACHE_MB)
  ~1.6 GiB at 1 GiB guests, and size SH_LEASE_RECLAIM_FREE_MB against it
- back-to-back grep numbers from one source (class-probe medians 388/112 ms)

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Paolo Dettori <[email protected]>
@pdettori
pdettori marked this pull request as ready for review November 12, 2026 03:29
Firecracker v1.17.0 (P4, E15 rig and SBX0 host) supports balloon
free_page_reporting (not preview; hinting is and stays out). Both guest
kernels (SBX0 6.18.51, E15 6.18.44) build in VIRTIO_BALLOON,
MEMORY_BALLOON, PAGE_REPORTING. Enable-before-boot means the balloon must
be in the golden snapshot (per-Exec affected; two options recorded).
File-backend restore makes reported pages fall back to the shared memfile.
Open: whether a restored balloon keeps reporting; one restore test.

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Paolo Dettori <[email protected]>
…sted)

A test snapshot with a reporting-only balloon, restored by the worker
with the File backend on the E15 rig: after a guest process touched
700 MiB and exited, the VM cgroup fell 734 -> 227 MiB in 5 s and to
81 MiB in 15 s; the control snapshot stayed at 734 MiB.

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Paolo Dettori <[email protected]>
Per-Exec VMs carry the reporting balloon too; their latency is checked
against a snapshot without it before plan 3 ships it.

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Paolo Dettori <[email protected]>
…sizing

Per-Exec with the balloon: true 83 -> 85 ms, python3 -c pass and a
256 MiB touch unchanged. Level 2 (a persistent interpreter): re-query
6.5 s -> 0.25 s, recompute 17.4 -> 11.2 s, ~500 MB held in a 1 GiB
guest; level 1 alone 5-17%. ADR decision 19 records the sizing.

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Paolo Dettori <[email protected]>
…motion

A lease VM starts as a pooled standby, so its cgroup cannot be one the
pool never handed out: when the VM becomes a lease VM the worker raises
its memory.max, and at lease end removes the cgroup instead of returning
it. Lease VMs and the balloon are plan 2's (was: plan 3).

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Paolo Dettori <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ready-for-ai-review Request automated AI code review from clawgenti

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants