fix(parser): treat Codex /goal continuation context as system content#886
Merged
Merged
Conversation
Codex /goal sessions inject continuation context as role=user records wrapped in <codex_internal_context source="goal"> (current) or <goal_context> (legacy). These were parsed as ordinary user turns, flooding long goal-oriented sessions with synthetic messages between real exchanges and inflating user_message_count. Route both wrappers through isCodexSystemMessage so they are dropped from the transcript, user counts, search, and analytics like other Codex internal envelopes. Detection is scoped to the structured wrapper (and the goal source for the modern form) so a real user message that quotes the goal text is preserved. Closes kenn-io#868
roborev: Combined Review (
|
wesm
pushed a commit
that referenced
this pull request
Jun 28, 2026
Refinement on top of #886 / 9bee8a3, which already taught the Codex parser to classify `/goal` continuation envelopes as system content for newly parsed sessions. This PR handles the archive and compatibility side of that fix. It bumps the parser data version to 56 on top of main's version-55 Kimi usage-event bump, so existing source-backed Codex sessions are non-destructively re-parsed and old stored `/goal` rows are removed from message lists and user-turn counts instead of remaining in persistent SQLite archives. It also adds read-path fallbacks for legacy rows that may still exist before reparse, or in rows that cannot be re-emitted from source files. Backend system-prefix filtering now uses a dedicated Codex goal-context predicate plus SQLite/PostgreSQL/DuckDB SQL variants, while frontend system-message detection and HTML/focused export use the same wrapper semantics. Both the current `<codex_internal_context ... source="goal">` form, including extra attributes, and the older `<goal_context>` wrapper stay out of search, transcript filtering, and exported sessions. The main tradeoff is the data-version bump: multi-host PostgreSQL deployments should upgrade `pg serve` and all pushers together, because older agentsview binaries reject rows written by a newer parser data version. Co-authored-by: Trent Nelson <tpn@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Codex
/goalsessions inject continuation context asrole=userrecords so the model keeps working toward the active thread goal. agentsview parsed these as ordinary user turns, so long goal-oriented Codex sessions filled with synthetic "Continue working toward the active thread goal…" messages between real exchanges, anduser_message_countwas inflated (which also feeds single-turn/automated session classification).This routes both envelope formats through the existing
isCodexSystemMessagegate so they are dropped from the transcript, user counts, search, and analytics — the same way<environment_context>,<skill>, and other Codex internal envelopes are:<codex_internal_context source="goal">…</codex_internal_context><goal_context>…</goal_context>Detection is scoped to the structured wrapper (and the
goalsource for the modern form), so a real user message that merely quotes the goal sentence is preserved. The change is parser-level and pre-storage, so it applies identically to the full and incremental parse paths and both storage backends.Where to look:
internal/parser/codex.go(isCodexGoalContextplus theisCodexSystemMessagewiring).Closes #868