From 126f2ce66d1b0eee257750eae3118d65b032eb5a Mon Sep 17 00:00:00 2001 From: godarg <216538197+godarg@users.noreply.github.com> Date: Tue, 17 Nov 2026 08:31:02 +0100 Subject: [PATCH] fix(bench): a checker that runs out of wall time is retried on --verify, never reported as refusing the artifact The gate run of 2026-11-17 turned the committed /2 fixture red on a loaded machine (bench-v3-acceptance, "run review-and-send-s1-r1: the checker rejects the session artifact"). Cause: re-verification caught every error of the checker process, including checker_timeout from its 10 s wall limit, and reported it as the checker refusing the artifact (session, export, condition trace) or the reference as invalid. The checker is deterministic (no clock, randomness or I/O), so a timed-out attempt judged nothing. The date was not involved: the whole unit suite passes with the clock moved by +366 and +3660 days. A re-judge of a stored artifact now runs a timed-out check again (retryCheckerTimeout, at most 3 attempts, each under the full 10 s limit, pauses 1 s and 2 s); only checker_timeout is retried. When every attempt runs out of time it says so: checker_timeout naming the run, or the reference's task and seed. The limit and a bench run's single attempt are unchanged. Test: tests/unit/checker-timeout-retry.test.ts stalls checker starts at the process boundary (tests/support/stall-checker.ts through NODE_OPTIONS); without the fix it fails with the exact message of the gate run. Signed-off-by: godarg <216538197+godarg@users.noreply.github.com> --- CHANGELOG.md | 8 +++ docs/benchmarks/README.md | 7 +++ docs/security/threat-model.md | 2 +- src/bench/verify.ts | 20 +++--- src/bench/world.ts | 10 ++- src/cli/messages.ts | 8 +++ src/cli/runtime.ts | 15 +++++ tests/support/stall-checker.ts | 17 ++++++ tests/unit/checker-timeout-retry.test.ts | 78 ++++++++++++++++++++++++ 9 files changed, 154 insertions(+), 11 deletions(-) create mode 100644 tests/support/stall-checker.ts create mode 100644 tests/unit/checker-timeout-retry.test.ts diff --git a/CHANGELOG.md b/CHANGELOG.md index 39aa618a..d41c5052 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -96,6 +96,14 @@ All notable changes are recorded here. The format follows ### Fixed +- `report --verify` no longer refuses a sound report because the machine is busy. A checker process + that ran into its 10-second wall limit was reported as the checker refusing the artifact ("the + checker rejects the session artifact", likewise for the export, the condition trace and a stored + reference), although the deterministic checker had judged nothing; on 2026-11-17 this turned the + committed `/2` fixture red on a loaded machine. A re-judge now runs a timed-out check again, up to + 3 attempts under the full limit each, and when every attempt runs out of time it says so + (`checker_timeout`, with the run or the reference's task and seed). The limit itself and a bench + run's single attempt are unchanged. - A browser that closes slowly no longer fails work that succeeded (issue #64, [PADR-0050](docs/adr/0050-browser-close-is-a-bounded-request.md)). Every browser Practonaut starts — the mirror's, the start check's, the render check's, the report card's — closes through one diff --git a/docs/benchmarks/README.md b/docs/benchmarks/README.md index e0734572..aa7cd95a 100644 --- a/docs/benchmarks/README.md +++ b/docs/benchmarks/README.md @@ -435,6 +435,13 @@ Two levels of checking, and the output always says which one ran: re-verifying a stored `/1` report ends with the first change of the bundled library; its consistency check stays. + Every checker call of `--verify` (session, export, condition trace, stored reference) runs in its + own process under the checker's 10-second wall limit. The checker is deterministic, so a process + that ran into that limit judged nothing: on a busy machine `--verify` runs it again, up to 3 + attempts, each under the full limit. Only when every attempt ran out of time does it stop, with + `checker_timeout` and the run (or the reference's task and seed) named, never with one of the codes + above: a timeout says nothing about the artifact. Run `--verify` again when the machine is less busy. + pass, pass@1, pass^k, mean actions and efficiency then follow from these values. Not re-verifiable and labelled *self-reported by the runner*: acceptedActions, rejected actions, undo, reset, host calls, wall time, exit status, notes, the client-reported model and diff --git a/docs/security/threat-model.md b/docs/security/threat-model.md index 66cf6cfb..1cfebba8 100644 --- a/docs/security/threat-model.md +++ b/docs/security/threat-model.md @@ -102,7 +102,7 @@ change with a test and an update of this table. No environment variable disables | Objects in state; actions per session | 10,000; 10,000 | `limit_exceeded` | same | | Undo snapshots | 1,000 or 64 MiB, then replay | — | same | | Predicates | depth 32, 4,096 nodes, 10⁶ evaluation steps | `checker_fuel_exhausted` | same | -| Checker process | 10 s wall, 256 MiB V8 heap | `checker_timeout` | same | +| Checker process | 10 s wall, 256 MiB V8 heap; a re-judge of a stored artifact (`report --verify`, a reference check) runs a timed-out check again, at most 3 attempts, each under the full limit | `checker_timeout` | same; `src/cli/runtime.ts` (`retryCheckerTimeout`) | | HTTP request body / headers | 64 KiB / 16 KiB; header deadline 10 s, request 30 s | `body_too_large` / 431 | `src/host/limits.ts` | | Request rate | burst 200, refill 50/s per host | `rate_limited` | same | | Reply size | 4 MiB | `result_too_large` | same | diff --git a/src/bench/verify.ts b/src/bench/verify.ts index 80b55a65..78d48150 100644 --- a/src/bench/verify.ts +++ b/src/bench/verify.ts @@ -46,7 +46,7 @@ import { isDeepStrictEqual } from 'node:util'; import { sha256Hex } from '../canonical/index.ts'; import { cliText } from '../cli/messages.ts'; import { safeText } from '../cli/output.ts'; -import { checkInProcess, traceInProcess } from '../cli/runtime.ts'; +import { CHECKER_ATTEMPTS, checkInProcess, isCheckerTimeout, retryCheckerTimeout, RuntimeError, traceInProcess } from '../cli/runtime.ts'; import { nativeMatchesState } from '../host/export-pair.ts'; import { PackageError } from '../package/index.ts'; import { LIMITS } from '../package/limits.ts'; @@ -79,6 +79,12 @@ async function artifact(directory: string, runId: string, name: string, expected return bytes.toString('utf8'); } +/** A checker that ran out of wall time in every attempt judged nothing: it is named as such + * (`checker_timeout`), never as the checker refusing the artifact. */ +function unjudged(error: unknown, runId: string): RuntimeError | null { + return isCheckerTimeout(error) ? new RuntimeError('checker_timeout', cliText('verifyCheckerTimeout', { run: runId, attempts: CHECKER_ATTEMPTS })) : null; +} + /** Re-judges one judged run from its artifacts against `world`; returns the session's text. */ async function rejudge(run: BenchRun | SessionRunV3, world: World, directory: string, artifactCode: BenchErrorCode, nativeName: string = RUN_ARTIFACTS.native): Promise { if (!run.artifacts) throw new BenchReportError(`run ${run.id} binds no artifacts; the report can be consistency-checked but not re-verified`); @@ -91,12 +97,12 @@ async function rejudge(run: BenchRun | SessionRunV3, world: World, directory: st if (session.log.length !== run.actions) throw new BenchReportError(cliText('verifyActions', { run: run.id, given: run.actions, actual: session.log.length })); const settings = { seed: run.seed, taskId: run.taskId }; let sessionRaw: CheckerVerdict, nativeRaw: CheckerVerdict | null = null; - try { sessionRaw = await checkInProcess(world, sessionText, settings); } - catch { throw new BenchReportError(cliText('verifyCheckerSession', { run: run.id })); } + try { sessionRaw = await retryCheckerTimeout(() => checkInProcess(world, sessionText, settings)); } + catch (error) { throw unjudged(error, run.id) ?? new BenchReportError(cliText('verifyCheckerSession', { run: run.id })); } if (nativeText !== null) { if (!nativeMatchesState(world, nativeText, session.state)) throw new BenchReportError(cliText('verifyNativeState', { run: run.id })); - try { nativeRaw = await checkInProcess(world, nativeText, settings); } - catch { throw new BenchReportError(cliText('verifyCheckerNative', { run: run.id })); } + try { nativeRaw = await retryCheckerTimeout(() => checkInProcess(world, nativeText, settings)); } + catch (error) { throw unjudged(error, run.id) ?? new BenchReportError(cliText('verifyCheckerNative', { run: run.id })); } } const stored = (() => { try { return parseJsonEntry(Buffer.from(checkerText), RUN_ARTIFACTS.checker, 64); } catch { return undefined; } })(); if (!isDeepStrictEqual(stored, JSON.parse(JSON.stringify({ session: sessionRaw, native: nativeRaw })))) @@ -175,8 +181,8 @@ async function verifyEvidence(run: BenchRunV2 | SessionRunV3, world: World, sess let derived: string; try { if ('reason' in timeline) throw new Error(timeline.reason); - derived = JSON.stringify(await traceInProcess(world, sessionText, timeline.timeline, { seed: run.seed, taskId: run.taskId })) + '\n'; - } catch { throw new BenchReportError(cliText('verifyTrace', { run: run.id })); } + derived = JSON.stringify(await retryCheckerTimeout(() => traceInProcess(world, sessionText, timeline.timeline, { seed: run.seed, taskId: run.taskId }))) + '\n'; + } catch (error) { throw unjudged(error, run.id) ?? new BenchReportError(cliText('verifyTrace', { run: run.id })); } if (derived !== texts.trace) throw new BenchReportError(cliText('verifyTrace', { run: run.id })); } diff --git a/src/bench/world.ts b/src/bench/world.ts index 2194924b..5dfddf63 100644 --- a/src/bench/world.ts +++ b/src/bench/world.ts @@ -19,7 +19,7 @@ import { runOracle, type OracleStep, type TaskOracle } from '../authoring/from-s import { canonicalJson, sha256Hex } from '../canonical/index.ts'; import { cliText } from '../cli/messages.ts'; import { displayPath, safeText } from '../cli/output.ts'; -import { checkInProcess, RuntimeError } from '../cli/runtime.ts'; +import { CHECKER_ATTEMPTS, checkInProcess, isCheckerTimeout, retryCheckerTimeout, RuntimeError } from '../cli/runtime.ts'; import { loadLibrary, LIBRARY_WORLD_DIR } from '../library/index.ts'; import { PackageError, packWorld, readArchiveFile, readWorldPackage } from '../package/index.ts'; import { parseJsonEntry } from '../package/json.ts'; @@ -192,9 +192,13 @@ export async function referenceProblem(world: World, taskId: string, reference: const session: SessionData = { schema: 'practonaut.session/1', world: { id: world.id, version: world.version }, seed, taskId, toolVersion: PACKAGE_VERSION, log: run.session.log, state: run.session.state, hash: run.session.hash }; let passed: boolean; try { - const verdict = await checkInProcess(world, JSON.stringify(session), { seed, taskId }); + const verdict = await retryCheckerTimeout(() => checkInProcess(world, JSON.stringify(session), { seed, taskId })); passed = verdict.passed && verdict.tasks.find(task => task.taskId === taskId)?.passed === true; - } catch (error) { return cliText('benchReferenceChecker', { task: safeText(taskId), seed, code: (error as { code?: string }).code ?? 'error' }); } + } catch (error) { + // A checker that ran out of wall time judged nothing: that is not a reason to call the reference invalid. + if (isCheckerTimeout(error)) throw new RuntimeError('checker_timeout', cliText('benchReferenceTimeout', { task: safeText(taskId), seed, attempts: CHECKER_ATTEMPTS })); + return cliText('benchReferenceChecker', { task: safeText(taskId), seed, code: (error as { code?: string }).code ?? 'error' }); + } return passed ? null : cliText('benchReferenceFails', { task: safeText(taskId), seed }); } diff --git a/src/cli/messages.ts b/src/cli/messages.ts index ccbfcc21..46ff2c58 100644 --- a/src/cli/messages.ts +++ b/src/cli/messages.ts @@ -619,6 +619,10 @@ export const CLI_CATALOG = { "en": "the reference of task {task} does not pass the checker: with seed {seed} its action {index} is rejected ({code})", "de": "die Referenz der Aufgabe {task} besteht den Prüfer nicht: mit Seed {seed} wird ihre Aktion {index} abgelehnt ({code})" }, + "benchReferenceTimeout": { + "en": "the reference of task {task} was not judged: with seed {seed} the checker did not finish within its 10 s wall limit in {attempts} attempts; is the machine busy?", + "de": "die Referenz der Aufgabe {task} wurde nicht beurteilt: mit Seed {seed} ist der Prüfer in {attempts} Versuchen nicht innerhalb seiner Grenze von 10 Sekunden fertig geworden; ist der Rechner ausgelastet?" + }, "benchReferenceChecker": { "en": "the reference of task {task} does not pass the checker: with seed {seed} the checker refuses it ({code})", "de": "die Referenz der Aufgabe {task} besteht den Prüfer nicht: mit Seed {seed} lehnt der Prüfer sie ab ({code})" @@ -863,6 +867,10 @@ export const CLI_CATALOG = { "en": "run {run}: the checker rejects the session artifact", "de": "Lauf {run}: der Prüfer lehnt das Sitzungsartefakt ab" }, + "verifyCheckerTimeout": { + "en": "run {run}: the checker did not finish within its 10 s wall limit in {attempts} attempts, so nothing was judged; is the machine busy? Run --verify again", + "de": "Lauf {run}: der Prüfer ist in {attempts} Versuchen nicht innerhalb seiner Grenze von 10 Sekunden fertig geworden, es wurde also nichts beurteilt; ist der Rechner ausgelastet? --verify erneut ausführen" + }, "verifyCheckerNative": { "en": "run {run}: the checker rejects the native export", "de": "Lauf {run}: der Prüfer lehnt den nativen Export ab" diff --git a/src/cli/runtime.ts b/src/cli/runtime.ts index 4a08f537..a37e3ad7 100644 --- a/src/cli/runtime.ts +++ b/src/cli/runtime.ts @@ -34,6 +34,21 @@ function integer(raw:string):number {if(!/^-?\d+$/.test(raw)||!Number.isSafeInte async function atomicFile(path:string,body:string):Promise{const tmp=path+".tmp-"+process.pid;try{await writeFile(tmp,body,{flag:"wx"});await rename(tmp,path);}catch(e){await rm(tmp,{force:true});throw e;}} /** The checker's condition trace of a judged session (PADR-0039), in the same separate process * with the same limits as a verdict. */ +/** How often a re-judge of a stored artifact runs the checker before it gives up on the wall limit. */ +export const CHECKER_ATTEMPTS=3; +/** The checker is deterministic (no clock, randomness or I/O), so an attempt that ran into its wall + * limit judged nothing: only the machine was too busy. A re-judge of a stored artifact (`report + * --verify`, a reference check) therefore runs the checker again, each attempt under the full ceiling, + * and only `checker_timeout` is retried: every other failure is the checker's answer. A bench run keeps + * its single attempt (`infra_error`). */ +export async function retryCheckerTimeout(attempt:()=>Promise,pause:(ms:number)=>Promise=ms=>new Promise(resolve=>setTimeout(resolve,ms))):Promise{ + for(let index=1;;index++){ + try{return await attempt();} + catch(error){if(!isCheckerTimeout(error)||index>=CHECKER_ATTEMPTS)throw error;await pause(1000*index);} + } +} +/** The checker process did not finish within its wall limit: nothing was judged. */ +export const isCheckerTimeout=(error:unknown):boolean=>error instanceof RuntimeError&&error.code==="checker_timeout"; export async function traceInProcess(world:World,session:string,timeline:readonly TraceEntry[],settings:{seed?:number;taskId?:string}={}):Promise{ const result=await checkInProcess(world,session,{...settings,trace:timeline}) as unknown as {trace?:ConditionTrace}; if(!result||typeof result!=="object"||!result.trace)throw new RuntimeError("checker_invalid",cliText("checkerProcess")); diff --git a/tests/support/stall-checker.ts b/tests/support/stall-checker.ts new file mode 100644 index 00000000..65c2961c --- /dev/null +++ b/tests/support/stall-checker.ts @@ -0,0 +1,17 @@ +// Preloaded into child processes through NODE_OPTIONS by tests/unit/checker-timeout-retry.test.ts: a +// checker process start (`src/checker/main.ts`) as a starved process on a busy machine sees it. Every +// checker start claims the next number in PN_STALL_DIR (start-1, start-2, …; mkdir is atomic); the +// starts listed in PN_STALL_AT then sleep past the checker's 10 s wall limit before the checker runs. +// Any other process, or a process without PN_STALL_DIR, is left alone. +import { mkdirSync } from 'node:fs'; +import { join } from 'node:path'; + +const directory = process.env.PN_STALL_DIR; +const stalled = new Set((process.env.PN_STALL_AT ?? '').split(',').filter(Boolean).map(Number)); +if (directory && /[\\/]checker[\\/]main\.(ts|js)$/.test(process.argv[1] ?? '')) { + for (let start = 1; start < 10_000; start++) { + try { mkdirSync(join(directory, `start-${start}`)); } catch { continue; } + if (stalled.has(start)) await new Promise(resolve => setTimeout(resolve, 12_000)); + break; + } +} diff --git a/tests/unit/checker-timeout-retry.test.ts b/tests/unit/checker-timeout-retry.test.ts new file mode 100644 index 00000000..6981804d --- /dev/null +++ b/tests/unit/checker-timeout-retry.test.ts @@ -0,0 +1,78 @@ +// The checker is deterministic, so a checker process that does not finish within its wall limit judged +// nothing: the machine was busy. Re-verifying a stored report runs it again and never reports such a run +// as the checker refusing the artifact. Regression for the gate run of 2026-11-17, where one starved +// checker start on a busy machine became "run review-and-send-s1-r1: the checker rejects the session +// artifact" for a committed report that verifies. +// +// The stall is made at the process boundary: tests/support/stall-checker.ts, preloaded into the checker +// processes through NODE_OPTIONS, holds the chosen checker starts past the 10 s limit. +import { test } from 'node:test'; +import assert from 'node:assert/strict'; +import { mkdtempSync, readdirSync, readFileSync, rmSync } from 'node:fs'; +import { tmpdir } from 'node:os'; +import { join } from 'node:path'; +import { fileURLToPath, pathToFileURL } from 'node:url'; +import { retryCheckerTimeout, RuntimeError } from '../../src/cli/runtime.ts'; +import { BenchReportError, validateBenchReportV2 } from '../../src/bench/report.ts'; +import { verifyBenchV2 } from '../../src/bench/verify.ts'; +import { libraryWorld } from '../../src/bench/run.ts'; + +const ROOT = fileURLToPath(new URL('../../', import.meta.url)); +const HOOK = pathToFileURL(join(ROOT, 'tests/support/stall-checker.ts')).href; +const FOLDER = join(ROOT, 'tests/fixtures/bench/v2'); +const report = (): ReturnType => validateBenchReportV2(JSON.parse(readFileSync(join(FOLDER, 'report.json'), 'utf8'))); +// verifyBenchV2 first checks the stored reference (checker start 1), then re-judges the session of +// run review-and-send-s1-r1 (start 2). +const SESSION_START = 2; + +/** Runs `work` with the listed checker starts stalled; returns its value or error and how many checker + * processes started (zero would mean the stall never reached a checker: the test would prove nothing). */ +async function withStalledStarts(stalled: number[], work: () => Promise): Promise<{ value?: T; error?: unknown; starts: number }> { + const directory = mkdtempSync(join(tmpdir(), 'pn-stall-')); + const saved = { NODE_OPTIONS: process.env.NODE_OPTIONS, PN_STALL_DIR: process.env.PN_STALL_DIR, PN_STALL_AT: process.env.PN_STALL_AT }; + process.env.NODE_OPTIONS = [saved.NODE_OPTIONS, `--import=${HOOK}`].filter(Boolean).join(' '); + process.env.PN_STALL_DIR = directory; + process.env.PN_STALL_AT = stalled.join(','); + try { + try { const value = await work(); return { value, starts: readdirSync(directory).length }; } + catch (error) { return { error, starts: readdirSync(directory).length }; } + } finally { + for (const [key, value] of Object.entries(saved)) { if (value === undefined) delete process.env[key]; else process.env[key] = value; } + rmSync(directory, { recursive: true, force: true }); + } +} + +test('a checker start that stalls past the wall limit is run again, and the committed report still re-verifies', async () => { + const outcome = await withStalledStarts([SESSION_START], () => verifyBenchV2(report(), FOLDER, libraryWorld)); + assert.equal(outcome.error, undefined, String((outcome.error as Error | undefined)?.message)); + assert.deepEqual([outcome.value?.reverified, outcome.value?.unjudged], [2, 0]); + assert.ok(outcome.starts > SESSION_START, `the stalled start was reached and followed by others (starts: ${outcome.starts})`); +}); + +test('a checker that never finishes within the wall limit is named as a timeout, never as refusing the artifact', async () => { + const outcome = await withStalledStarts([SESSION_START, SESSION_START + 1, SESSION_START + 2], () => verifyBenchV2(report(), FOLDER, libraryWorld)); + assert.ok(outcome.error instanceof RuntimeError, `a RuntimeError, not ${(outcome.error as Error | undefined)?.name}: ${(outcome.error as Error | undefined)?.message}`); + assert.ok(!(outcome.error instanceof BenchReportError)); + assert.equal(outcome.error.code, 'checker_timeout'); + assert.match(outcome.error.message, /run review-and-send-s1-r1: .*10 s wall limit in 3 attempts/); + assert.doesNotMatch(outcome.error.message, /rejects/); +}); + +test('only checker_timeout is retried, three attempts at most, with a growing pause', async () => { + const timeout = (): RuntimeError => new RuntimeError('checker_timeout', 'wall limit'); + const pauses: number[] = []; + const pause = async (ms: number): Promise => { pauses.push(ms); }; + + let calls = 0; + assert.equal(await retryCheckerTimeout(async () => { calls++; if (calls < 3) throw timeout(); return 'judged'; }, pause), 'judged'); + assert.deepEqual([calls, pauses], [3, [1000, 2000]]); + + calls = 0; + await assert.rejects(retryCheckerTimeout(async () => { calls++; throw timeout(); }, pause), (error: unknown) => error instanceof RuntimeError && error.code === 'checker_timeout'); + assert.equal(calls, 3); + + // A refusal is the checker's answer: it is never asked again. + calls = 0; + await assert.rejects(retryCheckerTimeout(async () => { calls++; throw new RuntimeError('checker_invalid', 'refused'); }, pause), (error: unknown) => (error as RuntimeError).code === 'checker_invalid'); + assert.equal(calls, 1); +});