mirror of
https://github.com/openai/codex.git
synced 2026-11-20 22:40:37 +00:00
## Why New client requests and automatic continuations can start more work while the app-server is draining. Shutdown also needs to account for requests still preparing or submitting work before they appear as running turns. ## What changed - Close a shared admission gate when shutdown begins, rejecting new turn work and thread lifecycle changes with the server-draining error. - Apply the gate to automatic turn starts, including queued work and goal continuations, and recheck serialized turn requests before execution. - Wait for admitted requests and running turns to finish, while preserving forced shutdown. Keep reads and `turn/interrupt` available during drain. ## Testing Add coverage for admission permit tracking, discarded queued requests, forced shutdown, and WebSocket drain behavior, including request rejection, interruption, and suppression of automatic continuations. GitOrigin-RevId: 1bc108aa00a427cfa41974fa9ec60754c2b968c2
26 lines
899 B
Rust
26 lines
899 B
Rust
use super::TurnAdmission;
|
|
use crate::error_code::INVALID_REQUEST_ERROR_CODE;
|
|
use codex_extension_api::TurnStartAdmission;
|
|
use pretty_assertions::assert_eq;
|
|
|
|
#[test]
|
|
fn drain_rejects_new_work_without_waiting_for_admitted_work() {
|
|
let admission = TurnAdmission::default();
|
|
let active = admission.subscribe_active();
|
|
let in_flight = admission.admit().expect("initial request admitted");
|
|
let automatic = admission
|
|
.admit_turn_start()
|
|
.expect("automatic start admitted");
|
|
admission.begin_drain();
|
|
assert_eq!(*active.borrow(), 2);
|
|
assert!(admission.admit_turn_start().is_none());
|
|
|
|
let error = admission.admit().err().expect("new request rejected");
|
|
assert_eq!(error.code, INVALID_REQUEST_ERROR_CODE);
|
|
assert_eq!(error.data, None);
|
|
drop(in_flight);
|
|
assert_eq!(*active.borrow(), 1);
|
|
drop(automatic);
|
|
assert_eq!(*active.borrow(), 0);
|
|
}
|