Skip to content

Conversation

@kfiramar
Copy link

@kfiramar kfiramar commented Jan 16, 2026

Summary

  • fix a macOS Terminal.app input regression when shell_snapshot is enabled by isolating the snapshot subprocess from the interactive TTY
  • prevent snapshot shells/.zshrc from flipping terminal modes while the TUI is in raw mode
  • add CODEX_SHELL_SNAPSHOT so users can guard tty-touching rc logic if needed

Bug Details

When shell_snapshot is enabled, Codex spawns a login shell (zsh -lc) and sources ~/.zshrc to capture aliases/functions/env. On some setups (e.g., Terminal.app + a .zshrc that runs stty/tput or emits escape sequences), the snapshot shell writes to the live TTY and changes terminal modes. While the Codex TUI is in raw mode, this breaks input handling: Enter/backspace stop working and raw escape sequences like ^[[O appear (often after alt-tab). Disabling shell_snapshot avoids the issue.

Repro Steps (macOS)

  1. Enable shell_snapshot (TUI /experimental → “Shell snapshot”, or set [features].shell_snapshot = true in ~/.codex/config.toml and restart).

  2. Create a minimal zshrc that touches the tty:

    mkdir -p /tmp/codex-tty-repro
    cat > /tmp/codex-tty-repro/.zshrc <<'EOF'
    stty sane 2>/dev/null
    EOF
  3. Launch Codex with that rc:

    ZDOTDIR=/tmp/codex-tty-repro codex
  4. When the TUI appears, input is broken (Enter/Backspace don’t work). After alt‑tabbing, you may see raw escape sequences like ^[[O.

  5. Confirm that disabling snapshot restores input:

    ZDOTDIR=/tmp/codex-tty-repro codex --disable shell_snapshot

Why It Failed Before

The snapshot subprocess inherited the controlling TTY and ran .zshrc while the TUI was in raw mode. Any tty mode changes or escape output from the snapshot shell hit the live terminal, which flips the terminal state out of raw mode and effectively “breaks” input handling for the running TUI. The failure is config-dependent, so it only shows up when shell_snapshot is enabled and .zshrc (or a plugin) touches the TTY.

Fix

Detach the snapshot subprocess from the controlling terminal and avoid inheriting stdin:

  • stdin set to /dev/null
  • setsid() before exec on Unix
  • env CODEX_SHELL_SNAPSHOT=1 for rc guards

This keeps snapshot output capture intact while preventing tty side effects.

Testing

  • not run (missing just tool in environment)

Issue

Prevent snapshot shells from inheriting the interactive TTY by

- routing stdin to /dev/null

- detaching from the controlling terminal (setsid)

- tagging snapshots with CODEX_SHELL_SNAPSHOT

Refs: openai#9383
@github-actions
Copy link
Contributor

github-actions bot commented Jan 16, 2026

All contributors have signed the CLA ✍️ ✅
Posted by the CLA Assistant Lite bot.

@kfiramar
Copy link
Author

I have read the CLA Document and I hereby sign the CLA

github-actions bot added a commit that referenced this pull request Jan 16, 2026
@etraut-openai
Copy link
Collaborator

@codex review

@etraut-openai
Copy link
Collaborator

Thanks for the contribution.

Please fix the CI failure — a simple formatting issue. Just ask codex to run formatting tool locally. You can ignore the Bazel failures.

@etraut-openai etraut-openai added the needs-response Additional information is requested label Jan 16, 2026
Copy link
Contributor

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 7ab0ff888a

ℹ️ 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".

kfiramar and others added 3 commits January 17, 2026 01:35
Unset CODEX_SHELL_SNAPSHOT after sourcing rc files so it

does not get captured by export -p in snapshot output.
@kfiramar
Copy link
Author

@codex review

@chatgpt-codex-connector
Copy link
Contributor

@kfiramar
Copy link
Author

kfiramar commented Jan 16, 2026

@etraut-openai Feel free to run the formatting CI and the review again

@kfiramar
Copy link
Author

kfiramar commented Jan 19, 2026

@etraut-openai Do you know if there's a plan to merge it soon?

jif-oai added a commit that referenced this pull request Jan 19, 2026
@etraut-openai
Copy link
Collaborator

@kfiramar, it's a national holiday in the U.S. today (MLK Day), so most Codex team members are on vacation. We'll try to get it merged later this week.

@etraut-openai etraut-openai removed the needs-response Additional information is requested label Jan 20, 2026
@etraut-openai
Copy link
Collaborator

@kfiramar, thanks for the contribution. We've made other changes recently that address this issue, so this PR is no longer needed.

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.

2 participants