Skip to content

πŸ› Sessions: give a session a refresh-less Codex/OpenCode login copy - #19117

Merged
kubestellar-prow[bot] merged 1 commit into
v5from
fix/18740-session-login-no-refresh
Nov 18, 2026
Merged

kubestellar-prow[bot] merged 1 commit into
v5from
fix/18740-session-login-no-refresh

Conversation

@clubanderson

Copy link
Copy Markdown
Member

Fixes #18740

Root cause. copyLoginFiles (src/crux/agent/usersession_home.go) gave a session a full copy of .codex/auth.json and opencode/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).

  • A session gets the shared file with every refresh token emptied: Codex tokens.refresh_token and OpenCode refresh of each oauth entry 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.
  • The shared file the agents link to stays the single refreshable owner; only the agents' CLIs refresh it. The hive replaces a session's copy (atomically, 0400, as the session's uid, through the existing copy script) when the shared file was written after it, on every credential-bridge poll and at start/resume.
  • Adopt-back from πŸ› Sessions: adopt a Codex or OpenCode login refreshed in a session back into the shared loginΒ #18793 is kept: a complete, strictly newer login found in a session (a full copy from an earlier release refreshed there, or a sign-in inside the session) is adopted under the existing lock and changed-file guard, and the session is then put back on a refresh-less copy. A full copy carrying the shared file's own refresh token is downgraded too. A refresh token the shared file does not hold that is not newer is the session's own login and is left alone.
  • Token values are compared only for equality and never logged; file modes unchanged (0400 session copies, shared file keeps its mode).

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.
  • Existing adopt-back tests updated to expect a refresh-less session copy.

πŸ€– Generated with Claude Code

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>
@kubestellar-prow kubestellar-prow Bot added the dco-signoff: yes Indicates the PR's author has signed the DCO. label Nov 18, 2026
@clubanderson clubanderson added lgtm Indicates that a PR is ready to be merged. approved Indicates a PR has been approved by an approver from all required OWNERS files. labels Nov 18, 2026
@kubestellar-prow kubestellar-prow Bot added the size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. label Nov 18, 2026
@kubestellar-prow

Copy link
Copy Markdown
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

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@github-actions

Copy link
Copy Markdown
Contributor

Open PR overlap check

Base branch: v5

Conflicts are checked with every PR merged onto the current tip of v5, so a PR that only needs a rebase is not reported as conflicting with its siblings.

PR Title Relation Files
#19098 ✨ Shadow-mode authorization decision seam for the push broker's changed-files guard same files src/docs/security-model.md
#19099 ✨ Session taint: observe-only recorder for what a session has read same files src/docs/security-model.md

@kubestellar-prow
kubestellar-prow Bot merged commit 70fd4b7 into v5 Nov 18, 2026
103 checks passed
@kubestellar-prow
kubestellar-prow Bot deleted the fix/18740-session-login-no-refresh branch November 18, 2026 20:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved Indicates a PR has been approved by an approver from all required OWNERS files. dco-signoff: yes Indicates the PR's author has signed the DCO. lgtm Indicates that a PR is ready to be merged. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

πŸ› Sessions: a session's Codex/OpenCode login copy can still refresh and diverge from the shared login (follow-up to #18793)

1 participant