[codex] Use background agent task auth for backend calls#18094
[codex] Use background agent task auth for backend calls#18094adrian-openai merged 4 commits intomainfrom
Conversation
| config: &McpConfig, | ||
| ) -> HashMap<String, McpServerConfig> { | ||
| with_codex_apps_mcp_with_authorization_header( | ||
| servers, auth, config, /*authorization_header_value*/ None, |
There was a problem hiding this comment.
it is on purpose to be none atm?
There was a problem hiding this comment.
Yes, this is intentional. with_codex_apps_mcp is the legacy/default wrapper. Passing None means “no explicit authorization header override,” and then the helper falls back to the old bearer-token behavior.
The new AgentAssertion-aware path is with_codex_apps_mcp_with_authorization_header(...), where callers pass the background authorization header after applying the feature gate. I also checked workspace call sites: the old with_codex_apps_mcp(...) wrapper is basically just the compatibility/default path plus tests; the product paths that need background auth are using the new _with_authorization_header form.
shijie-oai
left a comment
There was a problem hiding this comment.
Overall it is fine but I wonder do non inference related request need to enforce task_id check? Or we are enforcing it for all requests to chatgpt? Just want to understand better cause we are covering a lot of items here.
| const AGENT_IDENTITY_BISCUIT_TIMEOUT: Duration = Duration::from_secs(15); | ||
|
|
||
| #[derive(Clone)] | ||
| pub struct BackgroundAgentTaskManager { |
There was a problem hiding this comment.
Funky idea: (probably not great and break existing paradigm) why can we not just get a generic task id back when an agent identity is created for doing work outside of inferencing?
There was a problem hiding this comment.
Discussed offline - best solution is to eventually move to a scope-based, inference can only be called with a task, and control plane calls can be made just by the agent identity itself, but until then, background task it is!
| #[serde(default, skip_serializing_if = "Option::is_none")] | ||
| pub background_task_id: Option<String>, |
There was a problem hiding this comment.
This looks longer living than a task id for a session?
There was a problem hiding this comment.
Yep! This is the background/control-plane task id for calls that do not naturally belong to a live Codex thread: models manager, cloud tasks, connectors, MCP app setup, etc. It is stored in auth.json alongside the persisted agent identity so those background calls can use AgentAssertion auth without needing a session rollout item.
c72faed to
68a45b4
Compare
40b89e8 to
42f625d
Compare
68a45b4 to
c6d377f
Compare
a722d39 to
72acf86
Compare
2d2fd76 to
044222d
Compare
72acf86 to
797959a
Compare
## Summary This is the AgentAssertion downstream slice for feature-gated agent identity support, replacing the oversized AgentAssertion slice from PR #17807. It isolates task-scoped downstream AgentAssertion wiring on top of the merged PR3.1 work without re-carrying the earlier agent registration, task registration, or task-state history. This PR includes the task-scoped bug-fix call sites from the review: generic file upload auth, MCP OpenAI file upload auth, and ARC monitor auth. Broader user/control-plane calls move to PR4.1 and PR4.2. ## Stack - PR1: #17385 - add `features.use_agent_identity` - PR2: #17386 - register agent identities when enabled - PR3: #17387 - register agent tasks when enabled - PR3.1: #17978 - persist and prewarm registered tasks per thread - PR4: this PR - use task-scoped `AgentAssertion` downstream when enabled - PR4.1: #18094 - introduce AuthManager-owned background/control-plane `AgentAssertion` auth - PR4.2: #18260 - use background task auth for additional backend/control-plane calls ## What Changed - add AgentAssertion envelope generation in `codex-core` - route downstream HTTP and websocket auth through AgentAssertion when an agent task is present - extend the model-provider auth provider so non-bearer authorization schemes can be passed through cleanly - make generic file uploads attach the full authorization header value - make MCP OpenAI file uploads use the cached thread agent task assertion when present - make ARC monitor calls use the cached thread agent task assertion when present ## Why The original PR had drifted ancestry and showed a much larger diff than the semantic change actually required. Restacking it onto PR3.1 keeps the reviewable surface down to the downstream assertion slice. ## 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-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` - `cargo test -p codex-login agent_identity` - `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`
797959a to
44c3502
Compare
Summary
Introduces a single background/control-plane agent task for ChatGPT backend requests that do not have a thread-scoped task, with
AuthManagerowning the default ChatGPT backend authorization decision.Callers now ask
AuthManagerfor the default ChatGPT backend authorization header.AuthManagerdecides whether that is bearer or background AgentAssertion based on config/internal state, while low-level bootstrap paths can explicitly request bearer-only auth.This PR is stacked on PR4 and focuses on the shared background task auth plumbing plus the first tranche of backend/control-plane consumers. The remaining callsite wiring is split into PR4.2 to keep review size down.
Stack
features.use_agent_identityAgentAssertionfor downstream callsAgentAssertionauthWhat Changed
codex-loginagent_identity.background_task_idseparately from per-session task stateBackgroundAgentTaskManagerprivate tocodex-login; call sites do not instantiate or pass it aroundAuthManagerthe ChatGPT backend base URL and feature-derived background auth mode from resolved configAuthManagerdefault ChatGPT authorization through app listing, connector directory listing, remote plugins, MCP status/listing, analytics, and core-skills remote callsValidation
just fmtcargo 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-skillscargo test -p codex-login agent_identitycargo test -p codex-model-provider bearer_auth_providercargo test -p codex-core agent_assertioncargo test -p codex-app-server remote_controlcargo test -p codex-cloud-requirements fetch_cloud_requirementscargo test -p codex-models-manager manager::testscargo test -p codex-chatgptcargo test -p codex-cloud-tasksjust 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-skillsjust fix -p codex-app-servergit diff --check