fix: exit process when ACP connection closes#530
Open
WayChan wants to merge 1 commit intoagentclientprotocol:mainfrom
Open
fix: exit process when ACP connection closes#530WayChan wants to merge 1 commit intoagentclientprotocol:mainfrom
WayChan wants to merge 1 commit intoagentclientprotocol:mainfrom
Conversation
In oneshot mode (e.g. via ACPX), the claude-agent-acp process does not exit after the client closes the stdin pipe. `process.stdin.resume()` keeps the Node.js event loop alive indefinitely, causing orphan process accumulation on the host. Root cause: `runAcp()` discards the `AgentSideConnection` instance, so nothing listens for connection closure to trigger `process.exit()`. Fix: return the connection from `runAcp()` and call `process.exit(0)` when `connection.closed` resolves (i.e. when stdin reaches EOF). Persistent sessions are unaffected — the client keeps stdin open, so `connection.closed` does not fire until the client explicitly disconnects. Co-Authored-By: Claude Opus 4.6 <[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.
Summary
AgentSideConnectionfromrunAcp()instead of discarding itconnection.closedand callprocess.exit(0)on resolutionProblem
When used in oneshot mode,
claude-agent-acpdoes not exit after the client closes the stdin pipe.process.stdin.resume()keeps the Node.js event loop alive indefinitely. Over time, orphan processes accumulate on the host (~97MB RSS each), eventually exhausting system resources.Root cause
runAcp()creates anAgentSideConnectionbut discards the reference. TheConnection.#receive()loop detects stdin EOF and firesabortController.abort(), resolvingconnection.closed— but no code listens for it to triggerprocess.exit().Fix
acp-agent.ts:runAcp()now returns theAgentSideConnectioninstanceindex.ts: Awaitsconnection.closedand callsprocess.exit(0)Impact
connection.closeddoes not fire until explicit disconnectTest plan
🤖 Generated with Claude Code