TUI: Up-arrow enters cross-session history before recalling the first prompt in a new session
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:
- Second prompt from the current session
- One or more prompts from unrelated sessions
- 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?
- Ensure persistent history contains at least one prompt from an older session.
- Start a fresh Codex TUI session.
- Send a distinctive first prompt, such as
first prompt from new session 12345. - Send a second prompt, such as
second prompt from new session 12345. - Clear the composer and press Up repeatedly.
Actual order:
second prompt from new session 12345- Prompts from older, unrelated sessions
- The first prompt is missing from its expected position and may not be recallable at all
Expected order:
second prompt from new session 12345first prompt from new session 12345- 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.
1 Comment
I investigated this and prepared a tested fix:
Root cause:
SessionConfigured: installing history metadata clears local history, and pulling the queued prompt back for editing would incorrectly retain an unsent entry.Proposed fix:
HistoryEntryonly after the message or!cmdis actually accepted.Coverage includes:
!cmdand bare-!help paths.Validation:
just test -p codex-tui: 3,251 passed, 4 skipped.just fix -p codex-tuijust fmtThe 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.