Conversation
e95924a to
4181fb6
Compare
e5b9532 to
5e7b7e4
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 5e7b7e46ad
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| }; | ||
|
|
||
| let window = window.unwrap_or(ReconstructedWindow { | ||
| let window = window.or(initial_window).unwrap_or(ReconstructedWindow { |
There was a problem hiding this comment.
Skip source session windows when reconstructing forks
When a fork is created from a source rollout that has a SessionMeta.context_window but has not compacted, InitialHistory::Forked passes only the source rollout into reconstruction. This fallback then installs that source window id into the new fork instead of leaving the fork's freshly generated initial_window_id in fallback_ids, so the fork's model-visible token-budget context and future compaction metadata reuse the parent window id and no longer match the fork's own session_meta header. Please gate this SessionMeta fallback to the matching/resumed thread, or skip it for forks, so forks keep their own initial window.
AGENTS.md reference: AGENTS.md:L103-L111
Useful? React with 👍 / 👎.
| }; | ||
|
|
||
| let window = window.unwrap_or(ReconstructedWindow { | ||
| let window = window.or(initial_window).unwrap_or(ReconstructedWindow { |
There was a problem hiding this comment.
Preserve legacy compaction window counts
When a rollout has the new session_meta.context_window but contains legacy compacted records without window_number (for example, after importing or resuming a forked older rollout), this fallback now chooses the session-meta window with number: 0 and never reaches the existing fallback_window_number based on the compaction count. That resets the restored window ordinal, so the next compaction can reuse window_number 1 and current_window_id() reports the wrong thread_id:0/:1 sequence for a history that was already compacted; keep using the counted fallback when compactions lack explicit window metadata.
AGENTS.md reference: AGENTS.md:L103-L111
Useful? React with 👍 / 👎.
23a0295 to
8042485
Compare
4c16d83 to
3dd08b4
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 3dd08b4769
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| }; | ||
|
|
||
| let window = window.unwrap_or(ReconstructedWindow { | ||
| let window = window.or(initial_window).unwrap_or(ReconstructedWindow { |
There was a problem hiding this comment.
Keep persisted IDs for number-only compactions
When a rollout has the new SessionMeta.context_window but its surviving compaction only carries a legacy window number and no UUID fields (for example an older numeric window_id deserialized into window_number), window is already Some, so this or(initial_window) drops the persisted initial UUID. apply_rollout_reconstruction then fills the missing IDs from the freshly generated session fallback, causing the model-visible context-window IDs and subsequent compaction metadata to change on each resume of that forked/imported legacy history; merge the session-meta ID into number-only compacted windows instead.
AGENTS.md reference: AGENTS.md:L94-L101
Useful? React with 👍 / 👎.
Record the initial AutoCompactWindowIds window_id in session_meta.context_window so JSONL tailers can observe the first context window before any compaction item exists. Thread creation now requires an initial_window_id string, while rollout JSONL keeps that value under the context_window namespace without writing derived chain fields for the initial window. Rollout reconstruction derives window 0 state from that initial_window_id when no compaction window metadata exists. Forks intentionally use the same reconstruction path; consumers that need to distinguish copied initial-window metadata can use thread_id. Legacy compactions without window_number continue to use compaction-count fallback accounting. Verification: - just test -p codex-protocol - just test -p codex-rollout recorder_materializes_on_flush_with_pending_items - just test -p codex-core reconstruct_history_restores_initial_window_from_session_meta - just test -p codex-core reconstruct_history_prefers_compacted_window_over_session_meta - just test -p codex-core reconstruct_history_preserves_legacy_compaction_count_with_session_meta_window - just test -p codex-core reconstruct_history - just test -p codex-core record_initial_history_reconstructs_forked_transcript - just test -p codex-thread-store - just test -p codex-state - just test -p codex-app-server thread_read_returns_summary_without_turns - just test -p codex-rollout persistence_metrics - just fix -p codex-protocol -p codex-rollout -p codex-thread-store -p codex-core -p codex-app-server - just fix -p codex-core -p codex-rollout - just fix -p codex-core
Why
PR #29494 made context-window IDs visible to the model by wrapping the token-budget window payload in
<context_window>, but rollout JSONL consumers still could not see the initial window identity by tailing the session file. Compacted rollout items carry window IDs only after compaction has happened, so a session with no compaction had no durable JSONL record for window 0.This change gives tailing consumers a stable initial-window record at session creation time.
What Changed
session_meta.context_window.window_idfor the initial context-window identity.CreateThreadParamsnow requiresinitial_window_id: String, so thread-store callers cannot accidentally create new threads without window-0 metadata.AutoCompactWindowIdsused to initializeSessionState, keeping runtime state and JSONL metadata aligned.session_meta.context_window.window_idas the initial-window fallback and deriveswindow_number = 0,first_window_id = window_id, andprevious_window_id = Noneinternally.thread_id.window_numberstill use compaction-count fallback accounting instead of being reset to window 0 by the initial-window fallback.JSONL Shape
Real rollout JSONL is one object per line. This example is expanded for readability, but shows the new initial
session_meta.context_windowrecord followed by the existing compacted rollout item shape that also carries window IDs:{ "timestamp": "2026-06-22T12:00:00.000Z", "type": "session_meta", "payload": { "session_id": "<THREAD_ID>", "id": "<THREAD_ID>", "timestamp": "2026-06-22T12:00:00.000Z", "cwd": "/repo", "originator": "codex", "cli_version": "0.0.0", "source": "cli", "model_provider": "<MODEL_PROVIDER>", "context_window": { "window_id": "<INITIAL_WINDOW_ID>" } } } ... { "timestamp": "2026-06-22T12:34:56.000Z", "type": "compacted", "payload": { "message": "<COMPACTION_SUMMARY>", "replacement_history": [ "..." ], "window_number": 1, "first_window_id": "<INITIAL_WINDOW_ID>", "previous_window_id": "<INITIAL_WINDOW_ID>", "window_id": "<NEXT_WINDOW_ID>" } }The nested
context_windowobject is intentional: it gives rollout consumers a stable namespace for context-window metadata while only writing the non-derivable initialwindow_id. For the initial window,window_number,first_window_id, andprevious_window_idare derived internally instead of being written to the rollout.Verification
just test -p codex-protocoljust test -p codex-rollout recorder_materializes_on_flush_with_pending_itemsjust test -p codex-core reconstruct_historyjust test -p codex-core record_initial_history_reconstructs_forked_transcriptjust test -p codex-thread-storejust test -p codex-statejust test -p codex-app-server thread_read_returns_summary_without_turnsjust test -p codex-rollout persistence_metrics