mirror of
https://github.com/openai/codex.git
synced 2026-11-27 23:31:09 +00:00
Keep app-server thread RPCs active until delegated work completes (#43950)
## Why Thread startup, running-thread resume, and rollback could outlive their request handlers, allowing connection draining and request serialization to finish too early. ## What changed - Await thread startup and listener completion for running-thread resume and rollback. - Release the thread-list permit before waiting for resume completion so the listener can finish rollback responses. - Release pending rollback waiters when clearing a listener, and discard queued requests when their connection closes. ## Testing Add coverage for releasing queued requests and rollback waiters, and pipeline resume during rollback to check that both responses complete. Update diagnostics expectations to allow startup to remain in flight after its response is queued. GitOrigin-RevId: 138156179afbc40de29965820db7fa9cd3669cc7
This commit is contained in:
1 parent
589874be81
commit
102e1763b9
8 files changed
+134
-42
No files matched your search
@@ -57,7 +57,10 @@ pub(crate) struct PendingThreadResumeRequest {
|
||||
// ThreadListenerCommand is used to perform operations in the context of the thread listener, for serialization purposes.
|
||||
pub(crate) enum ThreadListenerCommand {
|
||||
// SendThreadResumeResponse is used to resume an already running thread by sending the thread's history to the client and atomically subscribing for new updates.
|
||||
SendThreadResumeResponse(Box<PendingThreadResumeRequest>),
|
||||
SendThreadResumeResponse {
|
||||
request: Box<PendingThreadResumeRequest>,
|
||||
completion_tx: oneshot::Sender<()>,
|
||||
},
|
||||
// EmitThreadGoalUpdated is used to order goal updates with running-thread resume responses and goal clears.
|
||||
EmitThreadGoalUpdated {
|
||||
turn_id: Option<String>,
|
||||
@@ -95,7 +98,7 @@ pub(crate) struct TurnSummary {
|
||||
#[derive(Default)]
|
||||
pub(crate) struct ThreadState {
|
||||
pub(crate) pending_interrupts: PendingInterruptQueue,
|
||||
pub(crate) pending_rollbacks: Option<ConnectionRequestId>,
|
||||
pub(crate) pending_rollbacks: Option<(ConnectionRequestId, oneshot::Sender<()>)>,
|
||||
pub(crate) turn_summary: TurnSummary,
|
||||
pub(crate) last_terminal_turn_id: Option<String>,
|
||||
/// Lets an internal runtime replacement wait until the old listener has processed Core's
|
||||
@@ -143,6 +146,7 @@ impl ThreadState {
|
||||
let _ = cancel_tx.send(());
|
||||
}
|
||||
self.shutdown_drain_waiter = None;
|
||||
self.pending_rollbacks = None;
|
||||
self.listener_command_tx = None;
|
||||
self.current_turn_history.reset();
|
||||
self.listener_thread = None;
|
||||
@@ -247,6 +251,28 @@ mod tests {
|
||||
use codex_utils_absolute_path::AbsolutePathBuf;
|
||||
use pretty_assertions::assert_eq;
|
||||
|
||||
#[test]
|
||||
fn clear_listener_releases_pending_rollback() {
|
||||
let (completion_tx, mut completion_rx) = oneshot::channel();
|
||||
let mut state = ThreadState {
|
||||
pending_rollbacks: Some((
|
||||
ConnectionRequestId {
|
||||
connection_id: ConnectionId(1),
|
||||
request_id: RequestId::Integer(1),
|
||||
},
|
||||
completion_tx,
|
||||
)),
|
||||
..Default::default()
|
||||
};
|
||||
|
||||
state.clear_listener();
|
||||
|
||||
assert_eq!(
|
||||
completion_rx.try_recv(),
|
||||
Err(oneshot::error::TryRecvError::Closed)
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn note_thread_settings_reports_only_effective_changes() {
|
||||
let mut state = ThreadState::default();
|
||||
|
||||
Reference in new issue
Block a user