Skip to content

perf(agents): share remote catalog revisions across worker contexts - #182902

Merged
steipete merged 1 commit into
mainfrom
steipete/perf-model-catalog-worker-heap-20261024
Oct 24, 2026
Merged

steipete merged 1 commit into
mainfrom
steipete/perf-model-catalog-worker-heap-20261024

Conversation

@steipete

@steipete steipete commented Oct 24, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

The model-catalog worker retains a separate structured clone of the same remote catalog for every prepared workspace. Multi-workspace catalogs therefore keep model rows and strings repeatedly even when all workspaces use the same publisher revision.

User Impact

Reduces retained catalog-worker memory without changing catalog rows, source selection, credentials, or workspace plugin registrations. No configuration or migration is required.

Why This Change Was Made

Before establishing a request's remote-catalog scope, reuse the same (sourceUrl, revision) already owned by the worker's startup snapshot or an existing workspace generation. The publisher hashes the catalog content into the revision, and this is already the prepared-context fingerprint's remote identity. Distinct sources and revisions remain distinct. Existing context replacement releases superseded ownership; there is no new cache or eviction policy.

Workspace registrations must remain separate: evicting them can recapture native ESM graphs that Node cannot unload. The production change adds 23 lines to share the immutable data while preserving that lifecycle contract. The script and test are separate proof scaffolding. Simplification pass: no additional cache, state owner, compatibility branch, or public export.

Evidence

Acceptance declared before baseline: local macOS, Node 26.12.1, real worker pool, 20 synthetic workspace contexts, 5,000 remote model rows, two successive revisions, 40 successful catalog requests per run; five alternating fresh-worker baseline/candidate runs with forced worker GC. Accept a consistent retained-heap reduction of at least approximately 5% with correctness preserved.

Post-GC worker heap Baseline mean (MiB) Candidate mean (MiB) Paired mean delta Samples per side
One workspace 130.140 130.147 +0.007 MiB (+0.01%) 5
20 workspaces, first revision 163.254 133.763 -29.491 MiB (-18.06%) 5
20 workspaces, replacement revision 165.039 135.081 -29.958 MiB (-18.15%) 5

All 200 catalog requests per side succeeded. Final baseline range: 164.884–165.090 MiB; candidate range: 135.078–135.089 MiB. External memory stayed at 6,249,553 bytes on both sides; ArrayBuffers differed by at most 16 bytes in the final samples.

Measurements used base 803ad1fdc36e3473b4a9c538fd3dfb4a15f4431a; the candidate worker bytes are unchanged after rebasing onto current main for this PR.

Separate synthetic snapshot attribution: the largest catalog-context Map falls from 32,060,088 to 1,648,704 modeled retained bytes. Estimated excess duplicate-string bytes fall from 11,082,200 to 1,198,040. The baseline contains 4,591 unique script identities and no duplicate scripts; code-associated retained subtrees account for 56,946,456 bytes (overlapping categories, not additive). These source-runtime snapshots include tooling and do not predict an absolute production worker heap.

Reproduction (use fresh output paths; both owner directories mirror the same relative worker file):

node --import ./scripts/tsx.mjs scripts/perf/catalog-worker-retention-measure.ts \
  --output /path/to/new-fixture --owner-dir /path/to/baseline-or-candidate

The regression fails on the original worker with two retained remote generations instead of one and passes on the candidate. It also exercises catalog output, source/revision separation, replacement, and null restoration. Snapshot proof covers actual collected heap beyond the diagnostic root counts.

Focused checks passed (32 tests across five files):

  • src/agents/prepared-model-catalog-worker.heap.integration.test.ts (7 tests; approximately 29.1 seconds test time).
  • src/agents/prepared-model-catalog-worker.workspace-heap.integration.test.ts (1 test).
  • src/agents/prepared-model-catalog-retained-data.test.ts (2 tests).
  • test/scripts/eager-import-closure.test.ts and test/scripts/pr-wrapper-source-closure.test.ts (22 tests).
  • Export-name collision guard, changed-file type-aware lint, oxfmt, and git diff --check.

The focused invocation used the repository's pinned test runtime. Retention measurements used Node 26.12.1. Test worker preparation took 58.1 seconds; grouped test wall times were 14.29 / 82.98 / 67.07 seconds. An initial focused attempt was invalidated by formatting during artifact compilation and was rerun with fixed source; it is excluded from product results.

PR CI on cf359de2a8b5282b37a415f152f2255a712589be completed with three red checks (one substantive test shard and two aggregate gates); all other required checks passed or were skipped. The sole substantive failure is inherited: models-dispatch.catalog.integration.test.ts → “dispatches a discovered model outside the agent workspace and preserves it after withdrawal” → Unknown model: opencode/live-only-model, with the same requireImageCapableModel / resolveImageRuntime stack in both this PR job and the newest scheduled main job, main SHA a67706486489054461cf4ee9f8cca32cd5587517. No CI reruns were requested. The aggregate CI gate reports the failed selected Node test shard; Security Review itself completed successfully. GitHub's Codex review also completed without findings.

Independent subagent review (autoreview route unavailable): scoped-clean, no actionable P0–P2 findings. The helper refused the requested route because it did not match the operator configuration; configuration was not changed. No Testbox/Crabbox lease was allocated; broad validation belongs to PR CI.

Limits: synthetic owner-level retention, not full-Gateway throughput, allocation, promotion, GC-pause, or latency evidence. The fixture disables plugin execution/network discovery; the integration tests cover normal catalog and workspace lifetime behavior. The inherited startup snapshot still follows the existing worker lifetime; this change removes per-workspace copies, not that startup root. Production benefit depends on catalog size and the number of workspaces sharing a revision. After deployment, look for a lower catalog-worker heap plateau as workspaces warm, while catalog contents and refresh behavior remain unchanged. Leave this PR open for lead verification and merge.

@clawsweeper

clawsweeper Bot commented Oct 24, 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.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 24, 2026 •

Copy link
Copy Markdown
Contributor

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-24T22:13:14.647539Z b6fb50a New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@openclaw-barnacle openclaw-barnacle Bot added scripts Repository scripts agents Agent runtime and tooling size: M labels Oct 24, 2026
@clawsweeper clawsweeper Bot added clawsweeper:intake:feature Preliminary submission classification; full source review pending. P2 Normal backlog priority with limited blast radius. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. 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 Oct 24, 2026
@clawsweeper

clawsweeper Bot commented Oct 24, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs changes before merge.

What this changes

This PR shares identical remote catalog snapshots across worker workspace contexts while preserving separate plugin registrations.

Example: Twenty workspaces prepare two successive remote catalog revisions containing 5,000 models each.

  • Before: Reported post-GC worker heap after replacement averages 165.039 MiB.
  • After: Reported heap averages 135.081 MiB, with all 200 catalog requests succeeding.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) A focused, apparently correct optimization with useful worker-boundary measurements and regression coverage; proof remains synthetic rather than through the shipped Gateway.
Proof confidence 🦐 gold shrimp (3/6) The maintainer-authored PR is outside the ordinary contributor proof gate; its macOS Node 26.12.1 worker-pool measurements report reduced retained heap across 20 workspaces and revision replacement, supported by real-worker regression coverage rather than shipped Gateway evidence.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Performance · Worth it: Yes · Fix scope: Complete
User problem: Multi-workspace Gateways retain repeated copies of identical remote model catalogs.
Reason: The maintainer-authored direction has a demonstrated retention benefit and preserves catalog content, authentication, and workspace lifecycle contracts.

Merge readiness

⛔ Needs changes before merge - 1 item remains

Keep this PR open: it provides a focused, measured retention improvement absent from current main, with no actionable introduced defect found; GitHub reports a merge conflict.

Priority: P2
Reviewed head: cf359de2a8b5282b37a415f152f2255a712589be

Before merge

  • Complete next step - The PR owner should resolve GitHub's reported merge conflict and validate the affected resolution on the resulting head.

Findings

None.

Tests

  • Missing end-to-end proof: Supplied measurements exercise the real worker pool with synthetic catalogs, without a full Gateway refresh-and-turn scenario.
Agent review details

How this fits together

The catalog worker receives cloned preparation inputs from the Gateway, retains workspace plugin generations, and returns discovered models and authentication facts.

flowchart LR
  A[Gateway catalog owner] --> B[Worker task transport]
  B --> C[Catalog worker]
  D[Startup catalog snapshot] --> C
  E[Workspace generations] --> C
  C --> F[Scoped catalog preparation]
  F --> G[Models and authentication facts]
Loading

Technical review

Best possible solution:

Reuse immutable catalog snapshots through the existing worker owners while preserving workspace registrations and source/revision separation.

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

Current-main source retains each workspace's transported catalog snapshot independently; the supplied measurements and regression report confirm duplicate retention, but no target code was executed during this read-only review.

Is this the best way to solve the issue?

The patch fixes duplicate ownership at worker admission using existing snapshots, preserves the intentional workspace lifetime, and introduces no unnecessary production machinery.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 1e3ff306abaf.

Provenance checked

  • Remote catalog request scope keeps the original intent (504d290: Publish accepted catalog rows and prices together while admitted work retains its exact catalog generation.)
  • Per-workspace worker generations keeps the original intent (5e4b43c: Keep each workspace's current context to avoid recapturing native ESM graphs that cannot be unloaded.)

Testing

Proof path: in-process harness.

Security

None.

Evidence

What I checked:

Likely related people:

  • joshavant: Raw commit 1cb9f70 adds src/agents/prepared-model-catalog.worker.ts:65 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: medium; commits: 1cb9f70cb304; files: src/agents/prepared-model-catalog.worker.ts)

PR surface

Source +23, Tests +100, Docs +29, Other +189. Total +341 across 4 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 1 25 2 +23
Tests 1 101 1 +100
Docs 1 29 0 +29
Config 0 0 0 0
Generated 0 0 0 0
Other 1 189 0 +189
Total 4 344 3 +341

Labels

Label changes:

  • add P2: A measured memory improvement for multi-workspace Gateways with a focused implementation and limited behavioral scope.
  • add rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🐚 platinum hermit.
  • add status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action.

Label justifications:

  • P2: A measured memory improvement for multi-workspace Gateways with a focused implementation and limited behavioral scope.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🐚 platinum hermit.
  • 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 October 24, 2026, 5:45 PM ET / 21:45 UTC.

Reuse catalog snapshots already held by startup or workspace generations before entering request scope. Preserve workspace plugin ownership and source/revision isolation without another cache. Five alternating Node 26.12.1 runs reduce retained worker heap after replacement from 165.039 MiB to 135.081 MiB; all 200 requests per side succeeded.
@steipete
steipete force-pushed the steipete/perf-model-catalog-worker-heap-20261024 branch from cf359de to b6fb50a Compare October 24, 2026 22:11
@steipete
steipete merged commit 138f9f6 into main Oct 24, 2026
113 checks passed
@steipete
steipete deleted the steipete/perf-model-catalog-worker-heap-20261024 branch October 24, 2026 22:21
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 25, 2026
…penclaw#182902)

Reuse catalog snapshots already held by startup or workspace generations before entering request scope. Preserve workspace plugin ownership and source/revision isolation without another cache. Five alternating Node 26.12.1 runs reduce retained worker heap after replacement from 165.039 MiB to 135.081 MiB; all 200 requests per side succeeded.
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: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. scripts Repository scripts 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.

1 participant