Repository navigation
feat(server): let a host own and refresh its own Codex logins - #83
Merged
Merged
Conversation
A Codex ChatGPT login rotates its refresh token on every refresh and rejects reuse, so only one place can refresh it. Until now the host seed carried stripped copies of the laptop's logins, which die when each access token expires. The packer now carries `~/.t3/host-codex/<instanceId>/auth.json` whole (`--codex-host-logins`), falling back to a stripped laptop copy with one log line per account. On any server, a login it can refresh is refreshed by the instance's status probe (`account/read` with `refreshToken: true`) once less than 48 hours are left, checked hourly. Provisioning refreshes a login with less than a day left before copying it, still stripped, into a new box. Both go through the instance's serialized probe, so a refresh cannot race a usage probe. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Thread transfer impact✅ Thread transfer remains within every enforced ceiling.
Baseline: Scenario and decoded snapshot size10 historical turns, 5 command tools per turn, 878.9 KiB retained MCP result per historical turn, and a 1.05 MiB retained result in the measured turn.
Updated in place by a trusted workflow. PR artifacts are strictly validated and never executed. |
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
…ator Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
… a torn login - Refresh-ahead (the 48h probe flag, the hourly check, the 24h pre-copy refresh) runs only where `localAgentRuns` is false. Laptops and dev servers can share one Codex home, and two refreshing it at once would spend the same token, so Codex keeps its own schedule there. - Codex rewrites auth.json in place, so provisioning retries a login it cannot parse and then refuses it; `stripCodexRefreshToken` no longer passes an unparseable file through raw, and the packer refuses one too. - A host's own login past expiry after a failed refresh reports as signed out, and routing refuses it, with "sign in again with ~/.t3/provisioning/codex-site-login.sh and reseed". Copies keep the reseed wording. - After writing a seed, the packer renames each carried host login to `auth.json.packed-<seed name>` so nothing on the laptop can use it and a repack cannot carry its spent refresh token. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
…change Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
…k recovery The packer now applies the copy's parse check to a host login too, so a torn ~/.t3/host-codex/<id>/auth.json fails the pack instead of being carried and retired. The usage text says how to recover from a failed upload or a lost tarball, and the Codex accounts doc states the entrypoint's keep rule. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
A Codex ChatGPT login rotates its refresh token on every refresh, and the auth server rejects a reused one, so one login can only be refreshed in one place. Since #75, the host seed and every box get stripped copies of the laptop's logins. The laptop is the only refresher, and each cloud copy dies when its 10-day access token expires.
This gives the host its own login per account, made with
CODEX_HOME=~/.t3/host-codex/<instanceId> codex login --device-auth. The host is the only refresher of those logins. Boxes still get stripped copies and never refresh.What changed
pack-host-state.tstakes--codex-host-logins DIR(default~/.t3/host-codex) and carriesDIR/<instanceId>/auth.jsonwhole, since the host refreshes it. A missing file falls back to the stripped laptop copy and logs one line for that account.HostState.codexLoginsrecordshostorcopyper account. Once the seed is written, the CLI renames each carried file toauth.json.packed-<seed name>and prints one line per file. Nothing on the laptop can use it afterwards, and a repack can't carry a spent refresh token again.codex-site-login.shchecks forauth.json, so it treats that account as needing a fresh sign-in. The packer refuses a laptop or host login it can't parse, rather than carrying it raw or packing and retiring it. The usage text says how to recover: if the upload fails, upload the same tarball again; if the tarball is lost, rename eachauth.json.packed-<seed>back toauth.jsonand pack again.deploy-provision-manager.mjspasses no directory and carries copies only, because one login can't have two owners.localAgentRunsis false (T3CODE_LOCAL_AGENT_RUNS=false, which the T3 host sets). Laptops and worktree dev servers can share one Codex home, and two refreshing it at once would spend the same token. There, Codex keeps its own schedule.codexLoginRefreshDue(login, within, { now, localAgentRuns })is the one decision all three call sites use.unauthenticatedwith "<account>'s Codex login on this host expired; sign in again with ~/.t3/provisioning/codex-site-login.sh and reseed". Routing's refusal uses the same wording.auth.jsonin place with truncate and write (codex-rs/login/src/auth/storage.rs:206-222).freezeretries a Codex login it can't parse (3 reads, 100 ms apart), then refuses with "A Codex login on this manager could not be read, so it was not copied. Try again."stripCodexRefreshTokennow returnsundefinedfor text that isn't a JSON object, so nothing hands a raw file on.makeManagedServerProviderruns one at a time per instance. A refresh cannot overlap that account's usage probe or another refresh.docs/operations/cloud-provisioning.md: the Codex accounts section is rewritten in place.Codex mechanism (codex
rust-v0.157.1, commit36650394c5, the version the host image pins)account/readtakesGetAccountParams.refresh_token, whose doc says "requests a proactive token refresh before returning" (codex-rs/app-server-protocol/src/protocol/v2/account.rs:543-552).get_accountcallsself.refresh_token_if_requested(params.refresh_token)first (codex-rs/app-server/src/request_processors/account_processor/workspace_routing.rs:157-161). That callsauth_manager.refresh_token()and swallows its error (codex-rs/app-server/src/request_processors/account_processor.rs:1026-1039), which is why the hourly check rereads the file afterwards.AuthManager::refresh_tokentakesrefresh_lock, then does a guarded reload of auth.json. If the file changed since it was cached, it skips the refresh ("another process already refreshed"). If the account id no longer matches, it refuses (codex-rs/login/src/auth/manager.rs:2844-2881).persist_tokensrewrites auth.json and setslast_refresh(manager.rs:1598-1621). Codex's own proactive window is 5 minutes (manager.rs:204,3004-3024).Deploy order
These have to ship together, in this order:
~/.t3/host-codex/<instanceId>/auth.jsonexists for all 11 Codex instances.pack-host-state.tsafter step 2. Check that nono ~/.t3/host-codex/...fallback lines were printed.Without the entrypoint change, a later seed would put back an older refresh token and sign out that account. Once a seed is packed, nothing on the laptop may run Codex against
~/.t3/host-codex/<id>, because the host now owns those logins.Verification
vp test runoncodexLoginCopy.test.ts,ProvisionPreparation.test.ts,ProvisioningProviderProfile.test.ts,EnvironmentControl.test.ts,pack-host-state.test.tsandprovision-manager-accounts.test.ts: 136 passed. The tests use literal expectations:falsewhile the same login on a host istrue.localAgentRuns: false, the result isrefreshedAccounts: ["codex_host"], a box copy expiring at1791468000(2026-10-08T14:00Z) witht3-copy-cannot-refresh, and the host file atrt_rotated. WithlocalAgentRuns: true, nothing is refreshed, the box copy expires at1790676000(2026-09-29T10:00Z), and the host keepsrt_host.auth.jsonmakesfreezereject with the message above and leaves no manifest.codexLoginsis{ codex: "host", codex_uci: "copy" }. The host file is carried byte-for-byte.retireCarriedCodexLoginsreturns[.../codex/auth.json.packed-2026-09-27.1], and the directory then holds only that file, with the original contents. A truncated laptop login fails with "<home>/.codex/auth.json is not a Codex login". A truncated host login fails with "<home>/host-codex/codex/auth.json is not a Codex login" and stays in place, and letting host logins skip the check fails that test.localAgentRunsgate fails the three tests that cover it.HOME. It printed thecodex_ucifallback line andretired the host's Codex login to <tmp>/.t3/host-codex/codex/auth.json.packed-seed-v99, and left only that file.checkCodexProviderStatusonce against the realcodex-cli 0.157.1with a local token stub. Without the flag there was no token call. With it there was exactly onePOST /oauth/tokencarryingrt_old, and auth.json then heldrt_new.🤖 Generated with Claude Code