Branch before selected prompt fails when visible user message id differs from persisted thread item id

Resolved 💬 3 comments Opened Aug 16, 2026 by szepeviktor Closed Aug 16, 2026
💡 Likely answer: A maintainer (github-actions[bot], contributor) responded on this thread — see the highlighted reply below.

What version of Codex are you using?

Codex CLI 0.147.0

The affected local thread row reports:

  • source: cli
  • history_mode: paginated
  • model: gpt-5.5
  • reasoning_effort: medium

What issue are you seeing?

When I go back to an earlier prompt and try to branch before the selected prompt, Codex shows:

Failed to branch before the selected prompt: the selected prompt was not found in the persisted thread

The selected prompt text is present in the persisted thread. The problem appears to be that the visible timeline message id differs from the persisted UserMessage item id stored in thread_history_1.sqlite.thread_items.

Local evidence

Thread id:

01a00acd-8ff0-7901-8ad5-c5cccde4a8c7

The thread exists in both:

~/.codex/state_5.sqlite: threads.id
~/.codex/thread_history_1.sqlite: thread_turns/thread_items/thread_history_projection_state

The persisted thread contains the user prompts, but the JSONL response_item user message ids do not match the persisted UserMessage ids:

| Prompt | JSONL response_item id | persisted UserMessage id | turn_id |
|---|---|---|---|
| a fejlécek sorrendjével mi van? | msg_01a00ace-dbf9-71a1-a3f3-04a4e126b8c7 | 01a00ace-dbfb-7581-96ce-54f947d4a5d9 | 01a00ace-dbb3-7df2-b3bf-6f038c4a77a8 |
| most hasonlítsd a http2-vel! | msg_01a00ad0-393b-7770-89a5-68e27dd0f8c7 | 01a00ad0-393c-7692-87b6-8113732b1f15 | 01a00ad0-38fd-79d3-9cf5-376b515f7524 |
| most vészhelyzet van, elfogytak a szerver erőforrásai. | msg_01a00ad1-4547-7203-b105-15af3ae5f6a7 | 01a00ad1-4547-7203-b105-15b6ce03a343 | 01a00ad1-4500-7333-9554-ecb484e767e5 |
| én ezt raktam be: | msg_01a00ad2-ae81-7913-9f4b-112224bd4417 | 01a00ad2-ae81-7913-9f4b-11367269869b | 01a00ad2-ae30-7d60-840d-94360d691efd |
| nyomozd ki, ha visszamegyek a prompt-okban... | msg_01a00ad8-80eb-7893-bb64-7d614acbb249 | 01a00ad8-80ec-70b3-85e9-0a3f19a28e08 | 01a00ad8-8098-72c2-a7a5-4915a9a2e513 |

The thread_history_1.sqlite row for the current thread also shows the paginated projection state exists:

thread_history_projection_state:
('01a00acd-8ff0-7901-8ad5-c5cccde4a8c7', 1024120, 212)

thread_items max/count:
(208, 68)

thread_turns max/count:
(124, 6)

Why this looks like a bug

The error says the selected prompt was not found in the persisted thread, but the prompt is present. It looks like the branch-before-selected-prompt path may be looking up the selected visible msg_... id in the persisted item table, where the stored user message id is the non-msg_... 01a... id.

Expected behavior

Branching before a selected prompt should work when that prompt exists in the persisted paginated thread, even if the UI-visible message id and persisted UserMessage item id are different.

At minimum, the lookup should normalize or map the visible timeline item id to the persisted UserMessage id for the same turn/prompt.

Actual behavior

Codex refuses to branch and shows:

Failed to branch before the selected prompt: the selected prompt was not found in the persisted thread

Possible related area

This seems adjacent to paginated thread history / app-server fork or branch-before-prompt handling. I found open issue #17708 about app-server lifecycle/fork state becoming stale, but I did not find an existing issue for this specific selected-prompt/persisted-item id mismatch.

View original on GitHub ↗

3 Comments

szepeviktor · 11 days ago

Additional template details I should have included when opening this through the GitHub API:

What subscription do you have?

Plus

What platform is your computer?

Linux 6.1.0-52-amd64 x86_64 unknown

What terminal emulator and version are you using?

Codex is running in a bash shell in the local workspace. I do not have a more specific terminal emulator value from this session.

Codex doctor report

not available from this shell

I attempted to run:

codex --version
codex doctor --json

but the codex executable is not available on PATH inside the current shell environment, even though the persisted thread metadata records cli_version = 0.147.0.

github-actions[bot] contributor · 11 days ago

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

  • #38686

Powered by Codex Action

szepeviktor · 11 days ago

This appears to duplicate #37421. I missed that issue before filing this one.

The additional value in this report is the local evidence showing a concrete ID mismatch: the selected visible timeline user message has a msg_... id, while the persisted thread_history_1.sqlite.thread_items UserMessage for the same turn has a different 01a... id. That seems consistent with #37421's paginated-thread regression and may help confirm the lookup failure mode.

Feel free to close this as a duplicate if #37421 is the canonical tracking issue.