Repository navigation
perf(sessions): reduce child-owner resolution cost - #183531
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 reuses unchanged subagent memberships and descendant links to reduce session-list CPU and allocation. Example: A session list is refreshed while 48 parents with 200 children each receive run-status updates.
Review scores
ProductKind: Performance · Worth it: Yes · Fix scope: Complete Merge readiness✅ Ready for maintainer review Keep this PR open for landing: the focused optimization has measured value, addresses the earlier review request, and has no actionable correctness findings. Priority: P2 Before mergeNone. FindingsNone. Agent review detailsHow this fits togetherThe subagent registry maintains run membership and topology; Gateway session-list preparation consumes those facts to resolve child relationships while checking current execution ownership. flowchart TD
A[Run status publications] --> B[Registry membership indexes]
B --> C[Retained descendant keys]
C --> D[Current canonical rows]
D --> E[Gateway child owner resolution]
F[Live execution ownership] --> E
E --> G[Session list response]
Technical reviewBest possible solution: Land the existing-owner optimization with its bounded performance claims and preserve production fan-out confirmation as a deployment follow-up. Do we have a high-confidence way to reproduce the issue? Source shows unconditional relationship invalidation and remove/add index maintenance on status replacements; the PR supplies controlled owner and Gateway measurements, which this read-only review did not rerun. Is this the best way to solve the issue? The patch removes repeated work inside existing owners, preserves generation invalidation and iteration order, and avoids redundant retained-state reads for durable native lineage. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 981699fb940d. Provenance checked
TestingProof path: shipped entry point. SecurityNone. EvidenceWhat I checked:
Likely related people:
PR surfaceSource +10, Tests +148, Other +306. Total +464 across 11 files. Added test files: 0. 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 HistoryReview history (1 earlier review cycle)
Reviewed October 25, 2026, 11:56 AM ET / 15:56 UTC (Revision 2). |
3b72f73 to
a62be43
Compare
Codex Review SummaryThis 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. |
a62be43 to
515af4e
Compare
515af4e to
c7d4c4b
Compare
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
Child-owner resolution sits under every sessions.list via per-owner running-candidate and per-parent child-link selections. On Team those run about 57 and 47 times per list call (row-selection counters). Each run-state update rebuilt or reallocated index state. The registry run index now updates a run's buckets in place: - one update(previous, next) call instead of remove + add; - singleton buckets are retained on status updates. The read topology also changes: - its descendant cache holds child keys rather than run records, so status-only updates no longer clear it; - rows resolve from the live index at read time; - membership or generation changes still clear the cache. resolveSessionChildOwners decides `keep` for native lineage without loading the display run. getLatestLiveSubagentRunByChildSessionKey uses the live child/agent index directly. Owner matching is unchanged: the owner is derived from the child key, and unqualified keys still yield no owner. Evidence. Microbench (11 triples: main / prior candidate / this): - resolution CPU 3.904 / 3.612 / 1.091 ms per pass; - allocation 168.0 / 161.5 / 46.5 KB per update; - GC 0.0086 / 0.0083 / 0.0014 ms per update; - all pairs favor this change. Team-shape stress harness (real tool turns + native subagents; AB and BA, 40 turns each): - server list-handler mean 17.09 -> 15.91 ms and 16.51 -> 15.98 ms; - CPU, GC time and event-loop p99 lower in both orders; - completed turns equal. Not claimed: a reduction in parent-selection fan-out per list call. The harness produces no parent selections; this will be checked on Team via openclaw_session_row_selections_total by kind / openclaw_sessions_list_requests_total before and after the deploy. Runtime +10 LOC. 2,032 broad tests pass; exact-head CI green.
…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 (#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 #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.
…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.
What Problem This Solves
Child-owner resolution repeats membership and descendant-topology work while agent run-state rows change, adding CPU and allocation to session-list preparation.
User Impact
Session-list preparation spends less CPU and allocation resolving child owners. The controlled mixed-load comparison observed lower server list-handler mean, CPU, GC time and event-loop p99 in both orders, with equal completed turns. No UI, configuration, schema, durable-record or authority change.
Non-claim: parent-selection fan-out reduction is unproven. The canonical harness recorded no parent selections, and running-candidate selections were about seven per list with mixed order deltas. Those counters do not reproduce the target production fan-out.
Production confirmation:
openclaw_session_row_selections_totalby kind /openclaw_sessions_list_requests_totalbefore vs after deploy. The lead will assess those counters after deployment; this PR performs no deployment.Why This Change Was Made
The existing registry owner now retains unchanged child/requester membership on status-only row replacement. Descendant closures retain child membership and resolve current canonical rows through the retained child index; actual link/generation changes invalidate topology. This removes repeated owner-index reconstruction and redundant child-owner resolution while preserving latest-generation/revocation semantics and observable child ordering. Gateway selection callers are unchanged.
Application runtime grows by 10 LOC across six owner files. The requested non-test/non-doc aggregate is +316 (390 insertions, 74 deletions): runtime +10 and owner benchmark +306. The small runtime growth preserves membership reuse together with generation/link invalidation and child iteration ordering.
Evidence
Owner microbench: AWS
cbx_ecd65a6972ff,c7a.4xlarge, 16 observed CPUs / approximately 31 GiB RAM, Node 26.12.1. Eleven counterbalanced timing triples plus eleven separate allocation triples, main / earlier owner candidate / incremental candidate, 66 accepted processes. Each process exercises 48 parents × 200 children, 8,000 measured run-state updates and 240 resolution passes after warmup, through real registry writes, claims, publication and resolution with a prepared in-memory source adapter. All checksums agree.Medians [Q1, Q3]; each of eleven paired CPU/allocation/GC deltas favors the incremental candidate against both controls. Owner benchmark source: main
60cde0098c78c21d22acedcd775982ba0c206502, the earlier candidate is that base plus the supplied owner patch, and measured incremental candidatea459fce76ef3ecd091430d0d15a6b375f5b0e1c6. Subsequent lint cleanup and the retained-read correctness repair are not included in those timing figures.Owner benchmark paired deltas
Candidate minus control. Timing and allocation triples are separate experiments; row numbers identify the corresponding counterbalanced run within each experiment. Allocation uses decimal KB. All deltas below are negative.
Canonical mixed load: AWS run, lease
cbx_b845487cc57b, fixedc7a.4xlarge, 16 observed CPUs / approximately 31 GiB RAM, Node 26.12.1. Both revisions had independent frozen installs and full builds. Both 30-second smoke windows passed. Frozen base150134610a43deb46ce17ef427184403f711d9c2, measured candidate/toolinga62be43869bd52c7efcdf1e3d2ca6c0a20321c9b; no rebase/source/build changes during comparison.AB and BA, ten measured minutes plus one warmup minute per window: 10,800 synthetic sessions, 65 clients, four concurrent foreground mock-provider turns, 40 enabled plugins and 128 MiB transcripts. Timing only; allocation is covered by the owner benchmark. The controller requires
--pairs 2 --mode timing --minutes 10for both orders, forty measured minutes. Every window completed 40 foreground turns. All 160 Prometheus scrapes were collected; server handler and request-counter deltas agree at 1,173 per window.No earlier-candidate-style mixed-load GC regression was observed: GC time and event-loop p99 were lower in both orders. These are two controlled orders, not an eleven-pair significance claim. Server histogram p90 is bucket-interpolated over the first-to-last scrape interval; CPU/GC/event-loop and turn totals cover the measured window. Parent selection series were absent in all four windows; no reduction is claimed. Parent-selection fan-out remains unproven.
Retained-read correctness: the existing captured read-index contract survives a caller clearing its source Map. CI exposed a defect in the earlier candidate's input-Map lookup; cached child keys now resolve through the existing retained child index. The repair keeps one Map lookup, adds no container or runtime LOC, and extends the existing read-context test with descendant-list coverage. The numerical performance tables above describe their recorded measured revisions, before this repair.
Validation
Final source head:
c7d4c4bc8488bc8e0f3f48eac86df1c053fe75a7, rebased onto38753ff3b97dcd388165b063f32d4788324e2a08. Main's narrower worker-telemetry loader fix (#183579) replaces the PR's superseded generic resolver, test and documentation. All eleven remaining changed files—the six application owner modules, owner benchmark and four test files—are byte-identical to the complete broad-tested checkpoint515af4e5e936123c4aec29c9751043e2ea11f08c.Complete broad-domain proof, reused for that unchanged content: AWS validation run, lease
cbx_b1d9135b50b2,c7a.4xlarge, Node 26.12.1. Full registry: 87 files across six test projects, 1,567 passed / one existing benchmark case skipped (977.21 s wall). Full session-list/selection: 43 files, 333 passed / three skips (235.38 s). Full list/read/active-run methods: 17 files, 132 passed / three skips (160.74 s). The seven skipped cases are six existing opt-in benchmark files; no skip or expected-failure policy changed. These are checkpoint results, not a claim of rerunning all broad suites on the rebased head.Fresh integration proof on the final head: AWS run, lease
cbx_a158264efdab, fixedc7a.4xlarge, 16 observed CPUs / approximately 31 GiB RAM, Node 26.12.1. Independent frozen install and full build passed. Seven affected owner/list files passed 109 tests (108.06 s wall); upstream stress tooling passed six tests (4.05 s).pnpm test src/agents/subagents/registry/subagent-registry-read-context.test.ts --maxWorkers=1passed all five tests (42.44 s). The real isolated Gateway smoke passed with 108 synthetic sessions, 1 MiB transcripts and no warmup, using main's canonical loader. The owner checksum remained 51836 over 8,000 updates and 240 resolution passes, with zero topology rebuilds. Smoke/checksum results are setup/correctness proof, not a new timing comparison.Earlier changed-test wall times (
pnpm test <file> --maxWorkers=1): registry memory 44.55 s, registry queries 45.32 s, navigation lineage 63.74 s. They are earlier pinned-head figures; the fresh affected group and focused retained-read results are reported separately above.pnpm check:changed --base 38753ff3b97dcd388165b063f32d4788324e2a08 --head c7d4c4bc8488bc8e0f3f48eac86df1c053fe75a7 --timedcompleted in 915.37 s without skip flags. Core, all 29 core-test shards and scripts typechecks passed; formatting, lint and every other guard passed. The command exits 1 solely for global unused exports: one script and ten full-tree findings; production exports pass. The same scan on independently installed current maind754f7c3ae79e50de4471c60cfb115665bd9db45also exits 1 with the identical eleven findings, zero candidate-only findings.Inherited unused exports, identical on candidate and main
Fresh detached autoreview of the complete final candidate against its pinned base is clean through P2, with no accepted/actionable findings. Final source verification passed. No source changes followed that review.
Exact-head CI: run 40204128638 is green on
c7d4c4bc8488bc8e0f3f48eac86df1c053fe75a7: 69 successful checks, 54 skipped, one neutral; no failures or pending checks. No CI reruns were used to chase green. An earlier head's retained-source-Map regression was fixed as described above; its authentication diagnostic also passes on the broad-tested checkpoint and final CI.All owned leases have been stopped and provider cleanup is confirmed complete. Production fan-out confirmation remains open; this PR neither changes Gateway selection callers nor deploys to production.