Skip to content

Register agent tasks behind use_agent_identity#17387

Merged
adrian-openai merged 18 commits intomainfrom
dev/adrian/codex/agent-identity-register-task
Apr 16, 2026
Merged

Register agent tasks behind use_agent_identity#17387
adrian-openai merged 18 commits intomainfrom
dev/adrian/codex/agent-identity-register-task

Conversation

@adrian-openai
Copy link
Copy Markdown
Contributor

@adrian-openai adrian-openai commented Apr 10, 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

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.

Copy link
Copy Markdown
Contributor

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 5f089f4a53

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread codex-rs/core/src/codex.rs Outdated
Comment on lines +1534 to +1540
if let Some(agent_task) = state.agent_task() {
debug!(
agent_runtime_id = %agent_task.agent_runtime_id,
task_id = %agent_task.task_id,
"reusing cached agent task"
);
return Ok(Some(agent_task));
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P1 Badge Revalidate cached agent task against current auth binding

ensure_agent_task_registered returns a cached agent_task without checking whether auth/workspace binding changed. After re-auth or workspace switch, turns can keep using a task minted for the old binding because register_task() (the only path that recomputes current_binding) is skipped. This can cause authorization failures or cross-account credential reuse.

Useful? React with 👍 / 👎.

@adrian-openai adrian-openai force-pushed the dev/adrian/codex/agent-identity-register-agent branch from cd2ed35 to 7587c88 Compare April 10, 2026 23:49
@adrian-openai adrian-openai force-pushed the dev/adrian/codex/agent-identity-register-task branch from 5f089f4 to f530190 Compare April 10, 2026 23:53
@adrian-openai adrian-openai force-pushed the dev/adrian/codex/agent-identity-register-agent branch from 7587c88 to 0913111 Compare April 11, 2026 00:17
@adrian-openai adrian-openai force-pushed the dev/adrian/codex/agent-identity-register-task branch 2 times, most recently from b6ea8a1 to fd5337b Compare April 11, 2026 00:34
@adrian-openai adrian-openai force-pushed the dev/adrian/codex/agent-identity-register-agent branch from 6687bb9 to fb82a31 Compare April 11, 2026 01:02
@adrian-openai adrian-openai force-pushed the dev/adrian/codex/agent-identity-register-task branch from d25b68d to 321c151 Compare April 11, 2026 01:02
@adrian-openai adrian-openai force-pushed the dev/adrian/codex/agent-identity-register-agent branch from fb82a31 to bbeb95e Compare April 11, 2026 01:17
@adrian-openai adrian-openai force-pushed the dev/adrian/codex/agent-identity-register-task branch from 321c151 to 56cda90 Compare April 11, 2026 01:17
@adrian-openai adrian-openai force-pushed the dev/adrian/codex/agent-identity-register-agent branch from bbeb95e to 5735241 Compare April 11, 2026 06:43
@adrian-openai adrian-openai force-pushed the dev/adrian/codex/agent-identity-register-task branch 2 times, most recently from 3cbb522 to c1c3c37 Compare April 11, 2026 16:53
@adrian-openai adrian-openai force-pushed the dev/adrian/codex/agent-identity-register-agent branch from 5735241 to 458a631 Compare April 11, 2026 16:53
@adrian-openai adrian-openai force-pushed the dev/adrian/codex/agent-identity-register-task branch 3 times, most recently from fa9d205 to c66f085 Compare April 13, 2026 22:05
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 don't think we need this auth_binding concept with our auth.json changes. Can do smth like below:

match auth { CodexAuth::ChatgptAuthTokens(tokens) => { if let Some(agent_identity) = tokens.registered_agent_identity() { // preregistered path register_task_with_agent_identity(agent_identity).await } else if let Some(access_token) = tokens.authorization_bearer_token() { // human bootstrap path bootstrap_and_register_task(access_token, tokens.workspace_id()).await } else { Ok(None) } } _ => Ok(None), }

We shouldn't exist in a state where the agent workspace_id doesn't match up with the user workspace_id

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.

Session lifecycle

In the status quo, we fully persist session details on disk. With this change, we're creating an ephemeral 'task' in memory associated with a session. This is a bit off for a few reasons I think:

  1. It means if we turn off codex and start working on the same session later, it shows up as two different 'tasks' which seems like undesirable backend state.
  2. It means we add latency to every initial turn in order to make this HTTP call to create the task (idt it'd be too severe, but latency is a huge focus and we try to make most interactions go through websockets; if we can avoid i would).
  3. There are some API calls we make that are not session scoped, and some that are session scoped but aren't in the path where we create agent_task. If we're in a regime where there's no user token (i.e. programmatic codex), i believe these will just fail -- would need to make it robust to those.

I wonder if there's a cleaner implementation that loses some fidelity but just creates it on start?

Or if we can pass the session id itself as the task id?

@efrazer-oai
Copy link
Copy Markdown
Contributor

@codex review

@chatgpt-codex-connector
Copy link
Copy Markdown
Contributor

Codex Review: Didn't find any major issues. Keep them coming!

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@adrian-openai adrian-openai force-pushed the dev/adrian/codex/agent-identity-register-task branch 2 times, most recently from 1176180 to e0cef11 Compare April 15, 2026 01:48
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.

Approved to unblock, make sure to smoke test the path where there's no logged in chat user token locally! (i.e. programmatic agent identity)

@adrian-openai adrian-openai force-pushed the dev/adrian/codex/agent-identity-register-task branch from b65f7d4 to dfc5e05 Compare April 16, 2026 18:11
@adrian-openai adrian-openai merged commit 55c3de7 into main Apr 16, 2026
28 checks passed
@adrian-openai adrian-openai deleted the dev/adrian/codex/agent-identity-register-task branch April 16, 2026 21:30
@github-actions github-actions Bot locked and limited conversation to collaborators Apr 16, 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.

3 participants