Repository navigation
Description
What version of the Codex App are you using (From “About Codex” dialog)?
26.721.41059
What subscription do you have?
ChatGPT Plus
What platform is your computer?
Microsoft Windows NT 10.0.19045.0 x64
What issue are you seeing?
Codex repeatedly loses or fails to restore the active execution state of a long-running software-development task after automatic context compaction.
I was using GPT-5.6 Sol in Ultra reasoning mode with subagents enabled. During execution, the main agent and its subagents made substantial and observable progress toward completing the task. Codex inspected the relevant source files, modified the code, built the application, ran verification steps, and repeatedly reached what appeared to be the post-build testing or final-reporting stage.
However, after automatic context compaction, the agent began behaving as though a significant part of the completed work and current task state was no longer available.
It returned to earlier stages of the task, reread files that had already been analyzed, reran commands that had already completed, reopened implementation questions that had already been resolved, and repeated work previously performed by the main agent or its subagents.
The session repeatedly entered the following loop:
substantial progress → near completion → automatic context compaction → loss of active task state → repetition of completed work → another context compaction
The agent sometimes reformulated its reasoning differently, but functionally returned to the same earlier work instead of continuing from the latest valid checkpoint.
This continued for approximately two hours. The task was never completed, despite Codex reaching the build, post-build verification, or final-reporting stage several times.
Before the affected execution, my included weekly Codex usage allowance was approximately 100%. After the repeated execution loop, the allowance had decreased to 0%, while the requested task remained unfinished.
This is not a complaint about the normal usage cost of GPT-5.6 Sol, Ultra reasoning, or subagents. I deliberately selected this configuration and understood that it would consume more usage.
The issue is that the allowance was consumed by repeated work following context-compaction events rather than by continued progress toward completion.
What steps can reproduce the bug?
-
Open an existing local software project in Codex Desktop on Windows 10 x64.
-
Select GPT-5.6 Sol.
-
Select Ultra reasoning mode.
-
Allow Codex to use subagents.
-
Submit a multi-stage software-development task that requires:
- repository analysis;
- modification of existing source files;
- coordination between the main agent and subagents;
- building the application;
- post-build testing or verification;
- production of a final completion report.
-
Allow Codex and its subagents to work until substantial progress has been made.
-
Observe that Codex:
- identifies the relevant files;
- performs implementation work;
- modifies the code;
- builds the application;
- runs tests or post-build checks;
- approaches the final reporting stage.
-
Wait for an automatic context-compaction event.
-
Continue observing the agent after compaction.
-
Instead of continuing from the latest valid execution checkpoint, Codex begins repeating earlier work. Typical behavior includes:
- rereading files that were already inspected;
- rerunning repository searches;
- repeating diagnostic commands;
- reconsidering implementation decisions already made;
- reopening resolved problems;
- repeating work completed by subagents;
- returning from post-build verification to earlier repository analysis.
-
Allow the session to continue.
-
The repeated work consumes more context and causes another automatic context-compaction event.
-
After the next compaction, Codex again returns to earlier work instead of completing the task.
-
The cycle continues without a stable final result.
The problem reproduced repeatedly during attempts made on July 28–29, 2026.
Approximate execution pattern:
analysis → implementation → build → verification → near completion → context compaction → task-state regression → repeated analysis and implementation → another compaction
Observed usage impact:
- Weekly allowance before the affected execution: approximately 100%.
- Weekly allowance after approximately two hours: 0%.
- Final task result: not delivered.
- Exact token and context-window counters were not exposed in the desktop user interface.
- The application displayed automatic context-compaction events during the affected execution.
The affected conversation was also submitted directly through the built-in Codex feedback function. The feedback interface did not display a session ID to me.
What is the expected behavior?
Automatic context compaction should preserve a structured and reliable continuation checkpoint.
After compaction, Codex should continue from the latest valid execution state instead of reconstructing the task from an incomplete general summary or returning to an earlier phase.
At minimum, the preserved state should include:
- the exact current user request;
- the task acceptance criteria;
- the current execution phase;
- work already completed;
- work still remaining;
- files already inspected;
- files already modified;
- commands already executed;
- results of completed commands;
- build results;
- test and verification results;
- implementation decisions already made;
- issues already resolved;
- known unresolved issues;
- approaches already rejected;
- relevant findings returned by subagents;
- changes already completed by subagents;
- the exact next action;
- the explicit task-completion condition.
After context restoration, Codex should verify the current repository state and continue from the latest valid checkpoint.
It should not silently return to initial repository analysis, reopen resolved questions, or repeat completed commands and implementation work.
The runtime should also detect likely repetition loops, including:
- repeated reading of the same files without a new reason;
- repeated execution of the same searches or diagnostic commands;
- repeated reconsideration of the same resolved issue;
- repeated assignment of substantially identical work to subagents;
- repeated builds without intervening code changes;
- returning from final verification to initial analysis;
- repeatedly approaching completion without producing the final response.
When reliable continuation is no longer possible, Codex should stop and explicitly report that state instead of indefinitely consuming the user’s limited usage allowance.
Additional information
Environment
- Product: Codex Desktop for Windows
- Installation source: Microsoft Store
- Application version: 26.721.41059
- Operating system: Windows 10 x64
- Subscription: ChatGPT Plus
- Model: GPT-5.6 Sol
- Reasoning mode: Ultra
- Subagents: Enabled
- Dates observed: July 28–29, 2026
- Time zone: Europe/Kyiv, UTC+3
Severity and impact
Severity: High
The issue caused:
- failure to complete an otherwise finite software-development task;
- repeated loss or weakening of the current execution state;
- repetition of already completed work;
- apparent loss or weakening of subagent findings;
- repeated execution of commands and repository analysis;
- exhaustion of the entire included weekly Codex usage allowance;
- loss of approximately two hours of execution time;
- inability to continue using the selected Codex configuration;
- no completed final result.
This was not simply an incorrect answer or an unsuccessful implementation attempt.
The agent repeatedly reached the build, post-build verification, or final-reporting stage and then regressed after context compaction.
Regression information
This appears to be a regression.
I previously used Codex for comparable long-running software-development tasks. Automatic context compaction also occurred in earlier sessions, but it appeared less frequently and did not normally cause this degree of task-state regression.
Earlier sessions generally continued toward a logical completion after compaction. In the current behavior, compaction can cause the agent to return to substantially earlier stages and enter a non-terminating repetition loop.
Subagent-specific concern
Subagents were enabled during the affected execution.
Some work was completed or investigated by subagents, but after context compaction the parent agent sometimes behaved as though those findings or completed actions were no longer available.
Please investigate whether:
- subagent outputs are fully retained across parent-context compaction;
- completed subagent tasks remain marked as completed;
- the parent agent can distinguish completed subagent work from pending work;
- repository changes and conclusions produced by subagents survive compaction;
- repeated compaction progressively weakens or removes subagent results.
Possible affected components
The exact root cause cannot be determined from the user interface.
The behavior appears correlated with automatic context compaction and may involve:
- preservation of the active execution checkpoint;
- restoration of the current task phase;
- retention of completed and remaining work;
- retention of subagent results;
- synchronization between repository state and compacted conversation state;
- loss of command, build, or test results;
- repeated compaction of already compacted summaries;
- loss of the latest task-completion condition;
- absence of repetition-loop detection.
These are suspected affected areas, not confirmed root causes.
Requested investigation
Please investigate:
- Whether automatic context compaction preserves the latest active execution checkpoint.
- Whether the current task phase remains explicitly available after compaction.
- Whether completed work remains marked as completed.
- Whether command, build, and test results survive compaction.
- Whether subagent results remain available to the parent agent.
- Whether repeated compaction progressively removes important task state.
- Whether the restored state is synchronized with the actual repository state.
- Whether Codex can detect repeated post-compaction behavior.
- Whether the runtime can prevent non-terminating execution loops.
- Whether usage consumed during confirmed repetition loops can be identified in telemetry.
Reporting status
The affected conversation has already been submitted through the built-in Codex feedback function.
OpenAI Support has also been contacted regarding the account-level impact and the weekly allowance consumed during the failed execution.
Possible related reports include:
- Context auto-compaction loop repeatedly rereads files, loses progress, and consumes paid Codex credits #35226
- Context compaction forgets AGENTS rules: task progress can jump from 97% back to 42% #25792
- Compaction should preserve the current task checkpoint to avoid restart loops in long-running sessions #25900
- Pro plan unusable: lossy compaction silently rewrites instructions + unreapable subagent leak (5 compounding bugs, full telemetry) #25563
This report documents an independent reproduction involving Windows 10 x64, the Microsoft Store desktop application, ChatGPT Plus, GPT-5.6 Sol, Ultra reasoning mode, subagents, and complete exhaustion of the included weekly allowance.
Requested resolution
A complete resolution should include:
- reliable preservation of structured task state before compaction;
- restoration from the latest valid checkpoint;
- retention of completed and remaining work;
- retention of relevant subagent results;
- synchronization with the actual repository and build state;
- detection and prevention of repeated post-compaction execution;
- a safe stop condition when reliable continuation is impossible;
- protection against exhausting the user’s allowance through repeated completed work.
Activity
github-actions commentedon Jul 29, 2026
Potential duplicates detected. Please review them and close your issue if it is a duplicate.
Powered by Codex Action
Keesan12 commentedon Jul 30, 2026
This looks like a checkpoint-integrity failure rather than ordinary model drift. A useful regression test would persist the current phase, completed actions, modified files, verification outputs, and exact next action before compaction, then assert that the restored session does not repeat prior commands or reopen resolved decisions. A repeated-work detector should stop the run once the same phase or command sequence recurs without new repository state.
post1917a commentedon Aug 10, 2026
I have an independent metric-level reproduction that matches this issue and shows a mid-turn operational-state loss even though compaction reclaimed ample headroom.
Environment
26.803.5235.0258,400tokensObserved sequence
236,838 / 258,400input tokens.413,695characters of model-facing tool outputs, plus the tool calls and visible assistant progress messages.5,050-character preservation summary.5,450-character message: a 400-character service preface followed by that preservation summary verbatim.replacement_historycontained 19 items:usermessagesdevelopermessages20,370tokens; the first continuation request used21,254input tokens.The active turn had added roughly
65,500input tokens before compaction. Replaying its operational tail after compaction would therefore have produced a prompt of roughly86,000tokens in this case, still far below the258,400-token window.This appears distinct from a compaction that simply fails to reclaim enough space. The compaction reclaimed substantial space, but the immediate continuation lost the completed action sequence and restarted work that the preserved summary already described.
I understand from #14589 that dropping raw tool outputs and assistant reasoning was previously classified as working as intended. Could a maintainer clarify the intended behavior for this narrower failure mode?
PreCompactplusSessionStart(source="compact")intended as the supported mitigation for this case, or only as general extension points?I am not attaching the raw rollout or a screenshot because they contain unrelated private task context, but I can provide additional redacted structural metrics if useful.
Lexoid2 commentedon Aug 11, 2026
Thanks for documenting this in such detail. This matches the failure mode I observed very closely.
In my case, the problem also wasn't simply that compaction failed to reclaim enough context. Codex would compact successfully and continue the same active task, but then fall back to an earlier execution state and repeat work that had already been completed.
Your finding that the replacement history contained none of the assistant or tool execution trail, even though the continuation still had plenty of context headroom, seems especially relevant to what I observed.
It makes the difference between normal compaction and losing the current operational checkpoint much clearer.
I'd also be interested in a maintainer clarifying whether preserving some bounded part of the current-turn operational history is expected or planned, since that seems directly related to the repeated-work behavior reported here.
Thanks again for the independent reproduction.
barcuchj commentedon Sep 3, 2026
This overlaps with #36584 at the checkpoint/handoff level, but the failure documented here is more specific: automatic compaction can restore an earlier task state and repeat completed work, consuming time and usage.
A handoff/checkpoint should therefore be available as a manual recovery path before or after compaction, not only as a warning. It should persist the exact next action, completed and pending work, modified files, Git/worktree identity and dirty state, build/test results, artifacts, subagent findings, and unresolved blockers, then create a successor task while leaving the original intact for audit.
A useful regression test would assert that a resumed task does not repeat commands or reopen resolved decisions when repository state has not changed.
iliaschatt1993-code commentedon Sep 15, 2026
I’m exploring how people preserve state across long coding-agent sessions.
In your case, what is the one artifact you wish had persisted before compaction — decisions, next steps, verification state, or something else?
I’m trying to understand the failure mode properly.
barcuchj commentedon Sep 15, 2026
@iliaschatt1993-code Thanks for asking. The most important missing artifact was not another prose summary, but a structured execution checkpoint.
It should preserve:
If I had to choose the single most important field, it would be the exact next action together with the completed-versus-pending verification state.
In my case, Codex had reached build/verification and then, after compaction, behaved as if it had returned to an earlier phase. It reread files, repeated commands, and reconsidered resolved decisions. The failure was therefore loss of operational state, not merely loss of conversational context.
A HANDOFF.md-style artifact would be useful as a human-readable projection, but the runtime should also preserve machine-readable state so the next continuation can resume from the exact next action rather than reconstructing the task from a general summary.
John-Rood commentedon Sep 18, 2026
Nothing here needs a code change. The artifact @barcuchj described (the exact next action plus verification state) can be produced on current builds with one file and a write rule. The measurement from @post1917a above is why it has to be a file: after compaction the continuation receives the summary plus user and developer messages, with zero assistant turns, tool calls, or tool outputs carried over. It is reasoning about work it can no longer inspect, so it re-derives the task instead of continuing it.
RUN.mdat the repo root, one per task:Rules that make it hold:
git rev-parse HEAD,git status --porcelain). On a mismatch, fix the ledger before any other work.Put rule 3 in AGENTS.md so it covers every task, and repeat it in the task prompt for any run already in flight: Codex builds the instruction chain once per run, so an AGENTS.md edit does not reach a live session (developers.openai.com/codex/guides/agents-md).
For subagent work, have each subagent write its receipts under the same run directory before returning, and reference them from the main DONE list. Subagent tool output disappears at the boundary; the files do not.
Try it on the next long task: put a unique token in NEXT, trigger compaction mid-run (/compact), and confirm the continuation resumes from the token without re-reading old files. If a continuation ever runs the same command twice with no new artifact between the runs, stop it and reconcile from RUN.md.
barcuchj commentedon Sep 23, 2026
@samvallad33 Yes — I think persisting task state outside the compacted conversation and reloading/reconciling it after compaction is the right architectural direction.
The important distinction is between a conversation summary and execution state. A summary can say that implementation and testing were performed, but that is not enough to reliably determine what actually completed, what remains pending, what the exact next action is, which commands/tests produced verified results, or what subagents already established.
@John-Rood's
RUN.mdproposal is a useful workaround on current builds because it moves some of that state outside the compacted history. I would use something similar for long-running tasks today. But I don't think it means the underlying issue requires no product change.There is still a failure window if an action completes and compaction occurs before the model updates
RUN.md. More generally, users should not need to implement their own checkpoint protocol inAGENTS.mdto prevent an internal compaction mechanism from causing completed work to be repeated.Ideally, Codex itself would maintain persistent machine-readable execution state outside the compactable conversation history, including at least:
After compaction, Codex could reload that checkpoint, reconcile it against the actual repository state, and continue from the recorded next action rather than reconstructing operational state from a prose summary.
The ordering matters too: an action should only become “completed” once its result/receipt and updated task state have been persisted. Otherwise the same race can simply move from the conversation summary into the checkpoint mechanism.
So I see
RUN.mdas a good user-space mitigation and potentially a useful model for the feature, while persistent runtime-managed execution state would address the underlying regression.John-Rood commentedon Sep 23, 2026
@barcuchj The ordering point is the right place to tighten, and it exposes the gap in what I posted above: a journal written only after completion always loses whatever finished inside the window.
Write ahead of the action instead of behind it. Log the step as IN-FLIGHT with the exact command or target, then flip the line to DONE with the receipt once it lands. If compaction fires mid-step, the resume finds an in-flight line and reconciles that single item against the repo before anything else runs. Worst case shrinks from "completed work replayed" to "one line to verify".
And I agree it shouldn't stay a user-space protocol. Runtime-managed execution state that reloads and reconciles after compaction is the real fix; the file is the bridge for builds that don't have it yet.
barcuchj commentedon Sep 23, 2026
@John-Rood Agreed —
IN-FLIGHT → receipt → DONEcloses most of the race window and makesRUN.mda much stronger workaround.I would still emphasize that this should remain a temporary bridge rather than the expected user-side solution, especially because the workaround itself consumes the user's usage. Reading and updating the journal, producing receipts, and reconciling state after compaction all require additional model/tool work.
That matters particularly for this issue because one of the reported consequences of the regression is wasted usage from replaying completed work. Users should not have to spend additional usage implementing and maintaining a checkpoint protocol to compensate for an internal compaction mechanism.
If execution-state persistence is runtime-managed, the bookkeeping can happen at the system boundary rather than being repeatedly performed by the model as part of the user's task. The user-space journal is a good mitigation until that exists, but its cost should not become part of the normal workflow.
post1917a commentedon Sep 23, 2026
“Nothing here needs a code change” is an extraordinary conclusion to draw from a workaround. If users have to keep an
IN-FLIGHTjournal so Codex can get through its own automatic compaction, what exactly has been fixed?In my reproduction, compaction left ample context headroom, the continuing model received no assistant or tool trail, and Codex promptly repeated completed work. The repetition is the bug.
RUN.mdmay limit the damage, at the user’s expense in time and usage. It does not make the failure disappear. A workaround for lost execution state is evidence that execution state needs to survive compaction – not an argument for leaving the issue unfixed.John-Rood commentedon Sep 23, 2026
@post1917a Fair. "Nothing here needs a code change" overstated it. What I meant: nothing blocks a mitigation on current builds. The repetition is the bug and the fix belongs in the runtime, either carrying the current-turn tool trail across compaction or reloading a reconciled checkpoint at the boundary. The journal is only for runs in flight before that ships.
FateW99 commentedon Oct 21, 2026
Additional Windows desktop report, October 21, 2026:
After the most recent desktop update on this user's machine, automatic context compaction has repeatedly been followed by a return to an early instruction from the compacted conversation, rather than continuation from the current task state.
The user reports observing this many times: work has already been performed, automatic compaction occurs, and the assistant starts doing the earlier task again as if the completed steps had not happened. The distinctive symptom is reactivation of the initial/earlier instruction, beyond merely repeating a final explanation.
Environment: Windows desktop; installed package observed today:
26.1016.6573.0. This is the current local installation, not a verified version attribution for every previous occurrence. Affected model and exact occurrence count have not been recorded.Expected behavior:
Suggested regression scenario (not a newly executed controlled reproduction): complete Task A, move on to Task B in the same long conversation, allow natural automatic compaction, and verify that continuation advances Task B rather than restarting A or repeating its finished steps. Repeat across multiple compactions.
This is a user-observed recurrence report, not a proven root-cause analysis. No deterministic minimal reproduction, compaction-event trace, or before/after transcript has been captured for this new report. The correlation with a recent update and automatic compaction does not establish whether the defect is in the client, compaction summary, instruction restoration, or model behavior.
Related reports #42611 and #42695 describe similar historical-instruction replay in different workflows; a shared cause has not been established. This user's report does not identify cross-thread delivery as a prerequisite.
Please investigate durable preservation of task status and handled/superseded instruction identity across automatic compaction, and include this earlier-instruction replay in regression testing.
No private conversations, project files, credentials, local personal paths, or raw logs are attached.
ScottSiu1983 commentedon Nov 7, 2026
Adding a small, reproducible case that may be the sharpest form of this: with
codex execandgpt-6-astra, automatic compaction drops the user's task message entirely, so the continuation has no task at all.Environment: codex-cli 0.167.0 (also seen on 0.162.1), macOS arm64, ChatGPT plan, non-interactive
codex exec.Repro
Copy four ~50 KB source files into an empty directory as
f1.cpp…f4.cpp.Run, with the task on stdin:
Task: "Use
catto print f1.cpp, f2.cpp, f3.cpp, f4.cpp in full, one per command. Then write report.md with one line per file (name,wc -lcount, name of the last function defined). The last line of report.md must be the code word ORCHID-7731."Compaction triggers after about two files.
Result with gpt-6-astra: all 4 runs without a task file in the work directory lost the task (3 on 0.162.1, 1 on 0.167.0; one had
compact_promptoverridden, one had a thread goal set viacreate_goal). After compaction the model only sees the AGENTS.md instructions, replies with a generic acknowledgement and ends the turn; no report.md. In the rollout'scompacteditem,replacement_historyholds the developer messages and the AGENTS.md user message but not the task message; the task text appears only underretained_context.user_messages. Each compaction comes with 3-4codex_core::tools::router: error=Unable to perform operation: The backend request failed.lines.Same setup with the default Sol model (gpt-6.1-sol, 0.162.1): 3 of 3 runs completed after 3-6 compactions each, with zero backend errors.
replacement_historykeeps the task message verbatim plus acompactionitem, even whencompact_promptis overridden to return a single word.So for Astra the retained user messages do not seem to be rendered back into the post-compaction history.
What worked around it: a work-directory AGENTS.md pointing to a TASK.md file (the run completes, but the model re-reads everything after each compaction: about 1.7M input tokens vs about 0.56M for Sol on the same task), or
codex exec resume <id>with the task text sent again. A thread goal did not help in exec mode, since the process exits when the turn ends.Happy to share rollout excerpts if that helps.
John-Rood commentedon Nov 7, 2026
Your two arms are not comparable on one axis. In the model catalog the client fetches,
supports_experimental_contextis true forgpt-6-astraand false forgpt-6.1-sol, andapply_experimental_context(core/src/session/token_budget.rs) returns without doing anything when that flag is false. Sol cannot enter the experimental context path. Astra can.Eligibility is not activation. The same gate also requires
context_managementand then force-enablestoken_budget. Both are under development and default off on 0.166.0, which is the build I have here. If neither was set in your runs, the flag is not your cause and the split comes from somewhere else.The shape in your dump is diagnosable either way.
build_compaction_replacement_historyassembles prefix plus initial context plus the compacted body, andinsert_initial_context_before_last_real_user_or_summaryonly reaches its append branch when the compacted body carries no real user message, no user-message-like summary and no compaction item. Developer messages plus the AGENTS.md turn and nothing else is that branch exactly. So in those Astra runs the compacted body arrived empty: nothing to keep, nothing summarized. Sol's history keeps the task verbatim plus a compaction item, which is the normal branch.That is a different failure from a lossy summary, and worth separating in the report. A bad summary still leaves an item in the history. An empty compaction result leaves nothing but initial context, so your AGENTS.md pointer is the only thing that can put the task back, which is why the run costs 1.7M input tokens against 0.56M.
If you can paste the compacted item from one Astra run and its compaction request id, that settles whether the body came back empty or was dropped after it arrived.
The reason this class of bug keeps biting is that anything which has to survive the boundary cannot live inside the window. I built MemoryRouter for that: memory the agent searches after compaction instead of rebuilding state from the repo. https://docs.memoryrouter.ai/codex?utm_source=github&utm_medium=issue&utm_campaign=openai-codex