Skip to content

perf(models): avoid catalog workers for native login rechecks - #166434

Merged
steipete merged 1 commit into
mainfrom
steipete/perf-micro-prepared-model-catalog-cost-20260919
Oct 7, 2026
Merged

steipete merged 1 commit into
mainfrom
steipete/perf-micro-prepared-model-catalog-cost-20260919

Conversation

@steipete

@steipete steipete commented Oct 7, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Periodic native CLI login checks repeat catalog-worker preparation even when the published model catalog and stored credentials have not changed.

User Impact

Model lists keep detecting external CLI login/logout in the background while reusing the existing catalog across connections. Ordinary native-login checks no longer enter the prepared-model-catalog worker. Provider discovery and explicit credential refresh retain their existing behavior.

Why This Change Was Made

The catalog already belongs to the configured runtime generation; connection IDs do not select a new owner. The remaining minute-based native-login check captured availability in the parent and then dispatched an auth-refresh worker request that reconstructed plugin context and reread stored auth. Reuse the canonical ambient-credential preparer for this observation and pair it with the latest owner-held profiles. Only changed availability publishes; pending checks coalesce and retirement cancels their probe.

Production LOC delta: +55 across four files (tests excluded). The documented native-login freshness contract requires keeping background login/logout detection. Separating that observation from durable credential refresh needs a small generation-scoped preparer and cancellation boundary. The old periodic worker path is removed; explicit credential refresh remains the worker's responsibility. There is no fallback path or new configuration.

Related: #166037.

Evidence

Validated on Blacksmith Testbox tbx_01m49yskmx42zfegnhxny4ryr1 (blacksmith-testbox, openclaw-check):

  • New regression fails on the old implementation because a due login check dispatches 1 auth-refresh worker request; the candidate dispatches 0. The baseline adapts only the internal function argument list so it exercises the same assertion.
  • node scripts/run-vitest.mjs src/agents/prepared-model-runtime.native-login.test.ts --maxWorkers=1: 3 passed, 23 ms test time, 22.11 s cold wrapper duration including compiled-worker preparation.
  • node scripts/run-vitest.mjs src/gateway/server-methods/models.prepared.test.ts: 2 passed.
  • node scripts/run-vitest.mjs src/plugins/provider-runtime.synthetic-auth-discovery.test.ts src/agents/agent-auth-discovery.external-cli.test.ts src/agents/prepared-model-runtime.catalog-owner.test.ts: 41 passed.
  • Final five-file lint and node scripts/run-vitest.mjs src/agents/prepared-model-runtime.native-login.test.ts src/agents/prepared-model-runtime.scoped-refresh.test.ts: lint clean, 22 passed on tbx_01m4a2pgdqchafm5qn358dwe1y; 66.3 s combined remote command. This brings focused coverage to 65 distinct passing tests.
  • Paired OPENCLAW_BENCH_MODELS_LIST=1 benchmark through the real models.list handler, 120 requests / 6 concurrent callers: p50 31.32 → 26.96 ms, p99 72.94 → 47.85 ms, two session reads per warm request in both. Both baselines were already below 200 ms; this is a foreground regression guard, not a claim that production tail latency fell by the same amount.
  • Benchmark command wall time 26.08 → 26.68 s; compiler-inclusive peak test-command RSS 5,843,008 → 5,970,960 KiB. These are test-runner measurements, not Gateway heap measurements.
  • node scripts/run-tsgo.mjs -p tsconfig.core.json --incremental --tsBuildInfoFile .artifacts/tsgo-cache/core.tsbuildinfo and the changed-file agents-other test type graph: passed (combined remote command 161.5 s).

Independent Codex autoreview returned scoped-clean through P2, with no actionable findings. Subsequent gate cleanup reused the canonical preparation-options type and simplified an equivalent native-scope conditional. The complete staged gate passed with exit 0 on the isolated Linux rig after Testbox remained queued for more than twenty minutes: node scripts/check-changed.mjs --staged, on base 513871f9ca8e072b3af03a739091b34c61ee9048. It checked the exact five-file staged patch, passed all 27 core test type graphs, reported zero lint warnings/errors and zero runtime import cycles, and completed the native-state, database, sidecar, webhook, and pairing guards. No checks were disabled. The full gate ran from 03:03–03:38 UTC on October 7. The commit was then rebased cleanly onto current main; stable patch IDs before and after are identical. Published-head CI passed on ea96ec1c4ed36619080dbbbd43f7e97b1d05c342 in 456 s including admission. The new regression file passed all 3 cases in 60 ms of test time / 7.61 s reported file duration; its containing job took 130 s. The PR merged as 0a5311bc95c2b24fb664e9497ac110931f028ab3.

The supplied observation has 3,082.4 ms average worker duration at 0.9 tasks/minute and 948.3 ms models.list p99. Worker telemetry combines discovery and auth-refresh requests, so it does not establish that each slow model-list response awaited discovery. Production p99 after deployment remains unmeasured.

Observe native CLI login availability through the existing credential
preparer and pair it with the published auth store. Keep explicit credential
refresh in the worker, coalesce pending native checks, and publish only
changed availability while retaining cancellation and generation checks.

Add regression coverage for checks without worker requests, login/logout, saved-profile
precedence, and retirement. Native checks dispatch zero worker requests
instead of one; the synthetic models.list benchmark remains below 200 ms p99.
@clawsweeper

clawsweeper Bot commented Oct 7, 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.

@github-actions

github-actions Bot commented Oct 7, 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: ea96ec1c4ed36619080dbbbd43f7e97b1d05c342
  • Maintainer: @steipete
  • Repository role: admin

These security sensitive changes were made:

  • src/agents/agent-auth-discovery.ts: Controls credential persistence, secret resolution, or redaction. Check storage permissions, credential scope, and exposure in logs or responses.
  • 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.

@steipete
steipete enabled auto-merge (squash) October 7, 2026 03:46
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. 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 Oct 7, 2026
@clawsweeper

clawsweeper Bot commented Oct 7, 2026

Copy link
Copy Markdown
Contributor

Codex review: blocked before merge. Reviewed October 6, 2026, 11:49 PM ET / October 7, 2026, 03:49 UTC.

ClawSweeper review

What this changes

Periodic native CLI login checks reuse OpenClaw’s credential preparer and published profiles instead of rebuilding authentication through a catalog worker, with regression coverage for freshness, precedence, and retirement.

Merge readiness

⛔ Blocked before merge - 1 item remains

The optimization remains useful: current main still dispatches periodic login checks through the catalog worker. No actionable introduced defect was found, and this maintainer-authored PR should remain open.

Priority: P2
Reviewed head: ea96ec1c4ed36619080dbbbd43f7e97b1d05c342

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused optimization with coherent lifecycle handling, meaningful regression coverage, and reported proportional validation.
Proof confidence 🌊 off-meta tidepool Not applicable: The ordinary contributor-proof gate does not apply to this verified maintainer PR, and no material authority transfer triggers its exception. Reported handler benchmarking is supplemental; due-check transitions are covered by mocked owner tests rather than claimed live CLI proof. No stored-data contract changes.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: The ordinary contributor-proof gate does not apply to this verified maintainer PR, and no material authority transfer triggers its exception. Reported handler benchmarking is supplemental; due-check transitions are covered by mocked owner tests rather than claimed live CLI proof. No stored-data contract changes.
Evidence reviewed 10 items Pinned introduction: The reviewed delta is the verified base-to-head patch; its changes replace the periodic worker refresh without removing explicit credential refresh.
Still necessary on main: The pinned current-main implementation calls refreshScopedModelCatalogAuth for each due native-login check, which invokes the owner's worker-backed refreshAuth operation.
Lifecycle and profile precedence: The candidate retains the plugin generation, propagates retirement cancellation, reads current profiles after awaiting preparation, preserves saved-profile precedence, and checks currency before publishing changed modes. No persisted format or stored-setting change is introduced.
Findings None None.
Security None None.

How this fits together

OpenClaw’s prepared model catalog combines configured models with credential availability for model pickers. Background native-login observations update that availability while explicit credential refresh continues through the catalog worker.

flowchart TD
  A[Model list request] --> B[Recheck window and pending check]
  B --> C[Native CLI availability probe]
  D[Current published profiles] --> E[Combine credential availability]
  C --> E
  E --> F[Current generation and changed availability]
  F --> G[Publish model picker update]
Loading

Before merge

  • Add data-model compatibility proof - Confirm migration or upgrade compatibility proof before merge.
Agent review details

Security

None.

PR surface

Source +55, Tests +240. Total +295 across 5 files.

View PR surface stats
Area Files Added Removed Net
Source 4 89 34 +55
Tests 1 240 0 +240
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 5 329 34 +295

Review metrics

Metric Value Why it matters
Production growth justification production net +55 lines; tests +240 lines The body explains the added generation-scoped preparation and cancellation boundary, while removing the periodic worker path.

Stored data model

Persistent data-model change detected: unknown-data-model-change: src/agents/prepared-model-runtime.catalog-auth.ts. Confirm migration or upgrade compatibility proof before merge.

Technical review

Best possible solution:

Keep native availability observation within the existing catalog generation, preserve saved-profile precedence, and reserve worker reconstruction for explicit credential refresh.

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

Yes, source establishes that a due current-main native-login check reaches worker-backed authentication refresh; the captured body also reports a failing baseline regression. No runtime reproduction was executed during this read-only review.

Is this the best way to solve the issue?

Yes, the patch reuses the canonical credential preparer and current catalog owner while retaining explicit worker refresh, bounded checks, and retirement fencing.

AGENTS.md: found and applied where relevant.

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

Labels

Label changes:

  • add P2: This is a bounded model-catalog performance improvement that preserves the existing login-freshness contract.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: The ordinary contributor-proof gate does not apply to this verified maintainer PR, and no material authority transfer triggers its exception. Reported handler benchmarking is supplemental; due-check transitions are covered by mocked owner tests rather than claimed live CLI proof. No stored-data contract changes.

Label justifications:

  • P2: This is a bounded model-catalog performance improvement that preserves the existing login-freshness contract.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: The ordinary contributor-proof gate does not apply to this verified maintainer PR, and no material authority transfer triggers its exception. Reported handler benchmarking is supplemental; due-check transitions are covered by mocked owner tests rather than claimed live CLI proof. No stored-data contract changes.

Evidence

What I checked:

  • Pinned introduction: The reviewed delta is the verified base-to-head patch; its changes replace the periodic worker refresh without removing explicit credential refresh. (src/agents/prepared-model-runtime.catalog-auth.ts:489, ea96ec1c4ed3)
  • Still necessary on main: The pinned current-main implementation calls refreshScopedModelCatalogAuth for each due native-login check, which invokes the owner's worker-backed refreshAuth operation. (src/agents/prepared-model-runtime.catalog-auth.ts:485, 30d563e262aa)
  • Lifecycle and profile precedence: The candidate retains the plugin generation, propagates retirement cancellation, reads current profiles after awaiting preparation, preserves saved-profile precedence, and checks currency before publishing changed modes. No persisted format or stored-setting change is introduced. (src/agents/prepared-model-runtime.catalog-auth.ts:495, ea96ec1c4ed3)
  • Fresh preparation ownership: The existing synthetic-auth preparer keys completed observations by preparation owner; forwarding a fresh owner permits each due check to observe login changes without reusing a completed observation. (src/plugins/provider-synthetic-auth.ts:43, ea96ec1c4ed3)
  • Existing freshness contract: The Anthropic documentation defines background login/logout detection at most once a minute and states that native login tokens remain owned by Claude. The changed path observes availability rather than transferring execution authority. Public docs: docs/providers/anthropic.md. (docs/providers/anthropic.md:140, ea96ec1c4ed3)
  • Regression coverage and reported validation: The three added tests cover login/logout publication without worker refresh, saved-profile precedence, pending-check coalescing, and retirement fencing using fake time and a mocked provider hook. The captured PR body reports a failing baseline, 65 distinct passing focused tests, and a paired real models.list-handler benchmark; these were not rerun during this read-only review, and the benchmark does not directly prove a due native-login transition. (src/agents/prepared-model-runtime.native-login.test.ts:155, ea96ec1c4ed3)

Likely related people:

  • obviyus: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • steipete: 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.

@steipete
steipete merged commit 0a5311b into main Oct 7, 2026
127 checks passed
@steipete
steipete deleted the steipete/perf-micro-prepared-model-catalog-cost-20260919 branch October 7, 2026 03:54
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 7, 2026
…aw#166434)

Observe native CLI login availability through the existing credential
preparer and pair it with the published auth store. Keep explicit credential
refresh in the worker, coalesce pending native checks, and publish only
changed availability while retaining cancellation and generation checks.

Add regression coverage for checks without worker requests, login/logout, saved-profile
precedence, and retirement. Native checks dispatch zero worker requests
instead of one; the synthetic models.list benchmark remains below 200 ms p99.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling P2 Normal backlog priority with limited blast radius. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. security-sensitive-changed 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