Commit Graph
11116 Commits
Author SHA1 Message Date
Michael Bolin 6ad436de9b core: support dynamic auth tokens for model providers 2026-03-31 01:26:22 -07:00
Michael Bolin 0071968829 auth: let AuthManager own external bearer auth (#16287)
## Summary

`AuthManager` and `UnauthorizedRecovery` already own token resolution
and staged `401` recovery. The missing piece for provider auth was a
bearer-only mode that still fit that design, instead of pushing a second
auth abstraction into `codex-core`.

This PR keeps the design centered on `AuthManager`: it teaches
`codex-login` how to own external bearer auth directly so later provider
work can keep calling `AuthManager.auth()` and `UnauthorizedRecovery`.

## Motivation

This is the middle layer for #15189.

The intended design is still:

- `AuthManager` encapsulates token storage and refresh
- `UnauthorizedRecovery` powers staged `401` recovery
- all request tokens go through `AuthManager.auth()`

This PR makes that possible for provider-backed bearer tokens by adding
a bearer-only auth mode inside `AuthManager` instead of building
parallel request-auth plumbing in `core`.

## What Changed

- move `ModelProviderAuthInfo` into `codex-protocol` so `core` and
`login` share one config shape
- add `login/src/auth/external_bearer.rs`, which runs the configured
command, caches the bearer token in memory, and refreshes it after `401`
- add `AuthManager::external_bearer_only(...)` for provider-scoped
request paths that should use command-backed bearer auth without
mutating the shared OpenAI auth manager
- add `AuthManager::shared_with_external_chatgpt_auth_refresher(...)`
and rename the other `AuthManager` helpers that only apply to external
ChatGPT auth so the ChatGPT-only path is explicit at the call site
- keep external ChatGPT refresh behavior unchanged while ensuring
bearer-only external auth never persists to `auth.json`

## Testing

- `cargo test -p codex-login`
- `cargo test -p codex-protocol`





---
[//]: # (BEGIN SAPLING FOOTER)
Stack created with [Sapling](https://sapling-scm.com). Best reviewed
with [ReviewStack](https://reviewstack.dev/openai/codex/pull/16287).
* #16288
* __->__ #16287
2026-03-31 01:26:17 -07:00
Michael Bolin 947aa6f202 merge commit for archive created by Sapling 2026-03-31 01:19:11 -07:00
Michael Bolin e13e00c18a core: support dynamic auth tokens for model providers 2026-03-31 01:19:05 -07:00
Michael Bolin 1a1434d155 merge commit for archive created by Sapling 2026-03-31 01:12:36 -07:00
Michael Bolin 2bb3ea6f90 core: support dynamic auth tokens for model providers 2026-03-31 01:12:09 -07:00
Michael Bolin 7fb376dafc Merge ea9c6ab752 into sapling-pr-archive-bolinfest 2026-03-31 01:03:35 -07:00
Michael Bolin 6afaa7d62b auth: let AuthManager own external bearer auth 2026-03-31 01:03:24 -07:00
Michael Bolin ea9c6ab752 core: support dynamic auth tokens for model providers 2026-03-31 01:03:24 -07:00
Michael Bolin ea650a91b3 auth: generalize external auth tokens for bearer-only sources (#16286)
## Summary

`ExternalAuthRefresher` was still shaped around external ChatGPT auth:
`ExternalAuthTokens` always implied ChatGPT account metadata even when a
caller only needed a bearer token.

This PR generalizes that contract so bearer-only sources are
first-class, while keeping the existing ChatGPT paths strict anywhere we
persist or rebuild ChatGPT auth state.

## Motivation

This is the first step toward #15189.

The follow-on provider-auth work needs one shared external-auth contract
that can do both of these things:

- resolve the current bearer token before a request is sent
- return a refreshed bearer token after a `401`

That should not require a second token result type just because there is
no ChatGPT account metadata attached.

## What Changed

- change `ExternalAuthTokens` to carry `access_token` plus optional
`ExternalAuthChatgptMetadata`
- add helper constructors for bearer-only tokens and ChatGPT-backed
tokens
- add `ExternalAuthRefresher::resolve()` with a default no-op
implementation so refreshers can optionally provide the current token
before a request is sent
- keep ChatGPT-only persistence strict by continuing to require ChatGPT
metadata anywhere the login layer seeds or reloads ChatGPT auth state
- update the app-server bridge to construct the new token shape for
external ChatGPT auth refreshes

## Testing

- `cargo test -p codex-login`


---
[//]: # (BEGIN SAPLING FOOTER)
Stack created with [Sapling](https://sapling-scm.com). Best reviewed
with [ReviewStack](https://reviewstack.dev/openai/codex/pull/16286).
* #16288
* #16287
* __->__ #16286
2026-03-31 01:02:46 -07:00
Michael Bolin 06b566fca3 merge commit for archive created by Sapling 2026-03-31 01:01:03 -07:00
Michael Bolin 0b30a7a940 core: support dynamic auth tokens for model providers 2026-03-31 00:59:45 -07:00
Michael Bolin 4a42882bba auth: let AuthManager own external bearer auth 2026-03-31 00:59:42 -07:00
Michael Bolin 59ba8c8995 merge commit for archive created by Sapling 2026-03-31 00:34:48 -07:00
Michael Bolin f042fd7f74 core: support dynamic auth tokens for model providers 2026-03-31 00:34:36 -07:00
Michael Bolin 346440cb7b auth: let AuthManager own external bearer auth 2026-03-31 00:34:30 -07:00
Michael Bolin 86e6098af8 merge commit for archive created by Sapling 2026-03-30 22:52:15 -07:00
Michael Bolin e93aaed334 core: support dynamic auth tokens for model providers 2026-03-30 22:51:43 -07:00
Michael Bolin 5e3780a304 auth: let AuthManager own external bearer auth 2026-03-30 22:51:26 -07:00
Michael Bolin 32e8fa82ff merge commit for archive created by Sapling 2026-03-30 21:52:07 -07:00
Michael Bolin 56f793e8ec core: support dynamic auth tokens for model providers 2026-03-30 21:51:54 -07:00
Michael Bolin 4dd489f6bb auth: let AuthManager own external bearer auth 2026-03-30 21:51:54 -07:00
Michael Bolin 11bdc7eff3 merge commit for archive created by Sapling 2026-03-30 17:35:57 -07:00
Michael Bolin 218221b9f2 core: support dynamic auth tokens for model providers 2026-03-30 17:35:48 -07:00
Michael Bolin 1ec469265f merge commit for archive created by Sapling 2026-03-30 17:33:27 -07:00
Michael Bolin 0c6a595d1d auth: let AuthManager own external bearer auth 2026-03-30 17:33:19 -07:00
Michael Bolin d6c965ac5e core: support dynamic auth tokens for model providers 2026-03-30 17:33:19 -07:00
Michael Bolin 86131560f0 merge commit for archive created by Sapling 2026-03-30 17:24:40 -07:00
Michael Bolin 4e7d4648ef auth: generalize external auth tokens for bearer-only sources 2026-03-30 17:24:10 -07:00
Michael Bolin c0dac22598 core: support dynamic auth tokens for model providers 2026-03-30 17:24:10 -07:00
Michael Bolin 3da331840c auth: let AuthManager own external bearer auth 2026-03-30 17:24:10 -07:00
Michael Bolin 4b438b7b82 Merge c1c63e8f83 into sapling-pr-archive-bolinfest 2026-03-30 16:56:54 -07:00
Michael Bolin c1c63e8f83 core: support dynamic auth tokens for model providers 2026-03-30 16:55:43 -07:00
Michael Bolin 0cca7998a8 merge commit for archive created by Sapling 2026-03-30 16:51:54 -07:00
Michael Bolin 770ed064cf core: support dynamic auth tokens for model providers 2026-03-30 16:51:30 -07:00
Michael Bolin 4127419694 auth: let AuthManager own external bearer auth 2026-03-30 16:27:55 -07:00
Michael Bolin b397919da1 auth: generalize external auth tokens for bearer-only sources 2026-03-30 16:20:45 -07:00
Michael Bolin 2f37a8058d merge commit for archive created by Sapling 2026-03-30 15:41:21 -07:00
Michael Bolin 7c5ddebcae core: support dynamic auth tokens for model providers 2026-03-30 15:41:07 -07:00
Michael Bolin e953180be9 auth: generalize ExternalAuthTokens for bearer-only refreshers 2026-03-30 15:40:51 -07:00
Michael Bolin 19f0d196d1 ci: run Windows argument-comment-lint via native Bazel (#16120)
## Why

Follow-up to #16106.

`argument-comment-lint` already runs as a native Bazel aspect on Linux
and macOS, but Windows is still the long pole in `rust-ci`. To move
Windows onto the same native Bazel lane, the toolchain split has to let
exec-side helper binaries build in an MSVC environment while still
linting repo crates as `windows-gnullvm`.

Pushing the Windows lane onto the native Bazel path exposed a second
round of Windows-only issues in the mixed exec-toolchain plumbing after
the initial wrapper/target fixes landed.

## What Changed

- keep the Windows lint lanes on the native Bazel/aspect path in
`rust-ci.yml` and `rust-ci-full.yml`
- add a dedicated `local_windows_msvc` platform for exec-side helper
binaries while keeping `local_windows` as the `windows-gnullvm` target
platform
- patch `rules_rust` so `repository_set(...)` preserves explicit
exec-platform constraints for the generated toolchains, keep the
Windows-specific bootstrap/direct-link fixes needed for the nightly lint
driver, and expose exec-side `rustc-dev` `.rlib`s to the MSVC sysroot
- register the custom Windows nightly toolchain set with MSVC exec
constraints while still exposing both `x86_64-pc-windows-msvc` and
`x86_64-pc-windows-gnullvm` targets
- enable `dev_components` on the custom Windows nightly repository set
so the MSVC exec helper toolchain actually downloads the
compiler-internal crates that `clippy_utils` needs
- teach `run-argument-comment-lint-bazel.sh` to enumerate concrete
Windows Rust rules, normalize the resulting labels, and skip explicitly
requested incompatible targets instead of failing before the lint run
starts
- patch `rules_rust` build-script env propagation so exec-side
`windows-msvc` helper crates drop forwarded MinGW include and linker
search paths as whole flag/path pairs instead of emitting malformed
`CFLAGS`, `CXXFLAGS`, and `LDFLAGS`
- export the Windows VS/MSVC SDK environment in `setup-bazel-ci` and
pass the relevant variables through `run-bazel-ci.sh` via `--action_env`
/ `--host_action_env` so Bazel build scripts can see the MSVC and UCRT
headers on native Windows runs
- add inline comments to the Windows `setup-bazel-ci` MSVC environment
export step so it is easier to audit how `vswhere`, `VsDevCmd.bat`, and
the filtered `GITHUB_ENV` export fit together
- patch `aws-lc-sys` to skip its standalone `memcmp` probe under Bazel
`windows-msvc` build-script environments, which avoids a Windows-native
toolchain mismatch that blocked the lint lane before it reached the
aspect execution
- patch `aws-lc-sys` to prefer its bundled `prebuilt-nasm` objects for
Bazel `windows-msvc` build-script runs, which avoids missing
`generated-src/win-x86_64/*.asm` runfiles in the exec-side helper
toolchain
- annotate the Linux test-only callsites in `codex-rs/linux-sandbox` and
`codex-rs/core` that the wider native lint coverage surfaced

## Patches

This PR introduces a large patch stack because the Windows Bazel lint
lane currently depends on behavior that upstream dependencies do not
provide out of the box in the mixed `windows-gnullvm` target /
`windows-msvc` exec-toolchain setup.

- Most of the `rules_rust` patches look like upstream candidates rather
than OpenAI-only policy. Preserving explicit exec-platform constraints,
forwarding the right MSVC/UCRT environment into exec-side build scripts,
exposing exec-side `rustc-dev` artifacts, and keeping the Windows
bootstrap/linker behavior coherent all look like fixes to the Bazel/Rust
integration layer itself.
- The two `aws-lc-sys` patches are more tactical. They special-case
Bazel `windows-msvc` build-script environments to avoid a `memcmp` probe
mismatch and missing NASM runfiles. Those may be harder to upstream
as-is because they rely on Bazel-specific detection instead of a general
Cargo/build-script contract.
- Short term, carrying these patches in-tree is reasonable because they
unblock a real CI lane and are still narrow enough to audit. Long term,
the goal should not be to keep growing a permanent local fork of either
dependency.
- My current expectation is that the `rules_rust` patches are less
controversial and should be broken out into focused upstream proposals,
while the `aws-lc-sys` patches are more likely to be temporary escape
hatches unless that crate wants a more general hook for hermetic build
systems.

Suggested follow-up plan:

1. Split the `rules_rust` deltas into upstream-sized PRs or issues with
minimized repros.
2. Revisit the `aws-lc-sys` patches during the next dependency bump and
see whether they can be replaced by an upstream fix, a crate upgrade, or
a cleaner opt-in mechanism.
3. Treat each dependency update as a chance to delete patches one by one
so the local patch set only contains still-needed deltas.

## Verification

- `./.github/scripts/run-argument-comment-lint-bazel.sh
--config=argument-comment-lint --keep_going`
- `RUNNER_OS=Windows
./.github/scripts/run-argument-comment-lint-bazel.sh --nobuild
--config=argument-comment-lint --platforms=//:local_windows
--keep_going`
- `cargo test -p codex-linux-sandbox`
- `cargo test -p codex-core shell_snapshot_tests`
- `just argument-comment-lint`

## References

- #16106
2026-03-30 15:32:04 -07:00
Andrey Mishchenko 390b644b21 Update code mode exec() instructions (#16279) 2026-03-30 12:31:13 -10:00
Michael Bolin e9eff3f36d merge commit for archive created by Sapling 2026-03-30 15:12:22 -07:00
Michael Bolin 0110a82808 core: support dynamic auth tokens for model providers 2026-03-30 15:12:15 -07:00
Michael Bolin 6475f6e229 merge commit for archive created by Sapling 2026-03-30 14:41:48 -07:00
Michael Bolin 84ed96f3f7 core: support dynamic auth tokens for model providers 2026-03-30 14:41:33 -07:00
Michael Bolin f06f0a7f3e auth: generalize ExternalAuthTokens for bearer-only refreshers 2026-03-30 14:32:02 -07:00
rhan-oai 28a9807f84 [codex-analytics] refactor analytics to use reducer architecture (#16225)
- rework codex analytics crate to use reducer / publish architecture
- in anticipation of extensive codex analytics
2026-03-30 14:27:12 -07:00
Michael Bolin db6c7f9c4c merge commit for archive created by Sapling 2026-03-30 14:02:46 -07:00
Michael Bolin d4cf2faae8 core: unify request auth and 401 recovery plumbing 2026-03-30 14:02:34 -07:00