codex exec resume silently ignores an explicit ID when --last is also supplied
Description
codex exec resume --last <SESSION_ID> <PROMPT> accepts both selectors but silently ignores the explicit session ID. The prompt is sent to the most recent session instead. An accidental combination of the two selectors can therefore continue a different conversation without an error.
Reproduced on Windows with CLI 0.167.2 and 0.170.0-alpha.2. Current main c0cc9fc820f62e4dbdde68214dd6d792d6c8a7ee resolves --last before inspecting the supplied session ID.
Reproduction
Run from a checkout with Python SDK test dependencies installed, sdk/python/src and sdk/python/tests on PYTHONPATH, and CODEX_EXEC_PATH pointing to a CLI binary. This uses a temporary Codex home and a local mock model.
import json
import os
import subprocess
from pathlib import Path
from tempfile import TemporaryDirectory
from app_server_harness import AppServerHarness
with TemporaryDirectory(ignore_cleanup_errors=True) as tmp:
with AppServerHarness(Path(tmp)) as harness:
for i in range(4):
harness.responses.enqueue_assistant_message("ok", response_id=f"r{i}")
env = {**os.environ, "CODEX_HOME": str(harness.codex_home)}
def run(*args):
p = subprocess.run(
[os.environ["CODEX_EXEC_PATH"], "exec", "--skip-git-repo-check",
"--json", *args],
cwd=harness.workspace, env=env, input="", text=True,
capture_output=True, timeout=30, check=True,
)
events = [json.loads(line) for line in p.stdout.splitlines()
if line.startswith("{")]
return next(e["thread_id"] for e in events
if e["type"] == "thread.started")
a = run("seed A")
b = run("seed B")
picked = run("resume", "--last", a, "follow up")
texts = harness.responses.requests()[-1].message_input_texts("user")
print("A and B differ:", a != b)
print("both selectors chose A:", picked == a, "chose B:", picked == b)
print("request history:", [t for t in texts if t in ("seed A", "seed B", "follow up")])
print("ID-only control chose A:", run("resume", a, "follow up") == a)
Actual: The combined command succeeds, chooses B, and sends ["seed B", "follow up"]; the ID-only control chooses A.
Expected: Reject the conflicting selectors with a clear error, or otherwise explicitly resolve the conflict rather than silently ignoring the ID.
Possible fix
Reject the two-positional form when --last is present, while preserving the supported resume --last <PROMPT> form. Add a regression test covering two existing sessions.
I reproduced this on the official Linux Codex CLI 0.168.0 with two synthetic sessions and a local mock model. A was created first, then B:
| Command | Selected session | Request history |
|---|---|---|
codex exec resume --last 'last-only control' |
B | B seed and control prompt |
codex exec resume --last <A_ID> 'combined followup' |
B | B seed, prior B control, and follow-up; no A seed |
codex exec resume <A_ID> 'ID-only control' |
A | A seed and control prompt; no B seed |
All three commands exited successfully. The combined command gave no selector-conflict error, so the supplied A ID was silently ignored. Each command made one request to the local mock endpoint; no OpenAI service was called.
I also tested a local parser candidate against source commit 83a23c0: reject --last when both an explicit session ID and prompt are supplied, while preserving the supported single-positional --last <PROMPT> and ID-only forms. The regression failed before the change; afterward all 9 CLI parser tests passed, including the argument-update path. This is parser-level evidence; I have not run the patched CLI end to end or tested other platforms.