Repository navigation
perf(models): reduce catalog worker standing heap - #164428
Conversation
Use generation-owned metadata array identities for same-turn auto-enable reuse instead of retaining serialized copies of every manifest subtree. Keep normalized static provider catalogs as the sole prepared result and reuse them for discovery fallback. A synthetic Linux dist Gateway with two agents and 302 model rows reduces catalog worker post-GC heap from 149.62 MiB to 141.69 MiB (5.3%). The removed memo retained 7,669,416 bytes across 41,158 serialization string nodes.
|
🦞👀 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 3, 2026, 1:46 PM ET / 17:46 UTC. ClawSweeper reviewWhat this changesThe PR reduces model-catalog worker memory by comparing metadata snapshot identities and reusing normalized static provider catalogs, with regression coverage for fallback and authored overrides. Merge readiness✅ Ready for maintainer review This PR remains useful: current main still retains the serialization memo and redundant raw catalog results. No introduced correctness defect was found, and the reported Gateway benchmark supports the optimization. Likely related people: steipete and vincentkoc are medium-confidence routing candidates based on prior merged area work. Priority: P2 Review scores
Verification
How this fits togetherOpenClaw prepares model inventories from plugin metadata, provider catalogs, and user configuration. The catalog worker combines these sources into model listings and agent-specific model selection. flowchart TD
A[Plugin metadata and user configuration] --> B[Plugin auto-enable cache]
B --> C[Static catalog preparation]
C --> D[Normalized provider inventory]
E[Live provider discovery] --> F[Scoped discovery and static fallback]
D --> F
F --> G[Authored model overrides]
G --> H[Model listings and agent selection]
Before mergeNone. Agent review detailsSecurityNone. PR surfaceSource -36, Tests +35, Other -1. Total -2 across 11 files. View PR surface stats
Review metrics
Technical reviewBest possible solution: Keep one generation-owned normalized static inventory and use metadata identities with existing lifecycle invalidation. Do we have a high-confidence way to reproduce the issue? Yes: current-main source retains recursive serialization strings and recopying paths, and the supplied built-Gateway workload measures their heap cost. This review did not execute that workload. Is this the best way to solve the issue? Yes: the patch removes redundant retained representations while preserving lifecycle clearing, provider filtering, and authored override ownership. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against fc7e71bad258. LabelsLabel changes:
Label justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
|
Use generation-owned metadata array identities for same-turn auto-enable reuse instead of retaining serialized copies of every manifest subtree. Keep normalized static provider catalogs as the sole prepared result and reuse them for discovery fallback. A synthetic Linux dist Gateway with two agents and 302 model rows reduces catalog worker post-GC heap from 149.62 MiB to 141.69 MiB (5.3%). The removed memo retained 7,669,416 bytes across 41,158 serialization string nodes.
What Problem This Solves
Reduces standing model-catalog worker heap retained by recursively serialized plugin metadata and redundant raw static-catalog results.
User Impact
Catalog preparation retains less memory and reuses the prepared static inventory during discovery fallback. Provider selection, authored model overrides, and metadata-generation invalidation stay with their existing owners. No configuration or migration is required.
Why This Change Was Made
Worker heap snapshots traced serialized manifest subtrees to auto-enable's process-lifetime
stableFingerprintMemo. Its recursive WeakMap already trusted immutable object identity; compare the prepared candidate/plugin array identities directly and keep the existing same-turn and metadata-lifecycle invalidation.Static preparation now owns only normalized provider configurations. Discovery consumes them directly, including fallback after an absent live result, instead of retaining and recopying raw hook results or rerunning an already prepared static hook. The duplicate provider remapping map is removed.
Production TypeScript: −36 LOC. The requested non-test diff is 23 insertions / 60 deletions (−37 lines), including one generated, shrink-only assertion-baseline row.
Evidence
tbx_01m41a0ebcsxp8r4n5vdvmggy3, profileopenclaw-check, Node 24.19.0.8e4f1533a300and the reviewed patch, synthetic built Gateway: two agents, twelve configured providers, 302 returned models, 85,048-bytemodels.listpayload; repeated reads and explicit refreshes.The steady worker reduction is 7.93 MiB (5.3%), consistent across both captures. The catalog itself is small; the remaining footprint includes the loaded runtime/plugin graph (large source strings, compiled code, plugin file/metadata cache, and Node's module loader). No growing history of complete catalogs appeared across this run.
pnpm build: baseline and final passed (8m00s and 7m15s). Final auto-enable and plugin-context validation passed 53 tests across three files. Independent review: scoped-clean, no actionable P0/P1 findings.node scripts/check-changed.mjs --staged: passed, including all 27 core test typecheck graphs, formatting, lint, boundary/dead-export checks, and the assertion ratchet. The final gate plus timing/retention runs completed in 24m22s. The first gate exposed three obsolete fixture fields; the next required the serializer's removed assertion baseline to shrink. Both were corrected, and no gate was waived.55e3daa31530before publication;git range-diffreports an identical patch and all changed code/test files are byte-identical. Hosted CI validates the published head.Per-file
pnpm test <file> --maxWorkers=1wall time (same Testbox):plugin-auto-enable.core.test.tsprovider-discovery.catalog-copy-work.test.tsmodels-config.providers.endpoint.test.tsmodels-config.providers.implicit.discovery-scope.test.tsTimes include the repository runner/import/compiled-worker setup; test bodies remain below 5 seconds per file. The remaining changed test files only remove obsolete fixture fields. Hosted CI run 37141536635 passed on
6d900200f1e9: 65 successful jobs and 23 skipped jobs, 458 seconds elapsed. The 27 selected Node test jobs totaled 4,395 job-seconds (aggregate job duration, including setup; not per-file or incremental test cost). All PR checks were complete at verification: 90 passing, 47 skipped, none failing or pending.Limitations: synthetic unauthenticated catalog workload; no live provider requests or production restart. Snapshot memory includes the worker's loaded code/plugin graph, not just catalog JSON. The Testbox uses Node 24, so absolute heap is not directly comparable to a Node 26 deployment.