Garry's Opinionated OpenClaw/Hermes Agent Brain
TypeScript
test(progress): report the cpu_ms split, page faults and context switches when the idle-tick check fails (no assertion change)
garrytan0277743b99fa
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex ca33461579..af6cecbf71 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -19,6 +19,7 @@ identifiers and attribution are available in the pre-removal Git revision- **`scripts/ci-bounded-run.ts`** (new): `--attempt-s <n> [--retry-s <n>] [--hint <text>] -- <command…>`. It runs the command in its own process group. When an attempt is still running at its bound, it sends SIGTERM to the whole group and SIGKILL after a 10 s grace period. SIGTERM goes first so that `sudo apt-get`, which sudo can't forward a SIGKILL to, still gets the signal. The command is retried once, and a second failure stops the step with `::error::<command> stalled: no result after <n>s (<hint>) on attempt 2 of 2; giving up`. A failure that isn't a stall keeps its own output, is retried once, and is reported with its exit code.- **`scripts/ci-bun-install.ts`** now delegates to it, with the same environment knobs and the same annotation text. One behavior change: a stalled install's child processes now end with it. Before, only the direct child got SIGKILL, so a backgrounded grandchild outlived the attempt.- **`admin-browser` (`test.yml`):** `bun scripts/ci-bounded-run.ts --attempt-s 240 --retry-s 10 … -- bunx playwright install --with-deps chromium`, with a `timeout-minutes: 9` step cap, which covers two attempts, the pause and both grace periods. The job timeout stays at 12 minutes. A retry starts with whatever attempt 1 already finished: apt packages that got installed and a browser that got downloaded stay in place.+- **`test/progress.test.ts` cpu_ms diagnostics (no assertion change):** the `< 100` ms check on the idle tick failed once at 101 ms on Bun 1.4.3 CI. Side-by-side probes on 1.4.2 and 1.4.3 ruled out the two version suspects: `process.threadCpuUsage` is still per-thread, and `Atomics.wait` still parks rather than spins. The cause is still unknown, so the assertion and its bound are unchanged. A failure now reports where the CPU went: the thread CPU inside the 200 ms `Atomics.wait` against the tick calls around it, plus the process's minor and major page faults, involuntary context switches and all-thread CPU during the wait. Forcing 110 ms of allocation inside the window shows the split as `112.5 ms inside the 200 ms Atomics.wait, 0.5 ms in the tick calls around it; … 1580 minor and 0 major page faults, 14 involuntary context switches`.- **Proof:**- Forced stall: a real `bunx playwright install chromium`, with `PLAYWRIGHT_DOWNLOAD_HOST` pointed at a loopback server that accepts connections and never answers, and an 8 s bound. It was ended twice and stopped with the named error after 17 s, exit 1, with no Playwright process left behind.- `test/scripts/ci-bounded-run.test.ts` uses real stalling commands:diff --git a/test/progress.test.ts b/test/progress.test.tsindex 89874c0ee2..f2a83857e6 100644--- a/test/progress.test.ts+++ b/test/progress.test.ts@@ -157,15 +157,28 @@ describe('progress reporter', () => {const spinUntil = cpuMs() + 60;while (cpuMs() < spinUntil) { /* burn 60 ms of CPU */ }p.tick(1);+ const usageBefore = process.resourceUsage();+ const cpuBeforeWait = cpuMs();// Block the thread for 200 ms without yielding: an await would let other queued main-thread work (an earlier// test's timer, a GC pause) run and be billed to the phase, and the test means "the thread sat idle".Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, 200);+ const cpuInWait = cpuMs() - cpuBeforeWait;+ const usageAfter = process.resourceUsage();p.tick(1);p.finish();const [, worked, waited] = parseJsonl(read()) as Array<{ cpu_ms: number; elapsed_ms: number }>;expect(worked.cpu_ms).toBeGreaterThanOrEqual(60);expect(waited.elapsed_ms - worked.elapsed_ms).toBeGreaterThanOrEqual(190);- expect(waited.cpu_ms - worked.cpu_ms).toBeLessThan(100);+ const waitedCpuMs = waited.cpu_ms - worked.cpu_ms;+ expect(+ waitedCpuMs,+ `the second tick billed ${waitedCpuMs.toFixed(1)} ms of thread CPU (first tick, after the 60 ms spin: ${worked.cpu_ms.toFixed(1)} ms): ` ++ `${cpuInWait.toFixed(1)} ms inside the 200 ms Atomics.wait, ${(waitedCpuMs - cpuInWait).toFixed(1)} ms in the tick calls around it; ` ++ `process during the wait: ${usageAfter.minorPageFault - usageBefore.minorPageFault} minor and ` ++ `${usageAfter.majorPageFault - usageBefore.majorPageFault} major page faults, ` ++ `${usageAfter.involuntaryContextSwitches - usageBefore.involuntaryContextSwitches} involuntary context switches, ` ++ `${((usageAfter.userCPUTime + usageAfter.systemCPUTime - usageBefore.userCPUTime - usageBefore.systemCPUTime) / 1000).toFixed(1)} ms CPU on all threads`,+ ).toBeLessThan(100);});test('quiet mode emits nothing', () => {