mirror of
https://github.com/openai/codex.git
synced 2026-11-16 06:54:36 +00:00
feat(rollout): persist TurnItems for paginated thread rollouts (#30188)
## Description This PR makes new threads with `history_mode = "paginated"` persist `ItemCompleted(item: <turn_item>)` in their rollout JSONL file. Legacy threads keep persisting the existing legacy events. Because the format is selected per thread, a rollout is either legacy or paginated; we do not need to support mixed rollouts containing both representations. This PR depends on [#31473](https://github.com/openai/codex/pull/31473). ## Why Paginated thread history needs stable turn/item IDs and completed item snapshots so the later SQLite projector can materialize appended rollout JSONL without rebuilding the whole thread. Keeping the legacy persistence policy unchanged avoids changing historical rollouts or the readers that still consume them. ## What changed - Made rollout filtering history-mode aware. Paginated threads keep completed canonical `ItemCompleted` events and drop their redundant legacy projections; legacy threads keep the existing event set. - Made forks inherit the source thread history mode, so copied legacy history is never filtered as paginated. - Made paginated threads assign IDs to locally-created response items even when `Feature::ItemIds` is off, and reject streamed output items that arrive without server IDs. - Updated legacy turn replay, rollout list/search, and SQLite metadata extraction to understand completed canonical user-message items.
This commit is contained in:
1 parent
5892c7b69d
commit
2342b2c2a6
26 files changed
+497
-220
No files matched your search
@@ -1,6 +1,7 @@
|
||||
use std::path::PathBuf;
|
||||
|
||||
use codex_protocol::ThreadId;
|
||||
use codex_protocol::protocol::ThreadHistoryMode;
|
||||
use codex_protocol::protocol::ThreadMemoryMode;
|
||||
use codex_rollout::RolloutConfig;
|
||||
use codex_rollout::RolloutRecorder;
|
||||
@@ -115,13 +116,15 @@ pub(super) async fn append_items(
|
||||
store: &LocalThreadStore,
|
||||
params: AppendThreadItemsParams,
|
||||
) -> ThreadStoreResult<()> {
|
||||
let canonical_items = persisted_rollout_items(params.items.as_slice());
|
||||
if canonical_items.is_empty() {
|
||||
// LocalThreadStore rejects paginated threads before opening a writer.
|
||||
let persisted_items =
|
||||
persisted_rollout_items(params.items.as_slice(), ThreadHistoryMode::Legacy);
|
||||
if persisted_items.is_empty() {
|
||||
return Ok(());
|
||||
}
|
||||
let recorder = store.live_recorder(params.thread_id).await?;
|
||||
recorder
|
||||
.record_canonical_items(canonical_items.as_slice())
|
||||
.record_canonical_items(persisted_items.as_slice())
|
||||
.await
|
||||
.map_err(thread_store_io_error)?;
|
||||
// LiveThread applies metadata immediately after append_items returns. Wait for the local
|
||||
|
||||
@@ -694,6 +694,7 @@ mod tests {
|
||||
write_session_file(home.path(), "2025-01-03T17-00-00", uuid).expect("session file");
|
||||
let live_thread = LiveThread::resume(
|
||||
store,
|
||||
ThreadHistoryMode::Legacy,
|
||||
ResumeThreadParams {
|
||||
thread_id,
|
||||
rollout_path: Some(rollout_path),
|
||||
@@ -748,6 +749,7 @@ mod tests {
|
||||
.expect("external session file");
|
||||
let live_thread = LiveThread::resume(
|
||||
store,
|
||||
ThreadHistoryMode::Legacy,
|
||||
ResumeThreadParams {
|
||||
thread_id,
|
||||
rollout_path: Some(rollout_path),
|
||||
|
||||
Reference in new issue
Block a user