Skip to content

fix(spawnRun): a shell command's exit 1 is a failed run on Windows, not ENOENT - #28

Closed
sanctrl wants to merge 2 commits into
mainfrom
fix/shell-run-exit-code
Closed

sanctrl wants to merge 2 commits into
mainfrom
fix/shell-run-exit-code

Conversation

@sanctrl

@sanctrl sanctrl commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

What changes

On Windows, spawnRun({ shell: true }) reported every command line that exited with code 1 as not_started with spawn "<command>" ENOENT, as if the command did not exist. The CLI's agentchat listen --run "<command>" is the one caller: a Windows owner's command that got going and then failed with exit 1 (a provider refusal, a crash) was said to be missing, and its failure was never a could-not-process failure.

Cause: spawnRun spawns through cross-spawn. With shell: true, cross-spawn passes the call straight to child_process.spawn and resolves nothing (parse() returns before parseNonShell, so parsed.file stays unset), but it still installs its Windows hook (lib/enoent.js, verifyENOENT): an exit with status 1 and no resolved file is re-emitted as an error ENOENT. For a shell spawn that is every exit 1: cmd.exe /c exits 1 both for a command it cannot find and for a command that ran and failed with 1, so a failed run read as "not found".

Fix: shell runs use Node's child_process.spawn directly (identical for shell: true, minus the hook) and keep the exit code; the existing rule tells the two apart as on every platform: a non-zero exit with nothing on stdout is not_started, one after output is failed. Direct runs keep cross-spawn for PATHEXT and .cmd shim resolution. CHANGELOG (Unreleased); no version bump.

Commit 1 is the test alone, so the Windows job shows the failure before the fix.

Verification

  • Tests: local (macOS) pnpm type-check, pnpm build ok, pnpm test 39 files, 631 passed, 3 skipped. CI on commit 1 (26a803a, the tests alone): Windows failed exactly as reported: exit 1 after output came back not_started (ENOENT), the not-found case had exit code null (the hook's error), while exit 2 was failed; Linux and macOS passed. CI on commit 2 (8d784e4, the fix): Linux, macOS and Windows all green. The CLI's tests on Windows against this engine (packed and vendored in throwaway draft [do not merge] CI proof: CLI on Windows with the agent-core#28 shell-run fix agentchat-cli#17): green.
  • Review: self-review; no independent review yet (draft).
  • Live check: n/a: no release here; it ships with the next engine release, which the CLI bundles.

Risk and rollback

Shell runs only (the CLI's --run); preset and integration runs are not shell runs and keep cross-spawn. Rollback: revert.

`spawnRun({ shell: true })` runs the CLI's `listen --run` command line.
A command that got going and exited 1 must be a failed run with exit 1;
one the shell cannot find (sh 127, cmd.exe 9009, nothing on stdout) is
not started. Expected to fail on Windows until spawnRun stops routing
shell runs through cross-spawn, whose Windows hook turns every exit 1
of a shell spawn into a `spawn … ENOENT` error.
Shell runs (the CLI's `listen --run` command line) went through
cross-spawn. With `shell: true` cross-spawn resolves nothing, but its
Windows hook still re-emits every exit 1 as `spawn <command> ENOENT`:
a command that ran and failed with 1 became `not_started`, said to be
missing, and was never a could-not-process failure. Shell runs now use
Node's own spawn and keep the exit code; the existing rule tells a
command cmd.exe cannot find (exit 1, nothing on stdout: not started)
from one that ran and failed (exit 1 after output: failed). Direct runs
keep cross-spawn for PATHEXT and .cmd shim resolution.

The test's Windows exit code for a command not found is 1, as the
previous commit's CI run on Windows showed (cmd.exe /c exits 1).
sanctrl added a commit to agentchatme/agentchat-cli that referenced this pull request Nov 20, 2026
…er outlives its test

Windows CI failed the two could-not-process e2e tests: every run of the
stand-in command that exited 1 came back `not_started` with
`spawn "<command>" ENOENT`, so no failure was ever reported. The cause
is the engine's spawnRun: shell runs go through cross-spawn, whose
Windows hook re-emits every exit 1 of a shell spawn as ENOENT. Fixed in
agent-core (agentchatme/agentchat-agent-core#28); the CLI picks it up
with the engine pin at the release step.

- A CommandRunner test pins the contract directly: a command that ran
  and exited 1 is `failed` with exit 1, never "not found".
- The e2e tests stop every listener and watcher they started in
  afterEach (bounded at twice the engine's 10 s stop grace), so a test
  that fails before its own abort no longer leaves a listener running
  into the next test and spawning from a folder that is gone.
@sanctrl

sanctrl commented Nov 20, 2026

Copy link
Copy Markdown
Contributor Author

Included in the 0.7.1 release PR #29 (cherry-picked as 8821f2b and 9c9f963).

@sanctrl sanctrl closed this Nov 20, 2026
sanctrl added a commit to agentchatme/agentchat-cli that referenced this pull request Nov 20, 2026
…t-core 0.7.1, manual 2.4.0 (#16)

* feat(listen): one run per conversation, and could not process

With served texts that carry the per-conversation prompt, the engine's
receive loop starts one run per conversation that owes a reply (and one
for pending invites). The listener wires its runners into that:

- the --run command's environment comes from the engine's run context
  (runContextEnv): AGENTCHAT_WAKE_KIND can be `conversation`, a
  conversation run gets AGENTCHAT_CONVERSATION_ID, and every other run
  never inherits one;
- forward keeps one POST per wake (conversationRuns: false), its receiver
  reading the whole tray itself; the foreground and the installed
  listener take their loop options from one place (listenerRunOptions);
- a --run command has no runtime check, so a failed conversation run is
  reported only with other_run_completed evidence; the presets have the
  engine's runtime check;
- status and doctor show the engine's could-not-process lines.

listen, --help, README and CHANGELOG say how a wake becomes runs and
what could not process means for the owner.

Builds against the unreleased agent-core and agentchatme that add
conversation runs; the pins move at the release step.

* test: the presets' runtime check on the engine's JSON result; uninstall removes the ledger

The engine's Claude Code runtime check now asks for `--output-format
json` and judges the result object; the fake runtimes answer one when
it is asked for. With the engine's updated clearIntegrationStatus,
`listen --uninstall` removes could-not-process.json too: README,
CHANGELOG and the service comment say so, and the uninstall test checks
it.

* release: 0.4.0 — one run per conversation and could-not-process; agent-core 0.7.0, manual 2.4.0

* docs: upgrading a --run script from 0.3.0 (one run per conversation, AGENTCHAT_CONVERSATION_ID); drop the stale pin note

* test(listen): a --run command that exits 1 is a failed run; no listener outlives its test

Windows CI failed the two could-not-process e2e tests: every run of the
stand-in command that exited 1 came back `not_started` with
`spawn "<command>" ENOENT`, so no failure was ever reported. The cause
is the engine's spawnRun: shell runs go through cross-spawn, whose
Windows hook re-emits every exit 1 of a shell spawn as ENOENT. Fixed in
agent-core (agentchatme/agentchat-agent-core#28); the CLI picks it up
with the engine pin at the release step.

- A CommandRunner test pins the contract directly: a command that ran
  and exited 1 is `failed` with exit 1, never "not found".
- The e2e tests stop every listener and watcher they started in
  afterEach (bounded at twice the engine's 10 s stop grace), so a test
  that fails before its own abort no longer leaves a listener running
  into the next test and spawning from a folder that is gone.

* release: 0.4.0 — agent-core 0.7.1 (Windows --run exit codes, runtime check), agentchatme ^1.5.0; fake runtimes answer with a finished turn
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant