Skip to content

fix(pty): don't leak an outer session id into session-less PTYs - #178

Merged
ThomasK33 merged 1 commit into
mainfrom
fix/pty-env-no-session
Sep 24, 2026
Merged

ThomasK33 merged 1 commit into
mainfrom
fix/pty-env-no-session

Conversation

@ThomasK33

Copy link
Copy Markdown
Member

What

resolvePtyEnv (src/pty/createPty.ts) now treats a PTY spawned without a sessionId as session-less:

  • Inherited AGENT_TTY_ACTIVE and AGENT_TTY_SESSION_ID are removed. Before, AGENT_TTY_ACTIVE=true was always set and an outer AGENT_TTY_SESSION_ID passed through unchanged.
  • Caller env (--env) still wins, so precedence is unchanged.
  • An empty sessionId now fails an invariant rather than being silently treated as "no session".

Sessions (hostMain, which always passes sessionId) behave exactly as before. The only session-less caller is the doctor PTY spawn probe. Run inside an agent-tty session, it no longer claims to be a managed session or reports the outer session's ID.

Why

Closes #177. The documented contract in docs/USAGE.md ("a session reports its own ID") didn't hold for PTYs without a session.

Changes

  • src/pty/createPty.ts: drop inherited session vars when there's no sessionId; doc comment updated.
  • test/unit/pty/createPty.test.ts: covers stripping inherited values with no session id, caller env still winning with no session id, no vars set with no session id, rejecting an empty session id. Existing session tests are kept.
  • docs/USAGE.md: one sentence on session-less PTYs.

No CLI JSON, schema, or manifest changes.

Validation

mise run typecheck        # pass
mise run lint             # 0 warnings, 0 errors
mise run format-check     # pass
npx vitest run test/unit/pty test/unit/cli/commands/doctor*   # 3 files, 83 tests pass
mise run ci               # exit 0; 159 test files, 1645 tests pass

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

@ThomasK33

Copy link
Copy Markdown
Member Author

@codex review

@ThomasK33

Copy link
Copy Markdown
Member Author

@codex security review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 24, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-09-24T10:57:38.047921Z 9e5590a Manual request
🔒 Security Review ✅ Completed 2026-09-24T10:57:55.221003Z 9e5590a Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. 🎉

Reviewed commit: 9e5590a81c

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@chatgpt-codex-connector

Copy link
Copy Markdown

🛡️ Codex Security Review

Security review completed. No security issues were found in this pull request.

Reviewed commit: 9e5590a81c

View security finding report

Only the user who started this review can view the report in Codex.

ℹ️ About Codex security reviews in GitHub

This is an experimental Codex feature. Security reviews are triggered when:

  • You comment "@codex security review"
  • A regular code review gets triggered (for example, "@codex review" or when a PR is opened), and you’re opted in so security review runs alongside code review

Once complete, Codex will leave suggestions, or a comment if no findings are found.

@ThomasK33
ThomasK33 added this pull request to the merge queue Sep 24, 2026
Merged via the queue into main with commit a269ca4 Sep 24, 2026
12 checks passed
@ThomasK33
ThomasK33 deleted the fix/pty-env-no-session branch September 24, 2026 12:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

1 participant