Skip to content

fix(agents): avoid repeated config copies on catalog refresh - #190848

Merged
vincentkoc merged 2 commits into
mainfrom
perf/catalog-config-capture-reuse-20261102
Nov 2, 2026
Merged

vincentkoc merged 2 commits into
mainfrom
perf/catalog-config-capture-reuse-20261102

Conversation

@vincentkoc

@vincentkoc vincentkoc commented Nov 2, 2026 •

Copy link
Copy Markdown
Member

What Problem This Solves

Catalog refreshes repeatedly clone and freeze unchanged runtime and authored config during plugin registration, adding avoidable allocation pressure.

Related: #190564

User Impact

This change reduces repeated config preparation during catalog refreshes. Measured: 18.685% less warm allocation and 30.636% lower peak worker heap. The maintainer explicitly accepted the reported cold-heap increase and unresolved worker-loop timer tradeoff after reviewing both metrics. No config, storage, or operator action changes.

Why This Change Was Made

The worker already publishes each restored config/source pair through the runtime snapshot owner, which retains an immutable capture across equivalent publications. Registration was still consuming each fresh transport clone and missing that reuse.

Pass the publisher's captured config into both initial registration and expanded provider-scope registration. The existing runtime-plugin loader retrieves its paired authored source. Keep the transport config for request-local synthetic-auth receipts, credentials, and catalog processing. Remote revisions still rebuild registrations; no new cache or invalidation policy is introduced.

Production delta: +11 lines. The explicit parameter carries the existing owner's captured pair across both registration paths. Test delta: +40 lines in the existing real-worker fixture, with a matching dedicated test-line allocation; the shared baseline is unchanged.

Evidence

  • Source review: publisher equivalence includes runtime values, authored values, and resolution provenance. Existing capture projection preserves older generations' authored source.
  • Independent read-only review of the production change and corrected fixture: no actionable findings. Completed executable proof is listed below.
  • Local autoreview (Codex, P0–P2) of 7b5f7c6a4d8f1595a11cea77bf05179e235a26c7..98bda84c16b945fae15670f6bf5f4af8107ebef6: scoped-clean, no actionable findings. The review included the unchanged publication, capture, projection, synthetic-auth, registration, and fingerprint owners; it explicitly notes unrun tests and measurements. This uses the documented fallback because the local ClawSweeper checkout contains unrelated untracked work. Hosted review of exact head b01fd1c805349c80fd9d43bee0532f0bd343482c found no correctness or security findings and requested only maintainer disposition of the performance tradeoffs: fix(agents): avoid repeated config copies on catalog refresh #190848 (comment). That decision is recorded below; no source changes followed the review.
  • Targeted formatting and git diff --check: passed.
  • New real-worker regression expects distinct registration captures 1, 1, 2, 2 across two catalog revisions, a config change, and another catalog revision, while registration count advances 1, 2, 3, 4.
  • Exact-source Testbox proof: 67 tests across five files passed, core types, targeted lint and formatting passed. The repaired fixture fails on the baseline worker at the second capture (2, expected 1) and passes on the candidate. Source tree 9d3d802d6ea23876bf5b5f2234e0277e436c2428, now committed as b01fd1c805349c80fd9d43bee0532f0bd343482c. Native wrapper exited 0. Run: https://github.com/openclaw/openclaw/actions/runs/41400017229
  • The prior CI failure and hosted review identified a fixture defect: inherited Vitest defaults cloned its root config before each load. Pinning plugins.slots.memory = "none" preserves the same effective policy without that rewrite; capture-count assertions are unchanged. Independent source review of this correction was clean.
  • Both complete compiled builds passed through the native Git owner and scripts/worktree-setup.mjs full, with independent installs/build outputs and matching dependency-input digest b354dcbaf10f65858635172b5615b132a4824d3c8f206df7e8398f9745852fae. Baseline build commit 7b5f7c6a4d8f1595a11cea77bf05179e235a26c7; candidate build carrier cc955091495687ba5d3783b91b0714201217188a contains the exact candidate tree 9d3d802d6ea23876bf5b5f2234e0277e436c2428. Paired measurements completed; acceptance decision below.
  • Required sibling proof: worker secrets and provenance, rejected refresh recovery, released/neighboring generations, runtime-source projection, policy rewrites, and synthetic-auth scope.
  • Focused candidate tests: 114.61 s; negative-control shard: 36.72 s including worker preparation. The isolated proof command took 370.94 s including source dependency hydration, tests, types, lint and formatting. Broad CI for exact head b01fd1c805349c80fd9d43bee0532f0bd343482c: complete, with 52 successful jobs, 81 skipped jobs, one neutral job, and all three status contexts successful. The openclaw/ci-gate, dependency-review, and security-sensitive-review contexts passed: https://github.com/openclaw/openclaw/actions/runs/41402494941

Performance acceptance — declared before measurement

Baseline: 7b5f7c6a4d8f1595a11cea77bf05179e235a26c7. Candidate: this PR's reviewed head.

Use separate complete compiled builds and identical dependency inputs. Run five serial paired fresh-process comparisons, alternating order BC, CB, BC, CB, BC. Record actual CPU availability/affinity/quota, usable RAM, host load, Node version, source/build identities, and all results.

Committed workload:

node --import ./scripts/tsx.mjs scripts/perf/catalog-worker-retention-measure.ts \
  --built-worker "$BUILD_ROOT" --output "$FRESH_FIXTURE_ROOT" \
  --workspaces 1 --models 1000 --configured-models 1000 \
  --providers 2 --discovery-models 100 --runtime-plugin \
  --task-rounds 20 --measure-tasks

Run separate allocation-profile pairs with the same workload plus --sample-allocation; do not mix profiled timings into the timing comparison. The 19 warm operations are catalog rebuilds after remote-revision changes, not chat turns or cached reads.

Acceptance:

  • Equal catalog/runtime hashes and row counts for every paired operation; clean worker closure and process exit.
  • At least 5% lower median warm allocated bytes, consistent with eliminating repeated registration captures.
  • Report cold latency and post-GC heap separately from warm median/p95 latency, worker CPU, peak/final ordinary heap, GC time/p95, and aggregate RSS, with spread and all paired cells.
  • Every adverse metric stays visible. A worse metric requires explicit owner acceptance before landing. Any 20% regression in any paired cell is a stop, not a noise dismissal.
  • No unchanged rerun to replace an adverse result. Diagnostic attribution does not replace acceptance.
  • This workload proves catalog-worker behavior. It does not establish whole-Gateway RSS, under-load client latency, or a smaller-device memory budget.

Results: maintainer accepted the reported cold-heap and worker-loop tradeoffs. All 20 fresh-process runs completed successfully and every paired request retained equal catalog/runtime hashes and row counts. Native worker closure and process exit were clean; the wrapper exited 0 after native removal of both temporary build worktrees. None of the predeclared scored paired metrics regressed by 20%; the additional worker-loop diagnostic below did.

Host: Node 24.22.1, 4 CPUs with affinity 0-3, CPU quota max 100000, memory cgroup limit max, 15.419 GiB physical RAM, 14.286 GiB available after the builds; load average before measurement 2.947, 2.063, 1.165. Both builds and all measurements ran serially on the same Testbox. The compiled proof command took 647.696 s. Source dependency inputs matched exactly.

Values below are medians of the five per-process summaries, with min–max ranges. Warm p95 is calculated within each run's 19 warm requests. Allocation results come from five separate profiled pairs; their timings are excluded from the timing table. RSS includes the source-based controller plus the compiled worker and instrumentation; it is not whole-Gateway RSS or catalog-worker private RSS.

Metric Baseline median [range] Candidate median [range] Change
Cold request (ms) 799.528 [790.603–832.721] 799.223 [792.876–828.015] -0.038%
Cold post-GC worker heap (MiB) 89.331 [89.319–89.359] 89.373 [89.333–89.393] +0.047%
Warm median latency (ms) 103.795 [102.949–106.607] 87.208 [85.841–92.466] -15.981%
Warm p95 latency (ms) 146.854 [144.377–155.369] 135.037 [124.611–137.186] -8.047%
Warm worker CPU (ms) 1936.223 [1915.145–1943.773] 1568.262 [1551.264–1657.014] -19.004%
Warm peak worker heap (MiB) 212.507 [159.178–256.801] 147.403 [147.365–147.512] -30.636%
Warm final worker heap (MiB) 146.163 [127.654–172.950] 137.662 [136.302–138.531] -5.816%
Warm GC total (ms) 107.027 [103.624–115.579] 68.715 [64.955–77.342] -35.796%
Warm GC p95 (ms) 1.442 [1.355–1.571] 1.130 [1.069–1.280] -21.649%
Final aggregate process RSS (MiB) 974.445 [946.008–989.855] 931.375 [925.797–958.625] -4.420%
Warm sampled allocations (MiB) 2239.257 [2235.969–2247.843] 1820.842 [1820.259–1839.595] -18.685%

The allocation reduction is 418.415 MiB over 19 warm rebuilds (18.685%); median peak worker heap falls by 65.104 MiB. The adverse median is cold post-GC heap: +0.042221 MiB, or +43.234 KiB (+0.047264%). Individual cold-latency and final-heap cells also moved upward; every cell is retained below. The predeclared rule requires owner acceptance of a worse metric, so this result is not an automatic merge approval.

All paired cells (baseline → candidate; change)

Timing passes (BC, CB, BC, CB, BC):

Metric Pair 1 Pair 2 Pair 3 Pair 4 Pair 5
Cold request (ms) 832.721 → 792.876; -4.785% 799.528 → 793.193; -0.792% 798.988 → 803.098; +0.514% 790.603 → 799.223; +1.090% 815.825 → 828.015; +1.494%
Cold post-GC worker heap (MiB) 89.359 → 89.373; +0.016% 89.346 → 89.342; -0.005% 89.319 → 89.393; +0.083% 89.324 → 89.333; +0.009% 89.331 → 89.374; +0.048%
Warm median latency (ms) 106.607 → 85.924; -19.402% 104.167 → 91.836; -11.838% 102.997 → 87.208; -15.330% 103.795 → 85.841; -17.297% 102.949 → 92.466; -10.183%
Warm p95 latency (ms) 146.388 → 124.611; -14.876% 144.377 → 136.445; -5.494% 155.369 → 137.186; -11.703% 146.854 → 129.599; -11.750% 148.945 → 135.037; -9.337%
Warm worker CPU (ms) 1920.122 → 1551.264; -19.210% 1937.577 → 1657.014; -14.480% 1915.145 → 1562.248; -18.427% 1943.773 → 1568.262; -19.319% 1936.223 → 1656.287; -14.458%
Warm peak worker heap (MiB) 159.178 → 147.512; -7.329% 212.507 → 147.365; -30.654% 256.801 → 147.403; -42.600% 224.652 → 147.369; -34.401% 210.115 → 147.422; -29.837%
Warm final worker heap (MiB) 146.163 → 137.662; -5.816% 127.654 → 136.302; +6.774% 172.950 → 137.631; -20.421% 148.584 → 138.531; -6.766% 137.461 → 138.219; +0.552%
Warm GC total (ms) 104.658 → 64.955; -37.936% 115.022 → 76.736; -33.286% 103.624 → 65.721; -36.578% 107.027 → 68.715; -35.796% 115.579 → 77.342; -33.083%
Warm GC p95 (ms) 1.442 → 1.069; -25.891% 1.527 → 1.243; -18.580% 1.355 → 1.124; -17.071% 1.369 → 1.130; -17.447% 1.571 → 1.280; -18.495%
Final aggregate process RSS (MiB) 989.855 → 926.430; -6.408% 974.445 → 958.625; -1.624% 984.887 → 938.965; -4.663% 946.008 → 925.797; -2.136% 968.641 → 931.375; -3.847%

Separate allocation passes (BC, CB, BC, CB, BC):

Metric Pair 1 Pair 2 Pair 3 Pair 4 Pair 5
Warm sampled allocations (MiB) 2235.969 → 1820.842; -18.566% 2247.843 → 1820.344; -19.018% 2236.859 → 1839.595; -17.760% 2244.032 → 1820.259; -18.884% 2239.257 → 1829.611; -18.294%

Additional worker event-loop diagnostic

This histogram was recorded but was not in the predeclared scored metric list. It must still remain visible. It measures the worker's 1 ms timer sampling over the warm window, including inter-request gaps and the harness's 100 ms start/stop polling; it is a different population from catalog request latency. Node 24.22.1 creates an interval histogram and records elapsed time between timer callbacks (upstream source).

Diagnostic Baseline median Candidate median Change
Worker loop p95 (ms) 27.770879 56.229887 +102.478%
Worker loop p99 (ms) 67.829759 67.633151 -0.290%
Worker loop maximum (ms) 92.078079 79.691775 -13.452%
Histogram sample count 410.000000 355.000000 -13.415%
Pair Samples B → C p95 B → C (ms; change) p99 B → C (ms; change) Maximum B → C (ms; change)
1 454 → 352 22.511615 → 56.229887; +149.782% 61.571071 → 67.633151; +9.846% 94.633983 → 77.725695; -17.867%
2 405 → 381 29.130751 → 10.846207; -62.767% 68.550655 → 69.206015; +0.956% 93.454335 → 79.691775; -14.727%
3 410 → 448 27.770879 → 8.294399; -70.133% 67.829759 → 65.404927; -3.575% 87.687167 → 80.609279; -8.072%
4 404 → 355 28.000255 → 57.147391; +104.096% 66.060287 → 64.126975; -2.927% 92.078079 → 77.922303; -15.374%
5 434 → 353 24.985599 → 57.343999; +129.508% 69.664767 → 73.400319; +5.362% 87.621631 → 94.240767; +7.554%

Unresolved diagnostic: loop p95 increases by 102.478% at the cohort median, including >20% increases in pairs 1, 4 and 5. Loop p99 and maximum medians improve. A sampling-distribution explanation is plausible: 19 warm operations exceed 5% of histogram samples only in the three candidate runs with the p95 jump, while the other seven timing runs stay below 5%. This is an inference, not attribution proof: raw histogram bins and request-correlated timer samples were not retained. It does not erase the adverse result or establish client responsiveness. No unchanged performance rerun was used to replace these results.

Independent evidence audit reproduced all headline calculations and all 400 request hashes/cardinalities. Maintainer decision: accepted for landing on 2026-11-02. After being asked specifically about cold post-GC heap increasing by 43.234 KiB and worker timer p95 increasing from 27.770879 to 56.229887 ms, with attribution explicitly unproven, the maintainer approved continuation conditional on clean review. The exact-head review reports no correctness or security findings; CI passed. This resolves both maintainer-decision items in the review. The adverse measurements and uncertainty remain unchanged above; this is acceptance of the tradeoff, not a claim that the timer result was disproven. Testbox cleanup is confirmed completed.

Next diagnostic

Generated plugin catalogs are emitted by models-config.plan.ts with JSON.stringify, then ModelRegistry.loadCustomModels sends them through two JSONC replacement passes. Investigate a strict-JSON fast path in parseModelCatalogJson, retaining its existing JSONC path after a syntax error. This is a source-grounded follow-up, not part of this patch or a measured saving.

@vincentkoc vincentkoc self-assigned this Nov 2, 2026
@clawsweeper

clawsweeper Bot commented Nov 2, 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 agents Agent runtime and tooling size: S labels Nov 2, 2026
@vincentkoc
vincentkoc marked this pull request as ready for review November 2, 2026 03:58
@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. P2 Normal backlog priority with limited blast radius. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Nov 2, 2026
@clawsweeper

clawsweeper Bot commented Nov 2, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: blocked before merge.

What this changes

This PR reuses the runtime snapshot owner's immutable config capture for both catalog-worker registration paths.

Example: Four refreshes use config revisions 0, 0, 1, 1 with different remote catalog revisions.

  • Before: Registration creates four distinct config captures.
  • After: Registration still runs four times, but distinct captures advance 1, 1, 2, 2.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) The focused patch and repaired regression are sound; compiled-worker measurements support the benefit, while the explicit performance acceptance hold remains unresolved.
Proof confidence 🦐 gold shrimp (3/6) The ordinary contributor proof gate does not apply to this maintainer-authored PR; supplied evidence exercises the compiled production worker through the committed catalog workload on Node 24.22.1, with matching catalog/runtime results and reported allocation savings.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Performance · Worth it: Yes · Fix scope: Complete
User problem: Catalog refreshes spend avoidable CPU and memory preparing unchanged plugin-registration config.
Reason: The maintainer-authored direction reuses an existing owner and reports a substantial allocation reduction; performance acceptance remains a separate merge decision.

Merge readiness

⛔ Blocked before merge - 2 items remain

The previous fixture finding is fixed, and this review found no new correctness or security defects; the explicit performance hold still requires owner disposition.

Priority: P2
Reviewed head: b01fd1c805349c80fd9d43bee0532f0bd343482c
Owner decision: Required. See Decision needed.

Decision needed

  • Question: Should the measured allocation improvement be accepted despite the cold-heap increase and worker-loop p95 regression?
  • Recommendation: Keep the performance hold: Require attribution of the adverse worker-loop result before deciding whether this tradeoff is acceptable.
  • Why: The author explicitly preserves the performance hold, and the proposed histogram sampling explanation lacks retained request-correlated samples that would establish attribution.

Before merge

  • Await maintainer action - The catalog owner must resolve or explicitly accept the reported performance tradeoffs before landing.
  • Resolve maintainer decision - Resolve the maintainer decision shown above before merge.

Findings

None.

Agent review details

How this fits together

The catalog worker receives configuration, provenance, metadata, and request-local credentials, registers provider plugins, and returns discovered catalog rows and credential facts.

flowchart LR
  A[Worker request] --> B[Runtime snapshot owner]
  B --> C[Immutable config capture]
  C --> D[Plugin registration]
  A --> E[Request local credentials]
  D --> F[Catalog discovery]
  E --> F
  F --> G[Catalog result]
Loading

Technical review

Best possible solution:

Retain the existing snapshot owner and request-local credential path, with landing held until the catalog owner resolves the reported performance tradeoffs.

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

Current-main source shows fresh transport configs reaching registration despite an existing reusable publication capture; the PR reports a baseline-negative and candidate-positive real-worker regression, which this read-only review did not execute.

Is this the best way to solve the issue?

Carrying the existing owner's capture through both registration paths is the smallest complete fix, preserving registration invalidation, authored-source provenance, and request-local credentials without another cache.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 796b14713458.

Provenance checked

Testing

Proof path: in-process harness.

Security

None.

Evidence

What I checked:

PR surface

Source +11, Tests +40, Other +2. Total +53 across 3 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 1 20 9 +11
Tests 1 41 1 +40
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 1 2 0 +2
Total 3 63 10 +53

Labels

Label changes:

  • add merge-risk: 🚨 other: Worker-loop timer p95 more than doubles in the reported cohort despite improved request latency; the performance acceptance hold remains unresolved.
  • add rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🐚 platinum hermit.
  • add status: ⏳ waiting on maintainer: Only explicit maintainer approvals or decisions remain; merge is still blocked.
  • remove rating: 🧂 unranked krab: Current PR rating is rating: 🦐 gold shrimp, so this older rating label is no longer current.
  • remove status: ⏳ waiting on author: Current PR status label is status: ⏳ waiting on maintainer.

Label justifications:

  • P2: This is a focused catalog-refresh allocation improvement without an established urgent user-facing failure.
  • merge-risk: 🚨 other: Worker-loop timer p95 more than doubles in the reported cohort despite improved request latency; the performance acceptance hold remains unresolved.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🐚 platinum hermit.
  • status: ⏳ waiting on maintainer: Only explicit maintainer approvals or decisions remain; merge is still blocked.

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.

History

Review history (1 earlier review cycle)
  • reviewed 2026-11-02T04:15:11.193Z sha 98bda84 :: needs changes before merge. :: [P2] [P2] Pin the fixture's plugin defaults before asserting capture reuse

Reviewed November 2, 2026, 1:58 AM ET / 06:58 UTC (Revision 2).

@vincentkoc

Copy link
Copy Markdown
Member Author

@clawsweeper re-review

Please review exact head b01fd1c805349c80fd9d43bee0532f0bd343482c. The reported fixture defect is repaired without weakening its assertions. Baseline-negative/candidate-positive proof, 67 passing tests, types/lint/format, both complete builds, and all paired measurements are in the PR body. The production change is unchanged.

Merge remains held for explicit owner disposition of the reported cold-heap increase and additional worker-loop diagnostic, plus required CI/review. This request is for review only.

@clawsweeper

clawsweeper Bot commented Nov 2, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added merge-risk: 🚨 other 🚨 Merging this PR has meaningful risk outside the owned taxonomy. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on maintainer Only explicit maintainer approvals or decisions remain; merge is still blocked. and removed rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Nov 2, 2026
@vincentkoc
vincentkoc merged commit b26eb54 into main Nov 2, 2026
165 checks passed
@vincentkoc
vincentkoc deleted the perf/catalog-config-capture-reuse-20261102 branch November 2, 2026 11:39
@vincentkoc

Copy link
Copy Markdown
Member Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 3, 2026
…w#190848)

* fix(agents): reuse captured config during catalog refresh

* test(agents): pin catalog capture fixture memory policy
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling merge-risk: 🚨 other 🚨 Merging this PR has meaningful risk outside the owned taxonomy. P2 Normal backlog priority with limited blast radius. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. size: S status: ⏳ waiting on maintainer Only explicit maintainer approvals or decisions remain; merge is still blocked.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant