codex icon indicating copy to clipboard operation
codex copied to clipboard

fix interactive "resume --last" prompt handling and reinstate session-id conflict

Open dkhokhlov opened this issue 2 weeks ago • 2 comments

Addressed issues:

  • https://github.com/openai/codex/issues/6717#issuecomment-3584958320
  • https://github.com/openai/codex/pull/6719#discussion_r2541117561

Changes

  • change --last flag 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_with between --last and 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 --last and 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.

dkhokhlov avatar Dec 03 '25 21:12 dkhokhlov

@codex review

dkhokhlov avatar Dec 03 '25 21:12 dkhokhlov

@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!

etraut-openai avatar Dec 04 '25 22:12 etraut-openai

@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

dkhokhlov avatar Dec 06 '25 13:12 dkhokhlov

@codex review

dkhokhlov avatar Dec 08 '25 02:12 dkhokhlov

@codex review

dkhokhlov avatar Dec 08 '25 03:12 dkhokhlov

@codex review

dkhokhlov avatar Dec 08 '25 03:12 dkhokhlov

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

dkhokhlov avatar Dec 08 '25 04:12 dkhokhlov

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.

etraut-openai avatar Dec 08 '25 16:12 etraut-openai