fix(terminal): agent-browser cleanup handles agents that relocate the socket dir (v0.227.2)#378
Merged
Merged
Conversation
… socket dir (v0.227.2) Follow-up to v0.227.1. End-to-end testing on a real qa session showed the exit trap was ineffective for the agents that actually leak: `agent-browser close --all` keys off the SOCKET DIR, not the namespace, and qa/engineer/site-porter/website-bot export a custom AGENT_BROWSER_SOCKET_DIR to a writable per-session dir (real HOME is read-only under systemd ProtectHome). So the trap's plain close --all (which only had the server's default socket dir) found "No active sessions" and left the daemon running. The trap now finds THIS session's daemons by the AGENT_BROWSER_NAMESPACE they reliably inherit, recovers each one's own AGENT_BROWSER_SOCKET_DIR from its /proc environ, and closes it scoped to that (SIGTERM straggler fallback). Namespace-scoped, so it never touches another session's browser; the plain close --all runs first for the default-socket-dir / macOS case. Verified against a real custom-socket-dir daemon. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_019zMSbnPEbqSVPGLasTKENp
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.
Follow-up to #377 (v0.227.1), caught by end-to-end testing on a real
qasession.The gap
v0.227.1's exit trap ran
agent-browser close --allscoped to the session'sAGENT_BROWSER_NAMESPACE. Butclose --allkeys off the socket dir, not the namespace — verified live:close --allwith namespace only → "No active sessions", daemon survives.close --allwith the socket dir → "✓ Closed session", daemon dies.And the agents that actually use the browser (
qa/engineer/site-porter/website-bot) export a customAGENT_BROWSER_SOCKET_DIRto a writable per-session dir, because their real HOME is read-only under systemdProtectHome(it's in their CLAUDE.md). So the trap's plainclose --all— which only had the server's default socket dir — missed their daemons entirely. The 0.227.1 fix was ineffective for exactly the agents that leak.The fix (
terminal/claude-launch.sh)The daemon reliably inherits
AGENT_BROWSER_NAMESPACE=aos-<session-id>in its environ even when the agent overrides the socket dir (verified). So the trap now:close --allfirst (covers default-socket-dir daemons / macOS), thenpgrep+ matchingAGENT_BROWSER_NAMESPACEin/proc/<pid>/environ, recovers each one's ownAGENT_BROWSER_SOCKET_DIRfrom that environ, and runsclose --allscoped to it — with aSIGTERMstraggler fallback.Still namespace-scoped, so it never touches another live session's browser. This stays a root-cause, session-owned cleanup at teardown (not a background GC) — it only ever targets the session's own namespace, at the session's own exit.
Verification
close --allleaves a custom-socket-dir daemon alive.close --all→ daemon gone, "closed cleanly".npm run build✓ ·npm run test:governance→ 68/68 ✓ ·bash -n claude-launch.sh✓🤖 Generated with Claude Code