Repository navigation
improve: reduce session update CPU for large subagent registries - #150429
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. Reviewed September 16, 2026, 11:44 PM ET / September 17, 2026, 03:44 UTC (Revision 5). ClawSweeper reviewWhat this changesThe PR reuses subagent membership lookups when preparing session updates and extends tests for membership changes, ordering, and cache retirement. Merge readiness✅ Ready for maintainer review This remains a useful optimization absent from current main. No actionable correctness defect was found, and the verified test merge resolves the previous conflict blocker. The performance claim is appropriately limited to the measured large-registry workload. Priority: P2 Review scores
Verification
How this fits togetherThe subagent registry combines retained SQLite records with live runs to describe session trees and controller relationships. Gateway session reads use these projections to construct session rows and updates. flowchart TD
A[Retained SQLite records] --> B[Registry snapshot]
B --> C[Derived membership lookup]
D[Requested sessions or controllers] --> C
C --> E[Selected records]
F[Current live runs] --> E
E --> G[Generation and liveness index]
G --> H[Gateway session rows and updates]
Before mergeNone. Agent review detailsSecurityNone. PR surfaceSource +188, Tests +266. Total +454 across 4 files. View PR surface stats
Review metrics
Technical reviewBest possible solution: Keep membership derived from the existing snapshot lifecycle while preserving live overlays, generation selection, and deterministic row order. Do we have a high-confidence way to reproduce the issue? Yes for the repeated-scan mechanism: current main rebuilds requester adjacency and filters retained records for scoped reads. The reported CPU magnitude comes from the supplied pinned replay, not a new execution during this review. Is this the best way to solve the issue? Yes. A lifecycle-owned membership lookup addresses repeated selection work without duplicating generation policy, adding configuration, or changing persistent storage; the evidence supports a bounded large-registry benefit. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 9a4468148bc0. LabelsLabel justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (4 earlier review cycles)
|
caeb600 to
a529a1d
Compare
7737441 to
1ca5e2e
Compare
|
Merged via squash.
|
Related: #105423 (already closed; this is additional performance work).
What Problem This Solves
Session updates repeatedly scan unrelated retained subagent runs when constructing a requested session tree or selecting its controller's runs.
User Impact
Large retained registries require less main-thread work to deliver session updates. In the bounded 1,024-row replay, all three pairs used 9.3–41.3% less main-thread CPU, with lower process CPU and wall time as well.
The small control is a material limitation: process CPU and wall time increased in all three zero-unrelated-row pairs, and main-thread CPU was mixed. Their cause is not established, and these results do not imply universal or production-wide savings.
Why This Change Was Made
The existing complete session-list snapshot now owns a lazily created membership lookup. Named publications update that derived membership with the snapshot; replacement, reset and database-context retirement discard it. Requested tree/controller reads select matching rows without rebuilding the retained requester graph each time.
The snapshot Map remains the row owner. The existing read index continues to decide generation and live-run policy, preserving superseded edges, current in-memory overlays and Map order. Initial lookup construction and its mutation costs are included in the replay. Full-record and maintenance projections keep their existing contracts; this introduces no schema or configuration change.
Evidence
sessions.listand notification flow completed all 12 predetermined fresh-process cells: 240 inputs, 192 deliveries and 48 expected stale non-deliveries. All six pairs retained complete payload/wire equality after exact fixture identity, phase-clock and workspace normalization. No cells were discarded or repeated.The table contains every paired outcome, in milliseconds, baseline → candidate. The primary window includes the first registered list, initial registry fill/lookup construction, four ownership phases and all 20 notification inputs, including assertions and broadcast serialization.
The comparison used baseline
82d4d1cc175549e222e3cb2605716f277eff6a00plus this unchanged candidate, Linux x64 with four logical CPUs, official Node 26.8.2, SQLite 3.53.4 and pnpm 12.3.4. Both arms had independent installs, stores and HOME directories. The host's newer CI bootstrap was recorded separately; it did not replace these benchmark-arm pins. Native generation preparation finished before every primary interval; setup, lifetime and cleanup controls were retained separately without subtracting them from the primary measurements.There are only three pairs per size. The full synthetic evidence was privately collected and verified, and the owned Testbox was stopped. Current main has since added session-row fields, so the recorded payload parity and CPU comparison apply to the pinned comparison above; hosted PR CI covers the published integration. No live-server performance improvement is claimed here.
RSS from the same twelve cells
RSS was recorded in the original experiment and is reported here without rerunning any cell. The table shows the entire fixture process at primary start and end, in MiB; parentheses give that arm's increase. The final column is the maximum individual-process RSS observed over the complete runner lifetime, including worker preparation, compiler work and cleanup. It is not a sum of concurrent processes.
The phase samples use
process.memoryUsage.rss(); lifetime maxima use Linuxwait4accounting. Initial RSS differs between processes, so end-RSS differences must not be treated as the change in memory growth. Within-primary growth was mixed: candidate minus baseline was +2.609, −31.465 and +3.574 MiB for controls, and −14.262, +4.078 and −11.625 MiB for targets. These whole-process observations do not isolate the retained lookup's memory cost, establish a memory saving, or show a steady-state production RSS change. Raw values and their source/collection hashes were independently rechecked from the saved artifacts.