Codex gets stuck in a pre-write context compaction loop on large projects, repeatedly re-reading instructions and never reaching file edits

Resolved 💬 10 comments Opened Jun 11, 2026 by SocialK Closed Jun 19, 2026
💡 Likely answer: A maintainer (github-actions[bot], contributor) responded on this thread — see the highlighted reply below.

What version of the Codex App are you using (From “About Codex” dialog)?

Version 26.608.12217 • Released Jun 9, 2026

What subscription do you have?

ChatGPT Pro, $200/month

What platform is your computer?

Windows 11 x64, Version 10.0.26200.8524

What issue are you seeing?

Hi Codex team,

I want to share product feedback from a real long-running Codex project. This is not about model quality. The model often reasons correctly. The problem is task execution reliability and state management in large projects with many project instruction files.

Issue summary:
Codex can get stuck for hours before making any file changes. In my case, a simple single-game data processing task ran for 2–4+ hours, but no files were edited. The task repeatedly entered the same loop:

  1. Read project hot files / rules.
  2. Read lock / registry / state files.
  3. Context automatically compacted.
  4. Reconnect / stream interruption happens.
  5. Codex resumes and re-reads the same files again.
  6. It never reaches the actual write/action phase.

Example repeated pattern:

  • “Continuing with one case…”
  • “First I will check lock and current versions…”
  • “Reading START_HERE / PROJECT_STATE / ACTIVE_TASK / CANONICAL_PATHS…”
  • context compaction
  • same sequence repeats again

Observed error:
stream disconnected before completion: websocket closed by server before response.completed

Why this matters:
For project/file-editing tasks, this is dangerous because the UI may show the task as working for hours, but the backend never reaches a durable write phase. The user cannot tell whether:

  • the task is still valid,
  • it is stuck in preflight,
  • files were partially written,
  • or the task should be stopped.

This becomes especially painful in projects with many instruction files, ledgers, registries, and safety rules. Codex appears to treat every reconnect/context compaction as a reason to re-run the full preflight, instead of resuming from a durable phase marker.

Expected behavior:
Codex should detect this loop and stop safely.

Suggested improvements:

  1. Add automatic pre-write loop detection.

If Codex reads the same instruction/state files multiple times without file edits or new useful output, it should stop and write a short status report.

  1. Add explicit task phase tracking.

For example:

  • preflight_started
  • preflight_done
  • write_started
  • validation_started
  • final_report_started
  • completed

After context compaction or reconnect, Codex should resume from the last durable phase instead of restarting preflight.

  1. Add a “write status report and stop” recovery action.

This would be very useful when the UI stream disconnects but the project state is unclear.

  1. Add a hard time/no-progress guard.

Example:
If no files were edited after 10–15 minutes in a file-editing task, Codex should ask whether to continue or stop with a report.

  1. Improve WebSocket disconnect handling.

When websocket closed before response.completed happens, the UI should clearly show:

  • backend still running,
  • backend completed,
  • backend failed,
  • stream only failed,
  • project state unknown.
  1. Support lightweight fast-path modes.

For small repeatable workflows, users need a way to tell Codex:

  • do not re-read all policies,
  • read only these exact files,
  • do not run broad search,
  • stop if exact paths are missing.

Current workaround:
I had to redesign my workflow around lightweight “analysis packets” instead of asking Codex to fully integrate every data point, because full integration often triggers long preflight loops.

Impact:
This makes Codex much less reliable for large project workflows, even on higher reasoning / faster settings. The issue is not just speed. It is that the agent can spend hours preparing to work without reaching the actual work.

Thank you. I hope this helps improve Codex’s long-running project reliability.

What steps can reproduce the bug?

Reproduction steps

This is a Codex App issue during long-running local project/file-editing tasks on Windows.

No code snippet is required to reproduce it. The issue happens while Codex is asked to edit a local project with multiple Markdown/JSON project instruction files, ledgers, registries, and status files.

Environment:

  • OS: Windows 11
  • Codex: Codex App / Codex inside ChatGPT
  • Model: GPT-5.5
  • Reasoning mode: Extra High
  • Speed mode: Fast
  • Project type: large local Codex project with many Markdown/JSON files
  • Git: either unavailable in PATH or explicitly disabled in the prompt

Steps to reproduce:

  1. Open a large Codex project on Windows with multiple project instruction/status files, for example:
  • _codex/00_START_HERE.md
  • _codex/01_ACTIVE_TASK.md
  • _codex/02_PROJECT_STATE.md
  • _codex/indexes/CANONICAL_PATHS.md
  • _codex/rules/*.md
  • _case_queue/*.jsonl
  • _case_queue/CURRENT_CASE_LOCK.json
  • runtime/registry JSON files
  1. Ask Codex to perform a small scoped file-editing task, for example:
  • read the current lock file;
  • process exactly one input item
  • do not use old chat memory;
  • do not run Git commands;
  • do not run broad project search;
  • write one small report and stop.
  1. Codex starts correctly, but before reaching the actual write phase it repeatedly reads the same project “hot files” and rules:
  • START_HERE
  • ACTIVE_TASK
  • PROJECT_STATE
  • CANONICAL_PATHS
  • lock / registry / ledger files
  • policy/rule files
  1. Context compaction happens automatically before the task reaches a durable write/edit phase.
  1. After compaction, Codex resumes and starts the same preflight again:
  • “Continuing with one case…”
  • “First I will check the lock and versions…”
  • “I will read the project hot files…”
  • “I will not process old cases…”
  • then it reads the same files again.
  1. This repeats many times. In one case, the task ran for more than 2 hours with no file edits at all. In another case, a small task ran for more than 4 hours.
  1. During this loop, the UI often shows:
  • Reconnecting /5
  • stream disconnected before completion: websocket closed by server before response.completed
  • Context automatically compacted
  1. The task state becomes ambiguous. It is not clear whether:
  • the backend task is still running;
  • the task failed;
  • the UI stream failed but backend continued;
  • some files were partially written;
  • or Codex is stuck in a pre-write loop.

Expected behavior:

  • Codex should not repeat the same preflight indefinitely after context compaction.
  • Codex should detect that it has read the same files multiple times without progress.
  • Codex should either proceed to the write phase or stop safely with a status report.
  • After a WebSocket disconnect, the UI should show whether the backend task is still running, completed, failed, or unknown.

Actual behavior:

  • Codex can spend hours in a pre-write loop.
  • It repeatedly re-reads the same project files after context compaction.
  • It often disconnects with websocket closed by server before response.completed.
  • The UI does not clearly indicate the real backend task state.
  • No durable status report is always produced before the stream disconnects.

Impact:

  • Long-running Codex project tasks become unreliable.
  • The user cannot tell whether the project state is clean.
  • Recovery prompts are required after many tasks.
  • Usage/time is consumed without meaningful file edits.
  • It becomes unsafe to queue follow-up tasks because the previous task state may be ambiguous.

Suggested improvement:

  • Add automatic pre-write loop detection.
  • Track task phases durably: preflight_started, preflight_done, write_started, validation_started, final_report_started, completed.
  • After reconnect/context compaction, resume from the last durable phase instead of restarting preflight.
  • Add a “write status report and stop” recovery action.
  • Add a hard no-progress guard, for example: if no files are edited after 10–15 minutes in a file-editing task, ask whether to continue or stop.
  • Show clearer backend state after WebSocket disconnect:
  • backend still running;
  • backend completed;
  • backend failed;
  • UI stream failed only;
  • project state unknown.

Approximate context/token usage: it start happening around week ago, PRO /200USD run out less than a week :( It felt less by how fast token use then when i started on 100USD

Attachments:
I can attach screenshots showing:

  • Reconnecting /5
  • websocket closed by server before response.completed
  • repeated Context automatically compacted
  • task running for hours with no file edits
  • repeated preflight messages

What is the expected behavior?

_No response_

Additional information

_No response_

View original on GitHub ↗

10 Comments

github-actions[bot] contributor · 1 month ago

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

  • #26720
  • #26696
  • #26274

Powered by Codex Action

SocialK · 1 month ago

Approximate context/token usage: it start happening around week ago, PRO /200USD run out less than a week :( It felt less by how fast tokens are were used when I was on a Pro/100USD - upgrade make it worse , less work more tokens. i tried to restore tokens with support but has no reply

mauriciorubio2 · 1 month ago

Agreed. This is a MASSIVE problem and they need to fix it asap.
https://github.com/openai/codex/issues/27590

SocialK · 1 month ago

Additional concrete example:

I have a task log where Codex worked for 4h 55m on a single scoped case.

During this time, it repeatedly did the same preflight sequence:

  • read START_HERE / PROJECT_STATE / ACTIVE_TASK / CANONICAL_PATHS;
  • read CURRENT_CASE_LOCK;
  • read runtime_registry_entry.json;
  • read hot_floors_manifest.json;
  • read policy/rule files;
  • context automatically compacted;
  • reconnect happened;
  • Codex resumed and repeated the same preflight again.

The task did not meaningfully progress into the write phase for hours.

At the end, the visible change was extremely small:
1 file changed +7 -7

This suggests the bottleneck is not the actual file edit. The bottleneck is that Codex gets stuck before writing, repeatedly rebuilding context after compaction/reconnect.

Expected behavior:
If Codex repeats the same preflight several times with no file edits, it should detect a pre-write loop and stop with a status report.

Actual behavior:
Codex keeps running for hours, consuming time/usage, while repeatedly reading the same files and not reaching durable write progress.

SocialK · 1 month ago

New update:

The same Codex task has now run for 6h 26m.

The task repeatedly:

  • reads START_HERE / ACTIVE_TASK / PROJECT_STATE / CANONICAL_PATHS;
  • reads CURRENT_CASE_LOCK / runtime registry / hot floors manifest;
  • says it will process exactly one case;
  • context automatically compacts;
  • reconnects;
  • resumes by repeating the same preflight.

After more than 6 hours, the visible result is only:
1 file changed +7 -7

This strongly suggests a pre-write context compaction loop:
Codex repeatedly rebuilds context and restarts preflight, but does not reach durable write progress.

The bottleneck is not the file edit itself. The actual visible edit is tiny. The problem is that task-state recovery after compaction/reconnect does not preserve the last durable phase.

SocialK · 1 month ago

is that normal 6% from a weekly token limits just one task which is not even write anything, previous week was fully leaked with this model bug.

<img width="2183" height="513" alt="Image" src="https://github.com/user-attachments/assets/b9b0ef80-6d1e-4eee-9f6d-c55cfdbb3358" />

SocialK · 1 month ago

Working for 9h 4m 41s - same task still running on the loop

SREDevOpsNL · 1 month ago

+1 — I am seeing a very similar regression, but on a newer Codex Desktop version.

Codex app version:
26.609.71450, released Jun 16, 2026

Platform:
Windows, Codex desktop app

Account:
Personal ChatGPT Plus account

Feedback ID:
019e97a5-b545-7641-bcec-cfcd9b53fca2

Issue:
After updating to 26.609.71450, Codex started over-expanding narrow tasks and spending a very long time on work that should be a small maintenance fix.

Concrete case:
I asked Codex to fix a simple smoke-test video artifact path mismatch.

Original request, shortened/sanitized:

Video of a demo smoke test run is moved to another folder: <repo>\test\test-results\smoke-artifacts\pvw-ui-smoke-demo\20260614-013147\01_PVW-US-09-...\playwright\videos\<test-name>\<hash>.webm Please check that smoke tests use again: <repo>\test\test-results\smoke-artifacts\pvw-ui-smoke-demo\20260614-013147\01_PVW-US-09-... where 20260614-013147 is DateTime-UniqueNumber specific to that test run.

Expected behavior:
Codex should keep the task narrow:

  • identify why the raw Playwright video remains nested under playwright\videos\...;
  • copy/promote the reviewer-facing video back to the scenario folder root, e.g. demo.webm;
  • make the minimal code/path fix if needed;
  • stop after minimal verification.

Actual behavior:
Codex worked for 3h 20m 33s and still did not properly complete the simple requested fix. It drifted into broader, unnecessary work such as:

  • reading startup/project context;
  • investigating runner behavior too broadly;
  • improving timestamp collision handling;
  • editing docs/runbooks;
  • editing review-pack notes;
  • changing more files than needed for the immediate path mismatch.

Codex later admitted the scope drift itself:

“You’re right to be angry. I overworked a simple artifact-path fix.” “I correctly identified that the raw Playwright video was nested under playwright\videos\<test-name>\<hash>.webm.” “I did copy it to the scenario root as demo.webm.” “Then I drifted into ‘improving’ the runner, docs, timestamp collision handling, and review-pack wording. That was not necessary for the immediate fix.”

Impact:
This consumed a large amount of Codex quota and made the desktop app unreliable for small maintenance tasks. The issue is not only raw slowness; it is also task-scope drift combined with very long agent runtime.

Why I think it is related to this issue:
The visible behavior matches the regression described here: narrow tasks that previously should have taken a few minutes now take tens of minutes or hours, with long stretches of context loading/searching/tool work before reaching the actual edit/verification phase.

Request:
Please treat this as a serious Codex Desktop agent-runtime regression affecting:

  • task scoping;
  • no-progress detection;
  • excessive context loading;
  • long-running task control;
  • quota consumption for small tasks.

I have uploaded in-app feedback from the affected Codex session.

Feedback ID:
019e97a5-b545-7641-bcec-cfcd9b53fca2

erictu-openai · 24 days ago

Post-closure regression signal from June 26:

  • Feedback/session: 019f000e-8002-7db0-8f9b-ef4962c7fcde
  • Model/mode: GPT-5.6 Max
  • Observed: the run continued for about 12 hours in a repeated cycle of checking code changes, finding more edge cases, and applying additional fixes until the user stopped it.
  • Expected: after repeated passes with no clear convergence, Codex should checkpoint, summarize completed work and remaining risks, and require an explicit continuation or bounded stop condition.

This is not the exact pre-write compaction/reconnect loop in the original report: the newer run was making/checking changes and continually expanding validation scope. It does overlap this issue's requested no-progress detection, hard time guard, and “status report and stop” recovery behavior.

Because this occurred after the issue was closed as completed, could an owner confirm whether it should be treated as a regression under #27588 or split into a separate post-write check/fix-loop issue?

SocialK · 24 days ago
Model/mode: GPT-5.6 Max

how did you get access to 5.6 Max? do you see any difference?
i'm on a pro subscription and they do not share with us this model access yet

<img width="743" height="310" alt="Image" src="https://github.com/user-attachments/assets/b4a106b8-1903-42b3-9ecb-5e58d821e6ba" />