Repository navigation
π [v6] claude auth: never re-bridge a credential that resolves to the shared login file - #17590
Conversation
β¦ shared login file An agent whose whole ~/.claude is still the legacy directory symlink to /data/home/.claude (paused or stopped since before the per-agent split, so no launch retired it) has a credential path that IS the shared login. The credential watchdog walks every managed agent, so the repair saw the shared file as a "private copy": it renamed it to .stale-<UTC> every cycle and, when the shared file held no token, linked .credentials.json to itself, logging every Claude agent out. The repair now resolves the link's directory before moving anything and refuses when the link path is, or resolves to, its target; the caller skips that layout with one warning per agent. The dashboard's credential-bridge-broken signal applies the same rule. The launch path already retires the directory link before it runs the repair (hivecommons#17039), so no new migration is added. Also pins that a sign-in's WriteCredentials replaces a self-referencing or dangling symlink. Refs hivecommons#17253 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01BQYnPGFJx81c8JXR3o1sg1 Signed-off-by: Danathar <Danathar@users.noreply.github.com>
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
There was a problem hiding this comment.
Correctness review (head b2ec457) β the guard does what the body says: claudeBridgeLinkIsTarget runs before moveAsideClaudeCredential (src/crux/agent/claude_credential_bridge.go:228-238), the launch path still retires the dir link before re-bridging (src/crux/agent/interactive_home.go:414 β :423 β :445), and the new tests pin both the untouched-inode and warn-once behaviours. No blocker.
One low-severity behaviour change to be aware of (advisory, not blocking):
Shared .claude dir absent β repair and dashboard signal both go quiet. claudeBridgeLinkIsTarget returns an error when EvalSymlinks(filepath.Dir(target)) fails (claude_credential_bridge.go:177-180). repairClaudeCredentialBridge turns that into nil, nil at debug level (:229-235), and claudeCredentialBridgeBroken returns false (:140-141). Before this PR, a real per-agent regular file with no shared dir was still moved aside and the symlink restored (dangling until the next sign-in), and the card showed "credential bridge broken". Now that agent is silently skipped every cycle and never reported. The link's own directory is known to exist (the Lstat at :218 succeeded), so a missing target dir can never be the same directory β it is safe to treat ErrNotExist there as "not the same" rather than "unknown":
targetDir, err := filepath.EvalSymlinks(filepath.Dir(target))
if err != nil {
if errors.Is(err, fs.ErrNotExist) {
// The link's directory exists (the caller just Lstat'ed a file in
// it), so an absent shared directory cannot be the same one.
return false, nil
}
return false, err
}
(needs "io/fs" in the import block.) If skipping is the intended choice, consider logging at Warn rather than Debug so the lost dashboard signal has a visible replacement.
β hive: agent=adjudicator backend=copilot model=claude-fable-5.1 copilot=1.0.88
Review follow-ups (below
|
|
Hive status β updated in place; edits do not notify. Full history is in the Activity Monitor. Review findings from Style / idiom review (read at head 1. Once-per-agent warning state is a package global; the repo idiom is a
|
β¦omes and harden shared-home permission handling (#17807) Top-up of #17767 (v5 squash 0cf675d) onto v6, merged into the credential bridge v6 already carries from #17253/#17590: - keeps v6's dashboard surface (credentialBridgeBroken, resume after sign-in) and the legacy-dir-link rules; - brings the sharedfile-based promotion, owner read through su-exec, newest-expiresAt rule, 5s bridge cadence (HIVE_CLAUDE_CREDENTIAL_BRIDGE_INTERVAL), and the fail-safe handling of an unreadable private file (left in place except on sign-in); - hardens the shared-home permission guard and credential promotion against non-regular files (entrypoint guard, sticky shared dot-dirs, crux/sharedfile writer for the Claude login and Copilot config); - a dashboard sign-in still recovers a shared credential path that is a dangling or self-referencing link (#17590), by unlinking it first. Supersedes #17678 and #17748. (cherry picked from commit 0cf675d) Signed-off-by: Andrew Anderson <andy@clubanderson.com>
Summary
The Claude credential bridge repair (Refs #17253) could rename the fleet's shared Claude login out from under every agent, and in one case link it to itself. That happened for an agent whose whole
~/.claudewas still the old directory symlink to/data/home/.claude. Through that link the agent's "private credential" is the shared login file. This PR makes the repair resolve the link's directory first and refuse to touch a path that is, or resolves to, the shared file. The dashboard's "credential bridge broken" signal follows the same rule. Such an agent is skipped with one warning, and its next launch already replaces the directory link.What went wrong
~/.claudeat launch, and the old whole-directory symlink is removed then. An agent that stayed paused or stopped was never relaunched, so it kept the old layout.<agent home>/.claude/.credentials.jsonand checks it withos.Lstat. Because the symlink is the parent directory, not the file, thatLstatsees a regular file: the shared login..credentials.json.stale-<UTC>.os.Symlinkfails with EEXIST. Nothing breaks, but the shared login is rewritten and a new.stale-*file is left on every cycle.os.Symlink(target, link)succeeds. The result is/data/home/.claude/.credentials.json -> /data/home/.claude/.credentials.json, a symlink to itself, so every Claude agent is logged out.Evidence from a live v6 hive: 182
.stale-*files beside the shared credential between 2026-11-08T16:41Z and 2026-11-09T19:41Z, then the self-loop at 19:41:54Z. The login detector paused every Claude agent, and the operator had to recover by hand. That hive was running a build that already included #17253. The files touched here have not changed between that build and the current v6 tip.What changes
claudeBridgeLinkIsTarget(link, target), reports whether the link path equals the target or sits in a directory that resolves (viafilepath.EvalSymlinks, thenos.SameFileas a fallback for bind mounts) to the target's directory.repairClaudeCredentialBridgecalls it before anything is moved aside. On a match it returns an error wrappingerrClaudeBridgeLinkIsTarget, so nothing is renamed, written or linked. This is the check that every repair goes through: launch, watchdog and sign-in.claudeCredentialBridgeBroken(which feeds the dashboard's "credential bridge broken (private stale file)" label) applies the same rule, so the legacy layout is no longer shown as a broken bridge.rebridgeClaudeCredentialturns that error into a skip and logs one WARN per agent (deduplicated with a package-levelsync.Mapkeyed by the link path). The warning names the legacy directory link and says the next launch retires it. It is not audited, because nothing changed. The mark is cleared on any other outcome, so if the layout comes back it is logged again.src/docs/agent-configuration.mdgains a short paragraph about the skipped layout.Why there is no new launch migration
#17039 already handles this at launch. In
setupPerAgentCLIHome, a symlinked~/.claudeis removed (os.Remove), and the function returns early if that fails. ThenmkdirAllNoFollowcreates a real directory, refusing any symlinked component, and only after that does it callrebridgeClaudeCredential. So the launch path never sees the shared file through the old link. A new test pins this order. The agents on the live hive kept the old layout only because they were not relaunched while the watchdog kept visiting them.Files
src/crux/agent/claude_credential_bridge.go: the guard, the error, the once-per-agent warning, and the matching rule inclaudeCredentialBridgeBroken.src/crux/agent/claude_credential_bridge_internal_test.go: new tests (below). The existing π [v6] claude auth: re-bridge per-agent credentials a token refresh replaced, and resume login-paused agents after sign-inΒ #17253 tests are unchanged.src/crux/claude/oauth_test.go: a recovery pin forWriteCredentials.src/docs/agent-configuration.md,changelog.d/fixed-claude-bridge-legacy-dirlink.md.Tests
None were run locally. The repo's AGENTS.md leaves that to CI; only
gofmt -lwas run.TestRepairClaudeCredentialBridge_LegacyDirLinkUsableSharedUntouched: old layout with a usable shared token. The repair returnserrClaudeBridgeLinkIsTarget, the shared file has the same inode and bytes, and there are no.stale-*files. On the tip, the shared file is renamed aside and rewritten (new inode, one stale file).TestRepairClaudeCredentialBridge_LegacyDirLinkTokenlessSharedNotSelfLinked: old layout with a token-less shared file. No symlink is created and the file stays a regular file. On the tip, this produces the self-loop.TestRepairClaudeCredentialBridges_LegacyDirLinkSurvivesWatchdogCyclesWarnsOnce: four watchdog passes. Nothing is re-bridged, the shared file is untouched, the warning is logged exactly once, and there is no "repair failed" line. On the tip, every pass adds a stale file.TestRepairClaudeCredentialBridge_RefusesLinkEqualToTarget: link == target is refused before anything is moved. On the tip, it renames the file and links it to itself.TestClaudeCredentialBridgeBroken_LegacyDirLinkIsNotBroken: false for the old layout (true on the tip), and still true for a real per-agent.claudeholding a private regular file.TestSetupInteractiveHome_LegacyDirLinkLaunchRetiresBeforeRebridge: pins the launch order described above. The shared file is untouched,.claudebecomes a real directory, and the credential link points at the shared file. This already passes on the tip; it guards the order.TestWriteCredentialsReplacesSelfAndDanglingSymlinks(crux/claude): pins how recovery works. A dashboard sign-in'sWriteCredentialsrenames over the path, which replaces a self-referencing or dangling symlink with a regular file holding the new tokens.Open question (out of scope)
Why did the refresh at about 19:08Z on 2026-11-09 leave a logged-out shared file? One possibility is refresh-token rotation between agents that share one file through the old layout. This PR changes no refresh handling.
Out of scope / follow-ups
subscriptionType..credentials.json.stale-*files. They are still never removed automatically.crux.Process, the dashboard status payload, the agent card JS and the API reference. For now, the hive log warning is the signal.Refs #17253
π€ Generated with Claude Code
https://claude.ai/code/session_01BQYnPGFJx81c8JXR3o1sg1