Repository navigation
perf(gateway): omit duplicate model catalogs from chat metadata - #165190
Conversation
Let clients reading models.list request only commands and swarm metadata. Preserve the default native and legacy model, account, and runtime-lock response, with unchanged request authority checks. Use the direct catalog owner for Control UI invalidation and remove its second catalog comparison and pending-reader machinery. Compact reads use the prepared command facts and skip unused model and ACP projections.
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
|
Codex review: needs maintainer review before merge. Reviewed October 4, 2026, 9:20 PM ET / October 5, 2026, 01:20 UTC (Revision 4). ClawSweeper reviewWhat this changesAdds compact Gateway chat metadata responses and updates the Control UI to refresh model choices through its existing catalog owner while preserving default native and legacy responses. Merge readiness✅ Ready for maintainer review Keep open: current main still transfers the duplicate catalog, and this PR provides useful, measured performance improvements. No actionable correctness finding or additional merge blocker was identified. Priority: P2 Review scores
Verification
How this fits togetherThe Gateway supplies chat commands and model-selection information to connected clients. The Control UI already reads model choices separately, so compact metadata avoids preparing and transferring the same catalog twice. flowchart TD
A[Chat metadata request] --> B[Session and profile access checks]
B --> C{Include model information?}
C -->|Yes by default| D[Model and session projection]
C -->|No| E[Prepared commands and swarm availability]
D --> F[Metadata response]
E --> F
G[Direct model catalog] --> H[Control UI model picker]
Before mergeNone. Agent review detailsSecurityNone. PR surfaceSource -91, Tests -31, Docs +6. Total -116 across 20 files. View PR surface stats
Review metrics
Technical reviewBest possible solution: Keep commands and model choices with their existing owners, using compact metadata for the bundled UI and the unchanged full response for default callers. Do we have a high-confidence way to reproduce the issue? Not applicable as a bug reproduction: this is a performance optimization. Current-main source confirms duplicate catalog projection, and the recorded before/after rig measures its cost. Is this the best way to solve the issue? Yes: an additive compact response removes redundant work while preserving existing callers and the direct catalog owner's lifecycle. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against a2affcf76e93. LabelsLabel changes: No label changes. Label justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (3 earlier review cycles) |
…claw#165190) * perf(gateway): omit duplicate model catalogs from chat metadata Let clients reading models.list request only commands and swarm metadata. Preserve the default native and legacy model, account, and runtime-lock response, with unchanged request authority checks. Use the direct catalog owner for Control UI invalidation and remove its second catalog comparison and pending-reader machinery. Compact reads use the prepared command facts and skip unused model and ACP projections. * fix(gateway): keep chat metadata projection types acyclic * refactor(gateway): keep prepared metadata facts type private
What Problem This Solves
Control UI metadata refreshes project and transfer a second model catalog even though
models.listalready owns the picker. Saved-session metadata also reads ACP state to produce a runtime-lock field the UI does not consume here.User Impact
The bundled Control UI requests compact metadata containing commands and swarm availability. Model/account data stays with its direct catalog owner. Existing native and legacy requests keep their default response, including runtime locking; there is no protocol-version or configuration change.
Why This Change Was Made
The prepared runtime already caches shared catalog preparation by generation. Warm requests still project the public model rows, apply role/fast-mode presentation, and serialize the duplicate catalog. An additional 30-byte
runtimeSelectionLockedfield causes anacpSessions.metadataworker request for each saved-session read.The additive
includeModels: falseoption skips those unused projections and reads existing command facts from the metadata generation. The UI removes its catalog-equality comparison, pending-result observer, and retained-scope exception. Matching session patches now invalidate the direct catalog through the existing coalesced refresh, rather than comparing a duplicate catalog first; this can add a direct catalog read for an otherwise unchanged patch.Default inclusion preserves the documented legacy/native contract. Native clients also support older Gateways which reject unknown parameters, so their request shape stays unchanged. Compact and catalog reads share the existing retired-owner rejection and retain final currency/request-authority checks. The presentation helper and projection type live together at their existing owner. Production delta excluding tests, test support, and docs: −91 LOC.
Evidence
Same synthetic fixture, same replacement Testbox (
blacksmith-testbox,openclaw-check,tbx_01m44ak2q91f2db17mbrx6mqr2, Linux / Node 24.19.0): six agents, six providers, 120 models with fast-mode settings, and 29 connections of one authenticated user. The rig exercises the actual handler, metadata runtime, catalog/command projection, SQLite profile authority, and a real persisted shared session selected bysessionKey. Published model/auth owner facts are injected; no live provider discovery is involved.Payload attribution: models 46,312 B; commands 15,058 B; account selection 77 B; model policy 80 B; runtime lock 30 B; swarm flag 19 B, plus outer punctuation. Thinking-level descriptions alone contribute 16,560 B within models. Neither revision rebuilds shared catalog preparation on warm reads; compact reads also avoid the public catalog reader entirely. Default legacy payloads remain exactly 61,272 B for drafts and 61,303 B for saved sessions, including the legacy fast-mode presentation.
Profile authority remains one worker request per call. In the saved-session burst, its elapsed phase averages 24.767 ms before and 27.813 ms after, including queue/worker scheduling. This fixture does not claim to reproduce a live 214–215 ms deployment observation or WebSocket queue timing. It has no native runtime alternatives, personal-account discovery, or ACP row. Process RSS across the complete rig was 492→1,088 MiB before and 498→1,013 MiB after; this is not a retained-heap improvement claim.
The new handler regression fails on the original code because it rejects
includeModels. The bounded retirement negative control fails on the intermediate compact path withCompact metadata repeatedly read a retired owner; the final regression rejects after one owner check. The final saved-session proof asserts zero ACP reads for compact responses and preserves the lookup/runtime-lock field for default responses. Closed draft authority and plugin retirement before replacement remain covered.Final proof: 790 focused tests and the full changed-code gate passed on
bfaa7c37806d; the type-only CI follow-ups pass architecture, core typing, and dead-code checks as detailed below; CI for34e661090f34passed. The original lane commitbfaa7c37806drebased without conflicts onto8bc460204197, preserving its patch ID. Follow-up628929134c62only removes a type-import back edge; emitted runtime behavior is unchanged. Performance measurements used the earlierf0b38edab5dabase and the same lane implementation. Independent review reported no actionable P0–P2 findings; the final return-type annotation was verified by compilation and matching source hashes. Broad coverage included 20 metadata/model files and eight UI consumer files, with corrected affected files rerun. The original published lane commit passed all 362 metadata/model tests in 20 files and all 428 UI consumer tests in eight files. The earlier focused proof also covered both existing plugin-retirement integration cases.Validation cost and remote run record
All heavy work ran on
blacksmith-testbox/openclaw-check. The CLI did not return run URLs. The initial lease wastbx_01m446gspy1nvrsahb5q3sx24s; its replacement istbx_01m44ak2q91f2db17mbrx6mqr2.pnpm install --frozen-lockfile;pnpm docs:listnode scripts/run-vitest.mjs ... --maxWorkers=1 -t "serves commands without preparing"INVALID_REQUESTfailure.check-changed --stagedcommandsas required; explicitly bound the reader toChatMetadataResult..rigartifacts widened selection to all lanes; canceled and verified no gate processes remained.tbx_01m44f7f2a898v2vybnzvkja6cbfaa7c37806d(145.29 s metadata/models, 7.60 s UI; 181.1 s total remote command).node scripts/check-changed.mjs --staged== exit=0, 22:30–23:21 UTC. Node 26.8.1 / pnpm 12.5.1, low CPU/I/O priority, worktree-local temp directory. Staged treecc247dc6ac5dmatches the published commit; worktree/index parity rechecked after completion.Measured one-worker file costs using
node scripts/run-vitest.mjs <file> --maxWorkers=1(the repository test entrypoint):chat-metadata-handler.test.tschat-metadata-runtime.native-session.test.tschat-metadata-runtime.test.tschat-metadata-runtime.cache.test.ts(final fixture)chat-metadata-store.test.tschat-metadata-refresh.test.tschat-send.test.tsThe handler wall time includes cold compiled-worker preparation and existing SQLite authority cases; its added compact-response case took 10 ms. The final four-file metadata rerun, including the new retirement case, passed 88 tests in 42.54 s of Vitest time. No real timer or per-test Gateway boot was added. Final-head CI took 663 s wall time and 10,665 summed job elapsed seconds (53 successful jobs, 19 intentionally skipped).
Rig gate outcome retained in its final log:
== exit=0 (23:21Z)CI follow-up: run 37244440515 failed
check-additional-runtime-topology-architectureand canceled dependent jobs. Its runtime cycle check passed, but Madge identified the type-onlychat-metadata-facts↔chat-metadata-session-projectionedge. The follow-up uses the projection module's existing narrower facts contract and removes the reverse import. On the approved rig,pnpm check:architecturepassed (Madge: zero cycles; all remaining architecture guards passed), followed bynode scripts/run-tsgo.mjs -p tsconfig.core.json --incremental --tsBuildInfoFile .artifacts/tsgo-cache/core.tsbuildinfo; the final marker wasLANE429_CYCLE_FIX_PASS. Independent review returned no actionable findings.CI dependency follow-up: run 37246887450 passed architecture, production typing, all test-type shards, and lint, but
check-dependenciesfound thatPreparedAgentFactsno longer needs to be exported after the narrowed projection contract. The cleanup makes that type private; all remaining references are in its defining module. Onopenclaw-node-01, in/srv/rig/wt-429-payload-20261004-2227,nice -n 10 ionice -c3 pnpm deadcode:fullpassed both scans with the cleanup applied (201.2 s and 263.3 s). An additional core typecheck was OOM-killed (exit 137); it is not counted as passing proof. The original full changed-code gate and prior CI typecheck results remain qualified to their recorded heads.Commit
34e661090f34contains only the private-type cleanup. Independent review completed with no actionable P0–P2 findings before commit.Final outcome: CI run 37250604424 passed on exact head
34e661090f34ab5c19db3ec42c4011596ec74194, including the aggregate CI gate: 53 successful jobs, 19 intentionally skipped, no failed or canceled jobs. Elapsed cost was 663 s wall time and 10,665 summed job seconds. The configured watcher merged the PR at 2026-10-05 01:25:27 UTC as84c2e861be4c763b8080819dbf0227a681492f6e. All Testbox leases were stopped.