Repository navigation
perf(agents): keep transcript readers out of catalog workers - #183196
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. |
ec08d22 to
121cbce
Compare
|
Codex review: needs maintainer review before merge. What this changesThis PR moves transcript context storage and detachment into a lightweight module so catalog workers avoid loading transcript readers. Example: Synthetic catalog worker with five workspaces, 5,000 remote rows, and a runtime plugin discovering 500 models.
Review scores
ProductKind: Performance · Worth it: Yes · Fix scope: Complete Merge readiness✅ Ready for maintainer review Keep this maintainer-authored PR open: the focused extraction preserves existing behavior and has measurable performance value, with no actionable patch defect found; CI remains unresolved. Priority: P2 Before mergeNone. FindingsNone. Agent review detailsHow this fits togetherCatalog workers load provider plugins to produce model snapshots; background-work detachment now imports the shared context store without pulling in transcript readers and actors. flowchart LR
A[Catalog request] --> B[Catalog worker]
B --> C[Plugin runtime]
C --> D[Background work detachment]
D --> E[Lightweight context store]
F[Transcript writer guards] --> E
B --> G[Model snapshot]
Technical reviewBest possible solution: Land the lightweight extraction with the existing writer guards and catalog lifecycle intact once the CI failure is resolved or shown to be inherited. Do we have a high-confidence way to reproduce the issue? Current-main imports establish the unnecessary reader coupling, and the supplied benchmark exercises the actual catalog worker; no target code was executed during this review. Is this the best way to solve the issue? The smallest complete fix is to relocate the existing context and detachment operation, migrate consumers, and preserve writer enforcement; this diff follows that approach. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 5181de212c10. Provenance checked
TestingProof path: in-process harness. SecurityNone. EvidenceWhat I checked:
Likely related people:
PR surfaceSource +8, Tests -9, Other +55. Total +54 across 34 files. Added test files: 0. View PR surface stats
Review metrics
LabelsLabel changes:
Label justifications:
Rank-up movesOptional improvements that raise the rating; they are not merge blockers.
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, 11:57 PM ET / October 25, 2026, 03:57 UTC. |
121cbce to
e72a244
Compare
Move the existing transcript context and detachment operation to a lightweight owner and migrate all consumers. Catalog workers no longer import the transcript reader graph through the plugin runtime. Five alternating synthetic source-worker pairs retained 142.570 to 137.597 MiB after forced GC, with identical catalog hashes. Production LOC is neutral. Preserve plugin source custody and worker lifecycle; no idle retirement or cache added.
Keep context types with the lightweight context owner and migrate all direct type consumers. This preserves the runtime implementation while satisfying the architecture guard. Prune the baseline entry for the removed transcript detachment mock.
Client socket closure does not join the Gateway generation\x27s detached preauth tasks. Keep the immediate session-mutation settlement assertion and use the existing active-work drain to verify that all remaining work settles without masking persistent leaks.
e72a244 to
cc63c4a
Compare
…w#183196) * perf(agents): keep transcript readers out of catalog workers Move the existing transcript context and detachment operation to a lightweight owner and migrate all consumers. Catalog workers no longer import the transcript reader graph through the plugin runtime. Five alternating synthetic source-worker pairs retained 142.570 to 137.597 MiB after forced GC, with identical catalog hashes. Production LOC is neutral. Preserve plugin source custody and worker lifecycle; no idle retirement or cache added. * fix(agents): keep transcript context contracts acyclic Keep context types with the lightweight context owner and migrate all direct type consumers. This preserves the runtime implementation while satisfying the architecture guard. Prune the baseline entry for the removed transcript detachment mock. * test(gateway): await detached connect work before asserting idle Client socket closure does not join the Gateway generation\x27s detached preauth tasks. Keep the immediate session-mutation settlement assertion and use the existing active-work drain to verify that all remaining work settles without masking persistent leaks.
What Problem This Solves
Catalog workers retain the transcript reader/actor import graph merely to detach background session work from its initiating transcript context.
User Impact
Reduces retained heap in the synthetic source-worker benchmark by 4.97 MiB (3.48%). Catalog contents and transcript-write authority are unchanged. No config, persistence, or worker restart policy changes.
Why This Change Was Made
Move the existing transcript AsyncContext and synchronous detachment function into one lightweight module. Writer producers and detached callers share the same context; all callers migrate, and the old export is removed. This removes 221 loaded scripts from the measured worker without adding a cache or retained prepared state. Production LOC: +127/-119 (net +8); tests: +20/-21. The eight additional lines are explicit type imports required to keep the context contract acyclic; runtime logic and retained state do not grow. The new module is included in the PR wrapper extraction inventory.
Idle retirement is deliberately deferred: catalog generations retain plugin source publication custody, and restarting a worker can recapture changed source. The existing worker-exit integration contract requires republishing borrowers. Avoiding that lifecycle change keeps this repair small and preserves ownership.
Evidence
Node 26.12.1, actual CatalogWorkerTaskPool, synthetic runtime plugin with 500 discovered models, 5,000 remote rows, five workspaces, two remote revisions, ten catalog requests per worker. Five alternating independent baseline/candidate launches; forced GC outside request timing. Baseline owner source:
27e08fc724c7ca8d01f3cf83066f0f45e7289977; final confirmation shares checkout base8ae44f9249540b4d377fb6b80f25f004a5d959e1. The five-pair confirmation below includes the acyclic type-layout repair.All 100 responses contain the same 501 entries and identical full-snapshot SHA-256 (
18a0b546b9b6d84f504fad0bcc67535689d0dfc9416a9562563bc65b9959578c). Heap after one request: 135.798 → 130.818 MiB; after five workspaces: 139.635 → 134.677 MiB (n=5 each).An exploratory baseline worker already retained 121.98 MiB before its first task. Worker heap snapshots analyzed with
scripts/heap-snapshot-diff.mjsshow loaded scripts 4,565 → 4,344 and code-tree retained bytes 59,875,544 → 57,291,464 (one snapshot per side). Retained subtree sizes overlap and are not added together.Timing is context only on this shared, compute-constrained host: first request mean 19,113 → 18,069 ms (n=5 each); subsequent requests mean 141.8 → 118.3 ms (n=45 each, ranges 66.7–273.2 / 55.6–252.1 ms). The earlier five-pair pass showed 142.570 → 137.597 MiB but warm latency went the other direction (171.2 → 192.5 ms, n=45 each), reinforcing that these uncontrolled timing figures are context only. No tail-percentile, allocation, CPU, promotion, or GC-time claim. Source-mode TypeScript-loader retention and host contention prevent projecting these heap/latency numbers to packaged Gateway RSS or restart cost. This removes a measurable import cost; most of the idle worker footprint remains.
Reproduce with
scripts/perf/catalog-worker-retention-measure.ts --output <new-dir> --workspaces 5 --models 5000 --runtime-pluginthrough the repository TS loader; the header documents baseline source substitution and optional worker snapshots.Validation:
--pruneremoves exactly one entry. Independent review is clean; normalized emitted JavaScript is identical across all nine TypeScript repair files.ws:preauthconnect work. The test now immediately verifies zero session mutations, then requires the existing Gateway drain to report idle/no blockers within five seconds. It does not clear or cancel work. Independent review is clean; all 14 tests inserver.sessions.create.lifecycle.test.tspass locally, bringing focused behavior proof to 102 tests. This failure was repaired, not labeled inherited.e72a24426fd506b7439c08c7607dc322892d1155. Completed successfully: 102 jobs passed and 23 were intentionally skipped, including all three PostgreSQL conformance shards and all repaired checks.After deployment, compare the catalog worker's idle heap at comparable generation/workspace counts; catalog contents, worker count/restarts, and request errors should remain stable. No production profiling is needed for this change.