openai / openai/codex

[CLI] Auto-compaction replays an already-answered user message as a new turn

Open
#42,611 2 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug CLI context session
Dominant language
Rust
Stars
125k
Forks
19.4k
PR merge metrics
PR metrics pending

Description

What version of Codex CLI is running?

codex-cli 0.153.0 is currently installed and is the latest published release. The captured reproduction occurred on codex-cli 0.152.1.

I have a local post-compaction mitigation enabled on 0.153.0, so I have not disabled it to force another reproduction. Disabling the mitigation could repeat state-changing commands in a real working session.

What subscription do you have?

ChatGPT Pro

Which model were you using?

gpt-5.6-sol, high reasoning

What platform is your computer?

Linux 6.18.33.2-microsoft-standard-WSL2 x86_64 unknown

What terminal emulator and version are you using (if applicable)?

Windows Terminal 1.24.11911.0, with Codex running inside WSL2. TERM=xterm-256color.

Codex doctor report

codex doctor --json was run on 0.153.0. The full report is omitted because it contains local paths. The relevant sanitized results were:

{
  "schemaVersion": 1,
  "overallStatus": "fail",
  "codexVersion": "0.153.0",
  "checks": {
    "auth.credentials": { "status": "ok" },
    "config.load": {
      "status": "ok",
      "model": "gpt-5.6-sol",
      "model provider": "openai"
    },
    "installation": {
      "status": "ok",
      "platform": "linux-x86_64",
      "version": "0.153.0"
    },
    "state.rollout_db_parity": { "status": "ok" },
    "network.provider_reachability": {
      "status": "fail",
      "summary": "one or more required provider endpoints are unreachable over HTTP"
    }
  }
}

The network failure was expected because doctor ran inside a restricted diagnostic sandbox. Normal authenticated Codex sessions work. The failure is unrelated to this report.

What issue are you seeing?

After automatic context compaction, Codex can treat the last retained pre-compaction user message as though it were a newly submitted message. It then acknowledges or acts on a request that was already answered, even though no new user event exists after compaction.

This is narrower than generic loss of task progress. The persisted event stream proves that the user message had already received an assistant response before compaction. The first assistant output after compaction answered that same message again.

Sanitized event sequence from the affected thread:

2026-09-02T16:40:29.685Z  response_item role=user
2026-09-02T16:40:40.941Z  response_item role=assistant, answers the user message
2026-09-02T16:42:13.065Z  compacted
2026-09-02T16:42:13.090Z  developer continuation context injected
2026-09-02T16:42:20.282Z  response_item role=assistant, answers the old user message again

There is no role=user response item between the compaction event and the erroneous assistant continuation.

The injected continuation context explicitly said not to treat retained pre-compaction user messages as newly submitted. It was present before the erroneous response, but advisory text was not sufficient to prevent the replay.

Affected root thread ID:

01a05c82-5659-76c1-a497-e81eadeac02c
What steps can reproduce the bug?
  1. Start a long-running Codex CLI task.
  2. Submit a normal user instruction or correction while the task is active.
  3. Let Codex acknowledge and answer that instruction.
  4. Continue the same active task without submitting another user message.
  5. Let automatic context compaction occur.
  6. Inspect the first assistant output after compaction.
  7. Codex may acknowledge, paraphrase, answer, or act on the already-handled pre-compaction user message again, as if the user had just submitted it.
  8. Inspect the rollout event order and confirm that there is no new user event after compaction.

In the captured reproduction, even a SessionStart continuation instruction that explicitly prohibited this behavior did not reliably prevent it.

What is the expected behavior?

Automatic compaction must preserve whether a user message has already been handled. A retained historical user message must not become a new turn merely because it is the latest visible user-role item in replacement history.

If there is no new user event after compaction, Codex should continue from the active work state recorded by the compaction summary. It must not acknowledge, answer, quote, paraphrase, or re-execute an already-handled user request.

This likely requires host-visible event identity or an explicit handled/consumed marker. Prompt text alone is not a reliable correctness boundary.

Additional information

Local mitigation:

  • A SessionStart hook for compaction injects a developer instruction that distinguishes retained history from a new user event.
  • The rule says to continue active work, or wait when message ownership is ambiguous.
  • This reduces the problem but cannot attach a machine-verifiable handled state to the retained message.

Related reports:

This report is distinct from the goal-related reports, and more specific than the broader task-state report, because the captured CLI event sequence does not require an active goal, /goal, or a Steered conversation. It shows an ordinary, already-answered user message being rebound as current input when no new user event exists.

Raw rollout files are not attached because they contain private task context and local paths. The thread ID and sanitized event sequence above should allow internal correlation.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by tracing automatic context compaction, the persisted rollout event stream, and the first continuation after a compacted event. Use the supplied event ordering to verify that no new user event exists; done means retained, already-handled user messages cannot be treated as new turns or trigger repeated actions.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
cli
Issue type
Bug
Difficulty
5/5
Estimated time
Over a week
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
32/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.