Repository navigation
perf(agents): stop retired model generations retaining runs - #168584
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: needs maintainer review before merge. What this changesThis PR materializes retired model generations’ native abort stacks so retained signals can release completed run state. Example: A Gateway retires a model-runtime generation while an older catalog snapshot remains reachable.
Review scores
ProductKind: Performance · Worth it: Yes · Fix scope: Complete Merge readiness✅ Ready for maintainer review Keep this PR open: it provides a focused repair for completed-run memory retention that current main still permits, with no actionable correctness or security findings. Priority: P2 Before mergeNone. FindingsNone. Tests
Agent review detailsHow this fits togetherThe prepared-model runtime owns generation retirement between model publication, configuration refresh, authentication changes, and catalog workers; it produces abort notifications consumed by retained snapshots and worker cleanup. flowchart TD
A[Runtime publication or refresh] --> B[Generation retirement owner]
B --> C[Native abort notification]
C --> D[Catalog worker cleanup]
C --> E[Retained snapshot signal]
B --> F[Materialize native error stack]
F --> G[Completed run state can collect]
Technical reviewBest possible solution: Land the focused retirement-owner repair while preserving native abort diagnostics and existing generation fencing. Do we have a high-confidence way to reproduce the issue? The source exposes the retained-signal/native-error path, and the supplied Node 26.8.1 GC experiment reports failure before the repair and collection afterward; this read-only review did not independently execute it. Is this the best way to solve the issue? Materializing the stack at the existing retirement owner directly addresses the reported retention edge with minimal code and preserves cancellation and diagnostic contracts. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 171df4e1c5a0. Provenance checked
TestingProof path: in-process harness. SecurityNone. EvidenceWhat I checked:
Likely related people:
PR surfaceSource +4, Tests +79. Total +83 across 4 files. Added test files: 1. View PR surface stats
Review metrics
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 10, 2026, 2:11 PM ET / 18:11 UTC. |
What Problem This Solves
Long-lived model-runtime snapshots can keep completed runs and their session histories in memory after the runtime generation is retired.
User Impact
Reduces Gateway memory growth after model-runtime generation changes without changing cancellation, runtime admission, or diagnostics.
Why This Change Was Made
A retained snapshot keeps its generation's abort signal. Node's default abort reason has a lazy stack that holds the retiring caller's function objects, including closures over completed run state. Materialize that stack at retirement so callers retain the native
AbortErrorand its diagnostic text without retaining those closures.The production snapshot had 195
SessionManagerinstances versus 18 in the earlier snapshot; their overlapping retained subtrees grew from 102 to 1,696 MiB. Strong paths passed through catalog snapshots → generation abort signals → unformatted error stacks → retiring run closures → session state. Simulating removal of these stack edges reduced reachable bytes by 1,811 MiB and released 69 managers. This is graph evidence, not a measured post-deployment reduction.Production LOC: +4. This preserves the exact native abort reason, synchronous notification, and stack diagnostics; the existing retirement owner handles the fix without a new cache, owner, or compatibility path.
Evidence
tbx_01m4kamf1myv3ppyrhta3vzjwn:node scripts/run-vitest.mjs src/agents/prepared-model-runtime.lifecycle.test.ts --maxWorkers=1passed both tests. New retention test: 92 ms; initial cold worker preparation made the file's first run 21.51 s. Initial attempt lacked dependencies; installed once withpnpm install --frozen-lockfileand reran successfully.cbx_b42a658dbd1b: changed-file gate passed core production types, all 27 core test type graphs, formatting, and preceding guards; its only failure was the repository-wide unused-export scan.cbx_68606ff1a95b: all nine remaining gate commands passed, including targeted lint and runtime import/boundary guards. Export-name collision guard passed.node scripts/run-vitest.mjs src/agents/prepared-model-runtime test/scripts/eager-import-closure.test.ts test/scripts/pr-wrapper-source-closure.test.ts test/scripts/ci-node-test-plan.test.tspassed all five shards in 250.81 s; the new retention case took 115 ms.06d231d65279a579b6cacbfb6a281e6fca1c5dbb:tools/solid-lint/index.mjs(default) andsrc/agents/tools/sessions-channel-fixture.test-support.ts(resolveSessionConversationStub,resolveSessionTargetStub). The earlier updater-export report is already fixed by main. No suppression or unrelated source change is included.3cfb066c0224328abbe696900ebf69dca0a31add.Materializing the native stack adds about 8 μs per retirement on the rig (median 5.3 → 13.3 μs over seven 1,000-operation samples); it is outside token processing.
The production snapshots were analyzed privately on an isolated rig. No snapshot contents are included. Other retained roots remain; the full reported hourly slope needs measurement after deployment.