fix interactive "resume --last" prompt handling and reinstate session-id conflict
Addressed issues:
- https://github.com/openai/codex/issues/6717#issuecomment-3584958320
- https://github.com/openai/codex/pull/6719#discussion_r2541117561
Changes
- change
--lastflag to accept optional prompt value (e.g.--last <PROMPT>) - simplify prompt handling by using
last_prompt()helper method - reject invalid or nonexistent session IDs with error message instead of silently creating new conversation
- reinstate clap's
conflicts_withbetween--lastand explicit session id - add tests for conflict validation, prompt forwarding, and invalid session ID rejection
Problems
1. Interactive codex resume --last didn't accept prompt values (#6717)
Problem: The interactive codex resume --last command used a boolean flag that couldn't accept a prompt value. Users couldn't provide a prompt directly after --last.
Before:
$ codex resume --last "next steps"
# --last was a bool flag, prompt was ignored
After:
$ codex resume --last "next steps"
# Now correctly accepts and forwards the prompt
2. codex exec resume silently ignored session_id when used with --last (#6719 discussion)
Problem: When both a session ID and --last were provided, the code silently ignored the session ID and used --last, potentially resuming the wrong session. This was unsafe for scripts and users.
Before:
$ codex exec resume 123e4567-e89b-12d3-a456-426614174000 --last
# Silently ignored the session_id and resumed most recent session
# Could touch the wrong session unintentionally
After:
$ codex exec resume 123e4567-e89b-12d3-a456-426614174000 --last
error: the argument '--last' cannot be used with '<SESSION_ID>'
# Fails fast with clear error message
3. Invalid session IDs silently created new conversations
Problem: When an invalid or nonexistent session ID was provided, codex exec resume silently created a new conversation instead of erroring, causing confusion.
Before:
$ codex exec resume sdfsdfgfds2546456 "2+2"
# Silently creates a new conversation (confusing!)
$ codex exec resume 123e4567-e89b-12d3-a456-426614174000 "2+2"
# (UUID format valid but session doesn't exist)
# Silently creates a new conversation
After:
$ codex exec resume sdfsdfgfds2546456 "2+2"
No saved session found with ID sdfsdfgfds2546456.
# Exits with error code 1
$ codex exec resume 123e4567-e89b-12d3-a456-426614174000 "2+2"
No saved session found with ID 123e4567-e89b-12d3-a456-426614174000.
# Exits with error code 1
Testing
Added tests for:
- Invalid session ID rejection (non-UUID format)
- Nonexistent valid UUID rejection
- Conflict validation between
--lastand session ID - Prompt forwarding when using
--last <PROMPT>
All existing tests pass, and the behavior now matches the interactive codex resume command which already had proper error handling.
@codex review
@dkhokhlov, if you're still interested in pursuing this PR, please resolve merge conflicts, take a look at the codex code review comment, and remove the "draft" status once you think it's ready for review by a codex team member. Thanks!
@dkhokhlov, if you're still interested in pursuing this PR, please resolve merge conflicts, take a look at the codex code review comment, and remove the "draft" status once you think it's ready for review by a codex team member. Thanks!
on it
@codex review
@codex review
@codex review
Codex Review: Didn't find any major issues. Keep them coming!
ℹ️ 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".
@etraut-openai - ready
Thanks for the contribution, but we're going to pass on this one. This is more of a feature than a bug fix. The codex resume --last was not designed to take an optional parameter.
Also, the code in this PR is pretty complicated, so even if this was something we wanted to address, it would need a lot of additional work.