Skip to content

PTYs spawned without a session inherit the outer AGENT_TTY_SESSION_ID (doctor probe) #177

Description

@ThomasK33

Problem

Since #166, resolvePtyEnv (src/pty/createPty.ts) sets AGENT_TTY_ACTIVE=true for every PTY and sets AGENT_TTY_SESSION_ID only when a sessionId is passed. When no sessionId is passed, an AGENT_TTY_SESSION_ID inherited from the parent environment goes through unchanged.

The only caller without a sessionId is the doctor PTY-spawn probe (src/cli/commands/doctor.ts, deps.createPty({...}) around line 472). So when doctor runs inside an agent-tty session, its throwaway probe process gets:

  • AGENT_TTY_ACTIVE=true, although it is not a managed session, and
  • the outer session's AGENT_TTY_SESSION_ID.

The impact is low because the probe is short-lived. But the environment contract documented in docs/USAGE.md ("a session reports its own ID") doesn't hold for PTYs without a session.

Expected

A PTY spawned without a sessionId must not claim a session. It should drop inherited AGENT_TTY_SESSION_ID and AGENT_TTY_ACTIVE rather than passing the outer values through. Explicit --env/caller env values should still win, matching the existing precedence.

Acceptance

  • resolvePtyEnv with no sessionId removes inherited AGENT_TTY_SESSION_ID and does not set AGENT_TTY_ACTIVE=true, or a clearly argued alternative (for example, making sessionId required and giving doctor an explicit opt-out).
  • Unit tests cover: inherited values stripped when there is no session id, caller env still wins, and existing session behavior is unchanged.
  • The resolvePtyEnv doc comment and docs/USAGE.md match the behavior.

Follow-up from #166.


Generated with xum • Model: anthropic:claude-opus-5-5 • Thinking: high

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    ready-for-agentFully specified, ready for an AFK agent

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions