Skip to content

/resume selecting the currently active session causes TUI to exit immediately #16756

Closed as duplicate

Description

@exqqstar

What version of Codex CLI is running?

codex-cli 0.118.0

What subscription do you have?

ChatGPT Plus

Which model were you using?

No response

What platform is your computer?

Darwin 25.2.0 arm64 arm

What terminal emulator and version are you using (if applicable)?

Terminal.app

What issue are you seeing?

Running /resume and selecting the currently active session in the picker causes the TUI to exit immediately. The user loses their current session without warning.This also occurs if you /resume the same session twice in a row without exiting.

What steps can reproduce the bug?

1.Start codex and begin a new interactive session
2.Send at least one message so the session is persisted
3.Type /resume and select the currently active session from the picker
4.The TUI exits immediately
This also occurs if you /resume the same session twice in a row without exiting.

What is the expected behavior?

Selecting the already-active session should be a no-op — the picker closes and the user returns to their current session unchanged.

Additional information

Root cause

SessionSelection::Resume in [app.rs:4055](https://github.com/openai/codex/blob/8d19646/codex-rs/tui/src/app.rs#L4055) does not check whether the selected thread is already active. The sequence:

  1. [resume_thread(same_id)](https://github.com/openai/codex/blob/8d19646/codex-rs/tui/src/app.rs#L4096) — succeeds (idempotent for an already-subscribed connection)
  2. [shutdown_current_thread()](https://github.com/openai/codex/blob/8d19646/codex-rs/tui/src/app.rs#L4101) — unconditionally calls [thread_unsubscribe(same_id)](https://github.com/openai/codex/blob/8d19646/codex-rs/tui/src/app.rs#L1544)
  3. App-server sees zero remaining subscribers (has_subscribers check) → spawns [shutdown_and_wait](https://github.com/openai/codex/blob/8d19646/codex-rs/app-server/src/codex_message_processor.rs#L5428) → broadcasts ThreadClosed
  4. TUI receives live ThreadClosed ([chatwidget.rs:6447](https://github.com/openai/codex/blob/8d19646/codex-rs/tui/src/chatwidget.rs#L6447)) → [on_shutdown_complete()](https://github.com/openai/codex/blob/8d19646/codex-rs/tui/src/chatwidget.rs#L3920) → immediate exit

Even without the exit, [replace_chat_widget_with_app_server_thread](https://github.com/openai/codex/blob/8d19646/codex-rs/tui/src/app.rs#L3319) would destroy and rebuild the ChatWidget, discarding any local UI state that AppServerStartedThread does not carry (the fields captured by [capture_thread_input_state](https://github.com/openai/codex/blob/8d19646/codex-rs/tui/src/chatwidget.rs#L3116) — pending steers, queued messages, collaboration mode, etc.).

Existing test coverage

Two existing tests validate two legs of the chain independently:

Other callers of shutdown_current_thread are safe: /clear always creates a new thread afterward, /fork always produces a new thread ID, and Ctrl+C sets pending_shutdown_exit_thread_id first.

Suggested fix

Add an early no-op guard before the cwd/config rebuild and resume_thread call, so the operation becomes a no-op when current == target, falling through to the shared schedule_frame() exit:

if self.chat_widget.thread_id().as_ref() != Some(&target_session.thread_id) {
    // ... existing resume logic unchanged
}

Reference implementation with regression test: [exqqstar/codex@bae38ef](https://github.com/exqqstar/codex/commit/bae38ef)

Happy to submit a PR if this aligns with the team's intended approach.

Activity

  1. added
    bug
    on Apr 4, 2026
  2. added
    CLI
    TUI
    on Apr 4, 2026
  3. github-actions commented on Apr 4, 2026

    @github-actions
    Contributor

    Potential duplicates detected. Please review them and close your issue if it is a duplicate.

    Powered by Codex Action

  4. removed
    CLI
    on Apr 4, 2026
  5. etraut-openai commented on Apr 4, 2026

    @etraut-openai
    Contributor

    Thanks for the bug report. This is already fixed on main and will be addressed in the next release.

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

    TUIbug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions