Repository navigation
perf(gateway): reuse ancestor child contributions - #186389
Conversation
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. |
|
🦞👀 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 real behavior proof before merge. What this changesThis PR retains child activity and visibility contributions so ancestor event presentation avoids repeatedly scanning every sibling for every viewer. Example: A parent has 500 children and 20 viewers receiving subagent progress events.
Review scores
ProductKind: Performance · Worth it: Yes · Fix scope: Complete Merge readiness⛔ Blocked before merge - 6 items remain Keep open: this maintainer-authored PR addresses measurable Gateway overhead, but introduces an import cycle, an invalid typed test configuration, and test growth that fails the repository ratchet. Priority: P2 Before merge
Findings
Tests
Agent review detailsHow this fits togetherThe Gateway resident session projection combines stored lineage, registry activity, clocks, and viewer membership into session rows delivered in lists and lifecycle events. flowchart TD
A[Session and membership publications] --> B[Resident session projection]
C[Run registry and scheduler] --> B
B --> D[Child contributions and visibility]
D --> E[Recipient row presentation]
E --> F[Lifecycle event delivery]
Technical reviewBest possible solution: Retain incremental contributions under the existing projection owner, break the display import cycle, and consolidate valid regression coverage within the test budget. Do we have a high-confidence way to reproduce the issue? Current main contains the repeated per-child presentation and membership loops, and the supplied owner measurements quantify their scaling; no target code was executed during this review. Is this the best way to solve the issue? Projection-owned incremental contributions fit the existing ownership model, but the shared child helper must avoid importing a higher-level display dependency that closes a runtime cycle. Full review comments:
Overall correctness: patch is incorrect AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against cc7380924bdb. Merge-risk optionsMaintainer options:
Provenance checked
TestingProof path: in-process harness. SecurityNeeds attention: No concrete disclosure exploit was established, but retained audience decisions need final-delivery revocation evidence. EvidenceSecurity concerns:
What I checked:
PR surfaceSource +908, Tests +323, Other +86. Total +1317 across 21 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 Reviewed October 27, 2026, 7:57 PM ET / 23:57 UTC. |
d8d9aa7 to
6603458
Compare
|
Addressed the findings against the earlier head in The PR body now also includes final-delivery proof from 24 captured synthetic frames. For both event kinds, committing a child’s shared→draft change during the owner’s socket send immediately removes nested/top-level child disclosure and swarm children for both later viewers in that same fan-out. The owner retains access; regrant restores disclosure; a later pre-broadcast revocation hides it again. This uses the real broadcaster, committed accessor writes and resident projection, with valid public viewer policy. Membership revoke/regrant is separately covered at the canonical prepared-policy owner. The temporary proof fixture was restored byte-for-byte; final-head CI continues on unchanged source. |
6603458 to
20f66c7
Compare
* perf(gateway): reuse ancestor child contributions * test(perf): use terminal states in ancestor churn fixture * fix(gateway): keep ancestor projection imports acyclic * test(subagents): accept prepared run identities in assertions
… line caps U9 brought subagent-registry-queries.ts to 698 counted lines (openclaw#186389) and subagent-registry-lifecycle-wake.ts to 700 (openclaw#186443). The fork's additions pushed them to 738 and 703, past the 700 cap. - The continuation-only reads (child-run liveness for orphan reap, requester ancestry) move to subagent-registry-queries.continuation.ts; subagent-registry-read and work-dispatch-execution import them there. - The requester-turn binding folds into upstream's existing window predicate as one ternary: a child bound to the requester turn matches by id, otherwise upstream's window applies. Bounds exist only for a requester run, so the result equals the fork's former filter. - The spawn-custody guard joins upstream's owner early-return; `entry` is computed first and has no side effects, so behaviour is unchanged. RED at 3178f4f: check:line-cap-ratchet, lifecycle-wake 700 -> 703, queries 700 -> 738. GREEN: ratchet bare and --base 8ea3ef8 0 (both files at 700); tsgo:core 0; oxlint clean; queries (incl. requester-window, raw-owner), registry-read, run-liveness, lifecycle-wake retry and work-dispatch suites green. Refs karmaterminal/openclaw-bootstrap#1727
What Problem This Solves
Progress events from one subagent repeatedly checked every sibling for every viewer. A parent with 500 children and 20 viewers performed 10,040 membership reads per event, making busy ancestor broadcasts expensive on the Gateway main thread.
User Impact
Large subagent trees require less main-thread CPU and allocation to publish session events. Recipient-visible rows, wire fields, authorization and timestamp refresh behavior are preserved.
Why This Change Was Made
The resident projection now updates child activity and disclosure contributions from the owning row, registry and membership changes. Descendant counts retain individual contributions across clock views. The event presenter consumes those prepared facts instead of scanning all siblings again.
Current runtime ownership, scheduler reservations, clock expiry and rewinds still invalidate the relevant facts. Private rows keep frame-scoped preparation, and deletion, archive demotion and disposal release retained parent state. The changed-parent refresh from #185954 remains intact.
This replaces the repeated sibling loops rather than adding a parallel presentation path. Production LOC grows because exact incremental disclosure and activity require reverse dependencies, bounded audience state, clock deadlines and explicit lifecycle invalidation; a parent-only cache would violate those contracts. Final LOC accounting is below with the measurements.
Evidence
Acceptance was declared before measurement: membership reads per event independent of 50/150/500 children with 20 distinct viewers, lower main-thread CPU and sampled allocation, and identical normalized payload hashes. The owner harness uses the real lifecycle publisher, resident/prepared rows and recipient delivery planner with synthetic sinks. Timing and allocation are separate, serial AB/BA pairs. Generated ancestor revision IDs are normalized; payload fields are otherwise compared byte-for-byte.
Steady-event measurements compare base
61722900dfe21a411f08325f32943a87571760c9with reviewed candidate8844bbf6ff5f. Subsequent repairs moved the unchanged child calculation and its types to acyclic modules and corrected test/benchmark fixtures. Final head is20f66c7546a78534392f34e7d25009356ba1b4dd, rebased ontob0961419e46b72a7b5e0b5f3fd509b58d1bbfbfc. The supplemental state pass below verifies byte-identical runtime/support/harness files against this final head. Two serial AB/BA pairs, 1,000 events per arm, 20 distinct viewers; separate untraced timing and sampled-allocation passes. All 24 steady-arm payload digests match across revisions. Clock fixed for reproducibility; advancing-clock behavior has a separate regression. CPU usesprocess.threadCpuUsage()on the main thread.Per-arm timing, host load and memory context
Each timing row has 1,000 consume samples. Memory is process RSS / heap used in MiB, before → after; these are snapshots, not retained-heap claims. Load is host 1-minute load before → after. Allocation-pass timings are excluded from latency claims.
Production source delta: +911 lines (benchmark +86 separately; tests net zero). This is deliberately larger than a memo: the new state replaces repeated sibling derivation while preserving live disclosure, subtree runtime ownership, clock-dependent expiry, archive eviction and frame-private rows. No per-tick coalescing is added, because it would change event ordering; unchanged prepared ancestor contributions and recipient rows are reused instead.
Reproduce each owner arm with the header-documented
scripts/perf/session-event-ancestors-measure.tsoptions (--arm candidate --shape wide --sessions 51 --clients 20 --pairs 1 --events 1000, then 151/501 sessions; separate--allocationspasses). The comparison used frozen source overlays from the two revisions.The final counter regression fails on current main
053da3a9bad240aa67482ae11b07dc5fce1e2200at 1,020 / 3,020 / 10,020 reads for prepared parent rows (limit 40). The candidate passes at all three sizes using valid public viewer policy. Canonical prepared invited-filter proof separately covers membership revoke/regrant, exact visible child rows, and stable exclusion keys after equivalent cycles. A separate clock-advance regression caught and now prevents stalesnapshotAtwhen one child finishes while another remains active. Reservation-only queued-grandchild changes and repeated equivalent exclusion states are also covered.Final focused proof: six files / 91 tests passed (registry queries, run liveness, scheduler, event parity, presentation, sharing policy); eager-import and PR-wrapper closure proof passed 32 tests. Earlier focused prepared-read, lineage, projection, archive and retention tests also passed. Scoped format/lint and export-collision checks passed. Core typechecking passed during implementation. Final-head CI passed on
20f66c7546a78534392f34e7d25009356ba1b4dd, including production/test types, architecture, baseline ratchets, selected test shards and built-artifact checks. No baseline or ceiling was raised.Initial CI found import cycles, invalid stored-status and role fixtures, and the added-test-line ratchet. Those are repaired: fixtures use canonical status/policy owners, shared contracts are acyclic, and repeated fixtures/assertions were consolidated without dropping authority cases. The final ratchet passes with zero net test lines despite main exceeding the raw ceiling. A later test-type check caught an over-specific assertion helper input; it now requires only the
runIdfield shared by full and prepared records, without a cast or runtime change.Independent subagent review (autoreview route unavailable) is clean after addressing its findings. The requested autoreview provider failed the helper's configured-route preflight; no configuration was changed.
The isolated Gateway fixture failed its premeasurement census. Under the explicitly approved fast path, this PR uses owner proof and focused tests plus CI; it does not claim whole-Gateway GC, event-loop or RPC latency results. No production load was started.
Supplemental persisted-state churn
Alternates a child’s canonical
done/failedstored state before each publication. Base50bb32ef09475b3f91e30ad0d9ec78a2c213a8e8; candidate runtime/support/harness hashes match final head. Two AB/BA timing pairs, 1,000 events per arm and 20 viewers: 12,000 events / 240,000 measured viewer frames, with matching wire hashes in every pair. Membership work is constant; the full write/refresh pipeline still has other costs that grow with tree size.State-pass per-arm context
Each row has 1,000 latency samples. Memory is RSS / heap used in MiB, before → after; host load is the 1-minute value.
Optional state allocation was omitted under a predeclared compute/CI decision before any allocation pair completed. One already-started baseline arm is diagnostic only. The complete steady allocation comparison above remains the allocation evidence.
Final-delivery authority proof
Supplemental proof on
660345898e8a(runtime bytes unchanged on final head) used the existing real Gateway connection/broadcaster, canonical committed session writes, registry, and three synthetic socket recipients with valid public viewer policy. A temporary extension of the event-parity fixture captured 24 fresh JSON frames and was restored byte-for-byte afterward (one selected test passed). Both nested and top-levelchildSessions, plus swarm children, were checked at final recipient delivery; per-recipient sequence numbers strictly increased.sessions.changedseqsession.messageseqThus warmed disclosure is invalidated before later recipients in the same fan-out. This is public sharing-visibility proof; invited-membership revocation remains separately covered through its canonical prepared-policy owner because public invitation-policy configuration is not activated. No production Gateway or user data was involved.