mirror of
https://github.com/openai/codex.git
synced 2026-11-15 21:50:46 +00:00
Add app-server support for reverting paginated threads (#38440)
## What changed - Add the experimental `thread/revert` request, which replaces a loaded paginated thread's durable history with the prefix before `beforeTurnId` while preserving the thread ID. - Interrupt any active turn, reload the replacement history without unloading the thread, preserve mutable thread settings, and emit `thread/reverted`. - Return backward pagination cursors for the retained turns and items, reject stale rollout paths after a revert, and document that local file changes are unaffected. ## Testing - Cover history replacement, pagination, stale paths, missing turns, subsequent turns, active-turn interruption, and preserved thread settings. GitOrigin-RevId: 435a8163ad4f310cc47219b436f6bdde21f2b83a
This commit is contained in:
@@ -1040,6 +1040,26 @@ impl ThreadManager {
|
||||
self.state.threads.write().await.remove(thread_id)
|
||||
}
|
||||
|
||||
/// Removes a thread only if `thread_id` still maps to `expected`.
|
||||
///
|
||||
/// Delayed cleanup uses this to avoid removing a replacement runtime registered under the
|
||||
/// same thread ID.
|
||||
pub async fn remove_thread_if_matches(
|
||||
&self,
|
||||
thread_id: &ThreadId,
|
||||
expected: &Arc<CodexThread>,
|
||||
) -> Option<Arc<CodexThread>> {
|
||||
let mut threads = self.state.threads.write().await;
|
||||
if threads
|
||||
.get(thread_id)
|
||||
.is_some_and(|thread| Arc::ptr_eq(thread, expected))
|
||||
{
|
||||
threads.remove(thread_id)
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
/// Tries to shut down all tracked threads concurrently within the provided timeout.
|
||||
/// Threads that complete shutdown are removed from the manager; incomplete shutdowns
|
||||
/// remain tracked so callers can retry or inspect them later.
|
||||
|
||||
Reference in New Issue
Block a user