Skip to content

Add feature-gated session segmentation - #27249

Closed
friel-openai wants to merge 1 commit into
dev/friel/rollout-reference-readersfrom
dev/friel/session-segmentation
Closed

friel-openai wants to merge 1 commit into
dev/friel/rollout-reference-readersfrom
dev/friel/session-segmentation

Conversation

@friel-openai

@friel-openai friel-openai commented Jun 9, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Add the disabled-by-default experimental session_segmentation feature.
  • Serialize append, flush, shutdown, and rotation through one per-thread writer transaction.
  • Publish immutable predecessor snapshots for compaction and forks without removing the canonical rollout path.
  • Collect immutable segments after the last active or archived canonical rollout stops referencing them.

This is the writer follow-up to #27968. That prerequisite owns the unchanged RolloutReferenceItem wire format and all reference-aware readers. This PR adds no database migration and does not change the wire format.

Write contracts

  • The canonical rollout path always names the complete predecessor or the complete successor. Rotation writes and closes a same-directory temporary successor, then commits it with one atomic replacement. There is no remove-then-rename sequence and no copy-over fallback.
  • The per-thread writer guard places every accepted append entirely before or entirely after rotation. An append cannot be acknowledged and then overwritten by the successor.
  • A compaction predecessor uses nth_user_message: None and consumes the bounded model-replay segment budget. A fork snapshot uses nth_user_message: Some(usize::MAX) and does not consume that budget.
  • Newly created rollouts have a segment_id. A legacy rollout without one is copied to a dedicated immutable initial path before publication, so its live canonical path cannot later resolve as the captured predecessor.
  • Immutable segment lifetime follows graph reachability, not the thread ID in the storage path. Deleting a parent retains segments referenced by a child; deleting the final referencing thread collects them.
  • Reference-backed full-history subagent forks intentionally preserve the exact parent transcript prefix, including reasoning and tool items. Copied-history fallbacks and last-N forks retain the existing materialization and sanitizer behavior.

If a failure occurs before atomic replacement, the old canonical file and writer remain usable. If reopening the successor fails after replacement, rotation atomically restores the predecessor. A retry also removes an immutable collision left by a process crash only after confirming that no canonical rollout references it.

Test plan

  • cargo test -p codex-thread-store (88 passed)
  • cargo test -p codex-rollout (85 passed)
  • cargo test -p codex-features (51 passed)
  • Focused codex-core compaction, alternate context-window, full-history subagent, inactive mid-turn fork, and repeated explicit-fork tests passed with RUST_MIN_STACK=33554432
  • bazel --batch test //codex-rs/thread-store:thread-store-unit-tests
  • Scoped just fix for codex-thread-store, codex-rollout, codex-features, and codex-core
  • just write-config-schema
  • bazel --batch mod deps --lockfile_mode=error
  • Argument-comment lint passed all 674 targets, including 127 manual Rust test targets, in Bazel batch mode
  • just fmt
  • git diff --check

The full codex-core --lib run passed 1,914 tests. Five unrelated tests failed because this sandbox exposes /tmp as a synthetic Git root; every changed core path passed independently.

@friel-openai friel-openai added CLI Issues related to the Codex CLI rust Pull requests that update rust code labels Jun 9, 2026
@friel-openai
friel-openai force-pushed the dev/friel/session-segmentation branch from 6d63707 to d6de718 Compare June 9, 2026 22:18
friel-openai added a commit that referenced this pull request Jun 10, 2026
@friel-openai
friel-openai force-pushed the dev/friel/session-segmentation branch from d6de718 to 4f22825 Compare June 10, 2026 17:50
@friel-openai
friel-openai marked this pull request as ready for review June 10, 2026 18:07
@friel-openai
friel-openai requested a review from a team as a code owner June 10, 2026 18:07

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 4f22825f9f

ℹ️ 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".

Comment thread codex-rs/rollout/src/list.rs Outdated
Comment thread codex-rs/core/src/agent/control/spawn.rs Outdated
Comment thread codex-rs/rollout/src/list.rs Outdated
@friel-openai
friel-openai force-pushed the dev/friel/session-segmentation branch from 47046e0 to b1573f3 Compare June 11, 2026 05:53
friel-openai added a commit that referenced this pull request Jun 11, 2026
@friel-openai
friel-openai force-pushed the dev/friel/session-segmentation branch from b1573f3 to 349965b Compare June 11, 2026 05:56
friel-openai added a commit that referenced this pull request Jun 11, 2026
@friel-openai
friel-openai force-pushed the dev/friel/session-segmentation branch from e8a1aea to d1bf0db Compare June 11, 2026 07:11
@friel-openai

Copy link
Copy Markdown
Contributor Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: d1bf0db5f6

ℹ️ 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".

Comment thread codex-rs/thread-store/src/local/live_writer.rs Outdated
Comment thread codex-rs/rollout/src/list.rs Outdated
Comment thread codex-rs/rollout/src/recorder.rs
Comment thread codex-rs/core/src/thread_manager.rs Outdated
Comment thread codex-rs/state/src/extract.rs

@jif-oai jif-oai left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don’t think we should land this as one PR. The goal—bounding live rollout files—is valid, but this introduces a graph of mutable file references before defining the core contracts: immutable snapshot identity, ownership/lifetime, deletion and GC, atomic rotation, failure behavior, and the distinction between bounded model replay and complete transcript history.

This would make the contract explicit and easier to reason about the PRs while reviewing.

My comments are still valid though and some probably need a refactor

Comment thread codex-rs/core/src/agent/control/spawn.rs Outdated
Comment thread codex-rs/core/src/thread_manager.rs Outdated
Comment thread codex-rs/rollout/src/list.rs Outdated
Comment thread codex-rs/thread-store/src/local/live_writer.rs Outdated
Comment thread codex-rs/thread-store/src/local/live_writer.rs Outdated
Comment thread codex-rs/thread-store/src/local/live_writer.rs Outdated
Comment thread codex-rs/app-server-protocol/src/protocol/thread_history.rs Outdated
Comment thread codex-rs/core/src/session/mod.rs Outdated
Comment thread codex-rs/thread-store/src/local/live_writer.rs Outdated
Comment thread codex-rs/rollout/src/metadata.rs Outdated
@friel-openai
friel-openai force-pushed the dev/friel/session-segmentation branch from ffbd02a to 0b4829e Compare June 13, 2026 00:10
@friel-openai friel-openai added the codex Label used by connector to tag PRs that have been reviewed by Codex label Jun 13, 2026
@friel-openai
friel-openai changed the base branch from main to dev/friel/rollout-reference-readers June 13, 2026 00:11
@friel-openai
friel-openai marked this pull request as draft June 13, 2026 00:11
@friel-openai
friel-openai force-pushed the dev/friel/session-segmentation branch from 0b4829e to ad31e8b Compare June 13, 2026 00:23
@friel-openai
friel-openai marked this pull request as ready for review June 13, 2026 00:36
@github-actions

Copy link
Copy Markdown
Contributor

Closing this pull request because it has had no updates for more than 14 days. If you plan to continue working on it, feel free to reopen or open a new PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLI Issues related to the Codex CLI codex Label used by connector to tag PRs that have been reviewed by Codex rust Pull requests that update rust code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants