Skip to content

Terminal cleanup: a dead supervisor always reads as a missing receipt - #64

Merged
BunsDev merged 1 commit into
mainfrom
fix-cleanup-flakes
Oct 2, 2026
Merged

BunsDev merged 1 commit into
mainfrom
fix-cleanup-flakes

Conversation

@BunsDev

@BunsDev BunsDev commented Oct 2, 2026

Copy link
Copy Markdown
Contributor

Investigation of the two test/terminal-cleanup.test.ts CI flakes recorded in docs/status.md.

EPIPE in supervisor death without a cleanup receipt… — root cause, fixed

stopTerminalProcess writes CLOSE to the supervisor's control socket. If the supervisor was killed and Node has not yet read its EOF, socket.destroyed is still false, the write hits a dead peer, and connection.on("error", fail) rejected with the raw write EPIPE before the "close" handler could report Terminal supervisor exited without confirming cleanup. Both refuse deletion; only the message depended on timing. Reproduced locally 1 in 200 (SIGKILL then immediate close).

  • Fix (terminal-process.ts): a socket error is kept as cause; "close" (which always follows "error") reports the missing receipt.
  • Test: supervisor death seen as a failed CLOSE write… blocks without yielding until the supervisor is a zombie or reaped, so the EPIPE path runs every time. Before the fix: 5/5 failures with write EPIPE. After: passes; the natural race probe went from 1/200 to 0/200.

ESRCH in cleanup timeout retains ownership… — not reproduced, now self-diagnosing

On #63's push run the supervisor the test froze with SIGSTOP was exited and reaped within 56 ms, and the finally's SIGCONT threw ESRCH over whatever the test body saw. Tested on macOS 26 (CI's OS), none reproduced:

Hypothesis Result
SIGSTOP lost while the helper execs the supervisor 0 / 684, delays 0–3 ms, state checked with ps
node-pty's macOS exit watcher SIGKILLs a child whose kqueue registration races exec (pty.cc:141-156) 0 / 6,000 spawns
supervisor already a zombie at SIGSTOP ruled out: kill() on a zombie succeeds on macOS, so ESRCH means reaped
the test body itself, 6 lanes + 2 full suites looping for load 0 anomalies in 360+ iterations, 24 suite runs green

The test now tolerates an already-gone process in its SIGCONT cleanup and asserts with how close() settled and the supervisor's exit, e.g. close() resolved, exit {"exitCode":143,"signal":0}. Next time: 143 = the stop never held, signal 9 = killed, 125 = startup failure.

Also found

Each terminal session leaks a PTY until the app quits (20 open/close cycles → 20 PTY fds held). Recorded in docs/status.md; fixed separately.

Tests

npm run build && npm run typecheck && npm test: core 15/15, desktop 146/146. terminal-cleanup.test.js 5× in a row: 8/8 each.

🤖 Generated with Claude Code

A supervisor killed just before close() can surface as EPIPE when CLOSE
is written before its EOF is read. The raw socket error rejected cleanup
with "write EPIPE" instead of "exited without confirming cleanup"; both
refused deletion, but the message depended on timing and the
"supervisor death" test failed on main CI for c9dcc7d. Keep the socket
error as the cause and let "close" report the missing receipt.

A new test blocks until the supervisor is gone before close(), so the
EPIPE path runs every time (5/5 failures before the fix, passing after).

The cleanup-timeout test's one CI failure (#63, kill ESRCH from its
SIGCONT) did not reproduce locally in 1,300+ attempts. It now reports
how close() settled and how the supervisor exited instead of failing on
its cleanup. status.md records that and a PTY leak found along the way.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Copilot AI balanced review requested due to automatic review settings October 2, 2026 00:55

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟢 Approval recommended

The focused implementation and regression tests correctly address the reported race without unresolved issues.

Review effort: Balanced
Findings: None

What changed in this PR

Fixes terminal cleanup error reporting and improves CI-flake diagnostics.

Changes:

  • Preserves socket errors as causes while consistently reporting missing cleanup receipts.
  • Adds deterministic EPIPE regression coverage.
  • Improves cleanup-timeout diagnostics and documents the remaining PTY leak.
File Description
apps/​desktop/​src/​main/​engine/​terminal-process.ts Normalizes dead-supervisor cleanup errors.
apps/​desktop/​test/​terminal-cleanup.test.ts Adds regression coverage and diagnostics.
docs/​status.md Updates terminal cleanup status and records the PTY leak.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@BunsDev
BunsDev merged commit 9d6a056 into main Oct 2, 2026
3 checks passed
@BunsDev
BunsDev deleted the fix-cleanup-flakes branch October 2, 2026 00:58
BunsDev added a commit that referenced this pull request Oct 2, 2026
Point the PTY-leak entry at #65 instead of its branch, note that no
packaged build has run the node-pty beta yet (v0.0.5's packaged e2e will
be the first), and add #64's consistent cleanup-failure message.

Co-authored-by: Claude Opus 5.5 <[email protected]>
BunsDev added a commit that referenced this pull request Oct 3, 2026
BunsDev added a commit that referenced this pull request Oct 3, 2026
* Release v0.0.5: Developer ID signed and notarized, Modex app icon

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* release-mac: sign, notarize and staple the DMG; CI imports the identity itself

electron-builder notarizes and staples only the app, so the first full run
refused an unstapled DMG. The script now signs the DMG by certificate hash
with a secure timestamp, notarizes and staples it, and verify checks its
leaf certificate and Gatekeeper verdict. CI imports the .p12 into its own
temporary keychain (CSC_KEYCHAIN) because electron-builder's keychain is
gone before the DMG step, which also lets CI resolve and sign by hash
exactly as a local run does.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* Release workflow: verify the annotated tag, not checkout's lightweight copy

actions/checkout leaves a pushed tag as a lightweight ref to the commit, so
`git tag -v` failed with "cannot verify a non-tag object of type commit" on
the v0.0.5-rc.1 rehearsal. Fetch the tag object first and refuse anything
that is not an annotated tag.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* release-mac: build @modex/core before the desktop release build

A fresh checkout has no packages/core/dist, so the v0.0.5-rc.2 rehearsal
failed in tsc with "Cannot find module '@modex/core'". A local worktree only
passed because the root build had already run there. The bundle ships
core's dist/, so the release build now produces it itself.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* docs: v0.0.5 release review (draft)

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* docs: v0.0.5 review verification numbers; status links #69

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* docs: record the #64 EPIPE test flake seen on #69's CI

Co-Authored-By: Claude Opus 5.5 <[email protected]>

---------

Co-authored-by: Claude Opus 5.5 <[email protected]>
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