Skip to content

fix(agents): report an agent killed by a signal as failed with exit 128+n - #188

Merged
howdeploy merged 2 commits into
howdeploy:mainfrom
BIackFIame:pr185/orch-exit-signal
Nov 1, 2026
Merged

howdeploy merged 2 commits into
howdeploy:mainfrom
BIackFIame:pr185/orch-exit-signal

Conversation

@BIackFIame

@BIackFIame BIackFIame commented Nov 1, 2026 •

Copy link
Copy Markdown
Contributor

Split out of #160 as a small, independent PR on 1.8.5 (it touches only what 1.8.5 does not already cover). It does not depend on the other parts.

Problem

node-pty reports a process that a signal ended as { exitCode: 0, signal: 9 }. TerminalManager.recordExit only looked at exitCode, so a subagent whose CLI was killed (out of memory, kill -9, a crashed wrapper) was recorded as done, exit 0.

Before:

  1. An orchestrator spawns an OpenCode subagent; the subagent's process is killed with SIGKILL.
  2. wait_for_agent returns reason: "done", exitCode: 0; get_agent_result says state: "done".
  3. The orchestrator reports the part as finished. The saved session restores as a clean exit, and HOME shows no failure.

After: the same kill is recorded as exitCode: 137, status: "failed", and the failure details start with The process was killed by signal SIGKILL (9). wait_for_agent returns failed, get_agent_result returns state: "failed", the saved session restores as failed and HOME's failure summary shows 137 with the signal line.

Change

process.onExit passes the signal on to recordExit. A non-zero signal is recorded the way a shell reports it, as 128 + signal, and its name (from os.constants.signals) is the first line of failureDetails, followed by the masked screen lines that were already collected. One file in src/ changes (+20/-6).

Why this and not less

Every reader of an exit already derives its state from metadata.exitCode (waitFor, result, persistedTerminalSession, failureSummary). Converting the signal once, where the exit is recorded, makes all of them right without touching any of them. Mapping only status would leave exitCode: 0 next to failed, and the session store and HOME summary would still disagree. 128+n is the convention shells and CI tools already use, so the number reads the same way it does in a terminal.

What changes for existing workflows

  • Clean exits and ordinary non-zero exits are unchanged (the reported code is used as before).
  • Exits CanvasTTY causes itself (closing a card, quitting the app) are unchanged: those sessions are removed before the kill and the exit handler ignores them.
  • A shell wrapper that catches the signal and exits with its own code still reports that code; nothing is named in that case because node-pty receives no signal.
  • Windows ConPTY reports no signals; nothing changes there.

Validation

  • New tests/subagent-signal-exit.test.mjs:
    • a fake PTY exit { exitCode: 0, signal: 15 } must give 143/failed with SIGTERM (15) named in the card, wait_for_agent, get_agent_result, the saved session and the HOME failure summary;
    • exits without a signal keep their code;
    • a real /bin/sleep under node-pty killed with SIGKILL must give 137/failed, and a real /usr/bin/true must stay done/0 (POSIX only).
  • On f3eee29 without the fix, the first and third tests fail (done/0 instead of failed/143 and 137); with the fix all pass.
  • tests/terminal-lifecycle.test.mjs: one source assertion follows the renamed line; it accepts CRLF (\r?\n), as the Windows checkout has.
  • npm run build (typecheck), npm run audit:secrets, the eager renderer bundle check and the full test suite pass. Full suite: 2654 tests, 2648 pass, 0 fail, 6 skipped. The renderer is untouched (eager bundle unchanged against the other branches; renderer-bundle-splitting passes).

…28+n

node-pty reports a process killed by a signal as exitCode 0 plus the
signal. recordExit dropped the signal, so an agent killed with SIGKILL
(out of memory, kill -9) was recorded as "done, exit 0": wait_for_agent
returned done, get_agent_result said done and the saved session restored
as exited.

Record such an exit the way a shell does, as 128+signal (SIGKILL -> 137),
mark the session failed and put the signal name first in the failure
details. Every reader of the exit (wait_for_agent, get_agent_result, the
session store, the HOME failure summary) already derives its state from
the exit code, so they now agree. Exits CanvasTTY causes itself (closing a
card, quitting) are unaffected: those sessions are removed before the
kill, and the exit handler ignores them.
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 1, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-01T10:42:41.218853Z 9c3f9f0 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

On the Windows CI runner the checkout uses CRLF, so the source assertion
added for the renamed line (a literal "\n" between two lines of
TerminalManager.ts) did not match. It now accepts "\r?\n".
@BIackFIame

Copy link
Copy Markdown
Contributor Author

The failure was ours. On Windows the checkout uses CRLF, and the source assertion this PR changed in tests/terminal-lifecycle.test.mjs ("failed PTYs preserve their final sanitized output as failure details") matched a literal \n between two lines of TerminalManager.ts. Fixed in 0b9300d: it now accepts \r?\n. The new signal tests were already skipped on win32.

@howdeploy
howdeploy merged commit e4e38ed into howdeploy:main Nov 1, 2026
7 checks passed
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.

2 participants