Skip to content

perf(gateway): omit duplicate model catalogs from chat metadata - #165190

Merged
steipete merged 3 commits into
mainfrom
steipete/perf-micro-chat-metadata-payload-20260919
Oct 5, 2026
Merged

steipete merged 3 commits into
mainfrom
steipete/perf-micro-chat-metadata-payload-20260919

Conversation

@steipete

@steipete steipete commented Oct 4, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Control UI metadata refreshes project and transfer a second model catalog even though models.list already 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 runtimeSelectionLocked field causes an acpSessions.metadata worker request for each saved-session read.

The additive includeModels: false option 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 by sessionKey. Published model/auth owner facts are injected; no live provider discovery is involved.

Metric Before After
Saved-session response payload 61,583 B 15,080 B (−75.5%)
Saved-session warm handler mean, 60 reads 8.266 ms 3.221 ms
Saved-session warm handler p95 11.067 ms 5.784 ms
Saved-session warm metadata-read mean 5.229 ms 0.380 ms
Saved-session 29-connection burst handler mean 128.859 ms 30.616 ms
Saved-session burst handler p95 197.363 ms 53.539 ms
Saved-session burst metadata-read mean 101.556 ms 0.968 ms
Saved-session ACP worker reads per request 1 0
Saved-session serialization mean 0.089 ms 0.029 ms
Draft warm handler mean 5.384 ms 0.899 ms
Draft warm metadata-read mean 3.381 ms 0.016 ms

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 with Compact 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 for 34e661090f34 passed. The original lane commit bfaa7c37806d rebased without conflicts onto 8bc460204197, preserving its patch ID. Follow-up 628929134c62 only removes a type-import back edge; emitted runtime behavior is unchanged. Performance measurements used the earlier f0b38edab5da base 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 was tbx_01m446gspy1nvrsahb5q3sx24s; its replacement is tbx_01m44ak2q91f2db17mbrx6mqr2.

Command / purpose Result
Initial warmup; pnpm install --frozen-lockfile; pnpm docs:list Passed.
Original-code handler regression via node scripts/run-vitest.mjs ... --maxWorkers=1 -t "serves commands without preparing" Expected INVALID_REQUEST failure.
Initial draft benchmark Fixture lacked an explicit system-agent selection; corrected before recording measurements.
Paired draft benchmark on initial lease Both passed; 61,552→15,080 B and 5.005→0.914 ms warm handler mean.
Metadata/model suites and UI consumers, one worker 786 passed; three new/updated expectations failed. Fixed the assumed swarm default and invalidated queued-catalog expectation.
Corrected six-file rerun All 256 tests passed.
Initial check-changed --staged Raw sync did not preserve the local index; empty-path result discarded.
Working-tree changed checks Caught line-cap growth and unrelated base drift, then strict runtime limit after typing passed. Moved existing presentation/types to their owner, reused test scope, and selected the lane base.
Targeted lint then changed-gate replay Lint passed; initial lease became completed mid-gate, exit 255 after 19 passing typecheck groups.
Replacement warmup Ready after approximately 16 minutes queued; same provider/profile.
Replacement early lint Caught generic inference treating commands as required; explicitly bound the reader to ChatMetadataResult.
Saved-session before/after rig, retirement negative control, 88 metadata tests, two lifecycle cases Passed; negative control failed for the intended bounded-loop reason. Command including compilation took 274.5 s.
Working-tree gate after benchmark Temporary .rig artifacts widened selection to all lanes; canceled and verified no gate processes remained.
First exactly-staged gate Canceled run had left a dist-artifact lock. Verified the recorded owner and all associated build/check processes had stopped, then released the task-owned lock using its documented recovery.
Final cache suite and exactly-staged gate Six cache tests and all typing passed. Knip found the now-internal session presenter still exported; removed that unused export.
Export-cleanup replay Source sync hit the provider's two-minute timeout before execution. Stopped the lease, committed/rebased the reviewed lane, and warmed the published ref.
Published-head lease tbx_01m44f7f2a898v2vybnzvkja6c Ready after more than 20 minutes queued; all 790 focused tests passed on bfaa7c37806d (145.29 s metadata/models, 7.60 s UI; 181.1 s total remote command).
Approved Linux rig fallback: node scripts/check-changed.mjs --staged Passed, == 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 tree cc247dc6ac5d matches 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):

File Tests Wall time
chat-metadata-handler.test.ts 36 33.91 s
chat-metadata-runtime.native-session.test.ts 6 11.78 s
chat-metadata-runtime.test.ts 40 10.33 s
chat-metadata-runtime.cache.test.ts (final fixture) 6 23.04 s
UI chat-metadata-store.test.ts 35 1.81 s
UI chat-metadata-refresh.test.ts 22 1.76 s
UI chat-send.test.ts 117 3.43 s

The 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:

Check Result
Core, test graphs, UI typing Passed
Script, production, full-tree unused-export scans 0 entries
Core lint, 18 files / 264 rules 0 warnings, 0 errors
UI style checks Passed
Native state schema v20 passed
Runtime import cycles 0
Database, media, sidecar, webhook and pairing guards Passed
Final helper marker == exit=0 (23:21Z)

CI follow-up: run 37244440515 failed check-additional-runtime-topology-architecture and canceled dependent jobs. Its runtime cycle check passed, but Madge identified the type-only chat-metadata-facts ↔ chat-metadata-session-projection edge. The follow-up uses the projection module's existing narrower facts contract and removes the reverse import. On the approved rig, pnpm check:architecture passed (Madge: zero cycles; all remaining architecture guards passed), followed by node scripts/run-tsgo.mjs -p tsconfig.core.json --incremental --tsBuildInfoFile .artifacts/tsgo-cache/core.tsbuildinfo; the final marker was LANE429_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-dependencies found that PreparedAgentFacts no longer needs to be exported after the narrowed projection contract. The cleanup makes that type private; all remaining references are in its defining module. On openclaw-node-01, in /srv/rig/wt-429-payload-20261004-2227, nice -n 10 ionice -c3 pnpm deadcode:full passed 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 34e661090f34 contains 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 as 84c2e861be4c763b8080819dbf0227a681492f6e. All Testbox leases were stopped.

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.
@clawsweeper

clawsweeper Bot commented Oct 4, 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 app: web-ui App: web-ui gateway Gateway runtime size: L labels Oct 4, 2026
@clawsweeper clawsweeper Bot added 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. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Oct 4, 2026
@clawsweeper

clawsweeper Bot commented Oct 4, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed October 4, 2026, 9:20 PM ET / October 5, 2026, 01:20 UTC (Revision 4).

ClawSweeper review

What this changes

Adds 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
Reviewed head: 34e661090f34ab5c19db3ec42c4011596ec74194

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused optimization with useful production-boundary measurements, preserved compatibility, and no actionable findings.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (live_output): The captured Testbox before/after results exercise the changed metadata handler and runtime against SQLite profile authority and a persisted session, demonstrating smaller responses and eliminated compact ACP reads while retaining default payloads. Provider facts are injected, so proof is scoped to this production boundary; no stored-data contract changes.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (live_output): The captured Testbox before/after results exercise the changed metadata handler and runtime against SQLite profile authority and a persisted session, demonstrating smaller responses and eliminated compact ACP reads while retaining default payloads. Provider facts are injected, so proof is scoped to this production boundary; no stored-data contract changes.
Evidence reviewed 9 items Introduced change ownership: Reviewed the pinned merge-base-to-head diff. The latest commit changes only PreparedAgentFacts from exported to private; the prior completed review reported no findings. The supplied test merge is stale against the pinned base and was not used to infer removals of current-main behavior.
Current-main necessity: Current main's closed chat.metadata parameter schema has no includeModels option, and its UI still requests metadata using the unmodified scope. The compact path is therefore distinct remaining work.
Latest release contract: The v2026.9.8 schema also lacks includeModels. Its source was inspected through GitHub's contents endpoint after the local release blob was unavailable.
Findings None None.
Security None None.

How this fits together

The 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]
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source -91, Tests -31, Docs +6. Total -116 across 20 files.

View PR surface stats
Area Files Added Removed Net
Source 11 92 183 -91
Tests 8 135 166 -31
Docs 1 8 2 +6
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 20 235 351 -116

Review metrics

Metric Value Why it matters
Protocol option 1 optional boolean; default inclusion preserved Existing callers retain their response while clients with a separate model reader can request compact metadata.
Measured saved-session payload 61,583 → 15,080 bytes (−75.5%) The recorded production-boundary rig demonstrates the intended transfer reduction.

Technical review

Best 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.

Labels

Label changes:

No label changes.

Label justifications:

  • P2: This is a bounded chat-metadata performance improvement with measured benefit and preserved default behavior.
  • 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 (live_output): The captured Testbox before/after results exercise the changed metadata handler and runtime against SQLite profile authority and a persisted session, demonstrating smaller responses and eliminated compact ACP reads while retaining default payloads. Provider facts are injected, so proof is scoped to this production boundary; no stored-data contract changes.
  • proof: sufficient: Contributor real behavior proof is sufficient. The captured Testbox before/after results exercise the changed metadata handler and runtime against SQLite profile authority and a persisted session, demonstrating smaller responses and eliminated compact ACP reads while retaining default payloads. Provider facts are injected, so proof is scoped to this production boundary; no stored-data contract changes.

Evidence

What I checked:

  • Introduced change ownership: Reviewed the pinned merge-base-to-head diff. The latest commit changes only PreparedAgentFacts from exported to private; the prior completed review reported no findings. The supplied test merge is stale against the pinned base and was not used to infer removals of current-main behavior. (src/gateway/server-methods/chat-metadata-facts.ts:21, 34e661090f34)
  • Current-main necessity: Current main's closed chat.metadata parameter schema has no includeModels option, and its UI still requests metadata using the unmodified scope. The compact path is therefore distinct remaining work. (packages/gateway-protocol/src/schema/logs-chat.ts:182, a2affcf76e93)
  • Latest release contract: The v2026.9.8 schema also lacks includeModels. Its source was inspected through GitHub's contents endpoint after the local release blob was unavailable. (packages/gateway-protocol/src/schema/logs-chat.ts, fc23bc864e45)
  • Compact path and authorization: The compact runtime returns prepared commands and swarm availability before model/account/ACP projection. The handler still resolves session/profile authority and rechecks it after the awaited read and before responding; no new authority-bearing state or principal access is introduced. (src/gateway/server-methods/chat-metadata-handler.ts:169, 34e661090f34)
  • Single catalog owner and upgrade behavior: Session events invalidate the direct catalog before metadata listeners reload. Existing refresh admission, transport settlement, and publication fences remain. Default inclusion retains the native/legacy response; ui/AGENTS.md explicitly establishes that the bundled UI and Gateway ship together without older-Gateway compatibility code. No persisted format or settings change is introduced. (ui/src/lib/chat/chat-metadata-cache.ts:102, 34e661090f34)
  • Recorded production-boundary proof: The captured PR body records a Linux/Node 24.19.0 Testbox before/after rig using the actual metadata handler, runtime, projections, SQLite profile authority, and a persisted shared session. Saved-session payload fell from 61,583 to 15,080 bytes, warm handler mean from 8.266 to 3.221 ms, and compact ACP reads from one to zero. Default payloads remained unchanged. Injected published provider facts limit these measurements to the exercised boundary; they do not establish live-provider discovery or WebSocket queue performance. (bfaa7c37806d)

Likely related people:

  • steipete: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • shakkernerd: 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 (3 earlier review cycles)
  • reviewed 2026-10-04T23:34:51.807Z sha bfaa7c3 :: needs maintainer review before merge. :: none
  • reviewed 2026-10-04T23:41:39.012Z sha bfaa7c3 :: needs maintainer review before merge. :: none
  • reviewed 2026-10-05T00:22:21.212Z sha 6289291 :: needs maintainer review before merge. :: none

@steipete
steipete marked this pull request as ready for review October 4, 2026 23:37
@steipete
steipete enabled auto-merge (squash) October 4, 2026 23:40
@steipete
steipete merged commit 84c2e86 into main Oct 5, 2026
128 of 129 checks passed
@steipete
steipete deleted the steipete/perf-micro-chat-metadata-payload-20260919 branch October 5, 2026 01:25
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 5, 2026
…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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

app: web-ui App: web-ui docs Improvements or additions to documentation gateway Gateway runtime 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. size: L 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