Skip to content

perf(agents): retain admission facts for async catalog reads - #175347

Merged
steipete merged 2 commits into
mainfrom
dbasync/quarantinefacts2
Oct 17, 2026
Merged

steipete merged 2 commits into
mainfrom
dbasync/quarantinefacts2

Conversation

@steipete

@steipete steipete commented Oct 17, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Repeated async generated-model catalog reads used the generic read-only child process. That process intentionally drops physical admission facts when its native reader closes, because it has no writer-publication relay. Each catalog read therefore repeats physical admission.

User Impact

Catalog results and refusal behavior are preserved. This removes a median 38 repeated admission statements (range 37–38) across five asynchronous catalog requests; catalog request counts stay unchanged. No user action or migration is required.

Why This Change Was Made

Route these reads through an owned read-only catalog task worker. The existing worker host/server exchange retained admission facts and owner invalidations; catalog rows are still queried on every call. Close the native reader before transferring the result in bounded frames. Remove the old pluginCatalog.read operation, factory, registration, and transport-specific test fixtures. Quarantine refusal, real-open corruption handling, and explicit fresh Doctor/restore/backup verification remain with their existing owners. No schema or engine change and no new admission protocol.

Remove the duplicate authority/identity assertion immediately following source capture. Accepted edge: a revoked queued read can waste internal work; the final authority, maintenance, and source-identity check still refuses disclosure.

T1 and compatibility

Scope Base Candidate
Catalog kernel T1 primitive calls 2 2
Async catalog Gateway MAIN SQL path 0 0

The two kernel primitives remain reachable through the released synchronous ModelRegistry.create, refresh, and unregisterProvider SDK contract. That contract explicitly preserves synchronous disk reads through December 31, 2026, with removal in the first January 2027 stable release. Bundled discovery already uses async/prepared APIs. The other native callers are Doctor-only. This PR does not relabel the shared kernel as worker-only or claim the area reached zero T1.

Measurement

Completed all three alternating shared-harness-v3 pairs, M1,C1,M2,C2,M3,C3, on base a2e6a6b0f9c437989aa8cdf80d495240381f7be8 and candidate 20dfa3519a8341a47446b1df1be5142183263803. Every arm passed restart, clean shutdown, runtime/source pinning, and attribution validation. The shared harness was unmodified; Node 26.12.0 and native libraries were pinned across arms, with compile cache disabled. One build per revision was reused with byte-verified outputs. No measured arm was discarded.

Values are median [min–max]. Cold/whole rows contain three observations per side; pooled warmed rows contain 30 turns per side. Raw rows count all threads by execution/dispatch window. Turn-attributed rows include only work with the corresponding turn cause; they do not erase background work from the raw totals.

Phase Base SQL / requests / MAIN Candidate SQL / requests / MAIN
Fresh boot 333 [333–348] / 89 [89–94] / 63 [63–63] 333 [333–335] / 89 [89–89] / 63 [63–63]
Connect 254 [27–261] / 25 [12–29] / 0 [0–0] 105 [88–261] / 23 [23–29] / 0 [0–0]
First turn 341 [320–529] / 107 [100–111] / 0 [0–9] 450 [303–479] / 103 [100–107] / 0 [0–9]
Boot + connect + first turn 914 [904–928] / 218 [217–221] / 63 [63–72] 897 [888–902] / 218 [215–219] / 63 [63–72]
Restart boot 343 [342–344] / 102 [102–102] / 59 [59–60] 343 [342–352] / 102 [102–106] / 59 [59–59]
Restart connect 57 [55–57] / 22 [22–22] / 0 [0–0] 55 [54–65] / 21 [21–22] / 0 [0–0]
Restart first turn 210 [206–240] / 70 [70–71] / 0 [0–0] 189 [174–228] / 69 [68–72] / 0 [0–0]
Restart combined 609 [605–640] / 194 [194–195] / 59 [59–60] 591 [586–625] / 195 [192–196] / 59 [59–59]
Warmed, raw pooled 62 [62–93] / 18 [18–23] / 0 [0–13] 62 [62–96] / 18 [18–23] / 0 [0–13]
Warmed, raw per-run medians 62 [62–62.5] / 18 [18–18] / 0 [0–0] 62.5 [62–62.5] / 18 [18–18] / 0 [0–0]
Warmed, turn-attributed pooled 62 [62–63] / 18 [18–19] / 0 [0–0] 62 [62–63] / 18 [18–19] / 0 [0–0]
Whole workload, raw 3560 [3553–3588] / 926 [923–928] / 149 [149–150] 3529 [3517–3551] / 925 [923–927] / 149 [149–149]
First turn, turn-attributed 179 [179–180] / 54 [54–54] / 0 [0–0] 172 [172–173] / 54 [54–55] / 0 [0–0]
Restart first turn, turn-attributed 142 [142–142] / 44 [44–44] / 0 [0–0] 136 [136–136] / 44 [44–44] / 0 [0–0]

The changed catalog owner removes 38, 38, and 37 statements in the three pairs (median 38), with five requests unchanged. Each side performs the same two all-scope and three key-filtered catalog reads. The removed admission work is nine engine/version probes, nine user_version reads, four or five quarantine decisions, four schema_version reads, four encoding reads, four schema inventory reads, and three metadata reads. C3 retains one cold quarantine decision lookup on a background catalog read during first turn; its stack passes through the quarantine store, admission reader, and catalog worker. It is real owner work, counted in the 6-statement result, not excluded as noise. The trace establishes the lookup but not why its retained fact was unavailable.

Phase Base SQL / requests / MAIN Candidate SQL / requests / MAIN
Catalog: first turn 22 [22–22] / 2 [2–2] / 0 [0–0] 2 [2–3] / 2 [2–2] / 0 [0–0]
Catalog: restart boot 3 [3–3] / 1 [1–1] / 0 [0–0] 1 [1–1] / 1 [1–1] / 0 [0–0]
Catalog: restart first turn 18 [18–18] / 2 [2–2] / 0 [0–0] 2 [2–2] / 2 [2–2] / 0 [0–0]
Catalog: warmed turns 0 [0–0] / 0 [0–0] / 0 [0–0] 0 [0–0] / 0 [0–0] / 0 [0–0]
Catalog: whole workload 43 [43–43] / 5 [5–5] / 0 [0–0] 5 [5–6] / 5 [5–5] / 0 [0–0]

Raw whole-workload medians change by −31 statements and −1 request. The same 194-statement registry open appears in every arm but shifts between connect and first turn: connect-only in M1/M2/C3, split 29/165 in C1 and 51/143 in C2, and first-turn-only in M3. These phase shifts are observed scheduling variation; they are not catalog savings. Credit only the catalog's median −38 statements (range −38 to −37) and zero request change; other operations and phase scheduling contribute to the difference. The raw per-run warmed median rises by 0.5 statement, below the campaign noise floor; pooled raw and turn-attributed warmed medians are unchanged. No catalog SQL, catalog dispatch (including SQL-free dispatch), or unmatched catalog read was observed during warmed turns. Generic worker stacks do not identify every possible caller, so this is no observed hidden changed-owner work, not universal attribution. Whole turn-attributed request medians are 400→401, outside the catalog cohort: pair deltas are +1 ACP first-turn request, −1 second-session settlement request, and +1 second-session settlement request. Three auth-profile helper engine probes also appear on every candidate first turn; these are outside the catalog cohort, and their causal independence is not established. No wall-time improvement is claimed on this loaded host.

Pinned database-worker inventory is unchanged: repository T1 186→186, catalog kernel 2→2; the released synchronous SDK exception above remains explicit.

The prewarm recapture cluster remains unresolved: its four earlier captures occurred beside real memory DDL, which does not prove that every capture was necessary. Additional cold snapshot reads originate in session-entry-cache owners; scheduling versus invalidation remains unproven. Neither lead is changed or claimed solved by this catalog PR.

Evidence

  • Two independent Codex review rounds: scoped-clean through P2. Subsequent CI repair removes one stale wrapper-inventory entry for the deleted reader operation.
  • Changed-file type-aware lint, formatting, and whitespace checks pass. Final inventory closure probe: no stale paths or missing runtime imports.
  • CI at 9019bf8d2092: catalog reader 3/3, model registry 23/23, prepared-model sources 13/13, read-only authorization 18/18, operation transport 9/9, and compile-cache process 1/1 pass. The reader tests cover canonical writes, quarantine set/clear, tracked schema damage, bounded transfers, and source replacement before disclosure.
  • That CI also passed all selected production/test types, lint, source contracts, Madge, T1 and dialect ratchets. Two wrapper test rows failed solely because their inventory named the deleted file; final head 20dfa3519a83 removes it. Final-head CI confirms both repaired wrapper rows and all selected Node/static jobs pass.
  • Canonical Knip: 8 production and 6 full-tree findings, 0 script findings. Every finding exactly matches main CI, with the relevant source/scanner inputs unchanged. This is an inherited-failure exception, not a clean scan.
  • Local focused retry had 70 existing passes, 4 platform skips, and two new-reader failures subsequently fixed and confirmed by CI. No repeated rename hang; internal test scratch peaked at approximately 405 MB and was removed.
  • No SDK surface or update-cell gate: this changes neither SDK signatures nor update, Doctor, schema migration, plugin-loading lifecycle, or service lifecycle implementations.

CI exception and focused diagnosis

Final-head CI completed with all selected type, lint, source-contract, Madge, T1/dialect and Node jobs passing. Its required aggregate is red from eleven mocked-Gateway browser cases in seven files: stream batching/composer invalidations, model labels, deferred model responses, focus handoffs, thinking menus and host-selector focus.

Each failed case was run once on the base and once on the final candidate using the same installed dependencies and pnpm test:ui:e2e, one worker and an exact name filter: 11/11 pass on each side (30 unrelated cases intentionally excluded). The complete UI tree and dependency manifests are identical between these revisions; these scenarios replace Gateway WebSockets and supply model responses directly, so they do not call the changed catalog worker. Delayed fixture requests/render/focus are plausible dependencies, not established failure causes.

The CI failures remain unreproduced, not proven inherited or fixed. This landing uses the authorized relaxed-CI exception after the one-line wrapper repair, with all static gates green or exactly attributed as inherited, owner tests passing, both focused browser comparisons passing, and no proven product regression. No browser assertion, timeout or retry was changed, and CI was not rerun to chase green. Browser CI reliability remains a follow-up.

Follow-up

Follow-up from the completed ClawSweeper review: normalize mixed-case custom agent directory IDs before selecting the read-only scope. The review identifies a potential Foo/foo mismatch that could retain a native reader beyond result transfer, especially relevant to file replacement on Windows. This is a P2 lifecycle follow-up; the review reports no security finding. It is left separate under the requested two-round review limit and relaxed landing policy. No new review was requested.

Scope

17 files; production/tooling +141/−49, tests +343/−221, docs +6. The production growth supplies the existing owned-pool transport and bounded result channel; it deletes the generic catalog operation and registration. No new admission protocol, schema, engine branch, or SDK signature.

@clawsweeper

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

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 17, 2026 •

Copy link
Copy Markdown
Contributor

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-17T08:35:47.323609Z 9019bf8 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation agents Agent runtime and tooling size: L labels Oct 17, 2026

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 9019bf8d20

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +32 to +33
catalogs = scope.run(input, () =>
readPluginModelCatalogEntries(input, PLUGIN_MODEL_CATALOG_CACHE_SCOPE, input.pluginIds),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Normalize the agent ID before entering the read scope

When agentDir resolves to a noncanonical owner ID (for example, a custom .../Foo/agent path), scope.run records Foo, but readPluginModelCatalogEntries normalizes it to foo before calling withScopedOpenClawAgentDatabaseReadOnly. The scope therefore does not match, so the read uses the global cached scope instead; this finally closes only the unused local scope, leaving the actual SQLite handle open through result transfer and until idle expiry or invalidation. That violates this worker's close-before-transfer contract and can block database replacement/cleanup, particularly on Windows. Normalize input.agentId when constructing both the scope target and read options, as the removed operation did.

Useful? React with 👍 / 👎.

@openclaw-barnacle openclaw-barnacle Bot added the scripts Repository scripts label Oct 17, 2026
@clawsweeper clawsweeper Bot added clawsweeper:intake:feature Preliminary submission classification; full source review pending. P2 Normal backlog priority with limited blast radius. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. and removed clawsweeper:intake:feature Preliminary submission classification; full source review pending. labels Oct 17, 2026
@clawsweeper

clawsweeper Bot commented Oct 17, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs changes before merge.

What this changes

This PR moves asynchronous model-catalog reads to an owned worker that retains physical database admission facts between requests.

Example: Repeatedly load persisted catalogs for agent main.

  • Before: The generic child discards admission facts when its native reader closes.
  • After: The task worker retains admission facts while querying catalog rows on every request.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) Useful performance work with real worker integration coverage, but the introduced reader-cleanup defect prevents merge.
Proof confidence 🦐 gold shrimp (3/6) This maintainer-authored PR is outside the ordinary contributor-proof gate; supplied evidence exercises real catalog workers in integration tests, while Gateway benchmark measurements remain pending.
Patch quality 🦐 gold shrimp (3/6) 1 actionable review finding remain.

Product

Kind: Performance · Worth it: Yes · Fix scope: Complete
User problem: Model discovery repeatedly pays physical database admission cost when loading persisted provider catalogs.
Reason: The maintainer-authored direction reuses existing admission ownership without adding configuration, stored formats, or a public API.

Regression provenance

Possible regression — suspected (reviewed change). No predecessor PR is attributed.

Merge readiness

⛔ Needs changes before merge - 1 item remains

Keep open: this maintainer-directed optimization is useful, but a P2 scope-matching defect leaves native readers open for noncanonical agent IDs.

Priority: P2
Reviewed head: 20dfa3519a8341a47446b1df1be5142183263803

Before merge

  • Normalize the agent ID before entering the read scope (P2) - For a custom directory such as /tmp/catalog-owner/Foo/agent, resolveAuthProfileDatabaseOwnerId can return Foo. scope.run records that raw ID, but withOpenClawAgentDatabaseReadOnly normalizes it to foo before exact scope matching. The read consequently uses cachedScope rather than this local scope, so the finally block closes an unused scope and leaves the actual native reader open through result transfer and until later cleanup. This breaks the close-before-transfer contract and can interfere with database replacement, especially on Windows. Restore the removed operation’s normalization and use the same normalized options for both calls.

Findings

  • [P2] Normalize the agent ID before entering the read scope — src/agents/plugin-model-catalog-read.worker.ts:32-33

Tests

  • Missing end-to-end proof: No shipped Gateway workload trace or base-to-head admission-count measurement is supplied.
Agent review details

How this fits together

Agent preparation and model registries request persisted catalogs from per-agent databases; the worker returns catalog rows while the host retains lifecycle and disclosure authority.

flowchart LR
  A[Agent preparation] --> B[Catalog read owner]
  B --> C[Owned task worker]
  C --> D[Catalog query kernel]
  D --> E[Agent database]
  F[Admission publications] --> C
  C --> B
Loading

Technical review

Best possible solution:

Keep the owned-worker transport and normalize the worker’s agent ID once before supplying identical options to the scope and query kernel.

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

At the reviewed head, an unregistered custom directory ending in Foo/agent produces scope ID Foo while the reader requests foo, selecting an unclosed cached scope; this was verified from source without executing target code.

Is this the best way to solve the issue?

Reusing the existing admission relay is a coherent optimization with a complete transport cutover, but the replacement must preserve the former operation’s normalized scope target.

Full review comments:

  • [P2] Normalize the agent ID before entering the read scope — src/agents/plugin-model-catalog-read.worker.ts:32-33
    For a custom directory such as /tmp/catalog-owner/Foo/agent, resolveAuthProfileDatabaseOwnerId can return Foo. scope.run records that raw ID, but withOpenClawAgentDatabaseReadOnly normalizes it to foo before exact scope matching. The read consequently uses cachedScope rather than this local scope, so the finally block closes an unused scope and leaves the actual native reader open through result transfer and until later cleanup. This breaks the close-before-transfer contract and can interfere with database replacement, especially on Windows. Restore the removed operation’s normalization and use the same normalized options for both calls.
    Confidence: 0.99
    Late finding: first raised on code an earlier review cycle already covered.

Overall correctness: patch is incorrect
Overall confidence: 0.96

AGENTS.md: found and applied where relevant.

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

Provenance checked

Testing

Proof path: in-process harness.

Security

None.

Evidence

Acceptance criteria:

  • pnpm test src/agents/plugin-model-catalog-read.test.ts src/agents/prepared-model-runtime.sources.test.ts --maxWorkers=1
  • node scripts/check-changed.mjs --base 20dfa35

What I checked:

Likely related people:

  • Peter Steinberger: Raw commit 93625aa adds src/agents/plugin-model-catalog.kernel.ts:20 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 93625aa3d10d; files: src/agents/plugin-model-catalog.kernel.ts)
  • Vincent Koc: Raw commit 54644ea adds src/agents/plugin-model-catalog.kernel.ts:34 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: medium; commits: 54644eab32b2; files: src/agents/plugin-model-catalog.kernel.ts)

PR surface

Source +93, Tests +122, Docs +6, Other -1. Total +220 across 17 files. Added test files: 1.

View PR surface stats
Area Files Added Removed Net
Source 9 141 48 +93
Tests 6 343 221 +122
Docs 1 6 0 +6
Config 0 0 0 0
Generated 0 0 0 0
Other 1 0 1 -1
Total 17 490 270 +220

Review metrics

Metric Value Why it matters
Production versus test LOC Production +141/-48; tests +343/-221 Production growth supplies the owned-worker adapter and bounded transfer channel; most test churn replaces fixtures for the retired generic operation.

Labels

Label changes:

  • add P2: A supported custom agent-directory spelling can retain a native reader beyond task completion and interfere with database replacement or cleanup.
  • add rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🦐 gold shrimp.
  • add status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action.

Label justifications:

  • P2: A supported custom agent-directory spelling can retain a native reader beyond task completion and interfere with database replacement or cleanup.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🦐 gold shrimp.
  • status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action.

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 October 17, 2026, 5:00 AM ET / 09:00 UTC.

@steipete

Copy link
Copy Markdown
Contributor Author

Follow-up from the completed ClawSweeper review: normalize mixed-case custom agent directory IDs before selecting the read-only scope. The review identifies a potential Foo/foo mismatch that could retain a native reader beyond result transfer, especially relevant to file replacement on Windows. This is a P2 lifecycle follow-up; the review reports no security finding. It is left separate under the requested two-round review limit and relaxed landing policy. No new review was requested.

@steipete
steipete merged commit 9c12710 into main Oct 17, 2026
174 of 183 checks passed
@steipete
steipete deleted the dbasync/quarantinefacts2 branch October 17, 2026 09:08
steipete added a commit that referenced this pull request Oct 17, 2026
The async catalog reader added in #175347 is a separate worker pool.
Reuse the fixture's existing source-worker observer instead of counting
all process workers. Keep every failure, replacement, and peak assertion.

Test-only: catalog publication, recovery, and update behavior are unchanged.
Original regression reproduced; all 18 importing files pass (76 tests,
391.73s wall with --maxWorkers=1). Targeted types/lint/format, architecture,
source contracts, and P2 review pass. Existing unrelated Knip exports remain.
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 18, 2026
…w#175347)

Route async generated-model catalog reads through the owned read-only worker pool so physical admission facts survive reader cleanup and owner publications invalidate them. Remove the generic catalog read operation and the duplicate post-capture check; preserve final disclosure authority and fresh row reads.

Owner tests and static gates pass, with exactly attributed inherited Knip findings. Eleven mocked-UI CI failures pass in focused base/head runs; land with the authorized relaxed-CI exception. SQL measurement evidence follows on the PR.
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 18, 2026
The async catalog reader added in openclaw#175347 is a separate worker pool.
Reuse the fixture's existing source-worker observer instead of counting
all process workers. Keep every failure, replacement, and peak assertion.

Test-only: catalog publication, recovery, and update behavior are unchanged.
Original regression reproduced; all 18 importing files pass (76 tests,
391.73s wall with --maxWorkers=1). Targeted types/lint/format, architecture,
source contracts, and P2 review pass. Existing unrelated Knip exports remain.
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 P2 Normal backlog priority with limited blast radius. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. scripts Repository scripts size: L status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant