mirror of
https://github.com/openai/codex.git
synced 2026-11-25 23:30:49 +00:00
## Summary Splits the larger PR4.1 background task auth rollout by moving additional backend/control-plane call sites into this downstream PR. This PR keeps callers on the same design as PR4.1: most code asks `AuthManager` for the default ChatGPT backend authorization header, and `AuthManager` decides bearer vs background AgentAssertion internally. Task-pinned inference auth remains separate because it needs the thread's registered task id. ## Stack - PR1: https://github.com/openai/codex/pull/17385 - add `features.use_agent_identity` - PR2: https://github.com/openai/codex/pull/17386 - register agent identities when enabled - PR3: https://github.com/openai/codex/pull/17387 - register agent tasks when enabled - PR3.1: https://github.com/openai/codex/pull/17978 - persist and prewarm registered tasks per thread - PR4: https://github.com/openai/codex/pull/17980 - use task-scoped `AgentAssertion` for downstream calls - PR4.1: https://github.com/openai/codex/pull/18094 - introduce AuthManager-owned background/control-plane `AgentAssertion` auth - PR4.2: this PR - use background task auth for additional backend/control-plane calls ## What Changed - pass full authorization header values through backend-client and cloud-tasks-client call paths where needed - move ChatGPT client, cloud requirements, cloud tasks, thread-manager, and models-manager background auth usage into this downstream slice - make app-server remote control enrollment/websocket auth ask `AuthManager` for the local backend authorization header instead of threading a background auth mode through transport options - keep the same feature-gated bearer fallback behavior from PR4.1 ## Validation - `just fmt` - `cargo check -p codex-core -p codex-login -p codex-analytics -p codex-app-server -p codex-cloud-requirements -p codex-cloud-tasks -p codex-models-manager -p codex-chatgpt -p codex-model-provider -p codex-mcp -p codex-core-skills` - `cargo test -p codex-login agent_identity` - `cargo test -p codex-model-provider bearer_auth_provider` - `cargo test -p codex-core agent_assertion` - `cargo test -p codex-app-server remote_control` - `cargo test -p codex-cloud-requirements fetch_cloud_requirements` - `cargo test -p codex-models-manager manager::tests` - `cargo test -p codex-chatgpt` - `cargo test -p codex-cloud-tasks` - `just fix -p codex-core -p codex-login -p codex-analytics -p codex-app-server -p codex-cloud-requirements -p codex-cloud-tasks -p codex-models-manager -p codex-chatgpt -p codex-model-provider -p codex-mcp -p codex-core-skills` - `just fix -p codex-app-server` - `git diff --check`
122 lines
3.4 KiB
Rust
122 lines
3.4 KiB
Rust
mod client_tracker;
|
|
mod enroll;
|
|
mod protocol;
|
|
mod websocket;
|
|
|
|
use crate::transport::remote_control::websocket::RemoteControlWebsocket;
|
|
use crate::transport::remote_control::websocket::RemoteControlWebsocketOptions;
|
|
|
|
pub use self::protocol::ClientId;
|
|
use self::protocol::ServerEvent;
|
|
use self::protocol::StreamId;
|
|
use self::protocol::normalize_remote_control_url;
|
|
use super::CHANNEL_CAPACITY;
|
|
use super::TransportEvent;
|
|
use super::next_connection_id;
|
|
use codex_login::AuthManager;
|
|
use codex_state::StateRuntime;
|
|
use std::io;
|
|
use std::sync::Arc;
|
|
use tokio::sync::mpsc;
|
|
use tokio::sync::oneshot;
|
|
use tokio::sync::watch;
|
|
use tokio::task::JoinHandle;
|
|
use tokio_util::sync::CancellationToken;
|
|
|
|
pub(super) struct QueuedServerEnvelope {
|
|
pub(super) event: ServerEvent,
|
|
pub(super) client_id: ClientId,
|
|
pub(super) stream_id: StreamId,
|
|
pub(super) write_complete_tx: Option<oneshot::Sender<()>>,
|
|
}
|
|
|
|
#[derive(Clone)]
|
|
pub(crate) struct RemoteControlHandle {
|
|
enabled_tx: Arc<watch::Sender<bool>>,
|
|
}
|
|
|
|
impl RemoteControlHandle {
|
|
pub(crate) fn set_enabled(&self, enabled: bool) {
|
|
self.enabled_tx.send_if_modified(|state| {
|
|
let changed = *state != enabled;
|
|
*state = enabled;
|
|
changed
|
|
});
|
|
}
|
|
}
|
|
|
|
pub(crate) struct RemoteControlStartOptions {
|
|
pub(crate) remote_control_url: String,
|
|
pub(crate) state_db: Option<Arc<StateRuntime>>,
|
|
pub(crate) auth_manager: Arc<AuthManager>,
|
|
pub(crate) transport_event_tx: mpsc::Sender<TransportEvent>,
|
|
pub(crate) shutdown_token: CancellationToken,
|
|
pub(crate) app_server_client_name_rx: Option<oneshot::Receiver<String>>,
|
|
pub(crate) initial_enabled: bool,
|
|
}
|
|
|
|
#[cfg(test)]
|
|
pub(crate) async fn start_remote_control(
|
|
remote_control_url: String,
|
|
state_db: Option<Arc<StateRuntime>>,
|
|
auth_manager: Arc<AuthManager>,
|
|
transport_event_tx: mpsc::Sender<TransportEvent>,
|
|
shutdown_token: CancellationToken,
|
|
app_server_client_name_rx: Option<oneshot::Receiver<String>>,
|
|
initial_enabled: bool,
|
|
) -> io::Result<(JoinHandle<()>, RemoteControlHandle)> {
|
|
start_remote_control_with_options(RemoteControlStartOptions {
|
|
remote_control_url,
|
|
state_db,
|
|
auth_manager,
|
|
transport_event_tx,
|
|
shutdown_token,
|
|
app_server_client_name_rx,
|
|
initial_enabled,
|
|
})
|
|
.await
|
|
}
|
|
|
|
pub(crate) async fn start_remote_control_with_options(
|
|
options: RemoteControlStartOptions,
|
|
) -> io::Result<(JoinHandle<()>, RemoteControlHandle)> {
|
|
let RemoteControlStartOptions {
|
|
remote_control_url,
|
|
state_db,
|
|
auth_manager,
|
|
transport_event_tx,
|
|
shutdown_token,
|
|
app_server_client_name_rx,
|
|
initial_enabled,
|
|
} = options;
|
|
let remote_control_target = if initial_enabled {
|
|
Some(normalize_remote_control_url(&remote_control_url)?)
|
|
} else {
|
|
None
|
|
};
|
|
let (enabled_tx, enabled_rx) = watch::channel(initial_enabled);
|
|
let join_handle = tokio::spawn(async move {
|
|
RemoteControlWebsocket::from_options(RemoteControlWebsocketOptions {
|
|
remote_control_url,
|
|
remote_control_target,
|
|
state_db,
|
|
auth_manager,
|
|
transport_event_tx,
|
|
shutdown_token,
|
|
enabled_rx,
|
|
})
|
|
.run(app_server_client_name_rx)
|
|
.await;
|
|
});
|
|
|
|
Ok((
|
|
join_handle,
|
|
RemoteControlHandle {
|
|
enabled_tx: Arc::new(enabled_tx),
|
|
},
|
|
))
|
|
}
|
|
|
|
#[cfg(test)]
|
|
mod tests;
|