Repository navigation
π claude: keep the rotated shared-login grant until it is durably written; one writer for the shared login - #18776
Merged
Conversation
β¦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>
This was referenced Nov 17, 2026
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
|
Signed-off-by: Andy Anderson <andy@clubanderson.com>
Contributor
|
New changes are detected. LGTM label has been removed. |
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 #18775
Safety follow-up to #18736 (hive refreshes the shared Claude grant itself).
What changed
.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.claude_credential_refreshedaudit (reason=new grant could not be saved), and a dashboard banner naming when the login the agents read expires. No token contents anywhere.invalid_grantis 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.replaceSharedClaudeLoginIfNewer(newclaude_shared_grant.go) is used by the refresher and bypromoteClaudeCredential, which the agent bridge and the session adopt-back both call. All three holdclaudeBridgeMu; the rule is usable and strictly later expiry.security-model.md,troubleshooting.md): who refreshes the login now, theHIVE_CLAUDE_SHARED_REFRESH=offfallback, 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_grantwith 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