mirror of
https://github.com/openai/codex.git
synced 2026-11-09 08:40:33 +00:00
[codex] fix terminal rollout event durability (#30144)
Currently session code does not flush the thread store after appending the `TurnComplete` / `TurnAborted` events. This isn't a problem in practice for local storage because append_items itself effectively blocks, but any thread stores that buffer in append_items and only commit on flush effectively never get these events persisted. The fix adds explicit rollout flushes at the terminal emitters after normal completion and interruption. Added test cases that assert the number of flushes when completing or aborting turns. These are admittedly a little brittle and I'm open to better ideas on how to add automated testing.
This commit is contained in:
2 files changed
+168
-3
No files matched your search
@@ -793,10 +793,14 @@ impl Session {
|
||||
false
|
||||
}
|
||||
};
|
||||
if !cleared_active_turn {
|
||||
return;
|
||||
if cleared_active_turn {
|
||||
self.emit_thread_idle_lifecycle_if_idle().await;
|
||||
}
|
||||
// Regular items were flushed before this terminal event was appended; buffering
|
||||
// thread writers may not flush it without another explicit barrier.
|
||||
if let Err(err) = self.flush_rollout().await {
|
||||
warn!("failed to flush rollout after emitting terminal turn event: {err}");
|
||||
}
|
||||
self.emit_thread_idle_lifecycle_if_idle().await;
|
||||
}
|
||||
|
||||
async fn take_active_turn(&self) -> Option<ActiveTurn> {
|
||||
@@ -896,6 +900,11 @@ impl Session {
|
||||
.lock()
|
||||
.await
|
||||
.clear_turn(&task.turn_context.sub_id);
|
||||
// Regular items were flushed before this terminal event was appended; buffering
|
||||
// thread writers may not flush it without another explicit barrier.
|
||||
if let Err(err) = self.flush_rollout().await {
|
||||
warn!("failed to flush rollout after emitting terminal turn event: {err}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user