Repository navigation
fix(harness): convert runGrader to async spawn — resolves #1237 same-process deadlock - #1250
Conversation
PR #1241 closed the stdin-pipe stall but the grader still hung 120s on storyboards that exercise upstream calls. Root cause: the harness boots the mock upstream HTTP server in the SAME Node process, then called `spawnSync` for the grader. spawnSync blocks the event loop — while it runs, the in-process upstream can't respond. Agent calls upstream, upstream's HTTP handler never gets a tick, agent blocks on the response, grader blocks on the agent, full deadlock at the configured timeout. Standalone reproducer (upstream in a separate process) ran identical spawnSync invocations to completion in ~1s, which ruled out stdio buffering, webhook-receiver port collision, and pipe-buffer exhaustion. The hang is specific to the harness's same-process upstream + sync child wait. Fix: convert `runGrader` to async — `spawn` + readable streams + Promise on `'close'`, with a SIGTERM-on-timeout via setTimeout. The event loop stays live, the upstream serves alongside the grader, the deadlock is gone. Also `await` the call site. Verified on signal_marketplace verify-mode: - Before: 22-line log, 120s timeout, traffic shows only 1 lookup hit. - After: 632-line log (full grader JSON), 1.5s wall, traffic shows the storyboard's full upstream activity. `overall_status: partial` matches direct-grader invocation. Resolves #1237 (the residual hang #1241 didn't catch).
Code review on PR #1250 (code-reviewer + nodejs-testing-expert converged on this) flagged a real failure path the prior version missed: if `spawn` fails to start the child (ENOENT, EACCES) Node emits 'error', and without a listener the harness throws an uncaught exception. Without also resolving the Promise on 'error', a failed spawn could hang the awaiter. Fix: - Settle the await on whichever of 'error' or 'close' comes first; capture the spawn error into the diagnostic. - New log line: `grader: spawn failed — ENOENT: ...` so a missing `node` binary surfaces clean instead of a stack trace. - Append the spawn-error message to `raw` so the matrix log carries it. Per DX expert review: rebuild the timeout-debug hint from the actual `args.join(' ')` so the fallback command can't drift from the spawn call. Also surface the `--mode build --keep` + `--mode verify` debug loop, which is the operator's actual recovery path. Verified spawn-error semantics with `spawn('nonexistent', [])` — the 'error' event fires with code ENOENT as expected. The TS narrowing dance (closure-assigned `let` → `never` at read site) routed through a wrapper object; comment explains why.
|
Expert review pass: 3 reviewers in parallel (code-reviewer, nodejs-testing-expert, dx-expert). Convergent finding: one blocker — missing Fixed:
Deferred to follow-ups (non-blockers):
Verified spawn-error semantics: |
|
Thanks for the thorough review pass. The Generated by Claude Code |
|
Agreed — the Generated by Claude Code |
|
Acknowledged — agree the current state looks good. Waiting on CI; will keep an eye on the run. Triaged by Claude Code. Session: https://claude.ai/code/session_019o91h3KWyxbAgSFZvejewE Generated by Claude Code |
The Check-for-changeset CI job classified the harness change as needing a release entry even though `scripts/manual-testing/` isn't shipped in the npm package's `files` field. Add a patch changeset documenting the fix so the gate passes; the published library is untouched. The changeset body explains the rationale so the next maintainer isn't confused by a "fix" entry that doesn't change runtime behavior.
Summary
PR #1241 closed the stdin-pipe stall but the grader still hung 120s on storyboards that exercise upstream calls. Root cause: the harness boots the mock upstream HTTP server in the same Node process, then called
spawnSyncfor the grader.spawnSyncblocks the event loop — while it runs, the in-process upstream can't respond. Agent calls upstream, upstream's HTTP handler never gets a tick, agent blocks on the response, grader blocks on the agent, full deadlock at the configured timeout.This is the residual hang flagged in #1237 that #1241 didn't address.
Diagnosis
A standalone reproducer (upstream in a separate child process) ran identical
spawnSyncinvocations to completion in ~1s across three stdio configurations (pipe/pipe,pipe/inherit,inherit/inherit). That ruled out:The hang was specific to the harness's combination of (a) in-process upstream + (b) synchronous child wait. Same-process deadlock.
Fix
Convert
runGraderto async:spawn+ readable-stream chunk collection +Promiseon'close', withsetTimeout→child.kill('SIGTERM')for the 120s cap. The parent event loop stays live, so the in-process upstream serves alongside the grader.Call site (
main()) getsawait.Verification
signal_marketplaceverify-mode against a kept blind-fixture workspace:_lookup/operator: 1only_lookup/operator: 2, /v2/cohorts: 2overall_status: partialmatches direct-grader invocation. The harness's traffic check still correctly flagsPOST /v2/activations: 0(separate storyboard-cascade issue, adcontextprotocol/adcp#3796).Refs
Test plan
🤖 Generated with Claude Code