Repository navigation
Terminal cleanup: a dead supervisor always reads as a missing receipt - #64
Merged
Merged
Conversation
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]>
Contributor
There was a problem hiding this comment.
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.
This was referenced Oct 2, 2026
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
Co-Authored-By: Claude Opus 5.5 <[email protected]>
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]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Investigation of the two
test/terminal-cleanup.test.tsCI flakes recorded indocs/status.md.EPIPE in supervisor death without a cleanup receipt… — root cause, fixed
stopTerminalProcesswritesCLOSEto the supervisor's control socket. If the supervisor was killed and Node has not yet read its EOF,socket.destroyedis still false, the write hits a dead peer, andconnection.on("error", fail)rejected with the rawwrite EPIPEbefore 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).terminal-process.ts): a socket error is kept ascause;"close"(which always follows"error") reports the missing receipt.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
SIGSTOPwas exited and reaped within 56 ms, and thefinally'sSIGCONTthrew ESRCH over whatever the test body saw. Tested on macOS 26 (CI's OS), none reproduced:SIGSTOPlost while the helper execs the supervisorpspty.cc:141-156)SIGSTOPkill()on a zombie succeeds on macOS, so ESRCH means reapedThe test now tolerates an already-gone process in its
SIGCONTcleanup and asserts with howclose()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.js5× in a row: 8/8 each.🤖 Generated with Claude Code