Repository navigation
perf(agents): share remote catalog revisions across worker contexts - #182902
Conversation
|
🦞👀 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 SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
Codex review: needs changes before merge. What this changesThis 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.
Review scores
ProductKind: Performance · Worth it: Yes · Fix scope: Complete 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 Before merge
FindingsNone. Tests
Agent review detailsHow this fits togetherThe 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]
Technical reviewBest 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
TestingProof path: in-process harness. SecurityNone. EvidenceWhat I checked:
Likely related people:
PR surfaceSource +23, Tests +100, Docs +29, Other +189. Total +341 across 4 files. Added test files: 0. View PR surface stats
LabelsLabel changes:
Label justifications:
Rating scale6/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. WorkflowClawSweeper edits this one comment on every review. Comment 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.
cf359de to
b6fb50a
Compare
…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.
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.
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):
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.tsandtest/scripts/pr-wrapper-source-closure.test.ts(22 tests).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
cf359de2a8b5282b37a415f152f2255a712589becompleted 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 samerequireImageCapableModel/resolveImageRuntimestack in both this PR job and the newest scheduled main job, main SHAa67706486489054461cf4ee9f8cca32cd5587517. 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.