Skip to content

ATCH_SESSION env var blocks all attach after detach #5

@DonaldoDes

Description

@DonaldoDes

Description

After detaching from a session, ATCH_SESSION remains in the shell environment. The self-attach guard in attach_main compares this stale value against the target socket path, blocking all subsequent attach attempts with:

atch: cannot attach to session 'X' from within itself

Reproduction

  1. atch -c session1 → detach (Ctrl+)
  2. atch list → shows session1
  3. atch -a session1 → error "cannot attach from within itself"
  4. unset ATCH_SESSION → attach works again

Root cause

The guard relies solely on matching the ATCH_SESSION environment variable against the socket path. It does not verify whether the current process is actually a descendant of the session's shell process.

Suggested fix

Replace the env-var-only check with a PID ancestry walk: read the session's shell PID from a .ppid file written by the master, then walk getppid() upward to confirm actual ancestry before blocking.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions