Skip to content

fix: large agent rosters repeat Claude login checks during startup - #139757

Merged
steipete merged 2 commits into
mainfrom
fix/prepared-runtime-publication
Sep 6, 2026
Merged

steipete merged 2 commits into
mainfrom
fix/prepared-runtime-publication

Conversation

@steipete

@steipete steipete commented Sep 6, 2026 •

Copy link
Copy Markdown
Contributor

Related: #139583. Reported by @609NFT.

What Problem This Solves

Fixes an issue where a Gateway with a large agent roster fails startup with a prepared model runtime publication timeout while the main process appears idle. The reproduction uses 632 distinct workspaces and a synthetic Claude CLI whose native-login status check takes 250 ms; no real accounts or credentials are involved.

Why This Change Was Made

The 9.2 asynchronous native-login change (#137071, 2640154) removed the Anthropic plugin's config-wide availability observation. The generic preparation cache correctly separates workspace generations, so static startup repeated the same native-login subprocess for each workspace, sequentially. The reproduced idle interval contains continuing subprocess probes, not a lost wake-up.

The Anthropic discovery owner now shares one observation for an exact config, environment, and capture signal. Runtime registration uses that same hook. A fresh capture rechecks native availability, and cancellation remains isolated. Generic workspace/plugin auth scopes and existing bounded catalog concurrency remain unchanged. Native-login work is constant per observation; iterating the roster remains linear.

Publication timeout diagnostics now name the pending stage and workspace agent. Completion still tracks the actual build after a deadline, preventing replacement work from overlapping a timed-out generation. The timeout helper removes unreachable abort-state handling while the publication wrapper removes an intermediate promise container.

User Impact

Large rosters no longer spend their startup budget repeating one host's Claude login check. A remaining publication stall identifies the pending preparation stage. The separate costs in plugin registration, schema preflight, and Control UI asset retention are outside this repair.

Evidence

Paired installed-package proof on Blacksmith Testbox tbx_01m1th03eya2s4f285g624eh6p, run 34012614304, lease stopped. Both packages ran on Node 24.19.0 with 4 reported CPUs, the same isolated synthetic state, 632 distinct agents/workspaces, and the same 250 ms claude auth status --json fixture returning loggedIn: false. The expected first-boot plugin convergence barrier was completed before measuring. Candidate used the canonical build/package command and was installed through npm into a separate prefix.

Observation Published 2026.9.2 Installed candidate
Native-login subprocesses 414 1
Model-runtime publication 138.156 s, timed out 21.5104 s, completed
Gateway ready No 88.903 s
Health probe 200 while publication remained pending 200 after ready
Process result Startup failure, exit 1 Clean shutdown, exit 0
Sampled peak RSS 1,586.18 MiB 1,889.31 MiB

The candidate peak includes successful post-ready initialization, which the failing baseline never reached; ready RSS was 1,667.5 MiB. These measurements establish startup recovery, not a memory-reduction claim.

Live-proof transcript (synthetic data only):

source: 1783a5839d1c60f152355a29a87d09e51fd24f97
materialized source tree: 3a0346d84a7a654329b4eb7e9e6143e4ab16b391
installed build-info commit: 1783a5839d1c60f152355a29a87d09e51fd24f97
candidate tarball SHA256: 116fa75f00123a59faa37bff9dca7a7046baed54a61e25c087807c74e60eed59
before: agents=632 workspaces=632 probes=414 publicationMs=138156
before: prepared model runtime publication timed out; ready=false; exit=1
after: agents=632 workspaces=632 probes=1 publicationMs=21510.4
after: ready=true health=200 timeout=false; clean exit=0
SUITE pass=true

The later commit 8cb178e88f6e25a3614285c99ffe850078a2a1ab changes only regression-test lint; all production bytes match the paired package proof. Final-head verification passed on Blacksmith Testbox tbx_01m1tj6k87c86sm6d6ewxs0hgm, run 34013469101, lease stopped. The exact-head build, canonical package check, npm installation, focused extension lint, and 632-agent startup all passed: publication 21.8909 s, one probe, ready at 90.786 s, HTTP 200, clean exit 0, sampled peak RSS 1,661.27 MiB. Materialized tree: 03a19a90417b898f15bde5be054b901f0c85f4f6. Installed build-info commit: 8cb178e88f6e25a3614285c99ffe850078a2a1ab. Candidate tarball SHA256: 9fe3e87b3eee27fdfa3edc9c738ab86705a137d6463ff32eae8dc0fe3d8cad71. All three task-owned proof leases are stopped.

Validation:

  • The 632-workspace owner regression under fake timers failed before the fix: only one preparation completed after 250 ms. Afterward all 632 complete with one probe.
  • Focused Anthropic, generic synthetic-auth scope, publication lifecycle, supersession, cancellation, and timeout-stage tests pass. The test-only lint repair retains all five new regression cases.
  • Local changed-file checks passed types, dead exports, core lint, and the remaining architecture guards. Local extension lint encountered an ancestor dependency outside the worktree; the same focused extension-lint gate passed on the flat final-head Testbox checkout.
  • Independent local and branch autoreviews found no actionable P0/P1 defects. CI first exposed three test-only lint errors, now fixed. Main's unrelated projection-fixture mismatch was repaired in fix(gateway): align history test fixture with projection state #139794. A refreshed merge snapshot (75ebc4a5b25a9842f94ea7a3ddc86192551dfe56) includes that repair; exact-head CI run 34015360518 and required openclaw/ci-gate passed on 8cb178e88f6e25a3614285c99ffe850078a2a1ab.
  • git diff --numstat: production 70 added / 73 removed (net -3); tests 133 added / 6 removed (net +127); docs 17 added / 0 removed.

The reproduction uses synthetic state shaped like the reported roster, not the reporter's private state. It establishes repeated native-login discovery as a concrete 9.2 regression; it does not claim a permanently unresolved promise was observed. ClawSweeper's requested packaged timing and RSS evidence is supplied above; no source findings were raised.

NO-FOLLOW-UP: This repair already consolidates the duplicated Anthropic hooks; the remaining cache dimensions protect distinct ownership boundaries.

Avoid repeating Claude CLI availability probes for each workspace during prepared model runtime publication. Keep config, environment, and cancellation ownership explicit and use one discovery hook for runtime registration. Name the pending stage in publication timeout diagnostics while retaining actual-build serialization.

Reported by @609NFT in #139583. Synthetic 632-workspace regression fails before the fix and passes with one native-login probe.
@clawsweeper

clawsweeper Bot commented Sep 6, 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 gateway Gateway runtime agents Agent runtime and tooling extensions: anthropic size: M maintainer Maintainer-authored PR labels Sep 6, 2026
@steipete
steipete marked this pull request as ready for review September 6, 2026 04:56
@clawsweeper clawsweeper Bot added P1 High-priority user-facing bug, regression, or broken workflow. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Sep 6, 2026
@clawsweeper

clawsweeper Bot commented Sep 6, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed September 6, 2026, 2:19 AM ET / 06:19 UTC.

ClawSweeper review

What this changes

Shares Claude login availability checks across agent workspaces and adds the pending preparation stage to startup timeout messages.

Regression provenance

Possible regression — probable (reviewed change; failure trace). No predecessor PR is attributed.

Merge readiness

✅ Ready for maintainer review

This remains a useful, well-supported startup repair: current main still repeats the login check, and the installed-package evidence demonstrates recovery. No actionable correctness or security finding remains.

Priority: P1
Reviewed head: 8cb178e88f6e25a3614285c99ffe850078a2a1ab

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused owner-level repair with strong packaged startup evidence and no actionable findings.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (terminal): Supplied paired installed-package traces exercise Gateway startup through Anthropic's real subprocess probe boundary with a slow synthetic Claude executable; the final head publishes all 632 workspaces with one probe and reaches ready before clean shutdown.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (terminal): Supplied paired installed-package traces exercise Gateway startup through Anthropic's real subprocess probe boundary with a slow synthetic Claude executable; the final head publishes all 632 workspaces with one probe and reaches ready before clean shutdown.
Evidence reviewed 8 items Current main still needs the repair: Fetched main's discovery hook invokes the native login probe on every preparation; it has no provider-local observation cache.
Latest release comparison: The supplied latest-release commit also contains the uncached probe. The requested repair is therefore absent from both inspected main and v2026.9.2.
Provider-owned observation and cancellation: The introduced cache keys observations by config, environment, and capture signal, checks cancellation before and after awaiting, and returns only the existing non-secret route marker. Runtime registration reuses this hook; the generic workspace-scoped preparation contract remains unchanged.
Findings None None.
Security None None.

How this fits together

Gateway startup prepares model availability for each configured agent workspace. The Anthropic plugin checks the host's Claude login, and those results feed model publication before the Gateway becomes ready.

flowchart TD
  A[Agent roster and environment] --> B[Workspace preparation]
  B --> C[Shared Claude availability observation]
  C --> D[Claude login status subprocess]
  D --> E[Model runtime publication]
  E --> F[Gateway ready]
  B --> G[Stage-aware timeout]
  E --> G
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source -3, Tests +127, Docs +17. Total +141 across 11 files.

View PR surface stats
Area Files Added Removed Net
Source 5 70 73 -3
Tests 4 133 6 +127
Docs 2 17 0 +17
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 11 220 79 +141

Review metrics

Metric Value Why it matters
Packaged startup recovery 632 workspaces: 414 probes and timeout → 1 probe and successful publication The paired installed-package measurements directly exercise the startup bottleneck this repair targets.

Root-cause cluster

Relationship: fixed_by_candidate
Canonical: #139583
Summary: This PR is a demonstrated candidate repair for the linked startup timeout mechanism; separate startup costs remain outside its scope.

Members:

Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything.

Technical review

Best possible solution:

Keep native-login observation sharing in the Anthropic owner while preserving fresh capture generations, cancellation isolation, and actual-build serialization.

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

Yes: current source repeats the host login probe across sequential workspace preparation, and the supplied installed-release transcript demonstrates the resulting timeout. This read-only review did not execute a current-main reproduction.

Is this the best way to solve the issue?

Yes: provider-local sharing removes repeated host work without weakening generic workspace ownership, increasing deadlines, or adding configuration.

AGENTS.md: found and applied where relevant.

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

Labels

Label justifications:

  • P1: The linked release regression prevents a real user's large agent roster from completing Gateway startup.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🦞 diamond lobster and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (terminal): Supplied paired installed-package traces exercise Gateway startup through Anthropic's real subprocess probe boundary with a slow synthetic Claude executable; the final head publishes all 632 workspaces with one probe and reaches ready before clean shutdown.
  • proof: sufficient: Contributor real behavior proof is sufficient. Supplied paired installed-package traces exercise Gateway startup through Anthropic's real subprocess probe boundary with a slow synthetic Claude executable; the final head publishes all 632 workspaces with one probe and reaches ready before clean shutdown.

Evidence

What I checked:

  • Current main still needs the repair: Fetched main's discovery hook invokes the native login probe on every preparation; it has no provider-local observation cache. (extensions/anthropic/provider-discovery.ts:17, e19a7694cef6)
  • Latest release comparison: The supplied latest-release commit also contains the uncached probe. The requested repair is therefore absent from both inspected main and v2026.9.2. (extensions/anthropic/provider-discovery.ts:17, 3928bad9badf)
  • Provider-owned observation and cancellation: The introduced cache keys observations by config, environment, and capture signal, checks cancellation before and after awaiting, and returns only the existing non-secret route marker. Runtime registration reuses this hook; the generic workspace-scoped preparation contract remains unchanged. (extensions/anthropic/provider-discovery.ts:18, 8cb178e88f6e)
  • Fresh capture ownership: Catalog requests create a new AbortController before capturing auth facts. The auth-warm owner likewise creates a fresh combined signal per warm generation and shares it across that generation's workspaces. These callers support the cache's freshness boundary. (src/agents/prepared-model-catalog-worker.ts:284, 8cb178e88f6e)
  • Actual-build serialization retained: Completion follows the actual build promise even when the caller's timeout fires; replacements wait for that completion and revalidate their lifetime before starting. The dynamic label reports the stage at the deadline. (src/agents/prepared-model-runtime.build.ts:697, 8cb178e88f6e)
  • Installed-package startup proof: The captured PR body records paired npm-installed runs with 632 workspaces and a real subprocess fixture taking 250 ms: v2026.9.2 made 414 probes and failed publication after 138.156 seconds; the candidate made one probe and completed publication in 21.5104 seconds. Final-head run https://github.com/openclaw/openclaw/actions/runs/34013469101 records one probe, publication in 21.8909 seconds, readiness, HTTP 200, and clean shutdown. This proves the changed startup path using synthetic state, without claiming reproduction of every cost in the reporter's private setup. Supplied context sourceRevision: 2d5fc8fc0c5cf45242b197f438b8733423797a0d561b555db32359329b424da7. (8cb178e88f6e)

Likely related people:

  • steipete: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • Ayaan Zaidi: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

History

Review history (4 earlier review cycles)
  • reviewed 2026-09-06T05:01:57.727Z sha 1783a58 :: blocked before merge. :: none
  • reviewed 2026-09-06T05:40:52.692Z sha 8cb178e :: needs maintainer review before merge. :: none
  • reviewed 2026-09-06T05:55:58.786Z sha 8cb178e :: needs maintainer review before merge. :: none
  • reviewed 2026-09-06T06:07:20.988Z sha 8cb178e :: needs maintainer review before merge. :: none

@steipete
steipete marked this pull request as draft September 6, 2026 05:48
@steipete
steipete marked this pull request as ready for review September 6, 2026 05:48
@steipete steipete closed this Sep 6, 2026
@steipete steipete reopened this Sep 6, 2026
@steipete
steipete merged commit d40d26a into main Sep 6, 2026
562 of 575 checks passed
@steipete
steipete deleted the fix/prepared-runtime-publication branch September 6, 2026 06:20
@steipete

steipete commented Sep 6, 2026

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 7, 2026
…penclaw#139757)

* fix: share native login discovery across agent workspaces

Avoid repeating Claude CLI availability probes for each workspace during prepared model runtime publication. Keep config, environment, and cancellation ownership explicit and use one discovery hook for runtime registration. Name the pending stage in publication timeout diagnostics while retaining actual-build serialization.

Reported by @609NFT in openclaw#139583. Synthetic 632-workspace regression fails before the fix and passes with one native-login probe.

* test: satisfy native login regression lint checks
obviyus added a commit that referenced this pull request Oct 6, 2026
…tartup (#166305)

## What Problem This Solves

Fixes: Claude CLI models stay hidden or disabled in the Control UI model picker and `openclaw models list` when Claude Code was logged out at Gateway start and the user logs in afterwards; only a Gateway restart or `models.list {refresh: true}` fixed it. A logout after startup was never reflected either.

## User Impact

User impact: after `claude auth login` (or a logout), the picker shows the right Claude CLI models within about a minute, without restarting the Gateway or reloading the page. How a logged-out Claude is displayed is unchanged.

## Why This Change Was Made

- The picker's availability filter already counts Claude Code's own login: `evaluateCliRuntimeModelAuthAvailability` reads the `claude-cli` auth mode from the `claude auth status --json` probe in `extensions/anthropic/provider-discovery.ts`.
- #129346 (fee4e77) made that probe run once per config generation so that "repeated model-list requests do not repeatedly launch the Claude CLI". #139757 (d40d26a) shared it across agent workspaces after 632-agent rosters timed out at startup, and documented that "explicit catalog/auth captures recheck availability".
- Nothing on the ordinary-read path rechecked it: `refreshExpiredModelCatalog` only renews providers with an inventory `expiresAt`, and the static `claude-cli` provider never gets one. So the startup result stayed for the whole generation.

The existing ordinary-read renewal hook now also rechecks CLI-backend native logins (CLI backends whose manifest declares `syntheticAuthRefs`, which today means `claude-cli`). The recheck runs in the background, deduplicates through the worker's existing `loadAuth`, and publishes a new catalog through the existing native-publication path only when the login state changed. The explicit `loadAuth` refresh and the recheck share one scoped-auth merge in `prepared-model-runtime.catalog-auth.ts`; `loadAuth` still returns only `{ authStore, authModes }`. Startup still probes once per shared generation, so both earlier PRs' cost limits hold.

## Bounded cost

- At most one `claude auth status --json` (existing 3 s timeout, process-tree kill) per prepared catalog owner per 60 s, and only while model lists are being read. An idle Gateway spawns nothing.
- Picker opens inside the window spawn nothing; concurrent reads share one in-flight probe.
- Nothing is published, and no catalog event is emitted, when the login state is unchanged.
- Measured on an isolated Gateway (below): 40 picker opens in 59 s started 1 probe; 14 opens during a 60 s login wait started 1 probe; probes were always at least 60 s apart.

## Evidence

**Regression test.** `src/gateway/server.chat-cli-auth.test.ts` adds "publishes Claude login changes after Gateway startup". It runs the real in-process Gateway, the real Anthropic plugin and `models.list`; only the `claude` executable is a fixture, and it records each `auth status` probe. It checks that the model is unavailable at startup, that a login inside the recheck window spawns no probe, that the model becomes available after the window with exactly one more probe, and that a logout makes it unavailable again with exactly one more probe. Each transition awaits the catalog publication rather than polling. With origin/main's catalog code the login publication never arrives and the test times out at 90 s; on this branch it passes in about 5 s. The full file (7 tests), the prepared-runtime suites that share its test harness, and `node scripts/check-changed.mjs` pass on this branch.

**Live Control UI, before and after.** Two isolated Gateways on one Mac, origin/main and this branch. State, config, `HOME` and `CLAUDE_CONFIG_DIR` were under /tmp, there was no Anthropic API key, and the config was shaped like our setup. Each used the real `claude` binary behind a wrapper that only counts `auth status` calls. Both started logged out. The login happened afterwards, by placing a Claude credentials file in each isolated `CLAUDE_CONFIG_DIR`. The picker was reopened in place and the page was never reloaded.

| | origin/main | this branch |
|---|---|---|
| Before login | ![origin/main before login: Anthropic shows 2 disabled rows](https://github.com/user-attachments/assets/416d0116-9aa1-4344-8127-123100a204b3) | ![branch before login: Anthropic shows 2 disabled rows](https://github.com/user-attachments/assets/aebe7782-7b11-495c-933c-2fc87bde3485) |
| After login | ![origin/main 3 minutes after login: still 2 disabled rows](https://github.com/user-attachments/assets/2c6ab23c-77b2-4240-a1f1-df5f398d6802) | ![branch after login: Anthropic shows all 6 configured models, enabled](https://github.com/user-attachments/assets/9e8413d2-abc0-4934-8dbd-8b6bf31b8a2f) |

- origin/main: 6 minutes and 27 picker opens after login, `claude auth status` in the same `CLAUDE_CONFIG_DIR` reported `loggedIn: true`, but the picker still showed 2 Anthropic rows and all 11 Claude rows disabled. One probe in total, at startup.
- This branch: all 15 Claude rows (6 configured `anthropic/*` and 9 `claude-cli/*`) were enabled on the first open after the window. After a logout they were disabled again on the next window. A re-login right after a recheck showed up after 60 s, with 14 picker opens and exactly 1 probe.

LOC vs origin/main: production +104/-25, tests +51/-3, docs +3/-1.

Co-authored-by: Ayaan Zaidi <[email protected]>
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 7, 2026
…tartup (openclaw#166305)

## What Problem This Solves

Fixes: Claude CLI models stay hidden or disabled in the Control UI model picker and `openclaw models list` when Claude Code was logged out at Gateway start and the user logs in afterwards; only a Gateway restart or `models.list {refresh: true}` fixed it. A logout after startup was never reflected either.

## User Impact

User impact: after `claude auth login` (or a logout), the picker shows the right Claude CLI models within about a minute, without restarting the Gateway or reloading the page. How a logged-out Claude is displayed is unchanged.

## Why This Change Was Made

- The picker's availability filter already counts Claude Code's own login: `evaluateCliRuntimeModelAuthAvailability` reads the `claude-cli` auth mode from the `claude auth status --json` probe in `extensions/anthropic/provider-discovery.ts`.
- openclaw#129346 (f4ade71) made that probe run once per config generation so that "repeated model-list requests do not repeatedly launch the Claude CLI". openclaw#139757 (13a4405) shared it across agent workspaces after 632-agent rosters timed out at startup, and documented that "explicit catalog/auth captures recheck availability".
- Nothing on the ordinary-read path rechecked it: `refreshExpiredModelCatalog` only renews providers with an inventory `expiresAt`, and the static `claude-cli` provider never gets one. So the startup result stayed for the whole generation.

The existing ordinary-read renewal hook now also rechecks CLI-backend native logins (CLI backends whose manifest declares `syntheticAuthRefs`, which today means `claude-cli`). The recheck runs in the background, deduplicates through the worker's existing `loadAuth`, and publishes a new catalog through the existing native-publication path only when the login state changed. The explicit `loadAuth` refresh and the recheck share one scoped-auth merge in `prepared-model-runtime.catalog-auth.ts`; `loadAuth` still returns only `{ authStore, authModes }`. Startup still probes once per shared generation, so both earlier PRs' cost limits hold.

## Bounded cost

- At most one `claude auth status --json` (existing 3 s timeout, process-tree kill) per prepared catalog owner per 60 s, and only while model lists are being read. An idle Gateway spawns nothing.
- Picker opens inside the window spawn nothing; concurrent reads share one in-flight probe.
- Nothing is published, and no catalog event is emitted, when the login state is unchanged.
- Measured on an isolated Gateway (below): 40 picker opens in 59 s started 1 probe; 14 opens during a 60 s login wait started 1 probe; probes were always at least 60 s apart.

## Evidence

**Regression test.** `src/gateway/server.chat-cli-auth.test.ts` adds "publishes Claude login changes after Gateway startup". It runs the real in-process Gateway, the real Anthropic plugin and `models.list`; only the `claude` executable is a fixture, and it records each `auth status` probe. It checks that the model is unavailable at startup, that a login inside the recheck window spawns no probe, that the model becomes available after the window with exactly one more probe, and that a logout makes it unavailable again with exactly one more probe. Each transition awaits the catalog publication rather than polling. With origin/main's catalog code the login publication never arrives and the test times out at 90 s; on this branch it passes in about 5 s. The full file (7 tests), the prepared-runtime suites that share its test harness, and `node scripts/check-changed.mjs` pass on this branch.

**Live Control UI, before and after.** Two isolated Gateways on one Mac, origin/main and this branch. State, config, `HOME` and `CLAUDE_CONFIG_DIR` were under /tmp, there was no Anthropic API key, and the config was shaped like our setup. Each used the real `claude` binary behind a wrapper that only counts `auth status` calls. Both started logged out. The login happened afterwards, by placing a Claude credentials file in each isolated `CLAUDE_CONFIG_DIR`. The picker was reopened in place and the page was never reloaded.

| | origin/main | this branch |
|---|---|---|
| Before login | ![origin/main before login: Anthropic shows 2 disabled rows](https://github.com/user-attachments/assets/416d0116-9aa1-4344-8127-123100a204b3) | ![branch before login: Anthropic shows 2 disabled rows](https://github.com/user-attachments/assets/aebe7782-7b11-495c-933c-2fc87bde3485) |
| After login | ![origin/main 3 minutes after login: still 2 disabled rows](https://github.com/user-attachments/assets/2c6ab23c-77b2-4240-a1f1-df5f398d6802) | ![branch after login: Anthropic shows all 6 configured models, enabled](https://github.com/user-attachments/assets/9e8413d2-abc0-4934-8dbd-8b6bf31b8a2f) |

- origin/main: 6 minutes and 27 picker opens after login, `claude auth status` in the same `CLAUDE_CONFIG_DIR` reported `loggedIn: true`, but the picker still showed 2 Anthropic rows and all 11 Claude rows disabled. One probe in total, at startup.
- This branch: all 15 Claude rows (6 configured `anthropic/*` and 9 `claude-cli/*`) were enabled on the first open after the window. After a logout they were disabled again on the next window. A re-login right after a recheck showed up after 60 s, with 14 picker opens and exactly 1 probe.

LOC vs origin/main: production +104/-25, tests +51/-3, docs +3/-1.

Co-authored-by: Ayaan Zaidi <[email protected]>
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 gateway Gateway runtime maintainer Maintainer-authored PR P1 High-priority user-facing bug, regression, or broken workflow. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: M status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant