Goal context is discarded during compaction, breaking objective continuation

Open 💬 1 comment Opened Jul 14, 2026 by wujekgreg

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:

  1. current source="goal" context through local compaction;
  2. legacy <goal_context> through local compaction;
  3. current goal context through remote compaction;
  4. 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 passed
  • just test -p codex-core compact::tests contextual_user_message::tests: 31 passed
  • just fix -p codex-core: passed
  • just fmt: passed

ProofTether patch

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.

View original on GitHub ↗

This issue has 1 comment on GitHub. Read the full discussion on GitHub ↗