Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
id: bugfix-1946
title: windows-bugfix-1814-check-time
protocol: bugfix
phase: pr
plan_phases: []
current_plan_phase: null
gates:
pr:
status: approved
requested_at: '2026-11-22T22:11:04.150Z'
approved_at: '2026-11-22T22:19:19.584Z'
iteration: 1
build_complete: false
history: []
started_at: '2026-11-22T21:53:06.605Z'
updated_at: '2026-11-22T22:19:19.585Z'
pr_ready_for_human: false
21 changes: 21 additions & 0 deletions codev/state/bugfix-1946_thread.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# bugfix-1946 thread

## Investigate
- File passes alone on this host (12 passed, 3 skipped).
- Reproduced under synthetic load (2x cores busy node workers + 8 loops launching cmd.exe), 300ms timeout:
`sleep 3` -> 4454 / 3429 / 3187 ms (fails the 2500ms bound); `sleep 30` -> 2905 / 3199 / 3434 ms.
- So the kill lands late (~3s: census + job terminate + taskkill, each a process launch), it does not fail to land.
No product bug; no escalation.
- Root cause is the test: with a 3s sleep the check can end on its own inside the teardown window and still
report "Timed out" (`killed` is set when the timer fires, checks.ts:115), so 2500ms can't tell late kill from no kill.
- Plan: sleep 30 in the three tests; bound 2500ms on POSIX, 15000ms on win32 (half the sleep, ~4x the worst
observed); assert the bound in all three; per-test timeout 45s so a missing kill fails on the bound, not on a timeout.

## Fix
- Test-only change in bugfix-1814-check-timeout.test.ts; checks.ts untouched.
- Mutation check: with the timeout's killGroup calls removed, all three tests fail at ~30.1s against the 15s bound.
- Full suite on this host, one run at a time, Tower PID 53132 before and after each:
run 1 via `porch done` (build 51.7s, tests 146.6s, passed first try); runs 2 and 3 `npm test`:
406 files passed / 9 skipped, 8110 tests passed / 247 skipped, both.
- Side note (not changed, out of scope): runCheck reports "Timed out" whenever the timer fired, even if the
command then exited on its own before the kill landed (`killed` is set at checks.ts:115).
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,20 @@ import { logCheckOverrides } from '../index.js';

const env: CheckEnv = { PROJECT_ID: '1814', PROJECT_TITLE: 'check-timeout' };

/**
* A check that only a kill can end early (#1946). With a 3-second sleep the check could finish on its own
* inside a slow Windows teardown and still report "Timed out", so a late kill and no kill looked the same.
*/
const SLOW_COMMAND = 'sleep 30';
/**
* How soon a 300ms timeout must end the check. On Windows the teardown is a census, a job termination and a
* taskkill, each its own process launch: about 3s under full-suite load (#1946), so the bound is half the
* sleep. POSIX signals the process group directly and keeps the tight bound.
*/
const KILLED_WITHIN_MS = process.platform === 'win32' ? 15_000 : 2500;
/** Long enough that a check nobody killed fails on KILLED_WITHIN_MS, not on the test timeout. */
const SLOW_TEST_TIMEOUT_MS = 45_000;

function writeProtocol(root: string, checks: Record<string, unknown>, defaults?: unknown): void {
const dir = path.join(root, 'codev/protocols/timeouts');
fs.mkdirSync(dir, { recursive: true });
Expand Down Expand Up @@ -62,16 +76,16 @@ describe('bugfix #1814: per-check timeout_ms', () => {
});

it('a protocol.json timeout_ms reaches the runner and kills the check at that value', async () => {
writeProtocol(root, { tests_py: { command: 'sleep 3', timeout_ms: 300 } });
writeProtocol(root, { tests_py: { command: SLOW_COMMAND, timeout_ms: 300 } });

const checks = getPhaseChecks(loadProtocol(root, 'timeouts'), 'implement');
expect(checks.tests_py.timeout_ms).toBe(300);

const [result] = await runPhaseChecks(checks, root, env);
expect(result.passed).toBe(false);
expect(result.error).toContain('Timed out after 0.3s');
expect(result.duration_ms).toBeLessThan(2500);
}, 15_000);
expect(result.duration_ms).toBeLessThan(KILLED_WITHIN_MS);
}, SLOW_TEST_TIMEOUT_MS);

it('a timeout_ms in defaults.checks is parsed too', () => {
writeProtocol(root, {}, { checks: { tests_py: { command: 'x', timeout_ms: 900_000 } } });
Expand All @@ -80,19 +94,21 @@ describe('bugfix #1814: per-check timeout_ms', () => {
});

it('a check without timeout_ms keeps the runner default', async () => {
writeProtocol(root, { build: { command: 'sleep 3' } });
writeProtocol(root, { build: { command: SLOW_COMMAND } });

const checks = getPhaseChecks(loadProtocol(root, 'timeouts'), 'implement');
expect(checks.build.timeout_ms).toBeUndefined();

const [result] = await runPhaseChecks(checks, root, env, 300);
expect(result.error).toContain('Timed out after 0.3s');
}, 15_000);
expect(result.duration_ms).toBeLessThan(KILLED_WITHIN_MS);
}, SLOW_TEST_TIMEOUT_MS);

it('a check timeout_ms takes precedence over the runPhaseChecks default', async () => {
const [result] = await runPhaseChecks({ slow: { command: 'sleep 3', timeout_ms: 300 } }, root, env, 60_000);
const [result] = await runPhaseChecks({ slow: { command: SLOW_COMMAND, timeout_ms: 300 } }, root, env, 60_000);
expect(result.error).toContain('Timed out after 0.3s');
}, 15_000);
expect(result.duration_ms).toBeLessThan(KILLED_WITHIN_MS);
}, SLOW_TEST_TIMEOUT_MS);

it.each([0, -1, 1.5, '900000', 2 ** 31])('rejects timeout_ms %j at load', (value) => {
writeProtocol(root, { tests_py: { command: 'x', timeout_ms: value } });
Expand Down
Loading