Repository navigation
perf(gateway): reduce session PR subscription allocation - #179909
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 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. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 2d7bdcb4f8
ℹ️ 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".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
2d7bdcb to
e9b4c3b
Compare
f47f33e to
7efd349
Compare
|
Codex review: needs maintainer review before merge. What this changesThis PR reuses revision-bound session lineage selections, groups notification work under one tracked operation, and adds a Gateway benchmark. Example: Eight Control UI tabs watch 50 session PR targets each while an unrelated session category changes.
Review scores
ProductKind: Performance · Worth it: Yes · Fix scope: Complete Merge readiness✅ Ready for maintainer review Keep open: this PR addresses concrete repeated allocation in a maintainer-directed performance improvement, and current main still performs the redundant selections; no actionable patch defect was found. Priority: P2 Before mergeNone. FindingsNone. Tests
Agent review detailsHow this fits togetherThe Gateway subscription owner consumes session-row notifications, prepares viewer-scoped PR targets from indexed lineage, and delivers authorized snapshots to Control UI clients. flowchart TD
A[Session row notifications] --> B[PR subscription owner]
B --> C[Session row projection]
C --> D[Revision bound child selections]
D --> E[Live viewer checks]
E --> F[Publication receipt reads]
F --> G[Authorized WebSocket snapshots]
Technical reviewBest possible solution: Retain the small revision-bound optimization under the existing projection and subscription owners, preserving live audience checks and native shutdown settlement. Do we have a high-confidence way to reproduce the issue? Current-main traversal selects children again for every reader, and notification handling separately tracks every eligible key; source inspection establishes that repeated work without executing target code. Is this the best way to solve the issue? The patch is a focused solution: it shares only structural candidates using the existing invalidation owner, retains per-reader authorization, and keeps concurrent reconciliation within the existing work lifetime. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against e76b87421a99. Provenance checked
TestingProof path: in-process harness. SecurityNone. EvidenceWhat I checked:
Likely related people:
PR surfaceSource +20, Tests +122, Docs +48, Other +538. Total +728 across 5 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 21, 2026, 5:54 PM ET / 21:54 UTC. |
Reuse structural child selections under the row owner sharing revision while retaining live per-viewer authorization and incognito exclusion. Track each stored-row notification once and preserve concurrent reconciliation and shutdown settlement. Add golden response and revision invalidation coverage plus a real Gateway allocation benchmark with per-subscriber validation and native work settlement.
7efd349 to
f646634
Compare
…9909) Share session PR structural child selections by the row owner's revision while keeping audience checks, incognito exclusion, and ancestor pruning live for every reader. Track each eligible row notification once across its concurrent reconciliations. Add golden/work-count regression coverage and a real Gateway benchmark with native settlement barriers. Corrected swapped pairs reduced allocation per notification by 12.5% with one tab and 37.7% with eight tabs. The lead accepted the full measured tradeoff under decision rule v5.1; the PR retains all pause and latency evidence.
Accepted for landing by the lead under decision rule v5.1 (2026-10-21). All four corrected interleaved/swapped pairs completed without guard interruption. The lead explicitly superseded the earlier v5 rejection and directed reopening and landing this PR. Full measurements, including adverse pause and internal-span results, remain below.
What Problem This Solves
Open Control UI tabs repeatedly select and sort the same session lineage when stored session rows change, creating avoidable allocation while reconciling session pull-request subscriptions.
User Impact
Session pull-request responses and viewer permissions stay unchanged. The Gateway shares structural selection work between readers of the same row revision and uses one async-work tracking operation for each notification.
Why This Change Was Made
The row owner already indexes parent links. This change reuses its structural child selections under its existing sharing revision; it does not cache authorized results. Every reader still performs live audience checks, excludes incognito rows, and prunes inaccessible ancestors. Preparing row state before looking up the revision also handles deferred registry-only parent changes. Selections acquired while a revision advances remain associated with the earlier revision.
The old per-key notification tracking loop is replaced by one tracked concurrent reconciliation. Runtime production grows by 20 lines: revision-bound structural reuse needs a weak map, while preserving per-reader authority prevents sharing the final selected response. The complete non-test delta is +606 lines: +20 Gateway, +538 standalone measurement harness, and +48 benchmark documentation; regression tests add 122 lines. The harness exercises a real Gateway and records per-tab allocation and native settlement. There is no new config, TTL, schema, public API, or dependency.
Evidence
Base:
f28e75c0f721a62b409658032648ef987383206b. Candidate:7efd3492da728a10e0fcd54e25d991b790025934.Real source Gateways on a deterministic 5,000-session / 4,000-retained-run fixture, 50 PR keys/tab, 256 subscribe RPCs and 1,000 category mutations per side. Each side records 2,000 eligible notifications at a 100 ms mutation schedule. Collected allocations are included; allocation sampling interval is 32,768 bytes. MB/GB are decimal.
Each workload uses two concurrent pairs under slot A, interleaved CPUs 96–127, swapping baseline/candidate placement in pair 2. The shared guard uses 2,500 ms and three consecutive failed minute checks, plus unchanged load/Dirty limits. All four corrected completed pairs are included in this decision. Prior-harness diagnostics and guard-interrupted attempts are excluded.
The committed workload is
scripts/perf/session-pr-subscriptions-measure.ts; fixture preparation is documented alongside it inscripts/perf/README.md. Per-side invocation, repeated for--clients 1and--clients 8:The candidate adds
--owner-suffix candidateto load the two hash-verified owner files beside the unchanged baseline owners. Pair 1 baseline uses 96,98,…,126 and candidate uses 97,99,…,127; pair 2 reverses them. Each pair holds.quiet.lock. Each side uses a systemd scope with CPUWeight=10, IOWeight=10, MemoryMax=12G, nice 19 and idle I/O. Preparation runs sequentially on CPUs 0–63. Corrected harness SHA-256:6618c29cee747300ddc19c4bca74e036cfbeefe9373a29dcd2df55c9e30bb218.Deltas are (candidate / baseline − 1) × 100. Decision is the mean of the two percentage deltas, not the ratio of aggregate metrics. Reject at ≥20% adverse mean, or ≥10% adverse in both pairs. P95 requires ≥200 samples/side and p99 ≥1,000. Major GC needs ≥50 collections/side; below that it is context and total GC carries the gate.
Decision rule v5.1 and lead acceptance
The updated rule is: per-pause minor-GC p95 is context, not a gate, when collection count fell at least 20% and total GC time did not rise. The lead explicitly declared this PR PASS and directed landing it under v5.1. This records that overall decision; the remaining sample-qualified adverse diagnostics below are preserved without relabeling their measured direction.
In the eight-tab pairs, minor collections fell 1,907→1,148 (−39.80%) and 1,821→1,167 (−35.91%). Total GC time fell in both pairs, with a −31.09% mean paired delta; promotion fell 50.44% and allocation per notification fell 37.67%. The full minor-GC p95 evidence remains in the table as context under v5.1. The one-tab pairs also meet the exception: minor collections fell 334→252 and 344→252, and total GC time fell in both pairs.
For accuracy, the recorded eight-tab candidate maximum minor-GC pause in pair 2 was 103.497 ms (n=1,167). The summary claim that all maximum pauses were below 50 ms does not hold. The updated minor-GC p95 rule uses collection-count reduction and total GC time; no measured values have been removed or changed for this acceptance.
Eight tabs
All four native barriers on every side report exactly one scope and zero pending work; baseline/candidate initial/final snapshots match. Source labels, owner hashes, CPU affinity, sample counts, and successful non-interrupted outcomes were verified directly against the captured results.
Lead decision: PASS under v5.1. Minor-GC p95 is context under the updated rule; all other measured cells remain visible as part of the lead-approved result.
Capture durations (baseline/candidate ms): pair 1: 99971.611/99949.745; pair 2: 99962.803/99945.160.
One tab
All four native barriers on every side report exactly one scope and zero pending work; baseline/candidate initial/final snapshots match. Source labels, owner hashes, CPU affinity, sample counts, and successful non-interrupted outcomes were verified directly against the captured results.
Lead decision: PASS under v5.1. Minor-GC p95 is context under the updated rule; all other measured cells remain visible as part of the lead-approved result.
Capture durations (baseline/candidate ms): pair 1: 99919.834/99916.670; pair 2: 99921.083/99921.522.
Incremental subscriber estimate
The mean 8-tab cost minus the mean 1-tab cost, divided by seven added tabs, gives the incremental allocation estimate. This is distinct from dividing the total eight-tab cost by eight.
Incremental allocation per notification per added tab: 3.424 → 1.974 MB (-42.35%). This cross-workload scaling estimate is context; the paired comparisons above use concurrent baseline/candidate runs within each workload.
Additional native diagnostics retained with lead acceptance
These internal spans are distinct from the controller RPC round trips above. All values are milliseconds. The complete diagnostic audit also evaluated low-count means/maxima and below-threshold changes; the earlier v5 threshold crossings remain recorded, while the lead’s explicit v5.1 PASS decision governs landing.
Correctness and CI proof
The current PR head is
f646634e1b77fc78b26bd1e48f42d0069fa3ff3c, rebased ontoce009c218d71084796395b9f83d7ee289b3b0f7dto resolve a README insertion conflict. Both benchmark documentation sections were preserved. Production files, tests, and the harness are byte-identical to the measured/reviewed head7efd3492da728a10e0fcd54e25d991b790025934; range-diff changes only README hunk context. README formatting and diff checks passed. Exact-head CI run 39684243661 completed successfully after this required rebase: all 64 jobs completed, with no failures.The work-count regression fails on unchanged production (11 child selections versus 4 after sharing). The candidate passed 87 focused tests with 1 existing skip across task PR selection, PR access, subscriptions, and subscription lifetimes. Golden responses cover separate viewers, personal receipts, incognito exclusion, and revocation; the selection regression covers reparenting and registry-only invalidation. All four corrected benchmark pairs preserve every requested snapshot and report zero pending work at all four native barriers.
Changed-file formatting and lint, the native core typecheck, the export-name collision guard, and 22 import-closure tests passed. The 41 subscription/lifetime tests passed again after preserving the no-work case for ineligible audiences. Independent reviews of the implementation and both benchmark repairs are clean through P2.
Pre-rebase PR CI run 39680500303 completed successfully on
7efd3492da728a10e0fcd54e25d991b790025934, includingopenclaw/ci-gate. CI previously caught a benchmark-only connection-error overload, which was fixed. The GitHub review finding about subscription acknowledgements preceding reconciliation was also fixed and resolved: native idle barriers now drain warm-up and timed-subscription work before profiling. Earlier interrupted and prior-harness attempts are excluded; all four completed corrected pairs are included. No CI reruns or additional benchmark runs were used to erase an adverse result.Limits and live signal
The supplied production profile attributed about 370 MB in 30 seconds, approximately 8.4% of main-isolate allocation, to this family before the change. This concentrated synthetic workload attributes roughly 96.7% of baseline main allocation to the family; its savings cannot be extrapolated to the whole production Gateway.
Notification latency above is the mutation RPC round trip, not each asynchronous listener's completion. Native settlement proves completion of the subscription work, but does not provide per-listener latency. The fixture omits transcript payloads and unrelated projects, cron, and approvals. Major GC remains context-only because every side has fewer than 50 collections; under-sampled percentiles are marked explicitly. No production Gateway was load-tested or deployed. The live share after deployment remains unmeasured.
The initial partial metric summary omitted GC pause percentiles, and the complete v5 audit led to closure. The lead subsequently accepted this PR under v5.1 and explicitly directed reopening and landing it. Which part of the structural-sharing/tracking change causes the longer individual pauses has not been isolated; the complete measured tradeoff remains documented above.