Distinguish turn-start thread persistence (#37926)

## What changed

- Add `PersistContext` to the thread-store persistence contract so stores can
  identify persistence requested immediately before model sampling. A
  `TurnStart` request may be enqueued in the background when later flush and
  shutdown operations fence it and report any failure; all other persistence
  remains synchronous.
- Use the turn-start context only for the initial input of a regular turn, while
  admission acknowledgments, steered input, and other persistence paths keep
  the standard durability behavior.
- Flush pending metadata before turn-start persistence and ensure shutdown is
  still attempted if that metadata update fails.

## Testing

- Verify that developer instructions and user input are persisted before the
  model request completes for a default paginated-history thread.

GitOrigin-RevId: 162f0ec796a61aebe66ca0b909fbcccec3047b85
This commit is contained in:
Bryan Ashley authored and copyberry committed 2026-08-11 03:35:45 +00:00
1 parent f8821d85eb
commit 722784e936
24 files changed
+289 -75

No files matched your search

+8 -2
View File
@@ -51,6 +51,7 @@ use crate::session::turn_context::TurnContext;
use codex_config::types::McpServerConfig;
use codex_features::Feature;
use codex_model_provider_info::ModelProviderInfo;
use codex_thread_store::PersistContext;
use codex_utils_path_uri::PathUri;
use super::ApprovalRequestReasons;
@@ -380,7 +381,10 @@ impl GuardianReviewSessionManager {
pub(crate) async fn trunk_rollout_path(&self) -> Option<PathBuf> {
let trunk = self.state.lock().await.trunk.clone()?;
trunk.session.ensure_rollout_materialized().await;
trunk
.session
.ensure_rollout_materialized(PersistContext::Standard)
.await;
match trunk.session.current_rollout_path().await {
Ok(path) => path,
Err(err) => {
@@ -966,7 +970,9 @@ async fn append_guardian_followup_reminder(review_session: &GuardianReviewSessio
async fn load_rollout_items_for_fork(
session: &Session,
) -> anyhow::Result<Option<Vec<RolloutItem>>> {
session.try_ensure_rollout_materialized().await?;
session
.try_ensure_rollout_materialized(PersistContext::Standard)
.await?;
session.flush_rollout().await?;
let live_thread = session.live_thread_for_persistence("guardian review fork")?;
let history = live_thread.load_history(/*include_archived*/ true).await?;