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

One pure rule says when a 1-CPU forge holds background work for its crew run, with its own small test #11635

Merged opened this

Check · Review · Land · Live done — Landed and live in production.

Merged

This adds the one-core rule as plain data, with a test, and nothing yet calls it.

shipped production is serving it deploy e1bbdcb

opened this

This adds the one-core rule as plain data, with a test, and nothing yet calls it.

  • src/core/one_core.ts:

- crewHoldsCore(cpus, activeCrewRuns) returns true only when cpus <= 1 and activeCrewRuns > 0. A zero or negative CPU count therefore counts as one core. - forgeCpus() reads availableParallelism() from node:os and clamps it to at least 1, so callers never read the machine themselves.

  • test/one-core.test.ts: five tests, pure and in-process.

- 1 CPU with a run is held; 1 CPU with none is not. - 2 and 4 CPUs with a run are not held. - 0 and negative counts read as 1. - forgeCpus() is a whole number of at least 1.

  • scripts/unreached-allow.json: lists src/core/one_core.ts. The follow-up pull that wires the first service to the rule should remove that entry.

bun x tsc --noEmit, bun test test/one-core.test.ts (5 pass) and bun scripts/gate.ts all passed in the sandbox before the push.

I left out every service, page and docs change; the next two pulls each wire one service to this rule. The test for forgeCpus() only checks its range, because the real CPU count can't be forced in-process.

To try it: bun test test/one-core.test.ts.

🤖 Generated with Claude Code

Closes #11597

commented

This adds the one-core rule as plain data, with a test, and nothing yet calls it.

  • src/core/one_core.ts:

- crewHoldsCore(cpus, activeCrewRuns) returns true only when cpus <= 1 and activeCrewRuns > 0. A zero or negative CPU count therefore counts as one core. - forgeCpus() reads availableParallelism() from node:os and clamps it to at least 1, so callers never read the machine themselves.

  • test/one-core.test.ts: five tests, pure and in-process.

- 1 CPU with a run is held; 1 CPU with none is not. - 2 and 4 CPUs with a run are not held. - 0 and negative counts read as 1. - forgeCpus() is a whole number of at least 1.

  • scripts/unreached-allow.json: lists src/core/one_core.ts. The follow-up pull that wires the first service to the rule should remove that entry.

bun x tsc --noEmit, bun test test/one-core.test.ts (5 pass) and bun scripts/gate.ts all passed in the sandbox before the push.

I left out every service, page and docs change; the next two pulls each wire one service to this rule. The test for forgeCpus() only checks its range, because the real CPU count can't be forced in-process.

To try it: bun test test/one-core.test.ts.

🤖 Generated with Claude Code

commented

I merged main into the branch and pushed it. The only conflict was scripts/unreached-allow.json, where main had added src/apps/cpu_rule.ts and this pull had added src/core/one_core.ts. The resolved file lists both, sorted.

Before the push, bun x tsc --noEmit and bun scripts/gate.ts showed no errors, and bun test test/one-core.test.ts passed all 5 tests. I did not run the rest of the suite here; the forge runs the full check on the push.

src/apps/cpu_rule.ts is a second CPU-rule file that arrived with main. I did not look at whether it overlaps with crewHoldsCore, so that is worth a glance in review.

🤖 Generated with Claude Code

Approved

Matches the issue exactly: a pure two-function module, five fast in-process tests, allow-list entry added, no new dependency, no web/TUI surface so no both-doors or docs duty. cpu_rule.ts (cpuStop) is a different rule (stop on over-use), so no overlap with crewHoldsCore. The preview is unaffected, since nothing calls the module. Next two things: (1) wire the first service to crewHoldsCore/forgeCpus and remove the allow-list entry in that pull; (2) note that machine CPU count may differ from a cell CPU limit (see contain.ts), so the caller should pass the right count.

Sign in to join this conversation.

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs