Repository navigation
Conversation
…n before SIGKILL sessions.json remembers each bridge by PID, and the CLI trusted that number: after a reboot (or a PID wrap) it belongs to whatever the OS started next, and `process.kill(pid, 0)` says "alive", so a command on a stale session failed to reach the socket and SIGTERMed/SIGKILLed an unrelated process on its way to a restart. The old bridge was also force-killed one second after SIGTERM, before it could finish the HTTP DELETE that ends the server-side session or the SDK's close-stdin → SIGTERM → SIGKILL escalation for a stdio child, orphaning it. New `identifyBridgeProcess()` (src/lib/bridge-process.ts) runs before any PID is signalled or trusted: it connects to the PID-specific IPC socket (a Windows named pipe cannot outlive its process; on Unix the stale file is probed, not trusted) and, when nothing listens there, reads the process command line (/proc/<pid>/cmdline on Linux, ps elsewhere), which must name the bridge script immediately followed by the session name. stopBridge(), ensureBridgeReady() and consolidateSessions() treat a recycled or dead PID as a crashed bridge, so the session reconnects and the stranger is left alone. stopBridge() then polls for up to 10 s — the bridge's own teardown budget — before SIGKILL. Fixes M5 and M6 of docs/security-review-2026-09.md. Covered by unit tests with real sockets and processes and by test/e2e/suites/basic/bridge-pid-reuse.test.sh. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015KycPokdVYqq2t5iGAiDxY
This branch has not been deployed
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.
A restart or
closecould kill an unrelated process:sessions.jsonremembers each bridge by PID, the OS recycles PIDs after a reboot, andstopBridge()SIGTERMed/SIGKILLed whatever had that number once the socket did not answer. The old bridge was also force-killed one second after SIGTERM, before its HTTP DELETE or the SDK's stdio child shutdown could finish, orphaning the child.src/lib/bridge-process.ts: a PID is signalled only after it is confirmed to be the session's bridge (its IPC socket answers, or its command line names the bridge script followed by the session name)stopBridge,ensureBridgeReadyandconsolidateSessionstreat a recycled or dead PID as a crashed bridge, so the session reconnects and the stranger is left alonestopBridgepolls for exit for up to 10 s (the bridge's own teardown budget) before SIGKILLtest/e2e/suites/basic/bridge-pid-reuse.test.shFixes M5 and M6 of
docs/security-review-2026-09.md. Refs #427 (the self-exiting superseded bridge this builds on). A separate resumed-session bug found on the way is filed as #484.🤖 Generated with Claude Code
https://claude.ai/code/session_015KycPokdVYqq2t5iGAiDxY