Connect app-server workspace discovery to model request routing (#46281)

## Why

Model requests need the selected workspace's routing constraints before sending content. A missing cached route cannot establish that a custom ChatGPT-auth destination is independent of the workspace.

## What changed

- Register the account processor as the workspace routing resolver for Responses HTTP, compaction, and WebSockets, enabling origin selection and routing headers while preserving API paths and rejecting routed HTTP redirects.
- Share concurrent discovery by auth generation, workspace, and backend configuration. Recover from discovery-time `401` responses while allowing token refreshes for the same auth owner.
- Require successful discovery before classifying custom destinations as independent, and require a new thread when a workspace-bound session's bootstrap origin changes.
- Refresh managed requirements using retained session configuration without fetching thread configuration again. Return typed routing errors without account or backend details.

## Testing

Extend coverage for discovery-time token refresh, retained provider definitions under managed requirements, and specific invalid-routing error categories.

GitOrigin-RevId: 090cda70daa91ee8acfbc973699d028111e54125
This commit is contained in:
acrognale-oai authored and copyberry committed 2026-09-17 19:12:42 +00:00
1 parent d7f8e48d7d
commit 0a5b999169
21 files changed
+505 -200

No files matched your search

@@ -13,7 +13,7 @@ use crate::AuthManager;
use crate::CodexAuth;
/// A successful discovery for one selected workspace.
#[derive(Clone, Debug)]
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct WorkspaceRouting {
pub chatgpt_account_id: String,
pub backend_origin: String,
@@ -44,7 +44,8 @@ pub struct WorkspaceRoutingRequest {
/// Resolves routing through the account owner's cache and requirements loader.
/// Returns no routing for independent destinations or no selected workspace.
/// Destination scope is decided here, before making a discovery request.
/// Custom ChatGPT-auth destinations require successful discovery before independence
/// can be established; a cache miss is not evidence of an independent destination.
/// Implementations must reject failed discovery and changes to the selected account.
pub trait WorkspaceRoutingResolver: Send + Sync {
fn resolve(
@@ -68,13 +69,15 @@ impl AuthManager {
let Some(resolver) = self.workspace_routing_resolver.get() else {
return Ok(None);
};
let auth_changes = self.auth_change_receiver();
let revision = *auth_changes.borrow();
let auth_changes = self.auth_change_state_receiver();
let owner_generation = auth_changes.borrow().owner_generation;
let resolver = resolver
.upgrade()
.ok_or_else(|| io::Error::other("workspace routing owner is unavailable"))?;
let routing = resolver.resolve(request).await?;
if *auth_changes.borrow() != revision
// Discovery may recover expired credentials for the same owner. Model
// client setup rebuilds routing and credentials after that revision change.
if auth_changes.borrow().owner_generation != owner_generation
|| routing.as_ref().is_some_and(|routing| {
auth.get_account_id().as_deref() != Some(routing.chatgpt_account_id.as_str())
})