Skip to content

[codex] Use AgentAssertion downstream behind use_agent_identity#17980

Merged
adrian-openai merged 4 commits intomainfrom
dev/adrian/codex/agent-identity-use-assertion-split
Apr 20, 2026
Merged

[codex] Use AgentAssertion downstream behind use_agent_identity#17980
adrian-openai merged 4 commits intomainfrom
dev/adrian/codex/agent-identity-use-assertion-split

Conversation

@adrian-openai
Copy link
Copy Markdown
Contributor

@adrian-openai adrian-openai commented Apr 15, 2026

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

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

Copy link
Copy Markdown
Contributor

@efrazer-oai efrazer-oai left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had Codex go find all the places that are still hardcoded to use Bearer as discussed on Slack, here are the results:

As it stands, we have successfully migrated the shared Responses HTTP, Responses websocket, compact, and ChatGPT-backend realtime-call paths.

But there are still several other backend surfaces that build Authorization: Bearer ... directly or go through helpers that only understand bearer tokens. Those still need to migrate if we want this change to be exhaustive.

Shared backend client paths that still need the new auth shape:

  • codex-rs/backend-client/src/client.rs
    • /wham/usage
    • /wham/tasks/list
    • /wham/tasks/{id}
    • /wham/tasks/{id}/turns/{turn_id}/sibling_turns
    • /wham/config/requirements
    • POST /wham/tasks

Current callers of that shared client include:

  • codex-rs/cloud-requirements/src/lib.rs
  • codex-rs/app-server/src/codex_message_processor.rs
  • codex-rs/cloud-tasks-client/src/http.rs

Direct backend callers that still attach bearer auth themselves:

  • codex-rs/codex-api/src/files.rs
    • /files
    • /files/{id}/uploaded
  • codex-rs/core/src/mcp_openai_file.rs
  • codex-rs/models-manager/src/manager.rs
    • /codex/models
  • codex-rs/codex-mcp/src/mcp/mod.rs
    • .../wham/apps
  • codex-rs/chatgpt/src/chatgpt_client.rs
    • shared GET helper used by:
      • codex-rs/chatgpt/src/get_task.rs
      • connector directory loading paths
  • codex-rs/core/src/connectors.rs
    • connector directory requests
  • codex-rs/core/src/plugins/remote.rs
    • /plugins/list
    • /plugins/featured
    • /plugins/{id}/enable
    • /plugins/{id}/uninstall
  • codex-rs/core-skills/src/remote.rs
    • /hazelnuts
    • /hazelnuts/{skill_id}/export
  • codex-rs/analytics/src/client.rs
    • /codex/analytics-events/events
  • codex-rs/core/src/arc_monitor.rs
    • /codex/safety/arc
  • codex-rs/app-server/src/transport/remote_control/enroll.rs
    • /wham/remote/control/server/enroll
  • codex-rs/app-server/src/transport/remote_control/websocket.rs
    • websocket handshake for /wham/remote/control/server
  • codex-rs/cloud-tasks/src/util.rs
  • codex-rs/cloud-tasks/src/env_detect.rs
    • /wham/environments
    • /wham/environments/by-repo/...

One backend hit I found that does not look like part of this auth migration is:

  • codex-rs/core/src/plugins/startup_sync.rs
    • backup archive fetch at /backend-api/plugins/export/curated

So the main point is: this PR fixes the shared model path, but it does not yet migrate all of the places where we talk to codex-backend.

@adrian-openai adrian-openai force-pushed the dev/adrian/codex/agent-identity-use-assertion-split branch from ed316a9 to d1373d4 Compare April 15, 2026 23:53
@adrian-openai adrian-openai changed the base branch from dev/adrian/codex/agent-identity-register-task to dev/adrian/codex/agent-task-state-prewarm April 15, 2026 23:53
@adrian-openai adrian-openai force-pushed the dev/adrian/codex/agent-identity-use-assertion-split branch 2 times, most recently from dfd9aa0 to 688aad3 Compare April 16, 2026 01:11
Copy link
Copy Markdown

@nicksteele-oai nicksteele-oai left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks clean to me

.map_err(|error| format!("failed to read ChatGPT auth for file upload: {error}"))?;
CoreAuthProvider::from_bearer_token(Some(token_data.access_token), token_data.account_id)
};
let uploaded = upload_local_file(
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will file upload with ChatGPT auth be affected if the above code block fails?

adrian-openai added a commit that referenced this pull request Apr 16, 2026
## Summary

Stack PR3 for feature-gated agent identity support.

This PR adds per-thread agent task registration behind
`features.use_agent_identity`. Tasks are minted on the first real user
turn and cached in thread runtime state for later turns.

## Stack

- PR1: #17385 - add
`features.use_agent_identity`
- PR2: #17386 - register agent
identities when enabled
- PR3: #17387 - this PR, original
task registration slice
- PR3.1: #17978 - persist and
prewarm registered tasks per thread
- PR4: #17980 - use `AgentAssertion`
downstream when enabled

## Validation

Covered as part of the local stack validation pass:

- `just fmt`
- `cargo test -p codex-core --lib agent_identity`
- `cargo test -p codex-core --lib agent_assertion`
- `cargo test -p codex-core --lib websocket_agent_task`
- `cargo test -p codex-api api_bridge`
- `cargo build -p codex-cli --bin codex`

## Notes

The full local app-server E2E path is still being debugged after PR
creation. The current branch stack is directionally ready for review
while that follow-up continues.
@adrian-openai adrian-openai force-pushed the dev/adrian/codex/agent-task-state-prewarm branch 2 times, most recently from ea5ec0a to 56f4b38 Compare April 17, 2026 03:35
@adrian-openai adrian-openai force-pushed the dev/adrian/codex/agent-task-state-prewarm branch 2 times, most recently from 3dcdb8d to 67cff31 Compare April 17, 2026 17:20
use tokio::time::timeout;

const DEFAULT_TIMEOUT: Duration = Duration::from_secs(10);
const DEFAULT_TIMEOUT: Duration = Duration::from_secs(20);
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hm maybe we should drop this? I assume it has to do with windows test flake?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes! The test is flaky locally as a result of the 10s.

Comment thread codex-rs/codex-api/src/files.rs Outdated
if let Some(token) = auth.bearer_token() {
request = request.bearer_auth(token);
if let Some(authorization) = auth.authorization_header_value() {
request = request.header(AUTHORIZATION, authorization);
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would enable us to use non bearer token (agent identity) for as the auth header vs bearer_auth is for bearer token only I assume.

Comment on lines 132 to 140
let shell_command = vec![
"powershell".to_string(),
"-Command".to_string(),
"Start-Sleep -Seconds 1".to_string(),
"cmd.exe".to_string(),
"/d".to_string(),
"/c".to_string(),
"ping".to_string(),
"-n".to_string(),
"2".to_string(),
"127.0.0.1".to_string(),
];
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No action: I think this is updated/different on latest main already.

Comment thread codex-rs/core/src/agent_identity/assertion.rs Outdated
pub struct ModelClientSession {
client: ModelClient,
websocket_session: WebsocketSession,
agent_task: Option<RegisteredAgentTask>,
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need this? agent_task is scoped to a session (thread) and here we are on the top level?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The field is in ModelClientSession,

  • The registered agent task is owned by the Codex thread/session state.
  • But each model turn needs to carry that task into all Responses requests made during that turn: HTTP stream, websocket prewarm, retries, continuation requests.
  • Putting it on ModelClient would be wrong because ModelClient is longer-lived and shared for the Codex session.
  • Passing it into every lower-level request method would be more error-prone.
  • Storing it on the per-turn ModelClientSession also lets the code avoid reusing a cached bearer-auth websocket when an AgentAssertion task is present.
    Let me know if you disagree with that ^

Comment on lines -112 to -117
let token_data = auth
.get_token_data()
.map_err(|error| format!("failed to read ChatGPT auth for file upload: {error}"))?;
let upload_auth = CoreAuthProvider {
token: Some(token_data.access_token),
account_id: token_data.account_id,
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did not realize that we have so many locally built headers....

Copy link
Copy Markdown
Collaborator

@shijie-oai shijie-oai left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense to me overall.

@adrian-openai adrian-openai force-pushed the dev/adrian/codex/agent-task-state-prewarm branch from e6f7ce3 to 0000662 Compare April 18, 2026 03:16
Base automatically changed from dev/adrian/codex/agent-task-state-prewarm to main April 19, 2026 22:45
@adrian-openai adrian-openai force-pushed the dev/adrian/codex/agent-identity-use-assertion-split branch 2 times, most recently from 68a45b4 to c6d377f Compare April 20, 2026 01:10
@adrian-openai adrian-openai force-pushed the dev/adrian/codex/agent-identity-use-assertion-split branch from 2d2fd76 to 044222d Compare April 20, 2026 05:17
@adrian-openai adrian-openai merged commit b44d285 into main Apr 20, 2026
34 of 36 checks passed
@adrian-openai adrian-openai deleted the dev/adrian/codex/agent-identity-use-assertion-split branch April 20, 2026 06:16
@github-actions github-actions Bot locked and limited conversation to collaborators Apr 20, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants