Skip to content

perf(sandbox): size capacity by CPU, pace starts under CPU pressure, fork-free device status - #4626

Merged
yannickmonney merged 2 commits into
mainfrom
perf/sandbox-cpu-aware-capacity
Oct 9, 2026
Merged

yannickmonney merged 2 commits into
mainfrom
perf/sandbox-cpu-aware-capacity

Conversation

@yannickmonney

Copy link
Copy Markdown
Contributor

What

CPU-aware capacity. With SANDBOX_MAX_SESSIONS unset, the spawner sized capacity from memory alone, so a 16 GiB / 4 vCPU host took 19 agent sessions of two CPUs each, and admission never looked at CPU. Capacity is now at most two sessions per CPU the daemon reports (still never below 8, at most 256; an explicit value wins).

CPU-pressure gate. The host-memory probe reads /proc/pressure/cpu beside /proc/meminfo where /proc describes the Docker host (the same locality verdict). While PSI some avg10 is at or above SANDBOX_CPU_PRESSURE_PERCENT (default 60, 0 off), creates and warm acquisitions are let in only from the front of the existing first-come line, one every ten seconds; the rest answer 429 host_cpu with their queue place and retry-after. Nothing is reclaimed for it (an idle session uses no CPU). Unknown or unreadable pressure refuses nothing, and a kernel without PSI is logged once. The platform already treats every 429 as SpawnerBusyError.

Fork-free device STATUS. A connected device ran docker ps --all (plus a CPU prime sample) for every STATUS every 15 s on the user's machine. STATUS now comes from the spawner's registry, creates in flight and unadopted objects, plus the daemon's totals (cached ten minutes) and /proc usage where local. A one-second fingerprint check reports a change at once; the 15 s heartbeat is unchanged, and reports never overlap.

Docs

  • SANDBOX_CPU_PRESSURE_PERCENT in the env reference (EN/DE/FR), .env.example and the sandbox README; the capacity sizing text and the upgrade note now cover the CPU cap.
  • docs/sessions.md and docs/devices.md describe the gate and the new STATUS source; there are two coverage rows in reference/automation/settings.md.

Tests

  • host-memory.test.ts: CPU cap sizing, reading PSI and the CPU count, failing open once, the switch-off, rejected CPU counts.
  • proc-stats.test.ts: parsing PSI.
  • session-routes.test.ts: creates and acquisitions taking turns under pressure, the line keeping its order, draining once pressure eases, unknown/off/below-threshold pressure, the inventory.
  • device.test.ts: a STATUS sent on change, nothing extra sent without a change.
  • capacity.test.ts: hostResources never runs ps, and it reports unknown resources when the daemon fails.
  • config.test.ts: parsing the new env var.

Automatic session capacity followed memory alone, so a 16 GiB host with
4 CPUs took 19 agent sessions of two CPUs each, and admission never
looked at CPU. Capacity is now also at most two sessions per CPU the
daemon reports (never below 8; an explicit SANDBOX_MAX_SESSIONS wins).

The host-memory probe reads /proc/pressure/cpu beside /proc/meminfo
where /proc describes the Docker host. While PSI "some avg10" is at or
above SANDBOX_CPU_PRESSURE_PERCENT (60; 0 off), creates and warm
acquisitions start one every ten seconds from the front of the
first-come line and the rest answer 429 host_cpu with their place.
Unknown pressure refuses nothing; a kernel without PSI is logged once.
A connected device ran `docker ps --all` (and the CPU prime sample) for
every STATUS, every 15 s, on the user's machine. STATUS now comes from
the spawner's own memory: registered sessions as running, creates in
flight and unadopted objects as starting, plus the daemon's totals
(asked at most every ten minutes) and /proc usage where /proc is the
Docker host's. A daemon that does not answer leaves resources unknown
instead of freezing the report.

The sessions' fingerprint is checked every second and a change is
reported at once, so the hub places creates on what the device runs
now; the 15 s heartbeat stays, and reports never overlap.
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