Files
codex/codex-rs/app-server/src/turn_admission_tests.rs
Eric Traut 07757f448f Explain session creation failures during server shutdown (#52721)
## Why

Graceful shutdown rejects new sessions with an invalid-request error. Give clients a structured shutdown reason and show command center users why session creation is paused.

## What changed

- Add `data: {"reason":"serverShuttingDown"}` to app-server shutdown admission errors while retaining JSON-RPC code `-32600`.
- Show a dedicated shutdown message explaining the wait for active turns and automatic reconnection for non-embedded servers. Recognize older servers by their exact draining message only when error data is absent, and preserve retained-worktree cleanup guidance.
- Keep the command center reconnect presentation when a shutdown error covers the initial overview and no conversation is open.

## Testing

Extend admission and WebSocket shutdown assertions, add embedded and daemon shutdown message snapshots, and cover reconnection with a shutdown error over the initial command center.

GitOrigin-RevId: f167144c0ddc77872afdf3daac8bb1c89f3425b4
2026-10-09 23:16:46 +00:00

29 lines
976 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,
Some(serde_json::json!({ "reason": "serverShuttingDown" }))
);
drop(in_flight);
assert_eq!(*active.borrow(), 1);
drop(automatic);
assert_eq!(*active.borrow(), 0);
}