Skip to content

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

Closed

Description

@clubanderson

Summary

Follow-up to #18724. User sessions get a copy of the hive's shared login file for several vendor CLIs. For Claude, #18728 stops a session from holding a refreshable login and adopts a newer login found in a session HOME back into the shared file. Two other vendors store a rotating refresh token in the copied file and can still split from the shared login the same way.

Which vendors

Copied file Rotates on refresh? Exposed
.codex/auth.json (ChatGPT login) yes yes
.local/share/opencode/auth.json (an OAuth provider entry) yes, depending on the provider yes
.gemini/oauth_creds.json, .gemini/google_accounts.json no no
.copilot/config.json no no

An API-key login in either exposed file does not rotate and is not affected.

What can happen

The CLI in a session refreshes its copy. The refresh rotates the refresh token, so the session's copy becomes the only valid login and the shared file the agents use is stale. Agents on that backend then fail to refresh and end at a login prompt until someone signs in again. Deleting the session deletes the only valid login.

What #18728 already does for these files

Only one thing: a session start or resume no longer overwrites a login file the session's CLI rewrote after the shared file was written. There is no adopt-back and no refresh-less copy for these vendors.

What is wanted

For each exposed vendor, the same guarantees #18724 lists for Claude:

  • a refresh inside a session never leaves the shared login stale;
  • deleting or ending a session never destroys the only valid login;
  • two holders never refresh concurrently into divergent tokens;
  • no credential contents are logged.

Options, per vendor:

  1. Adopt-back. When a session HOME holds a strictly newer valid login than the shared file, adopt it into the shared file atomically with an audit entry, decided by the file's own freshness fields and modification time only. Codex records a last-refresh time in its file; OpenCode records an expiry per provider entry.
  2. A copy that cannot refresh, where the CLI accepts one. This needs checking against each CLI: Codex may reject a login file with no refresh token.

Start from src/crux/agent/usersession_login.go and userSessionLoginFiles in src/crux/agent/usersession_home.go. Check first how agents share each of these files (Codex agents link to the shared file; see src/crux/agent/manager_homes.go), because the right single owner differs per vendor.

Constraints

  • Tests use synthetic credentials only.
  • Never log, print or audit credential file contents.
  • Update src/docs/security-model.md (the sessions section already names these two vendors as exposed).

Activity

  1. added
    help wantedDenotes an issue that needs help from a contributor. Must meet "help wanted" guidelines.
    on Nov 17, 2026
  2. hivecommons-hive commented on Nov 17, 2026

    @hivecommons-hive
    Contributor

    Thanks for filing this issue! To help us reproduce and investigate, could you please include the commit SHA of the build you're running?

    You can find it by running:

    git rev-parse --short HEAD
    

    Or check the bottom of the console UI for the version string.

    This issue will be on hold until a SHA is provided. Simply add a comment with the SHA and the label will be automatically removed.

  3. github-actions commented on Nov 18, 2026

    @github-actions
    Contributor

    PR #18793 has merged (#18793) and referenced this issue with a non-closing Refs #18740 rather than a closing keyword.

    This issue remains open because the merged PR did not use Closes / Fixes / Resolves. If the fix should close it on merge, use a closing keyword in the PR body; use the opt-in hive: needs-confirmation marker only when the reporter genuinely must verify before closure.

  4. clubanderson commented on Nov 18, 2026

    @clubanderson
    MemberAuthor

    Commit SHAs for the sweep: the adopt-back half of this issue landed in #18793 (80ec755); current v5 head is 6b79bed19.

    Remaining scope, which is what is still open here:

    1. A session's own copy of a Codex or OpenCode login can still refresh independently (option 2 in the description): make the session copy non-refreshing, or otherwise stop a session refresh and an agent refresh in the same window from diverging.
    2. Verify the assumed Codex and OpenCode auth file formats against live installs, and add a test fixture from a real file.
    3. Confirm src/docs/security-model.md covers the adopt-back (stale-file retention and audit entry) and that no credential value is ever logged.
  5. changed the title [-]🐛 Sessions: Codex and OpenCode OAuth logins can still split from the shared login when a session refreshes them[/-] [+]🐛 Sessions: a session's Codex/OpenCode login copy can still refresh and diverge from the shared login (follow-up to #18793)[/+] on Nov 18, 2026
  6. github-actions commented on Nov 18, 2026

    @github-actions
    Contributor

    @clubanderson this reads as a partial or uncertain confirmation, so the issue stays open. If it is fully fixed for you, reply /fixed to close it; otherwise please describe what is still outstanding.

  7. added
    hive/partially-addressedA merged PR addressed only part of this issue; remainder still actionable
    stage/010-actionableTriaged; eligible for the hive to pick up
    and removed on Nov 18, 2026
  8. self-assigned this
    on Nov 18, 2026
  9. clubanderson commented on Nov 18, 2026

    @clubanderson
    MemberAuthor

    Claimed. Remaining scope being worked: make a session's own Codex/OpenCode login copy unable to refresh independently of the shared login (option 2), plus the security-model docs check. The live-install check against real Codex and OpenCode files needs a person and stays open on this issue.

  10. hivecommons-hive commented on Nov 18, 2026

    @hivecommons-hive
    Contributor

    Hive status — updated in place; edits do not notify. Full history is in the Activity Monitor.

    PR #18881 covers this issue: #18881

    The PR body says this is partial/non-closing work (Refs/Part of or leave-open wording), so Hive will not add a closing keyword. GitHub will not show its issue-list PR icon without a closing keyword; the stage comment is the link.

  11. hivecommons-hive commented on Nov 18, 2026

    @hivecommons-hive
    Contributor

    Scanner verification of #18793: option 1 (adopt-back for Codex and OpenCode, with a kept stale copy and an audit entry) is merged and covers 'never leaves the shared login stale', 'deleting a session cannot destroy the only valid login' and 'no credential contents logged'. What remains is the 'two holders never refresh concurrently' guarantee: #18793 did not do option 2 (a copy that cannot refresh), because whether Codex or OpenCode accept a login file without a refresh token can only be checked by running each CLI. Leaving the issue open for that check. No implementation started.


    🐝 Hive Agent: scanner | Instance: hosted-available-oke-11-placeholder-r05x | SHA: unknown

    — hive: agent=scanner backend=claude model=claude-sonnet-5-5 claude=2.1.327

  12. clubanderson commented on Nov 18, 2026

    @clubanderson
    MemberAuthor

    Claimed by the maintainer: a dispatched agent is working this, one PR to follow where code is needed. Please do not open a parallel PR.

  13. clubanderson commented on Nov 18, 2026

    @clubanderson
    MemberAuthor

    Update on this issue from reading the public sources of Codex 0.170.0 (the version src/Dockerfile pins) and OpenCode v1.19.6 and v2.3.2. No live install was touched.

    1. Both CLIs require the refresh token key but accept an empty value. Codex: tokens.refresh_token is a plain String (token_data.rs:22); with auth_mode chatgptAuthTokens it is never refreshed (manager.rs:3578, 3660), and with chatgpt a failed refresh is only logged. OpenCode v1: refresh is a required string (auth/index.ts:16) and an oauth entry with an empty refresh just fails after expires (codex.ts:145). So a refresh-less session copy (option 2) looks feasible for both: medium confidence for Codex (an undocumented file path), high for the OpenCode v1 file. It needs the session copy re-synced before the access token expires.
    2. A bigger concern: session copies are written mode 0400. Both CLIs refuse to overwrite them, but only after the refresh exchange, so a session refresh could rotate the shared token and save the new one nowhere. Adopt-back would then never fire for these two vendors. The live check needs to confirm this.
    3. Neither CLI holds a cross-process lock around the refresh exchange (Codex's auth.lock covers only the commit and is per CODEX_HOME), so "never refresh concurrently" cannot be promised from outside. What holds: no torn file, no silent overwrite (Codex), and a safe failure for the loser.
    4. OpenCode v2 stores logins in SQLite and reads auth.json once, so the file logic here does not apply to it.
    5. Step 2 of the live check in security-model.md needs correcting: editing last_refresh and codex login status do not force a refresh.

    A read-only runbook with a tested redaction command is ready, and a fixture and tests are on a local branch. This stays open until the live check is done and the session-copy behavior in item 2 is decided.

  14. github-actions commented on Nov 18, 2026

    @github-actions
    Contributor

    @clubanderson this reads as a partial or uncertain confirmation, so the issue stays open. If it is fully fixed for you, reply /fixed to close it; otherwise please describe what is still outstanding.

  15. clubanderson commented on Nov 18, 2026

    @clubanderson
    MemberAuthor

    PR #19117 implements option 2: Codex and OpenCode session copies keep the refresh key with an empty value (like the Claude copy), the hive keeps each copy following the shared login, and adopt-back stays as the safety net. The live-install confirmation remains the manual check in security-model.md.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

help wantedDenotes an issue that needs help from a contributor. Must meet "help wanted" guidelines.hive/partially-addressedA merged PR addressed only part of this issue; remainder still actionablekind/bugCategorizes issue or PR as related to a bug.

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions