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

scout/forge:scout/11597-one-pure-rule-says-when-a-1-cpu-forge-ho → main 2 commits fork

  • Merged. scout/11597-one-pure-rule-says-when-a-1-cpu-forge-ho was merged into main as 316df68.

Review

Sign in to review this change.
3 files changed +32 −0
scripts/unreached-allow.json +1
@@ -1,5 +1,6 @@
11 [
22 "src/apps/cpu_rule.ts",
3 "src/core/one_core.ts",
34 "src/perf/page_budget.ts",
45 "src/perf/page_budget_read.ts",
56 "src/spawn/pod.ts",
src/core/one_core.ts added +12
@@ -0,0 +1,12 @@
1 import { availableParallelism } from "node:os";
2
3 /** True when a 1-CPU forge should hold background work for a crew run. */
4 export function crewHoldsCore(cpus: number, activeCrewRuns: number): boolean {
5 return cpus <= 1 && activeCrewRuns > 0;
6 }
7
8 /** The forge's own CPU count, at least 1. */
9 export function forgeCpus(): number {
10 const n = availableParallelism();
11 return Number.isFinite(n) && n >= 1 ? Math.floor(n) : 1;
12 }
test/one-core.test.ts added +19
@@ -0,0 +1,19 @@
1 import { expect, test } from "bun:test";
2 import { crewHoldsCore, forgeCpus } from "../src/core/one_core.ts";
3
4 test("1 CPU with a crew run is held", () => expect(crewHoldsCore(1, 1)).toBe(true));
5 test("1 CPU with no run is not held", () => expect(crewHoldsCore(1, 0)).toBe(false));
6 test("2 and 4 CPUs with a run are not held", () => {
7 expect(crewHoldsCore(2, 3)).toBe(false);
8 expect(crewHoldsCore(4, 1)).toBe(false);
9 });
10 test("0 or negative CPUs read as 1 cpu: held with a run", () => {
11 expect(crewHoldsCore(0, 1)).toBe(true);
12 expect(crewHoldsCore(-2, 1)).toBe(true);
13 expect(crewHoldsCore(0, 0)).toBe(false);
14 });
15 test("forgeCpus is a whole number of at least 1", () => {
16 const n = forgeCpus();
17 expect(Number.isInteger(n)).toBe(true);
18 expect(n).toBeGreaterThanOrEqual(1);
19 });

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs