From 17ccf6bd2e5b14ae0a49982b9bd2b476264da01f Mon Sep 17 00:00:00 2001 From: Dotta <34892728+cryppadotta@users.noreply.github.com> Date: Mon, 23 Nov 2026 08:11:35 -0600 Subject: [PATCH] fix(runner-tests): stop the host-control test wrapper from aborting at exit (#22624) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## Thinking Path > - Paperclip is the open source app people use to manage AI agents for work > - The paperclip-runner package has a live test that starts the native runner through a Python wrapper, `test/support/private-host-control.py` > - The wrapper has a daemon thread that reads frames from stdin. This thread stays blocked in `readline` after the native child exits > - At interpreter shutdown, Python must close stdin. The blocked thread holds the stdin buffer lock, so Python aborts with "could not acquire lock ... at interpreter shutdown, possibly due to daemon threads" (SIGABRT) > - On macOS, each abort opens a "Python quit unexpectedly" dialog. Long unattended agent sessions run this test many times and leave tens of dialogs (59 crash reports on one machine) > - This pull request makes the wrapper exit with `os._exit` after it flushes its receipts > - The benefit is a clean wrapper exit and no crash dialogs on developer machines ## Linked Issues or Issue Description **What happened?** Each run of `src/live/runnerd-codex-transport-release-resume.test.ts` aborts its Python wrapper with SIGABRT at exit. On macOS each abort opens a crash dialog. The crash reports show `_enter_buffered_busy` in `_io__Buffered_close` during `_Py_Finalize`, with a `forward` thread blocked in `_buffered_readline`. **Expected behavior** The wrapper exits with code 0 and no crash report after it emits the `exited` receipt. **Steps to reproduce** 1. On macOS or Linux, start `python3 test/support/private-host-control.py /bin/sh -c "sleep 0.3"` in a new process group with stdin as an open pipe. 2. Keep stdin open after the child exits. 3. The wrapper ends with SIGABRT. **Paperclip version or commit** master at cb4129a918 ## What Changed - `private-host-control.py`: exit with `os._exit(status)` after `main()` or `cleanup()`. This skips interpreter finalization. `emit()` already flushes every receipt, so no output is lost. - `src/live/private-host-control-wrapper.test.ts`: new regression test. It starts the wrapper with stdin open and expects exit code 0 and no signal. ## Verification - Red: with the old wrapper, the new test fails with `{ code: null, signal: 'SIGABRT' }`. - Green: with the fix, `npx vitest run src/live/private-host-control-wrapper.test.ts` passes 3 of 3 runs. - A manual reproduction script gave exit -6 before the fix and exit 0 (3 of 3) after it. ## Risks Low risk. The change affects only a test-support wrapper. `os._exit` skips `atexit` handlers and buffer flushes. The wrapper registers no `atexit` handlers, and it flushes stdout after each write. ## Model Used - Claude Opus 5.5 (`claude-opus-5-5`) in Claude Code, with tool use and code execution. ## Checklist - [x] I have included a thinking path that traces from project context to this change - [x] I have specified the model used (with version and capability details) - [x] I have checked ROADMAP.md and confirmed this PR does not duplicate planned core work - [x] I have searched GitHub for duplicate or related PRs and linked them above - [x] I have either (a) linked existing issues with `Fixes: #` / `Closes #` / `Refs #` OR (b) described the issue in-PR following the relevant issue template - [x] I have not referenced internal/instance-local Paperclip issues or links (only public GitHub `#NNN` / `github.com/paperclipai/paperclip` URLs) - [x] My branch name describes the change (e.g. `docs/...`, `fix/...`) and contains no internal Paperclip ticket id or instance-derived details - [x] I have run tests locally and they pass - [x] I have added or updated tests where applicable - [x] I have updated relevant documentation to reflect my changes - [x] I have considered and documented any risks above - [ ] All Paperclip CI gates are green - [ ] Greptile is 5/5 with no open P2s, recommendations, or follow-ups - [x] I will address all Greptile and reviewer comments before requesting merge 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: Claude Opus 5.5 --- .../live/private-host-control-wrapper.test.ts | 23 +++++++++++++++++++ .../test/support/private-host-control.py | 8 ++++++- 2 files changed, 30 insertions(+), 1 deletion(-) create mode 100644 packages/paperclip-runner/src/live/private-host-control-wrapper.test.ts diff --git a/packages/paperclip-runner/src/live/private-host-control-wrapper.test.ts b/packages/paperclip-runner/src/live/private-host-control-wrapper.test.ts new file mode 100644 index 00000000000..1e930b296c0 --- /dev/null +++ b/packages/paperclip-runner/src/live/private-host-control-wrapper.test.ts @@ -0,0 +1,23 @@ +import { spawn } from "node:child_process"; +import { fileURLToPath } from "node:url"; +import { expect, it } from "vitest"; + +const wrapper = fileURLToPath(new URL("../../test/support/private-host-control.py", import.meta.url)); + +// The wrapper's forward thread stays blocked reading stdin after the native +// child exits. Normal interpreter shutdown then aborted with SIGABRT, which on +// macOS opened a "Python quit unexpectedly" dialog for every test run. +it.skipIf(process.platform === "win32")("exits cleanly while its stdin is still open", async () => { + const child = spawn("python3", [wrapper, "/bin/sh", "-c", "sleep 0.3"], { + detached: true, stdio: ["pipe", "pipe", "ignore"], + }); + let stdout = ""; + child.stdout.on("data", (chunk: Buffer) => { stdout += chunk.toString("utf8"); }); + const exit = await new Promise<{ code: number | null; signal: NodeJS.Signals | null }>((resolve) => { + child.on("close", (code, signal) => resolve({ code, signal })); + }); + child.stdin.destroy(); + + expect(exit).toEqual({ code: 0, signal: null }); + expect(stdout).toContain('"fixture": "exited"'); +}, 15_000); diff --git a/packages/paperclip-runner/test/support/private-host-control.py b/packages/paperclip-runner/test/support/private-host-control.py index b24a4b3d763..5dac764d3d0 100644 --- a/packages/paperclip-runner/test/support/private-host-control.py +++ b/packages/paperclip-runner/test/support/private-host-control.py @@ -117,6 +117,7 @@ def main(): if __name__ == "__main__": + status = 0 try: if len(sys.argv) == 5 and sys.argv[1] == "--cleanup": cleanup() @@ -124,4 +125,9 @@ if __name__ == "__main__": main() except Exception: # Do not reflect subprocess arguments, ticket frames, or provider output. - sys.exit(1) + status = 1 + # The forward thread may still be blocked in stdin.readline holding the + # stdin buffer lock. Normal interpreter shutdown would then abort while + # closing stdin (SIGABRT plus a macOS crash dialog), so skip finalization. + # emit() already flushed every receipt. + os._exit(status)