Skip to content

improve: reduce model catalog allocations after configuration reloads - #160819

Closed
steipete wants to merge 1 commit into
mainfrom
codex/perf-catalog-config-capture-20260928
Closed

steipete wants to merge 1 commit into
mainfrom
codex/perf-catalog-config-capture-20260928

Conversation

@steipete

@steipete steipete commented Sep 29, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

After a neutral configuration reload, listing models and reading retained chat metadata can repeatedly copy the whole configuration for every model.

User Impact

Model selection and chat metadata do less allocation work after a reload while retaining the same models, authentication decisions, and readiness checks. No schema change, migration, configuration option, or operator action is required.

Why This Change Was Made

The managed reload publishes an equal-but-distinct runtime config object. Passing the prepared owner's original object into each model decision repeatedly reconstructs its source projection. The existing catalog projector now captures the runtime/source pair once and carries it through catalog preparation and retained metadata reads. This uses the existing capture owner and introduces no additional cache.

The original request stamps, observation identity, current-owner checks, live authentication store, authentication deadlines, and personal model pins retain their existing owners. Tests exercise the registered models.list handler and metadata preparation after an actual managed neutral publication.

Evidence

For a synthetic 32-model catalog, a single matched measurement produced:

Operation Full-config clones before → after Wall time before → after
Registered models.list 97 → 3 14.10 → 10.11 ms
Metadata preparation 97 → 3 15.94 → 8.06 ms
32 retained metadata reads 1,024 → 0 68.59 → 47.97 ms

The clone counts establish the bounded allocation improvement. These are single timing samples on an isolated Node 24.19.0 runner, not a whole-Gateway latency claim. Small-case timings were mixed, and whole-command peak RSS was essentially unchanged. The temporary benchmark is not added to the test suite.

The original regression fails with 4 and 97 projections exceeding the preparation bound for one and 32 models. The candidate passes with one projection per preparation and none during retained reads, while preserving returned values and owner retirement.

The final focused run passed 56 tests across eight files in 62.13 seconds command wall, using node scripts/run-vitest.mjs with --maxWorkers=1. Coverage includes native readiness and revocation, owner/config stamps, authentication deadlines, personal pins, published results, plugin runtime, and configured runtime choices. The two new regression bodies took 454 ms and 141 ms. The two updated configured-index/authentication cases took 456 ms and 99 ms. Their fixture now observes the actual index owner and live auth store; restoring the original per-row construction still fails the index bound with 5 > 1. Hosted CI measured 0.395 seconds across the two new regression bodies and 1.126 seconds for the updated index/authentication pair; these exclude setup and shard overhead.

The full changed gate passed core types, all 27 test type-check groups, four-file lint with zero warnings/errors, formatting, dead exports, schema/legacy-store guards, import cycles, and the remaining structural checks in 1,263.66 seconds. All 31 recorded source/toolchain inputs matched before and after execution. Incorporation onto main 632b150d462f preserves those inputs and all four reviewed file contents. Fresh independent P0–P2 review is clean.

The first hosted CI run passed all Node test shards. Its remaining browser shard exceeded the 25-minute job limit after two chat position-rail tests timed out at 120 seconds each. The required gate is red; the investigation below did not establish a product fix.

A bounded replay of the same merged source passed 81 files / 354 tests in 394.803 seconds command wall (392.55 seconds Vitest) on an isolated Node 24.19.0 runner with four-CPU affinity and three workers. The native Vitest result cache was cleared and all 81 files matched the original cold shard order before execution. The original failing reader-dark and 80-message LTR layout cases passed in 20.114 and 22.352 seconds. Test source, assertions, and the 120-second test limit were unchanged.

Across 155 matching cases, the hosted median non-rail duration was 7.27 times the replay duration. The original job retained no quota, memory, steal-time, or timeout-capture evidence sufficient to explain this broad slowdown; the isolated machine is not fully equivalent to that runner. A passing replay does not prove a fix. No UI repair or hosted rerun was made, and the failed required gate remains unresolved.

@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 complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@steipete
steipete marked this pull request as ready for review September 29, 2026 00:05
@openclaw-barnacle openclaw-barnacle Bot added gateway Gateway runtime agents Agent runtime and tooling size: M labels Sep 29, 2026
@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 Sep 29, 2026
@clawsweeper

clawsweeper Bot commented Sep 29, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed September 28, 2026, 9:38 PM ET / September 29, 2026, 01:38 UTC (Revision 3).

ClawSweeper review

What this changes

The branch reuses one captured configuration while preparing Gateway model choices and retained chat metadata, with regression coverage for a configuration reload.

Merge readiness

✅ Ready for maintainer review

Keep this PR open. Current main still has the repeated projection path, and the recorded benchmark and focused regression coverage support the optimization. I found no concrete introduced defect. The PR documents a browser CI timeout that the native landing gate must handle.

Priority: P2
Reviewed head: 934b477aa8e870f9c7b468c6c633f3c878380f10

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) The focused implementation, regression coverage, and measured production-path result support a normal good rating; the single timing sample has appropriately limited scope.
Proof confidence 🐚 platinum hermit (4/6) Sufficient (live_output): The PR records before/after measurements on an isolated Node 24.19.0 runner for registered Gateway model listing and retained chat-metadata reads after neutral reload, with fewer config clones and unchanged returned models. The synthetic-catalog test exercises those production entry points; 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 PR records before/after measurements on an isolated Node 24.19.0 runner for registered Gateway model listing and retained chat-metadata reads after neutral reload, with fewer config clones and unchanged returned models. The synthetic-catalog test exercises those production entry points; no stored-data contract changes.
Evidence reviewed 9 items Introduced production change: The PR captures configuration once for catalog decisions and reuses that captured value in catalog projection and model-list preparation.
Capture owner: The existing capture helper returns an already captured config unchanged; otherwise it pairs runtime config with its authored source projection.
Production entry points: The registered model-list handler calls the result builder, while chat metadata creates a catalog projector and passes it into model-list preparation.
Findings None None.
Security None None.

How this fits together

The Gateway reads an agent's prepared model catalog when clients list models or request chat metadata. Configuration and live authentication feed the catalog decisions, which produce visible choices and availability.

flowchart LR
  A[Configuration reload] --> B[Runtime and source capture]
  B --> C[Prepared model catalog]
  D[Live authentication] --> E[Model decisions]
  C --> E
  E --> F[Gateway model list]
  E --> G[Chat metadata]
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source +5, Tests +207. Total +212 across 4 files.

View PR surface stats
Area Files Added Removed Net
Source 1 10 5 +5
Tests 3 262 55 +207
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 4 272 60 +212

Review metrics

Metric Value Why it matters
32-model allocation measurement model list 97→3 clones; 32 retained metadata reads 1,024→0 The matched measurement quantifies the claimed improvement without presenting its single timing sample as a whole-Gateway latency result.
Production and test growth production +5 net lines; tests and test support +207 net lines The small production change has a stated justification, while the new managed-reload regression accounts for most growth and has reported test cost.

Technical review

Best possible solution:

Keep catalog decisions on the existing captured runtime/source pair while preserving live authentication checks and prepared-owner retirement.

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

Yes. A managed neutral reload yields an equal but distinct config, and the current-main call path plus the recorded 32-model measurement give a focused reproduction path; I did not execute code in this read-only review.

Is this the best way to solve the issue?

Yes. Reusing the existing config-capture owner is a narrow way to remove repeated projection work, and the added coverage checks returned models and owner retirement.

AGENTS.md: found and applied where relevant.

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

Labels

Label changes:

No label changes.

Label justifications:

  • P2: This is a bounded model-catalog performance improvement without evidence of an outage or urgent user regression.
  • 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 records before/after measurements on an isolated Node 24.19.0 runner for registered Gateway model listing and retained chat-metadata reads after neutral reload, with fewer config clones and unchanged returned models. The synthetic-catalog test exercises those production entry points; no stored-data contract changes.
  • proof: sufficient: Contributor real behavior proof is sufficient. The PR records before/after measurements on an isolated Node 24.19.0 runner for registered Gateway model listing and retained chat-metadata reads after neutral reload, with fewer config clones and unchanged returned models. The synthetic-catalog test exercises those production entry points; no stored-data contract changes.

Evidence

What I checked:

Likely related people:

  • Peter Steinberger: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • Ayaan Zaidi: 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 (2 earlier review cycles)
  • reviewed 2026-09-29T00:21:21.384Z sha 934b477 :: needs maintainer review before merge. :: none
  • reviewed 2026-09-29T00:47:02.017Z sha 934b477 :: needs maintainer review before merge. :: none

@steipete
steipete enabled auto-merge (squash) September 29, 2026 00:30
@clawsweeper clawsweeper Bot added the proof: sufficient ClawSweeper judged the real behavior proof convincing. label Sep 29, 2026
@openclaw-barnacle

Copy link
Copy Markdown

This pull request has been automatically marked as stale due to inactivity.
Please add updates or it will be closed.

@openclaw-barnacle openclaw-barnacle Bot added the stale Marked as stale due to inactivity label Oct 13, 2026
@roboclaw-bot

Copy link
Copy Markdown
Collaborator

Superseded by the merged model-list repair in #168733 and the remaining chat-metadata fix in #173850 (merge commit ac4a4567b561a6e47d5433459ab856a53f73d93d).

The current-source production-boundary regression verifies one full source projection after a neutral reload for both 1 and 32 models (previously 2 and 33), zero on retained reads, unchanged model/account results, and correct withdrawal after owner retirement. The replacement passed 58 focused tests and its exact-head CI.

Thanks @steipete for the original report and proposal. Closing this older implementation now that both paths are covered on main.

auto-merge was automatically disabled October 16, 2026 05:40

Pull request was closed

@RomneyDa
RomneyDa deleted the codex/perf-catalog-config-capture-20260928 branch October 22, 2026 05:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling 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: M stale Marked as stale due to inactivity 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.

2 participants