[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:
Tom authored and GitHub committed 2026-06-25 21:01:11 -07:00
1 parent 25f50de6ed
commit f5f812389e
2 files changed
+168 -3

No files matched your search

+12 -3
View File
@@ -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}");
}
}
}