Repository navigation
π Sessions: give a session a refresh-less Codex/OpenCode login copy - #19117
Merged
Merged
Conversation
A session's copy of .codex/auth.json and opencode/auth.json kept its refresh token, so the CLI in a session could rotate the fleet's login and race an agent's refresh into two diverged logins. The copy now keeps the required refresh key with an empty value, like the Claude copy, the hive replaces it when the shared file changes, and after adopting a newer login from a session puts the session back on a refresh-less copy. Fixes #18740 Signed-off-by: Andy Anderson <andy@clubanderson.com>
Contributor
|
[APPROVALNOTIFIER] This PR is APPROVED Approval requirements bypassed by manually added approval. This pull-request has been approved by: The full list of commands accepted by this bot can be found here. The pull request process is described here DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
Contributor
Open PR overlap checkBase branch: Conflicts are checked with every PR merged onto the current tip of
|
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.
Fixes #18740
Root cause.
copyLoginFiles(src/crux/agent/usersession_home.go) gave a session a full copy of.codex/auth.jsonandopencode/auth.json, refresh token included (only Claude went through the refresh-less path). The CLI in the session could therefore refresh its copy, rotating the shared grant: the session became a second refresh holder, and a session refresh and an agent refresh in the same window left two diverged logins. #18793 added adopt-back as a safety net but kept the refreshable copy (see the comment block at the top of usersession_login_rotating.go before this change).Fix (option 2, same model as Claude since #18724).
tokens.refresh_tokenand OpenCoderefreshof eachoauthentry keep their key (both CLIs require it) with"". Every other field and entry is copied unchanged. Per the source reading on the issue (Codex 0.170.0, OpenCode v1), both CLIs accept an empty value; the CLI keeps using the access token and a refresh attempt fails without rotating anything.Trade-off. Like Claude sessions, a Codex/OpenCode session now depends on an agent or a sign-in refreshing the shared login before its access token expires. Documented in security-model.md and api-reference/sessions.md. The live-install confirmation that both CLIs run with an empty refresh value remains the manual check in security-model.md (updated step 2).
Tests.
TestSessionRotatingLoginCopy_EmptiesEveryRefreshToken: table-driven copy shape for Codex and OpenCode (ChatGPT, API key, oauth and api entries, invalid input).TestSessionRotatingLogin_SessionCannotWriteADivergingRefresh: table-driven per vendor: CLI rewrites its refresh-less copy, agent refresh propagates, legacy full copy downgraded, legacy copy refreshed in session adopted then downgraded, losing race left alone.TestSessionRotatingLogin_ConcurrentAgentRefreshStaysTheSingleSource: per vendor, agent refreshes race the sweep and start checks; the shared file only ever holds agent writes, no adoption, and the session ends on a refresh-less copy of the last refresh.π€ Generated with Claude Code