Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- The hive's own refresh of the shared Claude login can no longer lose the rotated grant when the write fails: the new grant is saved to a private `.credentials.pending` file before the shared file is written, held 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; an `invalid_grant` is no longer final while a newer grant from an agent or session home exists, and the refresher, the agents' bridge and the session adopt-back now write the shared login through one "only if strictly newer" function (#18775).
37 changes: 37 additions & 0 deletions src/cmd/hive/claude_shared_login_alert.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package main

// claudeSharedLoginUnsavedAlertID is the dashboard system-alert id for "the
// hive refreshed the shared Claude login but could not write the new grant"
// (hivecommons/hive#18775). Raised and cleared level-triggered, once per
// evaluation cycle, from the agent manager's own account of the held grant.
const claudeSharedLoginUnsavedAlertID = "claude-shared-login-unsaved"

// claudeSharedLoginUnsavedSource is implemented by the agent manager.
type claudeSharedLoginUnsavedSource interface {
ClaudeSharedLoginUnsavedAlert() string
}

// claudeSharedLoginUnsavedSink is the subset of *dashboard.Server used.
type claudeSharedLoginUnsavedSink interface {
AddSystemAlert(id, severity, message string)
ClearSystemAlert(id string)
}

// reconcileClaudeSharedLoginUnsavedAlert raises the banner while a refreshed
// grant is held unwritten and clears it once it is saved. A runtime that does
// not hold grants (any other crux.Runtime) leaves it cleared.
func reconcileClaudeSharedLoginUnsavedAlert(sink claudeSharedLoginUnsavedSink, rt any) {
if sink == nil {
return
}
src, ok := rt.(claudeSharedLoginUnsavedSource)
if !ok {
sink.ClearSystemAlert(claudeSharedLoginUnsavedAlertID)
return
}
if msg := src.ClaudeSharedLoginUnsavedAlert(); msg != "" {
sink.AddSystemAlert(claudeSharedLoginUnsavedAlertID, "error", msg)
return
}
sink.ClearSystemAlert(claudeSharedLoginUnsavedAlertID)
}
1 change: 1 addition & 0 deletions src/cmd/hive/main_eval_cycle.go
Original file line number Diff line number Diff line change
Expand Up @@ -1355,6 +1355,7 @@ func runEvalCycle(
// (#18732) are waiting for an operator sign-in, not a restart: keep the
// dashboard banner level with the runtime's BackendAuth marks.
dashSrv.ReconcileClaudeLoginRevokedAlert(agentMgr.AllStatuses())
reconcileClaudeSharedLoginUnsavedAlert(dashSrv, agentMgr)

// Epoch captured before reading agent/governor state so a mutation that
// lands mid-build (restart-count/budget reset) drops this snapshot instead
Expand Down
22 changes: 4 additions & 18 deletions src/crux/agent/claude_credential_bridge.go
Original file line number Diff line number Diff line change
Expand Up @@ -475,27 +475,13 @@ func (m *Manager) relinkUnreadableAfterSignIn(agentName, link, target string) (*
// metadata by descriptor, and a refusal (sharedfile.ErrUnsafeLocation) when
// the shared directory or file is not what it should be.
func promoteClaudeCredential(data []byte, target string, now time.Time) (string, error) {
canonical, _, err := canonicalClaudeCredential(data, now)
_, tok, err := canonicalClaudeCredential(data, now)
if err != nil {
return "", err
}
// Refuse before the backup copy, not only at the write: the copy lands in
// the same directory, and the directory is part of what is being checked.
info, err := sharedfile.CheckLocation(target)
if err != nil {
return "", err
}
staleShared := ""
if info != nil {
staleShared, err = preserveClaudeCredential(target, now)
if err != nil {
return "", fmt.Errorf("preserve shared credential: %w", err)
}
}
if err := sharedfile.Replace(target, canonical, claudeSharedCredentialMode, sharedfile.Options{PreserveOwner: true}); err != nil {
return staleShared, err
}
return staleShared, nil
// The one writer of the shared login: re-checks, under the caller's
// claudeBridgeMu, that tok is strictly newer (claude_shared_grant.go).
return replaceSharedClaudeLoginIfNewer(tok, target, now, true)
}

// preserveClaudeCredential copies path to a unique stale name beside it,
Expand Down
Loading
Loading