Repository navigation
perf(memory): release diagnostic state on session retirement - #199761
Conversation
Reset/delete joins the session's producers and drains queued diagnostics before releasing activity aliases. Preserve idle progress and retry/recovery evidence until that lifecycle boundary. A 165-minute synthetic Gateway soak retained 1,861 retired session IDs and 882 deleted keys before the fix. The repeat retained none; diagnostic map growth fell from 0.750 to 0.053 MB/hour. Add repeatable same-process heap-pair tooling and extend the real deletion regression, which fails on the baseline. Release-note context: reclaim stale diagnostic activity after session reset or deletion without changing active-run recovery behavior.
|
🦞👀 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 Summary: ✅ CompletedThis 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 maintainer review before merge. What this changesThis PR releases diagnostic aliases during Gateway session reset/delete and extends the existing heap rig with a repeatable soak workload. Example: Delete session sess-active, indexed by agent:main:discord:group:dev and retired-alias.
Review scores
ProductKind: Bug fix · Worth it: Yes · Fix scope: Complete Merge readiness✅ Ready for maintainer review Keep open: this maintainer-authored PR repairs a demonstrated diagnostic memory leak still present on main, with no actionable correctness or security findings; exact-head CI remains pending. Priority: P2 Before mergeNone. FindingsNone. Agent review detailsHow this fits togetherGateway reset/delete joins session work, then invokes runtime cleanup; the diagnostic owner consumes progress events and indexes activity by session and run references. flowchart TD
A[Gateway reset or delete] --> B[Join session producers]
B --> C[Runtime cleanup]
C --> D[Drain queued diagnostics]
D --> E[Check existing lifecycle guard]
E --> F[Remove retired activity aliases]
Technical reviewBest possible solution: Retain the focused repair at the existing session-retirement boundary, preserving ordinary completion and recovery evidence. Do we have a high-confidence way to reproduce the issue? Current-main source retains activity aliases after session cleanup, and the supplied baseline deletion regression fails because retired progress remains readable; this read-only review ran no target code. Is this the best way to solve the issue? The patch fixes the existing diagnostic owner at the established retirement boundary, reuses the queue barrier, and preserves completion semantics with no unnecessary production machinery. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 8656c447df05. Provenance checked
TestingProof path: shipped entry point. SecurityNone. EvidenceWhat I checked:
Likely related people:
PR surfaceSource +20, Tests +17, Other +193. Total +230 across 7 files. Added test files: 0. View PR surface stats
Preflight sourceSource 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
LabelsLabel changes: No label 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 November 15, 2026, 4:15 PM ET / 21:15 UTC. |
…w#199761) Reset/delete joins the session's producers and drains queued diagnostics before releasing activity aliases. Preserve idle progress and retry/recovery evidence until that lifecycle boundary. A 165-minute synthetic Gateway soak retained 1,861 retired session IDs and 882 deleted keys before the fix. The repeat retained none; diagnostic map growth fell from 0.750 to 0.053 MB/hour. Add repeatable same-process heap-pair tooling and extend the real deletion regression, which fails on the baseline. Release-note context: reclaim stale diagnostic activity after session reset or deletion without changing active-run recovery behavior.
What Problem This Solves
Resetting or deleting sessions left their diagnostic activity and aliases reachable until the Gateway restarted.
User Impact
Gateways reclaim diagnostic state for sessions retired through reset/delete. Ordinary completion still preserves idle progress and retry/recovery evidence. There are no schema or configuration changes.
Why This Change Was Made
A same-process heap-snapshot pair found
activityByRefretaining every one of 1,861 retired parent-session IDs and 882 deleted session keys in a synthetic soak. Run-ID and recovery-fence cleanup already existed; session-alias cleanup did not.The existing reset/delete lifecycle already joins turn producers. It now drains the queued diagnostic prefix, checks its existing lifecycle guard, and asks the diagnostic owner to remove the retired activity's aliases.
Map.forEachavoids allocating entry pairs during this cold cleanup. The 20 added production lines are necessary to preserve idle/retry evidence until actual retirement; clearing every completed attempt would break that contract.The rig gains a repeatable
--soakmode with independent mock Responses streams, minute memory/CPU/GC/loop samples, hot reloads, and uninterrupted profiler tracking for meaningful object-ID comparisons.Evidence
Both accepted runs: 165 minutes, snapshots at minutes 35 and 165, 10,000 seeded sessions, 64 WebSocket clients, 40 fixture plugins plus runtime plugins, three concurrent mock Responses streams with real tool/result, subagent, cron, artifact and session-churn paths, and five hot config reloads. Baseline source:
7d7d86bb79ca24bfaf9343290cb22f80d705ab20(includes #199609 and #199615); candidate: the same source plus this 20-line production repair. Node 26.12.1. These measurements precede the final rebase; exact-head CI is separate evidence.Decimal MB. Loop rows summarize minute percentiles, not one aggregate percentile. The candidate check covers 1,884 retired parent IDs and 894 deleted keys. The causal result is removal of stale aliases; whole-Gateway differences are contextual, not attributed wholesale to this small repair. The soak did not trace allocation rate or capture RPC/server-handler latency and per-kind GC pause distributions; no A/A-based performance-regression claim is made.
Owner lifecycle microbenchmark: 2,000 unrelated retained sessions, 5,000 create/retire cycles per arm, four counterbalanced timing pairs and two separate allocation pairs. Baseline omits retirement as before; candidate calls the production cleanup.
Cleanup adds approximately 19.6 µs and 362 sampled allocation bytes per retirement. This is a small retention fix, not a CPU/allocation optimization.
The existing real
sessions.deleteregression failed on baseline because retired progress remained readable (1 intended failure, 20 other tests passed). With the fix: 21 deletion tests, 8 diagnostic-owner tests, 16 reset-cleanup tests, and 30 rig/import-closure tests passed. Root script and matching Gateway test typechecks, changed-file lint/format, and export-name collision checks passed. An exact 17-line test allocation covers the extension of the existing fixture.Two incomplete candidate attempts are excluded: initial store initialization and a minute-30 reload returned explicit metadata-changed/retry read responses. The final UI poller records only those two observed
chat.history/chat.metadataUNAVAILABLE responses and continues on the next scheduled poll; turns, mutations and unexpected errors remain fatal. The accepted candidate had zero retryable reads. One local test invocation overlapped build output publication and failed setup on a missing extension dist directory; the serialized post-build invocation passed.Larger growing owners in the baseline were bounded: SessionListViewCache 1.83 → 6.04 MB (512 entries / 32 MiB estimated cap), prompt-history trackers 1.85 → 3.02 MB (512 trackers / 16 MiB history), and replacement cache backing tables. Constructor retained totals overlap and are not summed. The fixture lacks real channel traffic, deep production transcripts, real plugin workloads, external tool runtimes and sandbox/worktree churn; it does not establish the cause of a larger production retention slope.
Exact-head CI passed on
3015721c1cce1eea01cb43139114cf80c1791302: CI run 43761136576, 69 passing checks across the PR and no pending or failed checks. No CI retries were needed.