mirror of
https://github.com/openai/codex.git
synced 2026-11-26 23:28:11 +00:00
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:
1 parent
f8821d85eb
commit
722784e936
24 files changed
+289
-75
No files matched your search
@@ -15,6 +15,7 @@ use crate::AppendThreadItemsParams;
|
||||
use crate::CreateThreadParams;
|
||||
use crate::LoadThreadHistoryParams;
|
||||
use crate::LocalThreadStore;
|
||||
use crate::PersistContext;
|
||||
use crate::ReadThreadParams;
|
||||
use crate::ResumeThreadParams;
|
||||
use crate::StoredThread;
|
||||
@@ -253,8 +254,14 @@ impl LiveThread {
|
||||
Ok(items)
|
||||
}
|
||||
|
||||
pub async fn persist(&self) -> ThreadStoreResult<()> {
|
||||
self.thread_store.persist_thread(self.thread_id).await?;
|
||||
pub async fn persist(&self, context: PersistContext) -> ThreadStoreResult<()> {
|
||||
if context == PersistContext::TurnStart {
|
||||
self.flush_pending_metadata_update_for_existing_history()
|
||||
.await?;
|
||||
}
|
||||
self.thread_store
|
||||
.persist_thread(self.thread_id, context)
|
||||
.await?;
|
||||
self.flush_pending_metadata_update().await
|
||||
}
|
||||
|
||||
@@ -265,9 +272,19 @@ impl LiveThread {
|
||||
}
|
||||
|
||||
pub async fn shutdown(&self) -> ThreadStoreResult<()> {
|
||||
self.flush_pending_metadata_update_for_existing_history()
|
||||
.await?;
|
||||
self.thread_store.shutdown_thread(self.thread_id).await
|
||||
let metadata_result = self
|
||||
.flush_pending_metadata_update_for_existing_history()
|
||||
.await;
|
||||
let shutdown_result = self.thread_store.shutdown_thread(self.thread_id).await;
|
||||
match (metadata_result, shutdown_result) {
|
||||
(Err(metadata_error), Err(shutdown_error)) => Err(ThreadStoreError::Internal {
|
||||
message: format!(
|
||||
"thread metadata update failed: {metadata_error}; thread shutdown failed: {shutdown_error}"
|
||||
),
|
||||
}),
|
||||
(Err(metadata_error), Ok(())) => Err(metadata_error),
|
||||
(Ok(()), result) => result,
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn discard(&self) -> ThreadStoreResult<()> {
|
||||
|
||||
Reference in new issue
Block a user