diff --git a/codex-rs/app-server/tests/common/mcp_process.rs b/codex-rs/app-server/tests/common/mcp_process.rs index ec3b0cb27c..66584f7dcb 100644 --- a/codex-rs/app-server/tests/common/mcp_process.rs +++ b/codex-rs/app-server/tests/common/mcp_process.rs @@ -484,10 +484,6 @@ impl McpProcess { method: &str, params: Option, ) -> anyhow::Result { - // Drop any stale notifications from previous requests so callers don't - // accidentally consume old events when waiting for the next response. - self.pending_notifications.clear(); - let request_id = self.next_request_id.fetch_add(1, Ordering::Relaxed); let message = JSONRPCMessage::Request(JSONRPCRequest { @@ -499,6 +495,14 @@ impl McpProcess { Ok(request_id) } + /// Clear any queued notifications. + /// + /// Tests can call this between turns when they want to guarantee that the + /// next read_* call sees only events from the new turn. + pub fn clear_pending_notifications(&mut self) { + self.pending_notifications.clear(); + } + pub async fn send_response( &mut self, id: RequestId, diff --git a/codex-rs/app-server/tests/suite/v2/turn_start.rs b/codex-rs/app-server/tests/suite/v2/turn_start.rs index cd35e31adc..03e721b807 100644 --- a/codex-rs/app-server/tests/suite/v2/turn_start.rs +++ b/codex-rs/app-server/tests/suite/v2/turn_start.rs @@ -553,6 +553,10 @@ async fn turn_start_updates_sandbox_and_cwd_between_turns_v2() -> Result<()> { ) .await??; + // Drop any leftover notifications from the first turn before we wait for + // events from the second turn. + mcp.clear_pending_notifications(); + // second turn with workspace-write and second_cwd, ensure exec begins in second_cwd let second_turn = mcp .send_turn_start_request(TurnStartParams {