Apply workspace routing to Guardian v2 classifier requests (#47162)

## Why

Classifier requests need to preserve their owning thread's workspace routing and account binding, including when reusing pooled connections or retrying after authentication changes.

## What changed

- Share the thread's `WorkspaceRoutingContext` with Guardian v2 and resolve routing before leasing HTTP or pooled WebSocket connections.
- Reuse WebSockets only when their connection key and authentication state still match. Cache HTTP transports by URL and redirect policy, rejecting redirects when routing requires it.
- Stop classification requests and retries when the account owner changes while allowing token refreshes for the same user and workspace.

## Testing

Add regression coverage for routing failures with prewarmed sockets, shared thread routing state, account switches during HTTP and WebSocket requests, same-account token refreshes, and HTTP redirect-policy cache changes.

GitOrigin-RevId: 7b3efcadb4797b6a2de2e28e7506b297b0728d69
This commit is contained in:
acrognale-oai
2026-09-22 02:33:29 +00:00
committed by copyberry
parent b23324986d
commit 30daed37ad
11 changed files with 575 additions and 24 deletions
@@ -13,11 +13,11 @@ pub const ACCOUNT_ROUTING_HEADER: &str = "x-openai-account-routing-override";
/// Routing scope for one session's provider. Once routed, it cannot become
/// independent merely because the account owner's bootstrap configuration changes.
/// Lookups and the first successful routing transition are serialized per session.
#[derive(Debug)]
/// Clones serialize discovery and share the first successful routing transition.
#[derive(Clone, Debug)]
pub struct WorkspaceRoutingContext {
pub(crate) chatgpt_base_url: String,
pub(crate) previously_routed: Mutex<bool>,
pub(crate) previously_routed: Arc<Mutex<bool>>,
pub(crate) session: Option<Arc<WorkspaceRoutingSession>>,
}
@@ -25,7 +25,7 @@ impl WorkspaceRoutingContext {
pub fn new(chatgpt_base_url: String) -> Self {
Self {
chatgpt_base_url,
previously_routed: Mutex::new(/*t*/ false),
previously_routed: Arc::new(Mutex::new(/*t*/ false)),
session: None,
}
}
@@ -67,7 +67,8 @@ async fn concurrent_discovery_cannot_forget_established_routing() {
Some(auth),
);
let mut first = provider.responses_api_provider(&context);
let mut second = provider.responses_api_provider(&context);
let classifier_context = context.clone();
let mut second = provider.responses_api_provider(&classifier_context);
let early_second = std::future::poll_fn(|cx| {
assert!(first.as_mut().poll(cx).is_pending());
std::task::Poll::Ready(second.as_mut().poll(cx))