Skip to content

πŸ› claude: keep the rotated shared-login grant until it is durably written; one writer for the shared login - #18776

Merged
kubestellar-prow[bot] merged 2 commits into
v5from
fix/shared-refresh-lost-write
Nov 17, 2026
Merged

kubestellar-prow[bot] merged 2 commits into
v5from
fix/shared-refresh-lost-write

Conversation

@clubanderson

Copy link
Copy Markdown
Member

Fixes #18775

Safety follow-up to #18736 (hive refreshes the shared Claude grant itself).

What changed

  • Lost-write window closed in-process. After a successful refresh the new grant is saved to .credentials.pending (0600, temp file, fsync, rename, dir fsync) before the shared file is touched, held in memory, and written with backoff (5 s doubling to 5 min, no overall limit). While a grant is held the token endpoint is never called. A pending grant newer than the shared file is adopted at boot; an older one is deleted.
  • Loud alert if the grant cannot be written: error log, claude_credential_refreshed audit (reason=new grant could not be saved), and a dashboard banner naming when the login the agents read expires. No token contents anywhere.
  • invalid_grant is reconciled first: the bridge and session adopt-back are run, and a different refresh token in the shared file means a newer grant exists, so the credential is not marked rejected.
  • One writer: replaceSharedClaudeLoginIfNewer (new claude_shared_grant.go) is used by the refresher and by promoteClaudeCredential, which the agent bridge and the session adopt-back both call. All three hold claudeBridgeMu; the rule is usable and strictly later expiry.
  • Docs (security-model.md, troubleshooting.md): who refreshes the login now, the HIVE_CLAUDE_SHARED_REFRESH=off fallback, and a live-check runbook for running CLIs. Changelog fragment.

Residual risk (stated plainly)

Closed while the process lives. Across a crash it is narrowed, not closed: the old refresh token dies when the provider answers, so there remains the gap between the answer arriving and the pending file's fsync, and the case where both files fail and the process dies before either recovers.

Gap 4 (does a running CLI re-read the rewritten file instead of refreshing with a cached token) cannot be tested here; the hive does not restart agents on a refresh. The runbook gives the live check.

Gap 3: the shared file is deliberately written as the typed token block only (dashboard sign-in, bridge and session paths all do this and tests assert it), so other keys in the file are dropped on purpose. Left as is; merging other keys would be a separate change.

Tests (synthetic credentials, fake token endpoint): write fails once then succeeds (one endpoint call), restart adopts pending, persistent failure gives no second refresh and raises the alert, invalid_grant with a newer grant is recovered, three racing writers settle on the newest, and a sentinel check on logs, audit and the banner.

πŸ€– Generated with Claude Code

…tten; one writer for the shared login

The provider kills the old refresh token the instant it answers, so a failed
write of the new credential lost the login for the whole fleet. The new grant
is now saved to a private .credentials.pending file first, held in memory and
retried with backoff without calling the token endpoint again, adopted at boot
after a crash, and a dashboard banner and log line say so when it cannot be
saved. invalid_grant is no longer final while a newer grant exists. The
refresher, the agents' bridge and the session adopt-back write the shared login
through one only-if-strictly-newer function under one lock.

Fixes #18775

Signed-off-by: Andy Anderson <andy@clubanderson.com>
@kubestellar-prow kubestellar-prow Bot added dco-signoff: yes Indicates the PR's author has signed the DCO. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. labels Nov 17, 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 17, 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

github-actions Bot commented Nov 17, 2026 •

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
#18793 πŸ› Sessions: adopt a Codex or OpenCode login refreshed in a session back into the shared login same files src/docs/security-model.md

Signed-off-by: Andy Anderson <andy@clubanderson.com>
@kubestellar-prow kubestellar-prow Bot removed the lgtm Indicates that a PR is ready to be merged. label Nov 17, 2026
@kubestellar-prow

Copy link
Copy Markdown
Contributor

New changes are detected. LGTM label has been removed.

@clubanderson clubanderson added the lgtm Indicates that a PR is ready to be merged. label Nov 17, 2026
@kubestellar-prow
kubestellar-prow Bot merged commit eed08d8 into v5 Nov 17, 2026
95 checks passed
@kubestellar-prow
kubestellar-prow Bot deleted the fix/shared-refresh-lost-write branch November 17, 2026 18:23
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.

πŸ› Shared Claude login: central refresh can lose the rotated grant on a failed write (close the lost-write window)

1 participant