fix: replace ATCH_SESSION env check with PID ancestry walk#9
Open
DonaldoDes wants to merge 1 commit intomobydeck:mainfrom
Open
fix: replace ATCH_SESSION env check with PID ancestry walk#9DonaldoDes wants to merge 1 commit intomobydeck:mainfrom
DonaldoDes wants to merge 1 commit intomobydeck:mainfrom
Conversation
…estry check The anti-recursion guard in attach_main relied solely on ATCH_SESSION to detect self-attach attempts. Because ATCH_SESSION is an inherited env var it could be stale (e.g. the variable set inside a session that has since been detached-from, or a shell-config export), causing every subsequent attach to be incorrectly blocked with "cannot attach from within itself". Fix: the master now writes the pty-child PID to <sockname>.ppid on session start and removes it on cleanup. attach_main reads this file and walks the process-ancestry tree (via libproc on macOS, /proc on Linux) to verify that the calling process is genuinely a descendant of the session shell before blocking the attach. If the .ppid file is absent or the recorded PID is not an ancestor, ATCH_SESSION is treated as stale and the attach proceeds. The ancestry check is also hoisted before require_tty() in cmd_attach and the legacy -a/-A/-c routes so the correct diagnostic fires even without a controlling terminal. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
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
ATCH_SESSIONenvironment variable check with a proper PID ancestry verification<socket>.ppidfileCloses #5
Test plan
ATCH_SESSIONno longer blocks attach🤖 Generated with Claude Code