Skip to content

refactor: load agent identity runtime eagerly#19763

Merged
efrazer-oai merged 1 commit into
mainfrom
dev/efrazer/agent-identity-eager-runtime
Apr 28, 2026
Merged

refactor: load agent identity runtime eagerly#19763
efrazer-oai merged 1 commit into
mainfrom
dev/efrazer/agent-identity-eager-runtime

Conversation

@efrazer-oai

@efrazer-oai efrazer-oai commented Apr 27, 2026

Copy link
Copy Markdown
Contributor

Summary

AgentIdentity auth previously registered the process task lazily behind a OnceCell. That meant the auth object could be constructed before its runtime task binding was known.

This PR makes AgentIdentity auth load the runtime task at auth load time and stores the resulting process task id directly on the auth object. The model-provider call path can then read a concrete task id instead of handling a missing lazy value.

Stack

  1. refactor: make auth loading async (merged)
  2. This PR: refactor: load AgentIdentity runtime eagerly
  3. fix: configure AgentIdentity AuthAPI base URL
  4. feat: verify AgentIdentity JWTs with JWKS

Important call sites

Area Change
AgentIdentityAuth::load Registers the process task during auth loading and stores process_task_id.
CodexAuth::from_agent_identity_jwt Awaits AgentIdentity auth loading.
model-provider auth Reads a concrete process_task_id instead of an optional lazy value.
AgentIdentity auth tests Mock task registration now covers eager runtime allocation.

Design decisions

AgentIdentity auth now treats task registration as part of constructing a usable auth object. That matches how callers use the value: once auth is present, the model-provider path expects the task-scoped assertion data to be ready.

Testing

Tests: targeted Rust auth test compilation, formatter, scoped Clippy fix, and Bazel lock check.

@efrazer-oai

Copy link
Copy Markdown
Contributor Author

@codex review

@efrazer-oai efrazer-oai force-pushed the dev/efrazer/agent-identity-auth-async branch from e251d8b to a20884a Compare April 27, 2026 04:52
@efrazer-oai efrazer-oai force-pushed the dev/efrazer/agent-identity-eager-runtime branch 2 times, most recently from ee7d9b3 to d69ac63 Compare April 27, 2026 04:55

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

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.

💡 Codex Review

.ok()
.flatten()

P1 Badge Preserve cached auth when reload cannot re-register task

load_auth_from_storage maps any auth-load error to None. Because AgentIdentity loading now makes a network registration call, a transient registration outage during reload() becomes None and set_cached_auth replaces a valid cached auth with logged-out state. This can deauthenticate active sessions on temporary backend blips.

ℹ️ 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/login/src/auth/manager.rs
Comment on lines +249 to +251
pub async fn from_agent_identity_jwt(jwt: &str) -> std::io::Result<Self> {
let record = AgentIdentityAuthRecord::from_agent_identity_jwt(jwt)?;
Ok(Self::AgentIdentity(AgentIdentityAuth::new(record)))
Ok(Self::AgentIdentity(AgentIdentityAuth::load(record).await?))

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.

P2 Badge Keep from_auth_storage local for AgentIdentity

from_agent_identity_jwt now awaits AgentIdentityAuth::load, which always performs register_agent_task. As a result, CodexAuth::from_auth_storage (used by local status/read paths) now depends on network availability and can fail/timeout even when callers only need to inspect stored auth state. This regresses offline behavior and adds avoidable startup latency.

Useful? React with 👍 / 👎.

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.

We shouldn't be able to start up Codex Agent Identity without network access, this is fine.

@efrazer-oai efrazer-oai force-pushed the dev/efrazer/agent-identity-eager-runtime branch 2 times, most recently from 64a404b to c21a966 Compare April 27, 2026 05:09
efrazer-oai added a commit that referenced this pull request Apr 27, 2026
## Summary

Auth loading used to expose synchronous construction helpers in several
places even though some auth sources now need async work. This PR makes
the auth-loading surface async and updates the callers to await it.

This is intentionally only plumbing. It does not change how
AgentIdentity tokens are decoded, how task runtime ids are allocated, or
how JWT signatures are verified.

## Stack

1. **This PR:** [refactor: make auth loading
async](#19762)
2. [refactor: load AgentIdentity runtime
eagerly](#19763)
3. [feat: verify AgentIdentity JWTs with
JWKS](#19764)

## Important call sites

| Area | Change |
| --- | --- |
| `codex-login` auth loading | `CodexAuth` and `AuthManager`
construction paths now await auth loading. |
| app-server startup | Auth manager construction is awaited during
initialization. |
| CLI/TUI/exec/MCP/chatgpt callers | Existing auth-loading calls now
await the same behavior. |
| cloud requirements storage loader | The loader becomes async so it can
share the same auth construction path. |
| auth tests | Tests that load auth now run in async contexts. |

## Testing

Tests: targeted Rust auth test compilation, formatter, scoped Clippy
fix, and Bazel lock check.
Base automatically changed from dev/efrazer/agent-identity-auth-async to main April 27, 2026 18:00
@efrazer-oai efrazer-oai force-pushed the dev/efrazer/agent-identity-eager-runtime branch 2 times, most recently from dfb08d0 to 381d0dc Compare April 27, 2026 18:09
@efrazer-oai efrazer-oai force-pushed the dev/efrazer/agent-identity-eager-runtime branch from 381d0dc to 248b00b Compare April 27, 2026 20:01
@efrazer-oai efrazer-oai marked this pull request as ready for review April 27, 2026 20:56
@efrazer-oai efrazer-oai requested a review from a team as a code owner April 27, 2026 20:56
@shijie-oai

Copy link
Copy Markdown
Collaborator

noice - I can rebase my cloud requirement PR onto this one.

@efrazer-oai efrazer-oai merged commit c08177f into main Apr 28, 2026
25 checks passed
@efrazer-oai efrazer-oai deleted the dev/efrazer/agent-identity-eager-runtime branch April 28, 2026 04:09
@github-actions github-actions Bot locked and limited conversation to collaborators Apr 28, 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