openai/codex · error · anyhow::Error
MCP client recovery semaphore closed
Error message
MCP client recovery semaphore closed
What it means
Sentinel guard in reinitialize_after_session_expiry: acquiring the session_recovery_lock semaphore failed because the semaphore was closed, so session recovery cannot proceed. Indicates the client is being torn down concurrently with a 404 session-expired recovery attempt.
Solutions
- Retry the request on a fresh client once shutdown completes
- Avoid issuing requests while the client is being shut down
Defensive patterns
Strategy: retry
When it happens
Trigger: Thrown at codex-rs/rmcp-client/src/rmcp_client.rs:1430 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of openai/codex@339751715c (2026-08-25).
Data as JSON: /api/errors/7f6faf6a71aa82b4.
Report an issue: GitHub.
Appendix: source
Thrown at codex-rs/rmcp-client/src/rmcp_client.rs:1430
.is_some_and(|error| {
matches!(
error,
StreamableHttpError::Client(
StreamableHttpClientAdapterError::SessionExpired404
)
)
})
}
async fn reinitialize_after_session_expiry(
&self,
failed_service: &Arc<RunningService<RoleClient, ElicitationClientService>>,
) -> Result<()> {
let _recovery_guard = self
.session_recovery_lock
.acquire()
.await
.map_err(|_| anyhow!("MCP client recovery semaphore closed"))?;
{
let guard = self.state.lock().await;
match &*guard {
ClientState::Ready { service, .. } if !Arc::ptr_eq(service, failed_service) => {
return Ok(());
}
ClientState::Ready { .. } => {}
ClientState::Connecting { .. } => {
return Err(anyhow!("MCP client not initialized"));
}
ClientState::Closed => {
return Err(anyhow!("MCP client is shut down"));
}
}
}
let initialize_context = selfView on GitHub (pinned to 339751715c)