Skip to content

perf(models): reduce catalog normalization allocations - #198591

Merged
vincentkoc merged 4 commits into
mainfrom
perf/catalog-normalization-allocations-20261114
Nov 14, 2026
Merged

vincentkoc merged 4 commits into
mainfrom
perf/catalog-normalization-allocations-20261114

Conversation

@vincentkoc

@vincentkoc vincentkoc commented Nov 14, 2026 •

Copy link
Copy Markdown
Member

What Problem This Solves

Refreshing large model catalogs repeatedly resolves the same provider hooks for every model, creating avoidable worker allocation and CPU pressure.

User Impact

The measured two-provider catalog workload allocates 39% less memory per refresh, runs warm requests 16% faster, and retains 3.51 MiB less worker heap. Cold-request median is effectively unchanged. No new setting, disabled feature, worker-pool consolidation, or persistent cache.

Why This Change Was Made

Reuse successful provider selections within one synchronous catalog pass, then discard them. Existing handle logic retries model-specific misses. Every model still runs its hooks; configured-provider isolation, in-place model updates, fallback order, and same-origin transport restrictions remain intact.

Evidence

Validation

  • 95 focused tests passed: provider runtime, the four new catalog-normalization cases, transport-origin restrictions, agent model discovery/membership/synthetic auth, and prompt-prefix stability.
  • Type-aware lint passed for all six changed files, including generated SDK declarations. Formatting and line-cap checks passed.
  • Both frozen-base and candidate sourcePerformance builds passed, including built plugin/control-plane checks. This profile does not claim full package/release qualification.
  • Local ClawSweeper reviewed the complete range through f0e58c37cdb7 with no actionable findings; independent source review also found no remaining issue.
  • Runtime builds and the 95-test suite used e68e8ab3c854; later commits only correct the test fixture. Final head cc462fa2cab4 passes all four normalization tests, type-aware fixture lint, and the exact core.test.plugins-platform TypeScript leaf that caught a missing workspaceDir field in CI. Production inputs are identical, so the benchmark and broader behavioral proof remain valid.
  • Ordinary models.list reads still serve published rows while catalog discovery refreshes in the background. This PR adds no RPC wait or UI loading state. Existing first-snapshot picker loading presentation is a separate follow-up.

Benchmark

Frozen base: 9cb3c14855e5a5216148a1c125f9240c5da1f6de. The acceptance rule was recorded here before comparisons: at least 15% lower median warm allocated bytes, identical catalog/runtime hashes, and no 20% median/p95 latency or retained-heap regression. All measured metrics meet it.

40 independent built-worker runs: five AB allocation pairs, five AB retained-heap pairs, and ten timing pairs (five AB plus five BA). Each run uses two workspaces, two providers, 5,000 overlay rows, 1,000 discovered rows per provider, and four task rounds. There are seven warm requests after the first cold request. Sampling and timing runs are separate. All catalog and runtime hashes match.

Metric Base median / p95 Candidate median / p95 Median change
Warm allocation / 7 requests (MiB) 705.51 / 707.25 428.29 / 434.71 -39.3%
Warm request (ms) 79.49 / 163.08 66.40 / 119.45 -16.5%
Cold request (ms) 977.94 / 1712.95 969.30 / 1557.50 -0.9%
Worker CPU / 7 requests (ms) 556.02 / 803.10 413.70 / 600.16 -25.6%
GC / 7 requests (ms) 26.52 / 51.16 26.31 / 35.96 -0.8%
Peak worker heap (MiB) 120.18 / 161.15 110.12 / 115.49 -8.4%
Post-GC worker heap (MiB) 74.42 / 74.43 70.91 / 70.91 -4.7%
Harness process RSS (MiB) 657.57 / 709.48 630.02 / 708.23 -4.2%

Allocation corresponds to 100.79 → 61.18 MiB per warm request. The first allocation profiles attribute 154.61 → 0.06 MiB to provider-selection preparation and 57.45 → 0.06 MiB to runtime lookup preparation.

Ranges: warm requests 48.88–220.94 → 39.07–175.29 ms; cold requests 654.65–1712.95 → 728.44–1557.50 ms; allocation 696.18–707.25 → 416.92–434.71 MiB; retained worker heap 74.34–74.43 → 70.84–70.91 MiB. Host load ranged 7.8–15.8. The initial five AB timing pairs showed a 7.2% slower cold median; five BA pairs were declared before running to counterbalance order, and every original sample remains in the combined results.

Reproduction, for each base/candidate build:

node --import ./scripts/tsx.mjs scripts/perf/catalog-worker-retention-measure.ts   --output <new-fixture-directory> --built-worker <build-root>   --workspaces 2 --providers 2 --models 5000 --discovery-models 1000   --task-rounds 4 --runtime-plugin --measure-tasks

Add --sample-allocation for the allocation pass. Omit --measure-tasks for post-GC retained-heap collection after each round.

This exercises the real catalog worker, not a full Gateway/client workload. Process RSS includes the TypeScript harness; the isolated retained-worker-heap result is the useful residency comparison. No claim of 39% lower Gateway RSS.

@clawsweeper

clawsweeper Bot commented Nov 14, 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.

@vincentkoc vincentkoc self-assigned this Nov 14, 2026
@openclaw-barnacle openclaw-barnacle Bot added agents Agent runtime and tooling size: M labels Nov 14, 2026
@vincentkoc
vincentkoc marked this pull request as ready for review November 14, 2026 03:04
@clawsweeper clawsweeper Bot added clawsweeper:intake:feature Preliminary submission classification; full source review pending. P2 Normal backlog priority with limited blast radius. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. and removed clawsweeper:intake:feature Preliminary submission classification; full source review pending. labels Nov 14, 2026
@clawsweeper

clawsweeper Bot commented Nov 14, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs changes before merge.

What this changes

This PR reuses provider selections within each synchronous model-catalog normalization pass.

Example: The reported built-worker workload refreshes catalogs across two workspaces and two providers.

  • Before: Warm requests allocate a reported 100.79 MiB each.
  • After: Warm requests allocate a reported 61.18 MiB each, with matching catalog and runtime hashes.

Review scores

Measure Result What it means
Overall readiness 🦪 silver shellfish (2/6) Useful, bounded performance work with production-worker benchmark evidence, currently blocked by a concrete test type error.
Proof confidence 🦐 gold shrimp (3/6) This maintainer-authored internal optimization supplies paired compiled-worker measurements through the production catalog worker, with matching output hashes; it does not claim a full Gateway or client workload.
Patch quality 🦪 silver shellfish (2/6) 1 actionable review finding remain.

Product

Kind: Performance · Worth it: Yes · Fix scope: Complete
User problem: Refreshing large model catalogs repeats provider-selection work and creates avoidable allocation and CPU pressure.
Reason: The maintainer-authored direction is approved, the measured workload shows meaningful savings, and the implementation introduces no user setting or persisted format.

Merge readiness

⛔ Needs changes before merge - 1 item remains

Keep open: this maintainer-authored optimization shows useful allocation savings, but its new test fixture violates the provider-registry return type.

Priority: P2
Reviewed head: f0e58c37cdb7372a1e5c2f7c28aa544ca54058e3

Before merge

  • [P2] Include workspaceDir in the typed registry selection fixture (P2) - The resolver supplied directly to createProviderHookRuntime returns a selection without workspaceDir. Its parameter is ReturnType<typeof createProviderRegistryResolver>, and that resolver's captureProviderRegistrySelection returns a required workspaceDir property, even when undefined. Consequently this callback is not assignable to the expected resolver type and the new test cannot pass the plugins-platform test typecheck. Return workspaceDir: params.workspaceDir alongside registry and the eligibility callback; no cast or production contract change is needed.

Findings

  • [P2] [P2] Include workspaceDir in the typed registry selection fixture — src/plugins/provider-model-normalization.test.ts:39
Agent review details

How this fits together

Model discovery passes registry rows through provider model and transport hooks, then compatibility normalization, before returning catalog models.

flowchart LR
  A[Model registry rows] --> B[Catalog normalization pass]
  B --> C[Existing provider runtime handles]
  C --> D[Provider model hooks]
  D --> E[Transport normalization]
  E --> F[Compatibility normalization]
  F --> G[Normalized catalog models]
Loading

Technical review

Best possible solution:

Keep the pass-local reuse and have the PR author return workspaceDir from the typed registry fixture.

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

Source inspection establishes the missing required workspaceDir property at the directly typed resolver injection; no target code or tests were executed during this read-only review.

Is this the best way to solve the issue?

The optimization follows the existing provider-selection owner and bounds reuse to one synchronous pass, preserving per-model hook execution without persistent cache or configuration changes.

Full review comments:

  • [P2] [P2] Include workspaceDir in the typed registry selection fixture — src/plugins/provider-model-normalization.test.ts:39
    The resolver supplied directly to createProviderHookRuntime returns a selection without workspaceDir. Its parameter is ReturnType<typeof createProviderRegistryResolver>, and that resolver's captureProviderRegistrySelection returns a required workspaceDir property, even when undefined. Consequently this callback is not assignable to the expected resolver type and the new test cannot pass the plugins-platform test typecheck. Return workspaceDir: params.workspaceDir alongside registry and the eligibility callback; no cast or production contract change is needed.
    Confidence: 0.99

Overall correctness: patch is incorrect
Overall confidence: 0.98

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 5765898e1a29.

Provenance checked

  • Discovered-model normalization keeps the original intent (89fcceb: Unify provider normalization while moving passive model browsing to the Gateway's published catalog.)
  • Provider hook runtime composition keeps the original intent (071f606: Compose provider operations at the native loader boundary and avoid broad execution imports during registration.)
  • Foreign transport fallback keeps the original intent (d978202: Prevent another provider's transport hook from redirecting requests and credentials to a different origin.)

Testing

Proof path: in-process harness.

Security

None.

Evidence

Acceptance criteria:

  • pnpm tsgo:core:test --stripe 5/5 --concurrency 2
  • pnpm test src/plugins/provider-model-normalization.test.ts --maxWorkers=1
  • pnpm exec oxfmt --check src/plugins/provider-model-normalization.test.ts
  • git diff --check

What I checked:

  • Pinned introduction and current main: Reviewed the introduced merge-base-to-head diff. Fetched main retains the original per-row implementation; its changes since the merge base do not alter the touched production files. (src/agents/model-discovery-normalize.ts:20, f0e58c37cdb7)
  • Required selection field omitted: The new resolver returns a selection without workspaceDir. createProviderHookRuntime accepts the actual registry-resolver type, whose captureProviderRegistrySelection always includes that required property, even when its value is undefined. (src/plugins/provider-model-normalization.test.ts:39, f0e58c37cdb7)
  • Exact-head typecheck failure: check-test-types-core-5 failed during the hosted core test-types step, and the aggregate CI gate also failed. The plugins-platform graph includes the added test and belongs to stripe 5; the missing selection property independently establishes a diff-caused type error. The downloaded job log was unavailable because its storage host is blocked, so its precise diagnostic was not inspected. (src/plugins/provider-model-normalization.test.ts:28, f0e58c37cdb7)
  • Scoped performance evidence: The PR reports paired built-worker measurements with matching output hashes, reduced allocation and warm latency, and essentially unchanged cold median. The committed measurement script invokes the real catalog worker pool and hashes returned catalog/runtime data; it explicitly excludes full Gateway workload claims. (scripts/perf/catalog-worker-retention-measure.ts:487, f0e58c37cdb7)
  • Related work remains distinct: fix(models): avoid redundant catalog normalization #191620 is an open PR by the same author sharing provider-handle plumbing, but it combines per-row reuse with route-comparison changes and records a performance hold; this PR adds reuse across a whole catalog pass with separate measurements. (efd5f11c372f)
  • Existing transport boundary preserved: The origin restriction established by fix(plugins): keep other plugins' transport hooks on the provider's origin #189423 remains in the existing transport owner; the new fallback-provider supplier changes selection reuse without removing the origin check or configured-provider isolation. (src/plugins/provider-runtime.ts:343, f0e58c37cdb7)

PR surface

Source +52, Tests +170. Total +222 across 6 files. Added test files: 1.

View PR surface stats
Area Files Added Removed Net
Source 5 88 36 +52
Tests 1 170 0 +170
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 6 258 36 +222

Preflight source

Source unknown. Source comparison at the observed PR snapshot only. Completion is self-reported; body, policy, tests, execution, and report bytes are not verified.

Review metrics

Metric Value Why it matters
Production versus test changes Production +88/-36 lines; tests +170 lines Production growth carries existing handles through a bounded catalog pass; the four tests cover reuse, model-specific misses, transport fallback, and mutated model identity.

Labels

Label changes:

No label changes.

Label justifications:

  • P2: A useful allocation optimization has a narrow, source-verifiable test-compilation blocker without an established urgent user regression.
  • rating: 🦪 silver shellfish: Overall readiness is 🦪 silver shellfish; proof is 🦐 gold shrimp and patch quality is 🦪 silver shellfish.
  • status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action.

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.

Reviewed November 13, 2026, 10:20 PM ET / November 14, 2026, 03:20 UTC.

@vincentkoc
vincentkoc enabled auto-merge (squash) November 14, 2026 05:12
@vincentkoc
vincentkoc merged commit 730ce41 into main Nov 14, 2026
128 checks passed
@vincentkoc
vincentkoc deleted the perf/catalog-normalization-allocations-20261114 branch November 14, 2026 05:20
@vincentkoc

Copy link
Copy Markdown
Member Author

Merged via squash auto-merge.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 15, 2026
* perf(models): reuse provider selection within catalog normalization

* test(models): exercise catalog transport changes

* style(models): satisfy catalog fixture block rule

* test(models): carry workspace in provider registry fixture
@conrathchad3-netizen

Copy link
Copy Markdown

Type- aware type-aware fixture-link what type of updates are usually available? I have over 300 apps right now, 230 android apps what should be updated vs not updated? Thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling P2 Normal backlog priority with limited blast radius. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. size: M status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants