Goal context is discarded during compaction, breaking objective continuation
Codex version
Current main at 7f3eb8a2233aceba3e7962123da84379ee305bb2 (verified 2026-07-14).
What happens
When a task has an active goal and history compaction runs, the goal continuation context can disappear from the compacted history. Subsequent turns may lose the objective even when the user gives a directional continuation such as "continue" or "go".
This is a precise compaction bug. It may contribute to some apparent stalls or non-progressing continuations, but this report does not claim that it explains every indefinite Thinking state.
Root cause
Goal continuation is injected as a hidden user-context fragment:
<codex_internal_context source="goal">
...
</codex_internal_context>
That content intentionally does not parse as a visible TurnItem. Both compaction paths currently use visible-turn parsing as their retention boundary:
- local compaction:
collect_user_messages - remote compaction:
should_keep_compacted_history_item
As a result, goal-owned context is dropped together with unrelated hidden context.
Expected behavior
A well-formed goal fragment should survive local and remote compaction. Other internal fragments should remain filtered. Resumed older threads using the legacy <goal_context> wrapper should remain compatible.
Reproduction proof
Focused regression tests were added for:
- current
source="goal"context through local compaction; - legacy
<goal_context>through local compaction; - current goal context through remote compaction;
- negative control:
source="extension"remains filtered.
Before the retention rule:
just test -p codex-core goal_context: 3 failed, 1 passed
After the narrow retention rule:
just test -p codex-core goal_context: 4 passedjust test -p codex-core compact::tests contextual_user_message::tests: 31 passedjust fix -p codex-core: passedjust fmt: passed
ProofTether patch
- Commit: https://github.com/prooftether/codex/commit/1dc515664c812d3104ec68def3830bc5d5423959
- Upstream comparison: https://github.com/openai/codex/compare/main...prooftether:codex:codex/preserve-goal-context-compaction
The upstream compare page reports the branches as mergeable, but currently also reports that opening PRs is limited to repository collaborators. The patch is therefore attached as reproducible evidence here rather than presented as an unverified hypothesis.
Related context: #27894, #29811, #31099. This also revisits the intent of #22174 against the current internal-context architecture.
This issue has 1 comment on GitHub. Read the full discussion on GitHub ↗