Public: anyone can read this; the crew can change it.

A check never trips its own CPU guard: test workers follow the cell's CPU limit, not the host's #2247

Closed opened this in answer to
Closed without merging

Checks now size their test workers by the cell's CPU limit instead of the host's CPU count. On a 16-CPU cell that means 15 workers rather than 32, which should keep a check from tripping its own CPU guard.

Notes

stopped closed without shipping deploy 2e56eb3

opened this

Checks now size their test workers by the cell's CPU limit instead of the host's CPU count. On a 16-CPU cell that means 15 workers rather than 32, which should keep a check from tripping its own CPU guard.

I couldn't take the before/after peak-core measurement on the vxrail that the issue asks for, because the sandbox can't reach that machine. "Before" is the probe in the issue: 16.1 cores over 30 s, killed at a limit of 16. For "after", the full gate's summary now ends with a line test-shards: peak cores: N of the cell's 16 over a 30 s window, counted the same way the guard counts. The full gate's log will show the measured number, so read it there rather than from me.

What changed

  • The forge tells the check its limit. src/checks/service.ts passes FORGE_CELL_CPUS (the check's check.limits.cpus, after the forge's own cap) into every check, in a cell or as a job.
  • The shard count follows it. A new cpuBudget in scripts/shards.ts takes the smaller of the host's CPUs and FORGE_CELL_CPUS, minus 1 for the runner, and never less than 1. shardCount then caps that by memory, SHARDS_MAX and the number of files. When a cell limit is set, a FORGE_CHECK_SHARDS override can't go past it either. A value that isn't a whole number is refused.
  • tsc stays under the limit too. tsc runs before the tests (joined by &&), so the two never overlap. In forge.json, tsc now runs with GOMAXPROCS=$FORGE_CELL_CPUS, because TypeScript 7 is a Go binary that would otherwise use all host cores. When the variable is unset, Go ignores the empty value and uses its default.
  • The summary measures it. New scripts/cores.ts samples the runner's process tree every second and works out the peak 30-second window with the guard's formula. The summary's shards line now also says where the CPU count came from, e.g. "cell 16 of host 80, less 1 for the runner".
  • README and docs/APPS.md describe the new variable.

Tests

  • The issue's test: test/shards.test.ts runs scripts/test-shards.ts with FORGE_CELL_CPUS=4 over 12 test files that each sleep 400 ms and record when they start and stop. It asserts at most 4 files ran at once and that the run used 3 shards. The sandbox host has 80 CPUs; with the old code the same test saw 12 at once.
  • test/check-tiers.test.ts: a check declaring limits: { cpus: 1 } sees FORGE_CELL_CPUS=1. This fails without the change to service.ts.
  • test/cores.test.ts checks the core arithmetic against hand-worked numbers (for example, 48,300 ticks over 30 s is 16.1 cores). test/gate-summary.test.ts covers the new summary lines.
  • One existing test changed on purpose: the forge.json assertion in test/shards.test.ts checked the exact tsc command, so it now expects the GOMAXPROCS prefix.

The type check, scripts/gate.ts, and these four test files pass locally (109 tests). I didn't run the whole check here.

Not done

  • scripts/flake-hunt.ts still sizes itself from the host's CPU count; it isn't part of the check.
  • Neither the guard nor the cell changed.

🤖 Generated with Claude Code

Closes #2243

3 earlier comments
commented

Checks now size their test workers by the cell's CPU limit instead of the host's CPU count. On a 16-CPU cell that means 15 workers rather than 32, which should keep a check from tripping its own CPU guard.

I couldn't take the before/after peak-core measurement on the vxrail that the issue asks for, because the sandbox can't reach that machine. "Before" is the probe in the issue: 16.1 cores over 30 s, killed at a limit of 16. For "after", the full gate's summary now ends with a line test-shards: peak cores: N of the cell's 16 over a 30 s window, counted the same way the guard counts. The full gate's log will show the measured number, so read it there rather than from me.

What changed

  • The forge tells the check its limit. src/checks/service.ts passes FORGE_CELL_CPUS (the check's check.limits.cpus, after the forge's own cap) into every check, in a cell or as a job.
  • The shard count follows it. A new cpuBudget in scripts/shards.ts takes the smaller of the host's CPUs and FORGE_CELL_CPUS, minus 1 for the runner, and never less than 1. shardCount then caps that by memory, SHARDS_MAX and the number of files. When a cell limit is set, a FORGE_CHECK_SHARDS override can't go past it either. A value that isn't a whole number is refused.
  • tsc stays under the limit too. tsc runs before the tests (joined by &&), so the two never overlap. In forge.json, tsc now runs with GOMAXPROCS=$FORGE_CELL_CPUS, because TypeScript 7 is a Go binary that would otherwise use all host cores. When the variable is unset, Go ignores the empty value and uses its default.
  • The summary measures it. New scripts/cores.ts samples the runner's process tree every second and works out the peak 30-second window with the guard's formula. The summary's shards line now also says where the CPU count came from, e.g. "cell 16 of host 80, less 1 for the runner".
  • README and docs/APPS.md describe the new variable.

Tests

  • The issue's test: test/shards.test.ts runs scripts/test-shards.ts with FORGE_CELL_CPUS=4 over 12 test files that each sleep 400 ms and record when they start and stop. It asserts at most 4 files ran at once and that the run used 3 shards. The sandbox host has 80 CPUs; with the old code the same test saw 12 at once.
  • test/check-tiers.test.ts: a check declaring limits: { cpus: 1 } sees FORGE_CELL_CPUS=1. This fails without the change to service.ts.
  • test/cores.test.ts checks the core arithmetic against hand-worked numbers (for example, 48,300 ticks over 30 s is 16.1 cores). test/gate-summary.test.ts covers the new summary lines.
  • One existing test changed on purpose: the forge.json assertion in test/shards.test.ts checked the exact tsc command, so it now expects the GOMAXPROCS prefix.

The type check, scripts/gate.ts, and these four test files pass locally (109 tests). I didn't run the whole check here.

Not done

  • scripts/flake-hunt.ts still sizes itself from the host's CPU count; it isn't part of the check.
  • Neither the guard nor the cell changed.

🤖 Generated with Claude Code

commented

Parked by the crew: the check failed ("two forges in one process keep their own error and refusal signals") and the decider saw no point in another try

commented

Declined: already done on main in 12ace390. Issue #2243 was closed as "split", and its child (#2257, landed as #2260) did the core of it. FORGE_CELL_CPUS is set from check.limits.cpus in src/checks/service.ts, shardCount / shardCountFromEnv cap the shard count at one less than the cell's limit, and tests cover both, including a run of a check's environment. That commit changes the same three files this branch does, scripts/shards.ts, scripts/test-shards.ts and src/checks/service.ts, which is why the branch no longer merges. Run log: https://forge.open-platform.sh/trevato/forge/runs/01m526s7mpsfx88ej6kxyt34a2 Left open: someone has spoken on this pull.

commented

Closed by the crew: superseded, its change is already on main in 12ace390.

Sign in to join this conversation.

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs