TUI: Up-arrow enters cross-session history before recalling the first prompt in a new session

Open 💬 1 comment Opened Jul 25, 2026 by gusholcomb

What version of Codex CLI is running?

0.145.0

Which model were you using?

gpt-5.6-sol

What platform and terminal are you using?

  • Darwin 24.6.0 arm64
  • Apple Terminal 455.1
  • TERM=xterm-256color

What issue are you seeing?

In a brand-new, non-forked TUI session, Up-arrow enters history from other sessions before recalling the first prompt from the current session.

For example, after sending two prompts in the new session, repeated Up presses produce this order:

  1. Second prompt from the current session
  2. One or more prompts from unrelated sessions
  3. First prompt from the current session, or an older identical copy of it

The first prompt should be part of the current-session history and should appear immediately after the second prompt. Users should not need to traverse another session to reach it.

Inspection of ~/.codex/history.jsonl confirmed that the foreign prompts belonged to different session IDs. The rollout metadata confirmed that the current session was a fresh user-created thread with forked_from_id: null.

What steps can reproduce the bug?

  1. Ensure persistent history contains at least one prompt from an older session.
  2. Start a fresh Codex TUI session.
  3. Send a distinctive first prompt, such as first prompt from new session 12345.
  4. Send a second prompt, such as second prompt from new session 12345.
  5. Clear the composer and press Up repeatedly.

Actual order:

  1. second prompt from new session 12345
  2. Prompts from older, unrelated sessions
  3. The first prompt is missing from its expected position and may not be recallable at all

Expected order:

  1. second prompt from new session 12345
  2. first prompt from new session 12345
  3. Only then, any persistent cross-session history

What is the expected behavior?

Up should exhaust all prompts submitted in the current session, in reverse submission order, before falling back to persistent cross-session history.

Additional information

Related to #12085, which reports broader cross-session Up-arrow behavior in the Codex App. This report is specifically about the CLI TUI failing to keep the first prompt in the current-session portion of the history.

The observed sessions were independent and non-forked. An older session happened to contain an identical prompt during the original investigation, which made the timeline look more complicated but is not required to reproduce the bug.

The relevant TUI ordering is:

  • Session configuration installs a snapshot of persistent history.
  • The first prompt is then submitted.
  • Later composer submissions are retained as local in-session history.
  • Up can therefore return later local submissions and then cross into the older persistent snapshot without returning the first prompt in between.

A regression test should seed one foreign persistent entry, submit two prompts in a fresh session, and assert that Up returns the second current-session prompt followed by the first current-session prompt before requesting the foreign entry.

View original on GitHub ↗

1 Comment

gusholcomb · 1 month ago

I investigated this and prepared a tested fix:

Root cause:

  • The CLI-provided initial prompt bypasses the composer's local current-session history recording.
  • Recording it at the initial call site is too early when submission happens before SessionConfigured: installing history metadata clears local history, and pulling the queued prompt back for editing would incorrectly retain an unsent entry.

Proposed fix:

  • Carry an explicit initial-message history policy through pre-configuration queueing.
  • Record the complete local HistoryEntry only after the message or !cmd is actually accepted.
  • Downgrade the policy after an accepted steer submission so rejection/retry cannot record it twice.
  • Preserve existing persistent-history behavior.

Coverage includes:

  • Direct configured initial-prompt recall before seeded persistent history.
  • Pre-configuration queue → metadata installation → drain.
  • A queued prompt pulled back into the composer without creating a history entry.
  • Accepted !cmd and bare-! help paths.
  • Steer rejection/retry without duplicate recall.

Validation:

  • just test -p codex-tui: 3,251 passed, 4 skipped.
  • just fix -p codex-tui
  • just fmt

The contribution guide says external PRs are invitation-only, so I have not opened an unsolicited PR. If a maintainer would like this submitted as a PR, the branch is ready.