Repository navigation
✨ [v6] claude auth: report long-lived-token vs dashboard-sign-in mode on auth status and surface 401 as token rejected - #17861
Conversation
… and surface 401 as token rejected Signed-off-by: scanner <280983584+hivecommons-hive[bot]@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 |
|
Hive status — updated in place; edits do not notify. Full history is in the Activity Monitor. hive/awaiting-ci: CI pending — sweep will merge when green. 🐝 Hive Agent: — hive: agent=scanner backend=copilot model=claude-fable-5.1 copilot=1.0.88 Review findings from docs-currency (read at head f01b915) The behavior changes land cleanly in
Minor: the token-mode pause body ( Review findings from Style/maintainability review at head 1. Two sources of truth for "long-lived-token mode" inside one code path. 2. Pause-notice remediation names only the env-var source. Minor: the hermetic operator-token test setup ( Review findings from Read the diff against the What I verified:
One observation, not a defect: in token mode Review findings from Style review (head 8e8f9b4) — approve with advisory Clean structure:
Review findings from Read the tree at What I verified
One note, not a defect — |
Open PR overlap checkBase branch: Conflicts are checked with every PR merged onto the current tip of No conflicting open PRs or same-file overlaps were found. |
There was a problem hiding this comment.
Read the v6 tree at 4e6b6cc including every caller of AgentHasValidCredential. This looks correct to me, and the behaviour in operator-token mode is coherent end to end:
- A login prompt on the long-lived token is no longer "healed" by a pointless restart.
AgentHasValidCredentialreturns false for claude in operator mode (src/crux/agent/authprobe.go:453), so the token-restart theory inmanager_poll.go:175is not entered,loginscan.Scan(loginscan.go:304,329) pauses the agent with thePauseNoticetoken-rejected title/body/hint instead of the/logintext, and the fleet watchdog'scredentialProven(watchdog_fleet.go:147) stays false so the reconciler pages an operator. The three consumers agree; none is left pointing at/login. - Start-failure reason is rewritten only on the exact class.
recordStartFailureLocked(start_failure.go:275) swaps the message forStartFailureLoginRequired && backend=="claude"only, keeping the detail suffix; other classes and backends are unchanged. - Rotation prober fails open rather than reading as a logout.
ClaudeProber.Probe(rotation.go:391-397) returnsfailOpen(Available: true,rotation.go:327), so no strand/rotation is triggered off the unused credentials file. - Status surfaces leak no token material.
/api/claude-auth/statusadds onlymode(dashboard/claude_auth.go), computed fromclaude.AuthMode()which returns a fixed label; the admin MCPclaude_auth_statustool is registered in the read-only set and the no-argument schema group (adminmcp.go:478) and proxies that endpoint.
Minor, not a finding: claude.OperatorToken() is re-evaluated per call here (env, then the token file) whereas the Manager reads it once at construction (manager.go:925). They can only disagree if the operator edits the token file mid-run, in which case the status endpoint would report "long-lived token" while running agents still hold the old value until restart — the notice body already tells the operator to restart the hive, so this is fine as is.
— hive: agent=reviewer-2 backend=copilot model=claude-fable-5.1 copilot=1.0.88
Mutation testingHead ❌ gremlins did not produce a report for 1 package(s), so no verdict can be derived from this run (see the job log):
Verdict: |
There was a problem hiding this comment.
Read against the v6 tree, including the consumers of AgentHasValidCredential. The change does what the body says and the three surfaces agree; looks correct to me. Two small notes, neither a defect.
Verified
Manager.claudeOperatorTokenis read once at construction (src/crux/agent/manager.go:612), so the newauthprobe.gocheck is stable for the process lifetime, matching howclaudeOperatorTokenMode()is already used incredentials_watchdog.go:270andclaude_credential_bridge.go:547.- Returning
falsefromAgentHasValidCredentialin token mode produces the intended routing at every caller:pkg/loginscan/loginscan.go:281→Verdict(...)lands onActionPauserather thanActionDeferAuthenticated, so the newPauseNoticewording reaches the operator;crux/agent/manager_poll.go:175skips the token-restart heal;crux/agent/watchdog_fleet.go:147setscredentialProven=false, so the fleet reconciler pages instead of staying silent. That is exactly the "heal would swallow the rejection" case the body describes. failOpen(pkg/rotation/rotation.go:327) already setsAvailable: truewithProbeErrCause, so the early return keeps the prober's existing degraded shape; the test asserts none of the watchdog's logout markers are in the message.pkg/dashboard/claude_auth.goalready importscrux/claude, and the JS consumers oflogged_in(core.js:43,tooltips-dialogs.js:930) only read the boolean, so the addedmodekey is additive.
Notes (info)
src/pkg/dashboard/claude_auth.go(newhandleClaudeAuthStatus): in long-lived-token modelogged_inistruewhenever a token is configured, not when it is accepted.tooltips-dialogs.js:931will therefore renderstate: 'ok'while Claude is answering 401 to that token; the rejection is only visible via the pause notice / start-failure reason this PR adds. That is a reasonable reading of "logged in" for an inference-only token the hive cannot probe, but theapi-reference.mdtext might say so explicitly ("configured", not "validated") so an operator does not readlogged_in: trueas a liveness check.src/crux/agent/authprobe.goandstart_failure.gocomparem.claudeOperatorToken != ""directly; the package already hasm.claudeOperatorTokenMode()(crux/agent/claude_operator_token_mode.go:24) for the same predicate. Using the helper would keep one definition of the mode.
— hive: agent=reviewer-2 backend=copilot model=claude-fable-5.1 copilot=1.0.88
|
Supersession sweep found that this PR's claimed issue is already closed by another merged PR.
Keeping this hive-authored PR open: with head b36d9d7 current with This comment is edited in place by the supersession sweep; it is not duplicated. |
There was a problem hiding this comment.
Read the Go changes against the v6 tree (a222a3e), including the surrounding code each hunk lands in. Looks correct to me, and I checked specifically that no token material can leave the process through the new surfaces.
What I verified:
claude.AuthMode()(crux/claude/operator_token.go) only testsOperatorToken() != ""; the string it returns is one of two fixed constants.handleClaudeAuthStatus(pkg/dashboard/claude_auth.go) emits{logged_in, mode}and nothing else, so exposing it through the read-only admin MCP toolclaude_auth_statusdoes not widen what the MCP can see. The tool is added to the read-only case list and the no-argsinputSchemacase inpkg/adminmcp/adminmcp.go, matchingToolLogSources.start_failure.gousesm.claudeOperatorToken != "", which is exactly the predicateManager.claudeOperatorTokenMode()already defines (crux/agent/claude_operator_token_mode.go:24), and that field is read once at construction, so the "token rejected" reason is consistent with the mode the credential bridge and watchdog already suspend on.loginscan.PauseNoticefactors the existing title/body out unchanged for the non-token case (compared against the removednotifier.Sendblock) and only diverges forbackend == "claude" && longLivedToken.rotation.go: the earlyfailOpensits before the credentials-file read inClaudeProber.Probe, andfailOpen/Provider()exist atrotation.go:327and:388; a long-lived token genuinely has no usage scope, so "unknown headroom, not a logout" is the right classification.
One observation, not a defect: in long-lived-token mode logged_in is true whenever the token is configured, independent of whether Claude currently accepts it. Rejection is surfaced through the start-failure reason and the pause notice instead. That split seems intentional per the body ("mode", not health), but a dashboard reader may expect logged_in to flip on a 401; worth a sentence in backend-auth-recovery-runbook.md if it is not already there.
Style nit only: start_failure.go could call m.claudeOperatorTokenMode() instead of re-spelling the comparison.
— hive: agent=reviewer-2 backend=copilot model=claude-fable-5.1 copilot=1.0.88
There was a problem hiding this comment.
Read against the v6 tree (merge-base a222a3e); looks correct to me, and I found no path by which token material reaches a surface.
What I verified:
crux/claude/operator_token.go:56-61—AuthMode()returns one of two fixed strings and never the token.pkg/dashboard/claude_auth.go:64-68returns only{logged_in, mode}; the admin MCP tool is a pure read of that route (adminmcp.go:801-802, argument-free schema at:478, listed inAllowedToolat:409).crux/agent/authprobe.go:453-455— returningfalsefor a claude agent in token mode is the right sign for both callers:loginscan.go:304-312then takes the pause branch instead ofActionDeferAuthenticated(which would hand a rejected token to the token-restart heal, as the body says), andwatchdog_fleet.go:147setscredentialProven=falseso the reconciler pages rather than stays silent. Non-claude backends are untouched by thebackend == "claude"guard.loginscan.go:46-61PauseNoticeandstart_failure.go:274-281both emitclaude.TokenRejectedMessageonly whenbackend == "claude"and the token is set; the default wording is byte-identical to whatScanproduced before (loginscan.go:341-349pre-change).rotation.go:391-397— the fail-open error text contains none of the watchdog auth markers, so the usage probe can't masquerade as a logout.
One observation, not a defect: rotation.go:395 and loginscan.go:329 call claude.OperatorToken() per tick, which falls through to an os.ReadFile of /secrets/claude-oauth-token whenever the env var is unset (operator_token.go:33-39). The Manager read the token once at construction (#17762); these two re-read it each cycle. Harmless at these tick rates, but if you want consistency, Manager could expose claudeOperatorTokenMode() to both.
— hive: agent=reviewer backend=copilot model=claude-fable-5.1 copilot=1.0.88
…ken sources, mirror docs Review fixes for #17861: - Scan took the Claude auth mode from a live claude.OperatorToken() read while AgentHasValidCredential used the Manager's construction-time snapshot, so a token file removed or rotated at runtime could yield a verdict from one mode and a notice from the other. Manager now exports ClaudeLongLivedToken() and Scan prefers it through the optional loginscan.ClaudeAuthModeReporter interface, falling back to claude.AuthMode() for runtimes that cannot say. The two new in-package checks route through claudeOperatorTokenMode() and rotation.go through claude.AuthMode(), so no caller compares the raw token any more. - The token-mode pause body named only HIVE_CLAUDE_OAUTH_TOKEN; it now names the _FILE source too and points at the runbook's "Replace a Claude operator token" section. - notifications.md and troubleshooting.md document the "Claude token rejected: <agent>" variant; api-reference/auth.md mirrors the index row for GET /api/claude-auth/status. - The hermetic operator-token test setup, duplicated across four test files, lives once in crux/claude/claudetest.SetOperatorToken. Hive-Fix-Attempt: 1/6 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Signed-off-by: scanner <280983584+hivecommons-hive[bot]@users.noreply.github.com>
There was a problem hiding this comment.
Correctness re-review of the delta f01b915…9bcec8c — all seven findings from the previous head are fixed (notifications.md row, troubleshooting.md paragraph, api-reference/auth.md row, _FILE source named in PauseNotice body at src/pkg/loginscan/loginscan.go:49-52, mode now sourced from the manager via ClaudeAuthModeReporter at loginscan.go:238-254, helper deduplicated into claudetest.SetOperatorToken). The manager-sourced mode is sound for the in-process runtime: cruxruntime.New returns the *agent.Manager unwrapped (src/cmd/hive/agent_runtime.go:29-38), so the type assertion at loginscan.go:250 succeeds; only the sidecar host falls back to the live claude.AuthMode() read.
One new in-scope issue introduced by the delta:
crux/claude/claudetest has no test files, so the coverage gate fails — src/crux/claude/claudetest/ contains only claudetest.go at this head. The per-package gate in .github/workflows/v2-tests.yml:2460-2466 marks any non-exempt package with no _test.go as BROKEN: NO TEST FILES, and the coverage check on this head fails with exactly crux/claude/claudetest: NO TEST FILES (run 43179121397). Fix: add src/crux/claude/claudetest/claudetest_test.go that calls SetOperatorToken(t, "")/SetOperatorToken(t, "sk-…") and asserts claude.OperatorToken() returns exactly the given value with the env/_FILE/default-file sources each pinned — that both satisfies the gate and pins the "one place that knows the full list of sources" promise in the package doc.
— hive: agent=adjudicator backend=copilot model=claude-fable-5.1 copilot=1.0.88
…iles The per-package coverage gate rejects a package with no test files (crux/claude/claudetest: NO TEST FILES). The test also proves the helper pins every token source and restores them. Hive-Fix-Attempt: 1/6 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Signed-off-by: scanner <280983584+hivecommons-hive[bot]@users.noreply.github.com>
There was a problem hiding this comment.
The code reads correct to me; the one thing blocking it is the red coverage check, and that is caused by this diff.
src/crux/claude/claudetest/claudetest.go is a new package with no _test.go. The per-package gate in .github/workflows/v2-tests.yml:2466 hard-fails any package go test -cover reports as [no test files] (the only exemption list, UNTESTED_CMD_MAINS, is for thin cmd/ mains and is empty). The coverage job log ends with exactly that:
COVERAGE GATE FAILED:
crux/claude/claudetest: NO TEST FILES
src/crux/claude/auth_mode_test.go and src/crux/agent/claude_operator_token_test.go do exercise SetOperatorToken, but from other packages, which doesn't count toward claudetest's own score. The fix is small: add src/crux/claude/claudetest/claudetest_test.go asserting that SetOperatorToken(t, "x") makes claude.OperatorToken() return "x" and SetOperatorToken(t, "") makes it return "" with claude.OperatorTokenFile pointing at a missing path. Same shape src/crux/cruxtest/recorder_test.go uses for that helper package.
What I verified in the tree, for the record:
AgentHasValidCredentialreturningfalsein token mode (src/crux/agent/authprobe.go:453) is safe for all three callers:manager_poll.go:175skips the token-restart heal (intended),loginscan.go:324lets the streak reachActionPause(intended), andwatchdog_fleet.go:147feedsCredentialProven, whichcrux/watchdog/classify.go:84-88documents as positive-evidence-only —falsecan only soften a verdict, never page.- The new
ClaudeProber.Probeerror text (src/pkg/rotation/rotation.go:394) contains none of the eightauthErrorMarkersinsrc/crux/watchdog/rotation_probe.go:39-48, so it classifies asAuthUnknown, notAuthFailed, as the body says. claude_auth.go:65-66short-circuits the credentials-file read in token mode, somodeandlogged_incarry no token material; the MCP tool is a pureReadPathwrapper (adminmcp.go:801).
One note, not a defect: loginscan.go:375 still passes "login required detected" as the Pause reason in token mode, so the dashboard pause reason will say "login required" while the notification says "token rejected". The body doesn't claim to change the pause reason, so I'm only flagging it as a possible follow-up.
— hive: agent=reviewer-2 backend=copilot model=claude-fable-5.1 copilot=1.0.88
There was a problem hiding this comment.
Read the diff against the v6 tree and the callers; this looks correct to me.
What I verified:
crux/watchdog/rotation_probe.go:39-48— the new fail-open error inpkg/rotation/rotation.go:393-399(claude usage unknown: agents run on the long-lived token…) contains none of theauthErrorMarkers, soProbeAuthreturnsAuthUnknown, notAuthFailed. The "can't loop or page as a logout" claim holds.crux/agent/authprobe.go:450-455— the three callers ofAgentHasValidCredential(manager_poll.go:175restart heal,watchdog_fleet.go:147credentialProven,loginscan.go:324) all read the newfalsethe intended way: the heal no longer swallows the 401, and loginscan reachesActionPausewith the token-rejected notice.pkg/loginscan/loginscan.go:249-254— in-process*agent.ManagersatisfiesClaudeAuthModeReporterand answers from the construction-time snapshot (manager.go:925), the same oneAgentHasValidCredentialandrecordStartFailureLockeduse; the liveclaude.AuthMode()read is only the remote-runtime fallback. Verdict and notice come from one source, as the comment says.pkg/dashboard/claude_auth.go:63-68andpkg/adminmcp/adminmcp.go:801-802— status payload is{logged_in, mode}only; nothing in the diff writes the token value anywhere, and the sentinel test covers API, MCP and log output.
One observation, not a defect: in long-lived-token mode logged_in is true whenever a token is configured (claude_auth.go:66), independent of whether Claude currently accepts it. A rejected token therefore still reads logged_in: true, mode: long-lived token, with the rejection surfacing only via the pause notice / start-failure reason. That matches the PR body's stated scope ("see which auth mode is live"), so I'm flagging it only so the docs wording isn't read as a liveness check.
#17890 is the v5 twin of this change (different base); not a duplicate.
— hive: agent=reviewer-2 backend=copilot model=claude-fable-5.1 copilot=1.0.88
|
Thank you for your contribution! Your PR has been merged. We'd love to hear how your experience was: share feedback |
Refs #17759 (closed by #17841; this PR adds
changelog.d/added-claude-auth-mode-status.md,src/crux/agent/authprobe.go,src/crux/agent/claude_operator_token_test.go,src/crux/agent/start_failure.go,src/crux/agent/start_failure_test.goand 13 more)Part of #17753 (child 3 of 4)
Why
Operators running Claude agents on the long-lived
claude setup-tokentoken (#17762) need to see which auth mode is live without the token leaking anywhere. They also need a rejected inference-only token to be reported as a rejected token. Today it looks like a logout and tells them to run/login, which cannot fix it.What
GET /api/claude-auth/statusnow returnsmode(long-lived tokenordashboard sign-in) alongsidelogged_in. The new read-only admin MCP toolclaude_auth_statuswraps the same route, so the dashboard and MCP report the same mode. Neither returns token material. Detection reusesclaude.OperatorToken()from ✨ claude auth: run Claude agents on an operator-supplied long-lived token (HIVE_CLAUDE_OAUTH_TOKEN) #17762 through a newclaude.AuthMode(). ✨ claude auth: run Claude agents on an operator-supplied long-lived token (HIVE_CLAUDE_OAUTH_TOKEN) #17762 added no set-token control, so this PR adds none to MCP either.Claude token rejected: generate a new one with claude setup-token;login-requiredstart failure records the same reason.AgentHasValidCredentialno longer treats a fresh dashboard credentials file as proof for a claude agent, because the agent doesn't use that file. Without this change, the token-restart heal would swallow the rejection.FetchProfile.ClaudeProber.Probe(usage/headroom) now fails open with a neutral "unknown" error in this mode. That error contains none of the watchdog auth markers, so it can't loop or page as a logout.agent-configuration.md, the auth recovery runbook,api-reference.md,admin-mcp.mdanddesign/admin-mcp.md. The design doc notes that the status route is the one in-scopeclaude-authroute. Added a changelog fragment.Tests
— hive: agent=scanner backend=copilot model=claude-fable-5.1 copilot=1.0.88 requested_by=@Danathar