Skip to content

improve: reduce session update CPU for large subagent registries - #150429

Merged
steipete merged 1 commit into
mainfrom
codex/team-session-registry-lookup-20260916
Sep 17, 2026
Merged

steipete merged 1 commit into
mainfrom
codex/team-session-registry-lookup-20260916

Conversation

@steipete

@steipete steipete commented Sep 17, 2026 •

Copy link
Copy Markdown
Contributor

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

  • The unchanged four-file candidate passed 98 focused tests, all selected changed-file checks, and independent review through P2. Regression coverage exercises shared edges, latest-generation vetoes, controller/child moves, delete/reinsert order, delayed fills, and context retirement.
  • The registered sessions.list and 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.
  • Separate counted proof reduced requester-closure visits from 12,312 to 2,052, plus one 1,026-row lookup construction. SQL calls remained 28; intentional full-swarm reads remained full. This is structural evidence rather than a production CPU percentage.

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.

Pair Unrelated retained rows Main-thread CPU Process CPU Wall
control-1 0 102.280 → 99.997 653.413 → 697.171 354.947 → 389.422
control-2 0 146.123 → 177.737 987.993 → 1151.257 495.929 → 523.765
control-3 0 123.075 → 112.627 702.960 → 726.667 401.694 → 420.460
target-1 1,024 187.831 → 110.231 1033.902 → 754.975 557.668 → 414.704
target-2 1,024 169.317 → 126.371 1067.264 → 822.502 559.212 → 411.904
target-3 1,024 150.653 → 136.605 900.893 → 851.659 467.970 → 449.995

The comparison used baseline 82d4d1cc175549e222e3cb2605716f277eff6a00 plus 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.

Pair Baseline primary start → end (increase) Candidate primary start → end (increase) Lifetime maximum, baseline → candidate
control-1 748.414 → 839.664 (+91.250) 745.879 → 839.738 (+93.859) 2322.703 → 2292.039
control-2 704.422 → 800.152 (+95.730) 718.746 → 783.012 (+64.266) 2380.719 → 2414.961
control-3 742.598 → 827.523 (+84.926) 741.039 → 829.539 (+88.500) 2425.406 → 2378.102
target-1 729.945 → 825.922 (+95.977) 746.340 → 828.055 (+81.715) 2663.207 → 2420.242
target-2 729.984 → 812.863 (+82.879) 723.148 → 810.105 (+86.957) 2385.121 → 2321.430
target-3 737.848 → 857.723 (+119.875) 725.852 → 834.102 (+108.250) 2664.262 → 2475.855

The phase samples use process.memoryUsage.rss(); lifetime maxima use Linux wait4 accounting. 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.

@clawsweeper

clawsweeper Bot commented Sep 17, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@openclaw-barnacle openclaw-barnacle Bot added agents Agent runtime and tooling size: L maintainer Maintainer-authored PR labels Sep 17, 2026
@steipete
steipete marked this pull request as ready for review September 17, 2026 00:59
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Sep 17, 2026
@clawsweeper

clawsweeper Bot commented Sep 17, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed September 16, 2026, 11:44 PM ET / September 17, 2026, 03:44 UTC (Revision 5).

ClawSweeper review

What this changes

The 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
Reviewed head: 1ca5e2e4c878e7670c1d3bd1d1aa095954742753

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused, coherent optimization with meaningful lifecycle coverage and candidly bounded performance evidence.
Proof confidence 🐚 platinum hermit (4/6) Sufficient (live_output): The supplied Testbox replay exercises registered session listing and notifications through the changed registry read path, reporting payload parity and lower large-registry CPU with startup lookup costs included. Its older comparison baseline and small-control slowdowns limit the claim; privately retained raw artifacts were not independently rechecked here.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (live_output): The supplied Testbox replay exercises registered session listing and notifications through the changed registry read path, reporting payload parity and lower large-registry CPU with startup lookup costs included. Its older comparison baseline and small-control slowdowns limit the claim; privately retained raw artifacts were not independently rechecked here.
Evidence reviewed 9 items Current main still performs the targeted scans: Current main rebuilds requester closure from cached values and iterates the cached records for scoped tree reads. Controller reads similarly filter the complete cached snapshot. The proposed membership lookup is additional work beyond the existing scoped SQL paths.
Lookup remains subordinate to the snapshot: The complete compact snapshot lazily owns the lookup. Named publications update its membership alongside copied records; replacement and database-context invalidation replace the owning state. Live records still overlay persisted selections.
Selection preserves existing policy: The lookup counts shared requester edges, retains all generations for selected children, preserves snapshot order, and incorporates current in-memory topology. Generation and liveness decisions remain with the existing read index; no authorization value or durable schema is introduced.
Findings None None.
Security None None.

How this fits together

The 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]
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source +188, Tests +266. Total +454 across 4 files.

View PR surface stats
Area Files Added Removed Net
Source 2 215 27 +188
Tests 2 294 28 +266
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 4 509 55 +454

Review metrics

Metric Value Why it matters
Production versus test growth Production net +188 lines; tests net +266 lines Production growth implements reusable membership selection, with the stated justification supported by reduced repeated traversal.
Benchmark scope 3 pairs per size; 9.3–41.3% lower target main-thread CPU All large-registry pairs improved, while all small controls increased process CPU and wall time, limiting generalization.

Technical review

Best 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.

Labels

Label justifications:

  • P2: This is a bounded session-update performance improvement for large retained registries, without evidence of an urgent outage.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (live_output): The supplied Testbox replay exercises registered session listing and notifications through the changed registry read path, reporting payload parity and lower large-registry CPU with startup lookup costs included. Its older comparison baseline and small-control slowdowns limit the claim; privately retained raw artifacts were not independently rechecked here.
  • proof: sufficient: Contributor real behavior proof is sufficient. The supplied Testbox replay exercises registered session listing and notifications through the changed registry read path, reporting payload parity and lower large-registry CPU with startup lookup costs included. Its older comparison baseline and small-control slowdowns limit the claim; privately retained raw artifacts were not independently rechecked here.

Evidence

What I checked:

  • Current main still performs the targeted scans: Current main rebuilds requester closure from cached values and iterates the cached records for scoped tree reads. Controller reads similarly filter the complete cached snapshot. The proposed membership lookup is additional work beyond the existing scoped SQL paths. (src/agents/subagents/registry/subagent-registry-state.ts:602, 9a4468148bc0)
  • Lookup remains subordinate to the snapshot: The complete compact snapshot lazily owns the lookup. Named publications update its membership alongside copied records; replacement and database-context invalidation replace the owning state. Live records still overlay persisted selections. (src/agents/subagents/registry/subagent-registry-state.ts:239, 1ca5e2e4c878)
  • Selection preserves existing policy: The lookup counts shared requester edges, retains all generations for selected children, preserves snapshot order, and incorporates current in-memory topology. Generation and liveness decisions remain with the existing read index; no authorization value or durable schema is introduced. (src/agents/subagents/registry/subagent-session-read-scope.ts:111, 1ca5e2e4c878)
  • Behavioral regression coverage: Read both changed test modules completely. They cover shared-edge removal, latest-generation vetoes, controller and child moves, delete/reinsert order, delayed replies, failed publications, and database retirement. Tests were inspected rather than executed under this read-only review. (src/agents/subagents/registry/subagent-registry-state.test.ts:297, 1ca5e2e4c878)
  • Previous conflict blocker resolved: Raw test-merge parents are the pinned main followed by the exact PR head. Comparing that result with its main parent changes only the four registry files; it does not remove the main-only date/time changes. Live REST metadata also reports the same head and base as mergeable. (1e2eb9e32f34)
  • Recorded production-path performance evidence: The supplied body at source revision 464a3e3a387ee49e3b44c1a84a4aa1bc77e725157ba92f79c03318868e81af3d reports a Linux Testbox replay through registered sessions.list and notifications: 12 fresh-process cells, 240 inputs, 192 deliveries, 48 expected stale non-deliveries, and complete normalized payload/wire parity. Large-registry main-thread CPU improved 9.3–41.3%; control process CPU and wall time increased in all three pairs. RSS measurements are included without claiming isolated lookup-memory savings. Raw artifacts were privately collected and were not independently inspected here.

Likely related people:

  • unknown: The claimed source-line change could not be verified from bounded local history. (role: source history unknown; confidence: low)

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

History

Review history (4 earlier review cycles)
  • reviewed 2026-09-17T01:07:31.518Z sha caeb60006bc3d2ed0f646564db6ac685743db002 :: blocked before merge. :: none
  • reviewed 2026-09-17T01:52:11.649Z sha caeb60006bc3d2ed0f646564db6ac685743db002 :: blocked before merge. :: none
  • reviewed 2026-09-17T02:50:13.773Z sha a529a1d3eb28d29a8dae750449cbee201de591c4 :: needs maintainer review before merge. :: none
  • reviewed 2026-09-17T03:25:59.800Z sha 7737441f50a4ff25a6b12e45e9ee814e892f5607 :: blocked before merge. :: none

@clawsweeper clawsweeper Bot added the proof: sufficient ClawSweeper judged the real behavior proof convincing. label Sep 17, 2026
@steipete
steipete force-pushed the codex/team-session-registry-lookup-20260916 branch from caeb600 to a529a1d Compare September 17, 2026 02:40
@steipete
steipete force-pushed the codex/team-session-registry-lookup-20260916 branch from 7737441 to 1ca5e2e Compare September 17, 2026 03:32
@steipete
steipete merged commit 2dbf888 into main Sep 17, 2026
211 checks passed
@steipete
steipete deleted the codex/team-session-registry-lookup-20260916 branch September 17, 2026 04:04
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling maintainer Maintainer-authored PR P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: L status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant