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
2026-08-11 03:35:45 +00:00
committed by copyberry
parent f8821d85eb
commit 722784e936
24 changed files with 289 additions and 75 deletions
+5 -1
View File
@@ -1,5 +1,6 @@
use super::*;
use codex_protocol::error::CodexErrorDetails;
use codex_thread_store::PersistContext;
impl AgentControl {
/// Submit a shutdown request for a live agent without marking it explicitly closed in
@@ -7,7 +8,10 @@ impl AgentControl {
pub(crate) async fn shutdown_live_agent(&self, agent_id: ThreadId) -> CodexResult<String> {
let state = self.upgrade()?;
let result = if let Ok(thread) = state.get_thread(agent_id).await {
thread.session.ensure_rollout_materialized().await;
thread
.session
.ensure_rollout_materialized(PersistContext::Standard)
.await;
thread.session.flush_rollout().await?;
let result = if matches!(thread.agent_status().await, AgentStatus::Shutdown) {
Ok(String::new())