Skip to content

fix: avoid blocking the Gateway during cold model catalog preparation - #161201

Merged
steipete merged 2 commits into
mainfrom
codex/prepare-catalog-auth-reads
Sep 29, 2026
Merged

steipete merged 2 commits into
mainfrom
codex/prepare-catalog-auth-reads

Conversation

@steipete

@steipete steipete commented Sep 29, 2026 •

Copy link
Copy Markdown
Contributor

Closes #161200

What Problem This Solves

Cold model catalog preparation still reads durable auth, plugin metadata, and auth-label paths synchronously on the Gateway thread.

User Impact

Model catalog preparation uses the existing database workers while preserving the caller’s credential source and auth labels. Env-only preparation also ignores published stored profiles without deleting them. No configuration or storage migration is required.

Why This Change Was Made

The auth owner now drives one lazy read policy through both its existing synchronous API and captured worker reads. Model preparation carries the original environment and authority through awaited work. Labels consume the selected raw storage path instead of reopening SQLite while formatting. Real model preparation tests follow their database-worker project and retain their built-SDK prerequisites.

Evidence

  • The real cold catalog regression reaches the correct model, credential, and label on the original source, then fails with eight host SQLite calls; the candidate passes with zero.
  • Two-root tests verify explicit environment selection and source retention across a held worker read. A separate original-source env-only regression fails with a published profile present; the candidate returns no stored profile and leaves the outside publication intact.
  • Canonical store, source/cleanup, OAuth, personal-account, and native-read cases: 44 passed. Display-path cases: 10 passed. Existing label and directive tests also passed.
  • Full build and changed-file gates passed. The final narrow env-only successor also passed core/test types, typed lint, and its actual regression. Independent review of the final source is clean through P2.
  • Clean committed runtime build passed. The selected model/catalog suites passed across scoped runs: 260 initial cases, 19 previously interrupted cases, six remaining worker cases, and the corrected capture-reuse case; three lower metadata worker cases passed. The capture test now measures one actual catalog thread rather than counting unrelated database workers. No live Gateway latency or throughput claim.

Cold-path cost and compatibility

A paired fresh-process run of the same real cold catalog fixture measured acquisition through lease disposal on original 0c8e56cf and final d89f94d1. Both reached the correct model, synthetic credential, and label; the original then failed the unchanged eight-host-SQL assertion, while the candidate passed with zero host SQL.

Measurement Original Candidate
Acquisition through cleanup 1.462 s 1.835 s
Process RSS before acquisition 342.1 MiB 349.6 MiB
Process RSS after cleanup 466.8 MiB 482.2 MiB
Process peak RSS, including startup 508.6 MiB 526.3 MiB

This is one isolated synthetic pair, not a statistical or live Gateway latency claim. It shows a 0.373 s cold-start cost in exchange for removing synchronous SQLite from the caller. RSS includes the test process and its Node worker threads, excludes external child processes, and is not a retained-memory/leak measurement. Wrapper/build time is excluded from the acquisition figures. The temporary numeric-only instrumentation was removed and all final source hashes reverified.

Measured test-body costs from retained successful runs (sums of Vitest case durations, excluding transform/import/runner overhead): inherited-store 13 cases, 7.893 s; display-path 10 cases, 5.478 s; auth-label 6 cases, 1.047 s; catalog resources 7 cases, 9.157 s; startup-static 6 cases, 1.329 s; corrected catalog capture-reuse case, 9.558 s. The existing 98-case directive file took 95.53 s including its runner/import/transform work; its unchanged status block was moved to test support for the line cap. That broad existing suite protects real directive persistence and model selection, not a new duplicate integration suite. The deleted auth-store test is replaced at its real shared-store/catalog consumers; fixture/support modules have no independent test runtime. CI's observed original 14-file Gateway group took 153.01 s before the unrelated fixture failure below.

The stored-data-model flag is a heuristic false positive: no schema, stored auth DTO, serialized representation, migration, retention, or permission changes. Existing auth SQLite readers and serializers remain authoritative; the change prepares their facts asynchronously and carries the selected path into presentation. The cold regression starts from credentials persisted by the existing writer and verifies the unchanged credential shape; inherited/OAuth/personal-account policy coverage also passes. No upgrade migration is required.

CI attribution

CI run 36575451638 is failed/cancelled, not green. Its sole failed root is eight existing session-event fixture assertions missing the canonical prepareSessionProjection callback. The same original 14-file/two-worker group reproduced 117 passes and those same eight failures on clean main dc6e5cd2, without this auth change; adding the exact callback option produced 125 passes. All decisive fixture/producer inputs are identical in the tested merge. The fail-fast monitor cancelled 94 sibling jobs, whose unexecuted coverage is not claimed. The exact helper correction is now on main in 68b547f6.

Landing uses the explicitly authorized native pre-existing-failure path with the exact failed run, tested merge, source comparison, independent baseline proof, and complete cancellation accounting. Current security and review checks remain enforced.

Share auth read policy between synchronous and prepared worker consumers,
carry the original environment through preparation, and prepare label paths
without reopening host databases. Preserve env-only profile isolation.

Route real model preparation tests through their database-worker owner and
retain the existing built SDK prerequisites.

Related: #161200
@clawsweeper

clawsweeper Bot commented Sep 29, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

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

ClawSweeper review in progress

ClawSweeper is reviewing this revision. This supersedes any previous blocked status.

View the workflow run.

@openclaw-barnacle openclaw-barnacle Bot added scripts Repository scripts agents Agent runtime and tooling size: XL labels Sep 29, 2026
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. 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 29, 2026
@clawsweeper

clawsweeper Bot commented Sep 29, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: blocked before merge. Reviewed September 29, 2026, 9:37 AM ET / 13:37 UTC (Revision 2).

ClawSweeper review

What this changes

Moves cold model catalog auth, plugin metadata, and label preparation toward worker-backed reads while preserving the selected credential source and rerouting related tests.

Merge readiness

⛔ Blocked before merge - 3 items remain

Keep open: the reviewed main revision still prepares cold catalog auth synchronously, and this PR is a distinct candidate fix for the linked report.

Priority: P2
Reviewed head: d89f94d10036ae027c00e114e7942582a80b2eb5

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) Production-boundary regression evidence supports a coherent owner-level repair; the remaining confidence gap is its measured cold-path cost.
Proof confidence 🐚 platinum hermit (4/6) Sufficient (live_output): The PR reports a real prepared-runtime cold catalog run using persisted synthetic credentials and SQLite workers: the original path made eight host SQLite calls, while the candidate made zero and retained the model, credential, and label. The source test covers that entrypoint and selected-root behavior; no stored-data contract changes, live Gateway latency claim, or paired time/RSS result is supplied.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (live_output): The PR reports a real prepared-runtime cold catalog run using persisted synthetic credentials and SQLite workers: the original path made eight host SQLite calls, while the candidate made zero and retained the model, credential, and label. The source test covers that entrypoint and selected-root behavior; no stored-data contract changes, live Gateway latency claim, or paired time/RSS result is supplied.
Evidence reviewed 7 items Current main still uses synchronous preparation: The pinned main revision calls the synchronous prepared auth-store loader while assembling agent facts; its catalog auth path also formats labels synchronously.
Introduced worker-backed catalog read: The PR awaits the auth owner's preparation operation, passes the original environment, and checks that the build is still current before consuming its facts.
Credential-source and authority handling: The auth owner selects published or durable profiles, preserves the env-only empty-store rule, and checks current read and caller authority around awaited worker reads. The added two-root and env-only cases exercise the nearest wrong-source scenarios.
Findings None None.
Security None None.

How this fits together

The Gateway prepares a model catalog from configured models, plugin metadata, and stored credentials. That preparation supplies model choices and auth labels to later agent and catalog requests.

flowchart LR
A[Gateway catalog request] --> B[Prepared model runtime]
B --> C[Auth store worker reads]
B --> D[Plugin metadata]
C --> E[Selected credentials and path]
D --> F[Model catalog assembly]
E --> F
F --> G[Models and auth labels]
Loading

Before merge

  • Resolve merge risk (P1) - Cold preparation now awaits additional per-agent auth and display-path worker reads, but paired wall-time and RSS measurements and changed-test runtime costs are not recorded; the Gateway readiness and memory effect remains unquantified.
  • Complete next step (P2) - Record paired before/after cold-preparation wall time and RSS and the measured cost of materially changed test files before merge.
  • Add data-model compatibility proof - Confirm migration or upgrade compatibility proof before merge.
Agent review details

Security

None.

PR surface

Source +728, Tests +661, Other +7. Total +1396 across 26 files.

View PR surface stats
Area Files Added Removed Net
Source 14 1487 759 +728
Tests 11 1114 453 +661
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 1 11 4 +7
Total 26 2612 1216 +1396

Review metrics

Metric Value Why it matters
Production versus test growth production +1487/-759, net +728; tests/tooling +1125/-457, net +668 The owner cutover adds substantial production code; its stated single-read-policy rationale merits a measured cold-path cost.
Database-worker test routing 40 existing suites routed The suite move changes where catalog and runtime regressions run and makes their measured test cost relevant.

Stored data model

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

Root-cause cluster

Relationship: fixed_by_candidate
Canonical: #161200
Summary: The linked open issue describes the same cold catalog host-SQLite path; this unmerged PR is its candidate fix.

Members:

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

Merge-risk options

Maintainer options:

  1. Measure the cold path (recommended)
    Record before/after cold-preparation wall time and RSS on the same scenario, plus the runtime cost of materially changed tests, before merging.

Technical review

Best possible solution:

Keep one auth-store owner for synchronous and prepared readers, and reuse its selected credentials and source path throughout each catalog generation.

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

Yes. The real prepared-runtime entrypoint with a cold persisted synthetic profile provides a focused path; the PR reports eight calling-thread SQLite calls before the fix and zero afterward, though this review did not execute it.

Is this the best way to solve the issue?

Yes. Reusing the auth owner's worker reads and carrying the selected environment through preparation fits the existing ownership boundary; the cold-path cost still needs measurement.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against dc6e5cd22712.

Labels

Label changes:

No label changes.

Label justifications:

  • P2: This is a bounded Gateway cold-path performance bug without a measured user-facing outage.
  • merge-risk: 🚨 availability: Additional awaited reads could affect cold Gateway readiness, and their time and memory cost has not been measured.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (live_output): The PR reports a real prepared-runtime cold catalog run using persisted synthetic credentials and SQLite workers: the original path made eight host SQLite calls, while the candidate made zero and retained the model, credential, and label. The source test covers that entrypoint and selected-root behavior; no stored-data contract changes, live Gateway latency claim, or paired time/RSS result is supplied.
  • proof: sufficient: Contributor real behavior proof is sufficient. The PR reports a real prepared-runtime cold catalog run using persisted synthetic credentials and SQLite workers: the original path made eight host SQLite calls, while the candidate made zero and retained the model, credential, and label. The source test covers that entrypoint and selected-root behavior; no stored-data contract changes, live Gateway latency claim, or paired time/RSS result is supplied.

Evidence

What I checked:

  • Current main still uses synchronous preparation: The pinned main revision calls the synchronous prepared auth-store loader while assembling agent facts; its catalog auth path also formats labels synchronously. (src/agents/prepared-model-runtime.agent-facts.ts:25, dc6e5cd22712)
  • Introduced worker-backed catalog read: The PR awaits the auth owner's preparation operation, passes the original environment, and checks that the build is still current before consuming its facts. (src/agents/prepared-model-runtime.agent-facts.ts:27, d89f94d10036)
  • Credential-source and authority handling: The auth owner selects published or durable profiles, preserves the env-only empty-store rule, and checks current read and caller authority around awaited worker reads. The added two-root and env-only cases exercise the nearest wrong-source scenarios. (src/agents/auth-profiles/store-read.ts:610, d89f94d10036)
  • Production-boundary regression: The added test acquires the real read-only prepared model runtime with a persisted synthetic credential, checks the selected model, credential, and label, and observes SQLite calls on the calling thread. The PR body reports eight such calls on original source and zero after the change; this review did not rerun it. (src/agents/prepared-model-catalog.resources.test.ts:257, d89f94d10036)
  • Prior review and remaining measurement: The completed prior ClawSweeper review at fix: avoid blocking the Gateway during cold model catalog preparation #161201 (comment) had no code findings and requested before/after cold-preparation time, RSS, and changed-test cost. The current PR body reports no live Gateway latency or throughput claim and provides no paired time or RSS measurement. (d89f94d10036)
  • Applicable performance policy: The agent guide requires before/after benchmarks for performance edits and seconds and RSS in the handoff. This applies to the cold Gateway preparation change. (src/agents/AGENTS.md:9, d89f94d10036)

Likely related people:

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

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

  • Report paired cold-preparation seconds and RSS, plus measured runtime for materially changed test files.

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 (1 earlier review cycle)
  • reviewed 2026-09-29T13:26:06.362Z sha f8989a7 :: blocked before merge. :: none

@steipete
steipete marked this pull request as ready for review September 29, 2026 13:29
@github-actions

Copy link
Copy Markdown
Contributor

⚠️ Security sensitive changes

This maintainer PR changes sensitive security components. This comment is informational because the PR author has repository Maintain or Admin access.

  • Current SHA: d89f94d10036ae027c00e114e7942582a80b2eb5
  • Maintainer: @steipete
  • Repository role: admin

These security sensitive changes were made:

  • src/agents/auth-profiles/inherited-store.ts: Controls credential persistence, secret resolution, or redaction. Check storage permissions, credential scope, and exposure in logs or responses.
  • src/agents/auth-profiles/paths.ts: Controls credential persistence, secret resolution, or redaction. Check storage permissions, credential scope, and exposure in logs or responses.
  • src/agents/auth-profiles/runtime-read.ts: Controls credential persistence, secret resolution, or redaction. Check storage permissions, credential scope, and exposure in logs or responses.
  • src/agents/auth-profiles/store-read.ts: Controls credential persistence, secret resolution, or redaction. Check storage permissions, credential scope, and exposure in logs or responses.
  • src/agents/auth-profiles/store.ts: Controls credential persistence, secret resolution, or redaction. Check storage permissions, credential scope, and exposure in logs or responses.
  • src/agents/model-catalog-auth-labels.ts: Controls credential persistence, secret resolution, or redaction. Check storage permissions, credential scope, and exposure in logs or responses.
  • src/agents/prepared-model-runtime.auth-store.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 merged commit 3d3bc8a into main Sep 29, 2026
199 of 298 checks passed
@steipete
steipete deleted the codex/prepare-catalog-auth-reads branch September 29, 2026 14:38
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via explicitly authorized admin squash with attributed pre-existing CI failures.

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

* fix: prepare model catalog auth without host SQLite reads

Share auth read policy between synchronous and prepared worker consumers,
carry the original environment through preparation, and prepare label paths
without reopening host databases. Preserve env-only profile isolation.

Route real model preparation tests through their database-worker owner and
retain the existing built SDK prerequisites.

Related: openclaw#161200

* test: verify catalog worker reuse through discovery threads
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. scripts Repository scripts security-sensitive-changed size: XL 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.

Cold model catalog preparation reads SQLite on the Gateway thread

1 participant