Skip to content

fix(models): Claude CLI models stay Sign-in needed after signing in until a Gateway restart - #197075

Merged
obviyus merged 1 commit into
mainfrom
fix/claude-cli-signin-after-gateway-start
Nov 11, 2026
Merged

obviyus merged 1 commit into
mainfrom
fix/claude-cli-signin-after-gateway-start

Conversation

@obviyus

@obviyus obviyus commented Nov 11, 2026 •

Copy link
Copy Markdown
Collaborator

Closes #196694
Related: #186358
Closes #191831

What Problem This Solves

Fixes: Claude CLI models stay "Sign-in needed" in /models and the Discord model picker, and /model rejects them, after you sign in to Claude Code, if the Gateway started while Claude Code was not signed in (or its first login check failed). Real turns through claude-cli worked, but these chat surfaces did not recover until a Gateway restart. The Control UI recovered or not depending on timing.

User Impact

User impact: signing in to Claude Code on the Gateway host now shows the Claude CLI models as available, and lets /model and the Discord picker select them, without restarting the Gateway. The first model list read after sign-in may still show the old state; the next read (or a direct /model) uses the new login.

Why This Change Was Made

  • The Gateway records Claude Code's login once at startup and is designed to recheck it after a minute while model lists are read (fix(models): recheck Claude CLI login for model lists after Gateway startup #166305, fix: recover Claude native login without Gateway restart #172471). That background recheck was started inside the plugin invocation scope of the request that triggered it. The claude auth status probe finishes after that request has replied and closed its scope, so publishing the result threw Plugin invocation scope is closed. The error was swallowed, so the stale "signed out" state stayed until restart. The recheck now runs in a detached async context (the same pattern the prepared-model-runtime refresh uses), and an unexpected failure is logged instead of hidden.
  • Only Gateway models.list (the Control UI) triggered that recheck. /models, the /model menu and the Discord picker read the same prepared data and never triggered it, so channel-only users could not recover even with a working recheck. They now trigger the same throttled recheck. /model selection awaits it, so a direct /model anthropic/... after sign-in works on the first try.
  • On main, recovery through the Control UI depended on timing: a models.list recheck published only if the probe finished before that request closed its scope. In my models.list-only base run it won that race and recovered. The failure shows up reliably when /models or /model triggers the recheck.
  • The probe cost limit is unchanged: at most one claude auth status per prepared catalog owner per minute, and only while pickers or selections are read.

Not changed: #196694 also suggests passing config into resolveCliRuntimeModelBackendBinding. On real Gateways the CLI backend binding was always present (instrumented binding={"provider":"anthropic","runtime":"claude-cli"} on every evaluation, including hot plugin enable and plugins.allow edits). That issue's failure is the same stale login state shown below, and it went away for the reporter after the Gateway restart. This PR leaves that binding call alone.

Evidence

Isolated Gateways (env -i, own state/config/profile/port), real Claude Code 2.1.322 with its real login. A PATH shim answers only claude auth status with loggedIn:false until a flag file is removed. Removing the flag stands in for claude auth login. Every other Claude call, including inference, goes to the real CLI. Commands go through Gateway chat.send (the auto-reply owner that channel commands use) and Gateway models.list (the Control UI picker data).

Step, after Claude Code sign-in (75 s+ wait) origin/main 63db5996 this branch
/models anthropic (1st read) Sign-in needed — Claude CLI · Claude Opus 5.5 same (this read starts the recheck)
/models anthropic (2nd read) still Sign-in needed, again after 3+ min anthropic/claude-opus-5-5 (Claude CLI · Claude Opus 5.5)
/model anthropic/claude-sonnet-5-5 A runtime is not available for anthropic/claude-sonnet-5-5: sign-in needed… Model set to anthropic/claude-sonnet-5-5 … Runtime set to claude-cli
direct /model anthropic/claude-opus-5-5 (no list read first) (same failure as above) Model set … Runtime set to claude-cli on the first try
Gateway models.list (Control UI picker data), models.list-only run recovered to available:true about 2 min after sign-in (its recheck finished while the request was open) available:true from the second read on
Gateway models.list after the /models and /model reads above still missing-auth (the recheck failed with the error below) available:true
real turn on the selected session n/a (selection rejected) CC10-AFTER-OK / CC10-DIRECT-OK via [agent/cli-backend] cli turn: provider=claude-cli
Gateway log on recheck Error: Plugin invocation scope is closed at prepareModelCatalogThinkingPolicies (instrumented; swallowed in production) none

Base instrumentation also showed the recheck probe returning status:"available" and computing {"claude-cli":{"source":"native","mode":"oauth"}}, then failing to publish. Readers kept authModes: {}.

Tests (red on base, green here):

  • src/agents/prepared-model-runtime.native-login.test.ts: a recheck whose plugin work finishes after the triggering read's invocation scope closes still publishes the login.
  • src/auto-reply/reply/commands-models.catalog-recovery.test.ts: /models and the Discord picker data (getModelsRuntimeChoices) recheck a later sign-in. Before the recheck the picker gets undefined choices, which is the "Could not confirm how to run this model" state with Submit disabled. After it, the choices include claude-cli.
  • src/agents/model-runtime-choice.test.ts: preparePublishedModelRuntimeChoice (/model, session model selection) rechecks before deciding.

Also ran 92 suites covering prepared-model-runtime, model-runtime-choice, /models commands, directive handling, gateway models.* methods, plugin-sdk model surfaces and the Discord model picker: all passed. node scripts/check-changed.mjs: format, line-cap, boundary, typecheck and changed-file guards passed. Two steps failed: lint core and the dead-export scan. Both report only files this PR does not touch. Running oxlint on the 6 changed files reports 0 warnings and 0 errors. The same lint core shard also exits 1 on an unmodified origin/main worktree at 63db5996.

Gaps: #186358 also reports that the Control UI composer's credential banner ignores the selected runtime choice. This PR does not change that check, so that issue stays open. Discord component clicks need a human Discord client, so I did not click through the picker. The picker's data owner (buildPreparedModelsProviderData) and its getModelsRuntimeChoices result are covered above. Control UI proof is the Gateway models.list response the picker renders. This is not a visual change.

Production +21/-2, tests +74 net, docs +3/-2.

@clawsweeper

clawsweeper Bot commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation agents Agent runtime and tooling extensions: anthropic size: S labels Nov 11, 2026
@github-actions

github-actions Bot commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

⚠️ Security sensitive changes

This maintainer PR changes sensitive security components.

No secops approval is required. This comment is informational because the PR author has Maintain or Admin access.

  • Current SHA: 8bd84bb181049f07d7c18e4a880c71183b94b14d
  • Maintainer: @obviyus
  • Repository role: admin

These security sensitive changes were made:

  • src/agents/prepared-model-runtime.catalog-auth.ts: Controls credential persistence, secret resolution, or redaction. Check storage permissions, credential scope, and exposure in logs or responses.

Carefully review these changes before merging.

@obviyus
obviyus force-pushed the fix/claude-cli-signin-after-gateway-start branch from 1f54c4c to 8bd84bb Compare November 11, 2026 06:31
@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. labels Nov 11, 2026
@clawsweeper

clawsweeper Bot commented Nov 11, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

This PR refreshes Claude CLI login availability after sign-in so model browsing and selection recover without restarting the Gateway.

Example: Sign in to Claude Code after Gateway startup, wait past the one-minute recheck window, then select anthropic/claude-sonnet-5-5.

  • Before: /model rejects the selection with “sign-in needed” despite working Claude CLI inference.
  • After: /model awaits the login recheck and selects the claude-cli runtime successfully.

Review scores

Measure Result What it means
Overall readiness 🦞 diamond lobster (5/6) A focused, owner-preserving repair with shipped Gateway behavior evidence, targeted regressions, and no actionable findings.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (live_output): The current PR records isolated real Gateways exercising chat.send commands and models.list with controlled signed-out status followed by real Claude Code login readiness, successful model selection, and real CLI inference; historical screenshots were not counted as current-head proof.
Patch quality 🦞 diamond lobster (5/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: Already authenticated Claude CLI users see stale sign-in prompts and cannot select models until restarting the Gateway.
Reason: The maintainer-authored repair restores documented native-login freshness without adding configuration, persistence, or another authentication owner.

Merge readiness

✅ Ready for maintainer review

Keep open: this PR repairs a current login-recovery failure using the existing catalog owner, with convincing Gateway traces and no actionable introduced defects found.

Priority: P2
Reviewed head: 8bd84bb181049f07d7c18e4a880c71183b94b14d

Before merge

None.

Findings

None.

Agent review details

How this fits together

Gateway and channel model controls consume prepared catalog and authentication facts; the catalog owner probes native CLI readiness and publishes updated availability for browsing and selection.

flowchart LR
  A[Model browsing] --> C[Prepared catalog owner]
  B[Model selection] --> C
  C --> D[Detached login recheck]
  D --> E[Claude auth status]
  E --> F[Publish current auth facts]
  F --> C
Loading

Technical review

Best possible solution:

Use the existing throttled catalog recheck independently of request lifetime, with background browsing and awaited selection recovery.

Do we have a high-confidence way to reproduce the issue?

The source exposes the inherited invocation-scope failure and missing caller hooks, corroborated by the author's base/candidate Gateway traces; this read-only review ran no target code.

Is this the best way to solve the issue?

This is a focused repair of the existing readiness owner: the closed request scope no longer owns background publication, and consumers request freshness without duplicating authentication policy.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 85e9a2f2071e.

Provenance checked

Testing

Proof path: shipped entry point.

Security

None.

Evidence

What I checked:

Likely related people:

  • Ayaan Zaidi: Raw commit f215c40 adds src/agents/prepared-model-runtime.catalog-auth.ts:471 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: f215c401e69a; files: src/agents/prepared-model-runtime.catalog-auth.ts)
  • Peter Steinberger: Raw commit 0a5311b adds src/agents/prepared-model-runtime.catalog-auth.ts:512 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 0a5311bc95c2; files: src/agents/prepared-model-runtime.catalog-auth.ts)

PR surface

Source +17, Tests +74, Docs +1, Other +2. Total +94 across 8 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 3 19 2 +17
Tests 3 76 2 +74
Docs 1 3 2 +1
Config 0 0 0 0
Generated 0 0 0 0
Other 1 2 0 +2
Total 8 100 6 +94

Preflight source

Source unknown. Source comparison at the observed PR snapshot only. Completion is self-reported; body, policy, tests, execution, and report bytes are not verified.

Review metrics

Metric Value Why it matters
Production versus regression coverage Production +19/-2; tests +76/-2 The small production change reuses existing owners; tests cover the closed-scope publication failure and distinct browsing and selection callers.

Labels

Label changes:

  • add P2: Incorrect native-login availability blocks model controls in affected sessions while Claude CLI inference remains usable.
  • add proof: sufficient: Contributor real behavior proof is sufficient.
  • add rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🦞 diamond lobster and patch quality is 🦞 diamond lobster.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.

Label justifications:

  • P2: Incorrect native-login availability blocks model controls in affected sessions while Claude CLI inference remains usable.
  • rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🦞 diamond lobster and patch quality is 🦞 diamond lobster.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.
  • proof: sufficient: Contributor real behavior proof is sufficient.

Rating scale

6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only. Repair and merge execution lanes are retired.

Reviewed November 11, 2026, 1:46 AM ET / 06:46 UTC.

@obviyus
obviyus merged commit 9a19582 into main Nov 11, 2026
132 checks passed
@obviyus
obviyus deleted the fix/claude-cli-signin-after-gateway-start branch November 11, 2026 06:50
@obviyus

obviyus commented Nov 11, 2026

Copy link
Copy Markdown
Collaborator Author

Merged via squash.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling docs Improvements or additions to documentation extensions: anthropic P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. security-sensitive-changed size: S status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

1 participant