Skip to content

perf(gateway): reduce registry allocations during session presentation - #184698

Merged
steipete merged 7 commits into
mainfrom
steipete/coldload-child-owner-presentation
Oct 26, 2026
Merged

steipete merged 7 commits into
mainfrom
steipete/coldload-child-owner-presentation

Conversation

@steipete

@steipete steipete commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Repeated session presentation allocates temporary objects while resolving child controllers and counting active descendants. A settled profile attributed 3.41 MB per 30 seconds to child-run lookup and 4.73 MB to descendant counting. This targets server allocation. The broader campaign observed 14 intermediate states during a signed-in reload of a dashboard deep link; this change makes no visual or first-paint claim.

Why This Change Was Made

Registry buckets use arrays, and their final element supplies the existing last-published lookup, deleting the separate latest-insertion map. Presentation reads a child bucket directly without the old iterator, per-call predicate, composite lookup key, or parent-comparison array. Live executor/reservation authority, agent ownership, incarnation matching, and generation ordering are preserved. This remains O(runs in the child's bucket), usually a singleton; it does not cache live authority.

Main already supplies prepared descendant arrays, indexed iteration, and shared active-only options (#184566). This branch keeps only the remaining thirteen-line fast return: entirely ended descendant sets return zero without filling a fresh count map with zero entries; unended work retains the existing window-specific count memo and clock semantics. Array replacement is linear in bucket size, and the whole-list measurements include that write cost. No protocol, durable record, configuration, or schema changes.

User Impact

This change preserves controller, parent, and navigation semantics in focused/property tests and reduces allocation on the synthetic workload, with measured allocation savings and the steady-state timing evidence below. No UI files change and no cold-load latency improvement is claimed.

Evidence

Final candidate: 5e2b04c0d31ae8ec4c79099d11009d523b745d1a.
Frozen new-main baseline: d3ce499054a038450b064a317d9a74615457cdd4, including #184566 (4293b683) and the nearby landed selection work. The overlapping descendant changes were dropped before both revisions were installed and fully built. No rebase or source changes occurred after those builds; post-measurement heads, runtime diffs, and benchmark/test hashes were verified.

One AWS c7i.4xlarge was used for both arms throughout: 16 vCPUs (8 Intel Xeon Platinum 8488C cores, two threads/core), 31 GiB RAM, full CPU affinity. This is the authorized alternative dedicated 16-vCPU class. Node 26.12.1 / pnpm 12.15.0. Lease cbx_c9383d0e4689; proof run.

The committed scripts/perf/session-child-owner-measure.ts uses the 10,800-session synthetic fixture, including 4,300 unarchived subagent records, 48 fixed churn roots, and 2,160 requester roots. Each group has eleven alternating AB/BA pairs, run serially on the same box: owner timing, list timing, owner allocation, and list allocation, 88 measured arms total. All completed without discarded or repeated pairs. Four full-size smoke runs, two call censuses, and both allocation-region qualifications passed first. The owner workload presents all 10,800 rows per pass and uses 8,000 updates / 1,000 warmup updates and 240 measured passes (518,400 descendant queries and 2,592,000 owner reads per arm). The production list workload uses 1,200 updates / 200 warmup updates and 36 measured 100-row pages from the full fixture. Whole-list totals include registry maintenance; counts and checksums agree between arms.

Targeted allocation uses separate temporal sampling regions after batched writes and index preparation. V8 optimization stays enabled; every sampled byte is counted. The owner region includes argument spreads and CPU bookkeeping, and both regions include sampling-boundary overhead. These are conservative region totals, not exact per-function allocation sizes. No overhead was subtracted. Whole-list allocation uses the unchanged global sampler. The raw region sums and 240 epochs per region were independently audited, as were all sixteen summary rows and all paired deltas; all 284 captured microbenchmark artifact hashes match.

The original 80% regional threshold was withdrawn after review of the complete comparison: the 80.8% / 75.1% targeted reductions (11/11 each), 3.3% whole-list allocation reduction (10/11), and +45 runtime LOC were accepted as a small consistent win. The additional gate is one canonical steady-state real-Gateway timing pass against these same frozen revisions, on one dedicated 16-vCPU AWS box after full installs/builds. Run --mode timing --minutes 10 --pairs 1 with the default 10,800-session / 65-client / 40-plugin workload. This is one AB pair (twenty measured minutes, plus setup/warmup), despite the original approximate forty-minute estimate. Report handler mean, row-selection counters per list, main CPU, GC, loop p99, achieved requests, and completed turns. No secondary regression under the declared IQR/paired rule; a single AB pair cannot establish an eleven-pair significance claim. The baseline and candidate below are medians, with IQRs in brackets; MB means decimal megabytes. Deltas are candidate minus baseline.

Allocation per pass Baseline MB [IQR] Candidate MB [IQR] Reduction Better pairs Paired median MB Allocation result
Owner-resolution region 8.551271 [8.536489, 8.578558] 1.644922 [1.630432, 1.658638] 80.764% 11/11 -6.916565 Accepted
Descendant-read region 0.292097 [0.289030, 0.294631] 0.072828 [0.071525, 0.073366] 75.067% 11/11 -0.219912 Accepted (75.1%)
Whole sessions.list 4.446363 [4.387811, 4.504785] 4.298783 [4.278530, 4.347474] 3.319% 10/11 -0.130574 Accepted

Whole-list resolution CPU was 17.856 → 18.528 ms/pass (paired median +0.281 ms); total thread CPU including updates was 19.832 → 20.477 ms/pass (paired median +0.272 ms). Both IQRs overlap and both have 8/11 adverse pairs, below the required 9/11. The total median rise is +0.646 ms (3.26%). Under the declared secondary regression rule these are inconclusive, with no demonstrated regression; The regional allocation results were accepted; the completed steady-state harness is reported separately below.

In representative pair 1, descendant-region samples attributed to native set fell from 53,724,360 to 497,008 bytes across 240 passes. The candidate's dominant remaining attribution is folded into readActiveDescendants (16,716,672 bytes). Inlining prevents a defensible finer allocation-site claim from this sample. The retained path handles active/unended work with the existing liveness/retention semantics; the fast return applies only to entirely ended descendants. A finer attribution or a different simplification would be needed for any further optimization. No unmeasured follow-up is included here.

All metrics, IQRs, and eleven per-pair deltas

Units follow the metric names: CPU/GC in milliseconds; allocation/retained heap in bytes. Whole-list thread CPU includes update work. Raw threadCpuMs is total measured-arm CPU; the PerList field normalizes it by the measured passes.

Workload / mode / metric Base median [Q1,Q3] Candidate median [Q1,Q3] Better pairs Median paired delta
owner / timing / resolutionCpuMsPerList 20.551846 [20.115619, 20.885177] 9.636225 [9.066500, 10.475358] 11/11 -11.009950
owner / timing / threadCpuMs 5157.064000 [5053.180000, 5237.439000] 2523.990000 [2373.298500, 2724.894000] 11/11 -2651.340000
owner / timing / threadCpuMsPerList 21.487767 [21.054917, 21.822662] 10.516625 [9.888744, 11.353725] 11/11 -11.047250
owner / timing / updateCpuMsPerUpdate 0.020400 [0.019622, 0.021226] 0.020833 [0.020378, 0.021525] 3/11 +0.000542
owner / timing / gcMsPerList 0.240494 [0.236970, 0.241739] 0.083573 [0.081126, 0.084273] 11/11 -0.156237
owner / timing / retainedHeapAfter 230413400.000000 [230408780.000000, 230423692.000000] 228775736.000000 [228769140.000000, 228783844.000000] 11/11 -1640088.000000
owner / timing / ownerCpuMsPerList 18.953242 [18.702265, 19.371885] 8.481663 [7.960681, 9.316856] 11/11 -10.222713
owner / allocation / ownerRegionAllocatedBytesPerList 8551270.533333 [8536488.900000, 8578558.200000] 1644922.233333 [1630432.366667, 1658637.850000] 11/11 -6916564.566667
owner / allocation / descendantRegionAllocatedBytesPerList 292096.733333 [289029.866667, 294630.866667] 72828.400000 [71525.333333, 73366.016667] 11/11 -219912.366667
list / timing / resolutionCpuMsPerList 17.855667 [17.556722, 18.364569] 18.528111 [17.733653, 19.192167] 3/11 +0.281028
list / timing / threadCpuMs 713.947000 [704.514500, 735.629000] 737.188000 [710.138500, 766.405500] 3/11 +9.801000
list / timing / threadCpuMsPerList 19.831861 [19.569847, 20.434139] 20.477444 [19.726069, 21.289042] 3/11 +0.272250
list / timing / updateCpuMsPerUpdate 0.033121 [0.032694, 0.034252] 0.033137 [0.031750, 0.034107] 6/11 -0.001669
list / timing / gcMsPerList 0.205439 [0.203187, 0.217922] 0.201294 [0.189938, 0.231866] 5/11 +0.000270
list / timing / retainedHeapAfter 293791872.000000 [293710404.000000, 293810976.000000] 292146064.000000 [292139428.000000, 292235856.000000] 11/11 -1571480.000000
list / allocation / allocatedBytesPerList 4446362.666667 [4387811.333333, 4504784.777778] 4298782.666667 [4278530.222222, 4347473.555556] 10/11 -130573.777778

Per-pair deltas (candidate − baseline):

owner / timing / resolutionCpuMsPerList: -11.152046, -9.868942, -11.196808, -11.858367, -10.126400, -12.429037, -9.610054, -9.411579, -10.617008, -11.009950, -12.075217
owner / timing / threadCpuMs: -2704.607000, -2382.535000, -2688.510000, -2865.235000, -2433.994000, -3001.459000, -2318.546000, -2274.037000, -2559.052000, -2651.340000, -2930.723000
owner / timing / threadCpuMsPerList: -11.269196, -9.927229, -11.202125, -11.938479, -10.141642, -12.506079, -9.660608, -9.475154, -10.662717, -11.047250, -12.211346
owner / timing / updateCpuMsPerUpdate: +0.000316, +0.001500, +0.002030, -0.000311, +0.001236, -0.000721, +0.000971, +0.000190, +0.000542, +0.001802, -0.001797
owner / timing / gcMsPerList: -0.156943, -0.155766, -0.159569, -0.157344, -0.156237, -0.161696, -0.159136, -0.152616, -0.154423, -0.154537, -0.150530
owner / timing / retainedHeapAfter: -1624520.000000, -1693120.000000, -1353016.000000, -2344192.000000, -1657072.000000, -1641696.000000, -1574472.000000, -1639880.000000, -1653904.000000, -1640088.000000, -1627640.000000
owner / timing / ownerCpuMsPerList: -11.002462, -9.704000, -10.222713, -11.615150, -9.922692, -11.525158, -9.335100, -9.212842, -10.091421, -10.272671, -11.455087
owner / allocation / ownerRegionAllocatedBytesPerList: -6862602.366667, -6860284.433333, -6897185.833333, -6931301.200000, -6873183.233333, -6916564.566667, -6924060.700000, -6902447.466667, -7058835.566667, -6976704.066667, -6978296.500000
owner / allocation / descendantRegionAllocatedBytesPerList: -216457.066667, -230119.100000, -221103.033333, -211934.766667, -222005.000000, -225545.266667, -223067.000000, -213583.466667, -214359.700000, -219912.366667, -218157.466667
list / timing / resolutionCpuMsPerList: +3.545361, +0.245722, -1.682639, -0.080278, +0.750444, -2.988389, +0.281028, +0.862556, +0.267750, +2.002139, +1.657639
list / timing / threadCpuMs: +133.349000, +7.167000, -62.127000, -8.741000, +28.694000, -108.916000, +9.801000, +34.629000, +5.052000, +75.883000, +62.805000
list / timing / threadCpuMsPerList: +3.704139, +0.199083, -1.725750, -0.242806, +0.797056, -3.025444, +0.272250, +0.961917, +0.140333, +2.107861, +1.744583
list / timing / updateCpuMsPerUpdate: -0.002522, +0.001258, -0.007669, -0.001669, +0.000753, -0.002193, +0.000631, -0.001803, -0.002404, +0.004000, +0.002651
list / timing / gcMsPerList: -0.023132, -0.019335, +0.014873, +0.025988, +0.035914, -0.021275, -0.024803, +0.000270, +0.012548, -0.049078, +0.052157
list / timing / retainedHeapAfter: -1467128.000000, -1449928.000000, -1569800.000000, -1574760.000000, -1559320.000000, -1569664.000000, -1679240.000000, -1662440.000000, -1571480.000000, -1711816.000000, -1601216.000000
list / allocation / allocatedBytesPerList: -157260.666667, +44196.666667, -240077.555556, -136003.111111, -130573.777778, -17051.111111, -257268.888889, -86131.555556, -57732.222222, -112433.111111, -224761.777778

Correctness, checks, and uncovered gates

Both frozen revisions completed full dependency installation and full builds. All twelve focused files passed on the final candidate: 174 tests, 640.24 seconds total wall time, each run independently with pnpm test <file> --maxWorkers=1. The controller equivalence property test compares against the original scan over seeded registry mutations, status transitions, replacement runs, generation/incarnation changes, and agent mismatch. Descendant tests cover nested/cyclic graphs, status/generation/replacement changes, and finite/nonfinite ended timestamps. The iterator regression added by #184566 remains intact.

Focused file Tests passed Command wall seconds
src/gateway/session-child-controller.test.ts 2 69.59
src/gateway/session-utils.navigation-lineage.test.ts 8 69.97
src/gateway/session-row-presentation.test.ts 9 58.42
src/gateway/session-utils-row.materialize.test.ts 10 55.69
src/agents/tools/sessions-send-communication.test.ts 41 87.95
src/agents/subagents/registry/subagent-registry-memory.test.ts 26 46.58
src/agents/subagents/registry/subagent-registry-read.scoped.test.ts 8 60.12
src/agents/subagents/registry/subagent-run-liveness.test.ts 4 4.28
src/agents/subagents/registry/subagent-liveness.owner-integration.test.ts 11 80.94
src/agents/subagents/registry/subagent-registry-queries.test.ts 25 45.37
src/agents/subagents/registry/subagent-child-owner-match.test.ts 14 4.04
src/agents/subagents/registry/subagent-controller-inputs.test.ts 16 57.29

Complete changed-file validation (node scripts/check-changed.mjs --base d3ce499054a038450b064a317d9a74615457cdd4 --head 5e2b04c0d31ae8ec4c79099d11009d523b745d1a --timed) took 1,263.51 seconds. Core types, every core-test typecheck shard, script types, lint, formatting, and guards passed. The dead-export scan failed with twenty findings; the same twenty reproduce on the untouched frozen main, with zero candidate-only findings. No check was skipped to obtain green.

A fresh complete-branch independent autoreview, including the full benchmark and registry owner source, is clean through P2. The first review attempt timed out after the full hour; the required retry produced a valid clean verdict. A subsequent conflict-free rebase left all five runtime files and the benchmark byte-identical to that reviewed source.

Steady-state real-Gateway timing

Both frozen revisions were independently installed and fully built again on AWS lease cbx_ba79d790dc09, one c7i.4xlarge in eu-west-2, before an AB setup smoke and the canonical command below. Harness run. The stock image initially lacked npm; that prerequisite was installed before either build or measurement, on the same retained box. No measured pair was discarded or repeated, and no source/rebase changes occurred after building.

node --import ./scripts/tsx.mjs scripts/perf/team-shape-stress.ts \
  --base <fully-built-baseline> --candidate <fully-built-candidate> \
  --output <new-synthetic-output> --mode timing --minutes 10 --pairs 1

The harness generates independent synthetic state for each arm: 10,800 sessions, 65 operator clients, four mock-provider turns per round, 40 enabled bundled plugins, 128 MiB synthetic transcripts, one-minute warmup, ten-minute measured duration per arm. One AB pair is twenty measured minutes plus setup, rather than the original approximate forty-minute estimate. The smoke is setup proof only. Timing does not sample allocations or force GC during measurement.

Metric Baseline Candidate Candidate − baseline
Server list handler mean ms 16.671298 16.879205 +0.207907
Parent selections/list 0.000000 0.000000 +0.000000
Running-candidate selections/list 7.522592 7.485081 -0.037511
Main thread CPU ms 74955.676000 75280.536000 +324.860000
Main thread CPU percent 12.492231 12.546422 +0.054191
GC seconds/minute 0.268357 0.270618 +0.002261
Event loop p99 ms 38.436863 40.927231 +2.490368
Completed turns 40.000000 40.000000 +0.000000
Client list p99 ms (noise context) 64.827837 63.260084 -1.567753

One AB pair: twenty measured minutes, not forty. Absent counter series mean no observed calls, not an improvement. Client list p99 is context; known A/A spread is approximately ±120 ms. This sample count cannot establish an eleven-pair secondary regression.

All row-selection counter kinds present in the captured Prometheus interval:

Counter kind Baseline calls/list Candidate calls/list Delta
agent 0.000853 0.000853 +0.000000
broad 0.000853 0.000853 +0.000000
running-candidate 7.522592 7.485081 -0.037511
store 0.057971 0.064791 +0.006820

Counter denominators are the captured sessions.list request-counter deltas, not client latency sample counts. Absent series mean no observed calls, not an improvement.

Base: 1173 list requests in the scrape interval; 1183 measured client list completions; 195.294 measured RPCs/minute; 40 completed turns.

Candidate: 1173 list requests in the scrape interval; 1183 measured client list completions; 195.495 measured RPCs/minute; 40 completed turns.

Descriptive within-run minute windows (not independent paired runs):

Metric Baseline median [IQR] Candidate median [IQR] Candidate − baseline by minute
main CPU percent 12.409583 [12.153749, 13.030126] 12.427108 [12.058119, 13.008461] -0.424659, -0.113811, -0.105505, +0.854713, -0.296084, -0.269934, +0.108944, +0.250251, +0.657785
GC seconds/minute 0.261869 [0.252049, 0.287700] 0.270016 [0.236448, 0.307739] -0.060623, -0.033501, -0.017683, +0.078480, -0.025421, +0.043171, +0.050433, -0.009878, +0.001903
minute loop p99 ms 38.207487 [36.995071, 39.387135] 40.173567 [37.748735, 40.632319] +0.720896, +0.884736, -0.720896, +3.080192, +1.245184, +0.425984, -2.195456, +2.392064, +4.292608

The captured intervals each contain 1,173 list requests. Counter task labels distinguish direct RPC work from background work: both arms recorded one agent and one broad selection attributed to sessions.list; running-candidate was 8,824 → 8,780 and store was 68 → 76, all attributed to other. Thus the normalized background counters are context, not per-RPC call-site counts. The extra eight background store selections are reported, with no consistent-regression claim from one pair. Both arms completed 40 turns and 108 committed timestamp writes, and every measured RPC error count is zero.

One AB pair cannot prove the eleven-pair sign-test condition; the minute windows are correlated descriptive samples. Handler mean and main CPU are separate boundaries; client list p99 retains its documented approximately ±120 ms A/A noise context. The acceptance assessment must use the observed results and this sample limitation.

Size, scope, and cleanup

Runtime-only delta: 100 insertions, 55 deletions, +45 LOC across five files. This is within the +60 limit; preserving live authority and incarnation/generation matching in the direct owner query requires the growth. The per-call gateway predicate/scan path and redundant latest-insertion map are deleted. The query-owner delta against new main is only thirteen added lines; #184566's prepared arrays, indexed iteration, shared options, and eliminated duplicate lookup are retained.

Requested non-test/non-doc stat (git diff --stat origin/main...HEAD -- ':!*.test.ts' ':!*test-support*' ':!docs/*'): 447 insertions, 135 deletions, +312 net, including +267 benchmark LOC. Runtime files: subagent-registry-memory.ts, subagent-child-owner-match.ts, subagent-registry-read.ts, subagent-registry-queries.ts, and src/gateway/session-utils-core.ts. Three focused test files and the committed benchmark complete the nine-file diff. No protocol, configuration, schema, or durable-state changes.

The allocation-proof lease cbx_c9383d0e4689 and its superseded validation leases are released. Harness lease cbx_ba79d790dc09 is confirmed released (i-0ce132000ad022ea5). All confirmed owned leases are released, and the harness cleaned up its isolated Gateways. The older uncertain request cbx_2e4f981e5370 was reconciled on its same AWS route in us-east-1: status and authoritative provider inspection return HTTP 404 not_found; no matching lease record is available to release, and no EC2 termination receipt is claimed.

This PR replaces closed #184152. Ready status follows the accepted allocation comparison and completed steady-state gate. Exact-head CI status and regression assessment are recorded below before handoff. Stop before merge.

Acceptance and CI

The completed steady-state pass shows no regression under the declared rule: handler mean +0.208 ms (1.25%), CPU +0.054 percentage points (0.43%), GC +0.0023 seconds/minute (0.84%), loop p99 +2.490 ms (6.48%). CPU, GC, and minute-loop-p99 IQRs overlap. The loop movement is below the absolute 10 ms paired-rise threshold; one AB pair cannot establish the multi-pair sign condition. Background selection-count differences are disclosed above, while direct-RPC counts and completed work agree. These are small/noisy secondaries, not demonstrated harm. This is a single timing-pair acceptance result, not a statistical speedup claim.

The measured allocation improvements are accepted under the small-wins bar: owner −80.8% and descendants −75.1% (11/11 each), whole-list allocation −3.3% (10/11), for +45 runtime LOC. The old 80% regional cutoff is withdrawn. Full per-pair allocation and CPU deltas remain above.

Exact-head CI run 40379329976 is green for 5e2b04c0d31ae8ec4c79099d11009d523b745d1a: 73 completed jobs, 46 successful and 27 scoped skips, with no failed jobs. openclaw/ci-gate is successful. There are no red CI jobs requiring main comparison. Three historical auto-response cancellations remain outside this successful CI run; no CI workflow was rerun. The earlier changed-file dead-export failure is classified against the identical frozen-main result above.

The independent autoreview is clean through P2. The exact-head GitHub code review reports no findings. The updated ClawSweeper review accepts the supplied production-path evidence, reports no actionable findings, and lists no before-merge items. The earlier extra authority-trace request was addressed with the real-registry admission regression and unchanged final-admission owner, as explained in the evidence response; no separate foreign-controller Gateway trace is claimed. One explicit re-review request was posted after updating the evidence.

Ready, open, mergeable, and stopped before merge. No merge or auto-merge.

Maintain the newest matching live controller in the registry and refresh it when executor or scheduler ownership changes. Remove row-time run scans while preserving generation ordering, partial session identities, foreign control, and durable parent navigation.

Release-note context: reduce session-list and Control UI row-presentation allocation without changing controller or parent relationships.
Share the existing execution ownership checks through a state-bound adapter, retain the controller scan negative control, and prepare runtime config before benchmark projection startup.
Match the Team harness 100-row list request while retaining the full 10,800-row fixture and all-row owner workload. This keeps setup within the existing exact-row preparation budget.
@clawsweeper

clawsweeper Bot commented Oct 26, 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 gateway Gateway runtime scripts Repository scripts agents Agent runtime and tooling size: L labels Oct 26, 2026
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Oct 26, 2026
@clawsweeper

clawsweeper Bot commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

This PR reduces temporary allocations in session-controller lookup and settled-descendant counting and extends the existing performance probe.

Example: Repeatedly list 100 sessions from a 10,800-session synthetic workspace.

  • Before: Median sampled allocation is 4.446 MB per list pass.
  • After: Median sampled allocation is 4.299 MB per list pass, with matching counts and checksums.

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused, correct optimization with substantial allocation evidence, production-entry-point validation, and green exact-head CI; Gateway timing conclusions remain bounded by one paired run.
Proof confidence 🐚 platinum hermit (4/6) Sufficient (live_output): The completed body evidence ties the reviewed registry changes to eleven paired allocation runs and a real isolated Gateway sessions.list comparison on the frozen baseline and candidate, with equal completed work and no RPC errors; the single Gateway AB pair supports the accepted timing assessment without establishing statistical speedup.
Patch quality 🦞 diamond lobster (5/6) No actionable review findings were identified.

Product

Kind: Performance · Worth it: Yes · Fix scope: Complete
User problem: Repeated session presentation spends avoidable CPU and allocation resolving child controllers and counting settled descendants.
Reason: The maintainer accepts the measured small allocation improvement and disclosed timing tradeoffs, while the implementation preserves existing user-visible relationships.

Merge readiness

✅ Ready for maintainer review

Keep open: this maintainer-authored PR delivers an accepted allocation improvement, with no actionable correctness or security findings and successful exact-head CI.

Priority: P2
Reviewed head: 5e2b04c0d31ae8ec4c79099d11009d523b745d1a

Before merge

None.

Findings

None.

Agent review details

How this fits together

Gateway session presentation consumes registry rows, session identities, and live execution or scheduler ownership to produce controller relationships and descendant counts.

flowchart TD
  A[Session list request] --> B[Session presentation]
  B --> C[Registry child buckets]
  C --> D[Live execution and reservation checks]
  D --> E[Controller relationship]
  B --> F[Descendant topology]
  F --> G[Active descendant count]
  E --> H[Session response]
  G --> H
Loading

Technical review

Best possible solution:

Retain this focused optimization in the existing registry owner with unchanged controller authority, ordering, and descendant-count semantics.

Do we have a high-confidence way to reproduce the issue?

Source inspection confirms the baseline's temporary lookup and count-map allocations, and the supplied paired measurements exercise them; no target code was run during this read-only review.

Is this the best way to solve the issue?

The change removes redundant representations and per-read allocations at existing owners, preserves live checks, and avoids a new invalidation lifecycle; new flags are confined to the benchmark.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 797f83a103a6.

Provenance checked

Testing

Proof path: shipped entry point.

Security

None.

Evidence

What I checked:

Likely related people:

  • Peter Steinberger: Raw commit b1ae600 adds src/agents/subagents/registry/subagent-registry-queries.ts:290 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: b1ae6004fc2c; files: src/agents/subagents/registry/subagent-registry-queries.ts)
  • RoboClaw: Raw commit 4e26493 adds src/gateway/session-utils-core.ts:172 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 4e26493aafd0; files: src/gateway/session-utils-core.ts)

PR surface

Source +45, Tests +214, Other +267. Total +526 across 9 files. Added test files: 1.

View PR surface stats
Area Files Added Removed Net
Source 5 100 55 +45
Tests 3 224 10 +214
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 1 347 80 +267
Total 9 671 145 +526

Review metrics

Metric Value Why it matters
Runtime versus test growth Runtime +100/-55 lines; tests +224/-10 lines The net 45 runtime lines replace allocation-heavy reads without a new cache or authority owner; test growth protects selection equivalence, queued replacement, released control, and descendant-count boundaries.

Labels

Label changes:

No label changes.

Label justifications:

  • P2: A measured server-allocation improvement with limited scope and no demonstrated urgent user-facing regression.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🦞 diamond lobster.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.
  • proof: sufficient: Contributor real behavior proof is sufficient.

Rating scale

6/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.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only. Repair and merge execution lanes are retired.

History

Review history (2 earlier review cycles)
  • reviewed 2026-10-26T14:19:16.623Z sha 5e2b04c :: needs real behavior proof before merge. :: none
  • reviewed 2026-10-26T18:52:54.686Z sha 5e2b04c :: needs maintainer review before merge. :: none

Reviewed October 26, 2026, 2:59 PM ET / 18:59 UTC (Revision 3).

@steipete steipete closed this Oct 26, 2026
@steipete steipete reopened this Oct 26, 2026
@steipete steipete changed the title experiment(control-ui): reduce registry read allocations [do not merge] perf(gateway): reduce registry allocations during session presentation Oct 26, 2026
@steipete
steipete marked this pull request as ready for review October 26, 2026 18:37
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-26T18:39:24.541362Z 5e2b04c Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@steipete

Copy link
Copy Markdown
Contributor Author

The completed final-head evidence is now in the PR body: 174 focused tests on 5e2b04c0, all eleven allocation pairs, and the full real-Gateway timing AB pass. The earlier review's references to pending performance results and 173 prior-head tests are superseded. The ready transition has triggered exact-head CI run 40379329976, which is still running.

The controller-release regression at sessions-send-communication.test.ts:484 uses the real registry row, a real execution claim, and the new controller query. That query is retained from importOriginal; only the separate latest-live-task reader is stubbed. The test prepares controller-only admission, releases the live claim, and observes the production admission assertion reject. It passed in the 41-test communication file. The independent seeded property test also compares controller/owner results against the original scan over status, replacement, generation, incarnation, and agent-mismatch transitions.

The delivery authorization owner is unchanged. Its assertTask check still resolves current control at final admission. The performance harness is not a foreign-controller/reassignment delivery trace, and no such trace is claimed. With no concrete authorization defect identified, I am not treating an additional adversarial delivery-race trace as a new requirement for this equivalent registry-read optimization. The production boundary regression, independent selection equivalence, fresh clean P2 source review, and completed Gateway workload are the supplied proof.

The measured allocation gains were accepted for the ready PR; the handoff still stops before merge. Please reassess the completed evidence and identify any concrete remaining defect.

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. and removed rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Oct 26, 2026
@clawsweeper clawsweeper Bot added the status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. label Oct 26, 2026
@steipete
steipete merged commit cfb41dd into main Oct 26, 2026
347 of 350 checks passed
@steipete
steipete deleted the steipete/coldload-child-owner-presentation branch October 26, 2026 19:03
@steipete

Copy link
Copy Markdown
Contributor Author

Lane 1871 is repairing restart recovery correctness in subagent-registry-run-launch.ts: direct operator-admitted child turns without a spawning requester turn currently omit their durable operator recovery source. The change will use the existing source-capture owner and cover repeated restart through the real registry and sessions.recover path. Separate recovery settlement will preserve an explicit Resume path when automatic authority restoration fails. No retention, indexing, query, or cold-load changes are planned; the merged work here remains intact.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 27, 2026
…penclaw#184698)

Row presentation resolved each child session's controller by iterating that child's runs through the registry (iterator, closure and owner tuples per call), and countActiveDescendantRuns walked descendant runs on every list. On Team these were among the top selection-side allocation families (getSubagentRunsForChildSession, resolveSessionChildController, countDescendantRuns).

The incremental registry run index (openclaw#183531) now keeps the latest matching controller per child session current through its existing update path, so presentation reads it directly. Descendant reads iterate the prepared buckets without per-call allocation, rebased on openclaw#184566, which already passes prepared descendants into countDescendantRuns. Results are identical; property tests cover status transitions, replacement runs and agent mismatches.

Evidence, 11 interleaved pairs on AWS c7i.4xlarge: owner-resolution allocation 8.551 -> 1.645 MB/pass (-80.8%, 11/11), descendant reads 292.1 -> 72.8 KB (-75.1%, 11/11), whole-list allocation 4.446 -> 4.299 MB (-3.3%, 10/11); CPU inconclusive. Team-shape harness (20 measured minutes): handler mean 16.67 -> 16.88 ms, main CPU 12.49% -> 12.55%, GC flat, 40/40 turns, zero RPC errors; no regression under the rule. 174 tests pass. Runtime +45 LOC.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling gateway Gateway runtime 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. scripts Repository scripts 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