Repository navigation
perf(gateway): reuse prepared session list ordering facts - #179211
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. |
9dced46 to
aef5629
Compare
aef5629 to
ef2cf50
Compare
|
Codex review: needs maintainer review before merge. What this changesThis PR prepares session ordering facts once per row revision and removes temporary sharing-authorization wrappers. Example: List 200 sessions from a 5,000-session inventory sorted by activity.
Review scores
ProductKind: Performance · Worth it: Yes · Fix scope: Complete Merge readiness✅ Ready for maintainer review Keep this PR open: it is a distinct, maintainer-directed optimization, and source review found no actionable correctness defect. Priority: P2 Before mergeNone. FindingsNone. Tests
Agent review detailsHow this fits togetherThe Gateway resident session projection receives committed session metadata and supplies ordered, filtered, viewer-authorized rows to session-list requests and related consumers. flowchart LR
A[Committed session metadata] --> B[Resident row projection]
B --> C[Prepared selection facts]
C --> D[Ordering and filters]
E[Current viewer authority] --> F[Sharing policy]
D --> F
F --> G[Session list response]
Technical reviewBest possible solution: Keep revision-bound ordering facts in the existing row owner and retain the current synchronous sharing boundary. Do we have a high-confidence way to reproduce the issue? Current-main source directly shows repeated pin and activity derivation during sorting, and the supplied owner measurements quantify that work; no target code was executed during this read-only review. Is this the best way to solve the issue? The patch follows the smallest complete approach: prepare facts at the existing revision owner, carry them through consumers, and remove comparator and authorization-wrapper allocation without introducing another cache. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against e3fbdbc7e238. Provenance checked
TestingProof path: in-process harness. SecurityNone. EvidenceWhat I checked:
Likely related people:
PR surfaceSource +24, Tests +25, Docs +24, Other +162. Total +235 across 19 files. Added test files: 0. View PR surface stats
Review metrics
LabelsLabel changes:
Label justifications:
Rank-up movesOptional improvements that raise the rating; they are not merge blockers.
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, 6:01 AM ET / 10:01 UTC. |
ef2cf50 to
566c11e
Compare
Keep sort and pin facts with the revision-bound row selection snapshot, compare those facts without temporary tuples, and pass prepared sharing authorization inputs directly. Preserve canonical aliases and viewer-specific disclosure. Add reproducible owner measurements and fixed-fixture list response capture.
566c11e to
6b95f35
Compare
|
@clawsweeper re-review The declared proof is complete and the PR body is current. All 20 golden requests match after the documented envelope-only normalization. Both swapped concurrent pairs completed on their first attempts with 100,000 list RPCs per side, valid percentile counts, and verified main-isolate GC traces. The v5 decision passes: mean sampled allocation −1.722%; promotion +10.053%; total GC +3.355%; sessions.list p99 +2.153%; event-loop p99 +1.573%. The higher promotion and GC costs are stated explicitly. Exact-head CI and code review are clean. |
|
🦞👀 Re-review progress:
|
Revert the ordering facts and sharing-wrapper changes from 2e36582 while preserving #179796 profile-reference handling and #180067 archive filtering. Retain the pin/sidebar-root behavior regression and reusable measurement support. The owner comparator gain did not produce the required per-request production gain. Gateway pairs were flat (+10% promotion, +1.6% CPU/RPC), and the change added 24 runtime lines. Production profiles include other commits, so the next production profile must establish the effect of this revert.
Revert 6cb819f (#180067) on top of the #179211 revert, preserving #179796 and later unrelated fixes. Restore archive-prefiltered ordering views and their callers. Production r182 made filterSessionEntries the top OpenClaw self frame: 233 to 1751 samples, inclusive selectSessionEntries samples/rpm 8.27 to 25.2, and main-thread busy 37% to 57% despite lower traffic. All 108 golden cases remain identical to the historical owner path.
…179211 and #180067 (#180166) * revert(gateway): restore sessions.list ordering before #179211 Revert the ordering facts and sharing-wrapper changes from 2e36582 while preserving #179796 profile-reference handling and #180067 archive filtering. Retain the pin/sidebar-root behavior regression and reusable measurement support. The owner comparator gain did not produce the required per-request production gain. Gateway pairs were flat (+10% promotion, +1.6% CPU/RPC), and the change added 24 runtime lines. Production profiles include other commits, so the next production profile must establish the effect of this revert. * revert(gateway): restore archive-specific session list filtering Revert 6cb819f (#180067) on top of the #179211 revert, preserving #179796 and later unrelated fixes. Restore archive-prefiltered ordering views and their callers. Production r182 made filterSessionEntries the top OpenClaw self frame: 233 to 1751 samples, inclusive selectSessionEntries samples/rpm 8.27 to 25.2, and main-thread busy 37% to 57% despite lower traffic. All 108 golden cases remain identical to the historical owner path. * chore(perf): remove retired session ordering benchmark registration
…79211) * perf(gateway): reuse prepared session list ordering facts Keep sort and pin facts with the revision-bound row selection snapshot, compare those facts without temporary tuples, and pass prepared sharing authorization inputs directly. Preserve canonical aliases and viewer-specific disclosure. Add reproducible owner measurements and fixed-fixture list response capture. * test(ui): carry prepared session sort facts in the shared fixture * refactor(gateway): narrow the session ordering type dependency * perf(sessions): support uninterrupted RPC allocation samples * fix(perf): allow unprofiled session list captures
…penclaw#179211 and openclaw#180067 (openclaw#180166) * revert(gateway): restore sessions.list ordering before openclaw#179211 Revert the ordering facts and sharing-wrapper changes from e3c341e while preserving openclaw#179796 profile-reference handling and openclaw#180067 archive filtering. Retain the pin/sidebar-root behavior regression and reusable measurement support. The owner comparator gain did not produce the required per-request production gain. Gateway pairs were flat (+10% promotion, +1.6% CPU/RPC), and the change added 24 runtime lines. Production profiles include other commits, so the next production profile must establish the effect of this revert. * revert(gateway): restore archive-specific session list filtering Revert f46e5d9 (openclaw#180067) on top of the openclaw#179211 revert, preserving openclaw#179796 and later unrelated fixes. Restore archive-prefiltered ordering views and their callers. Production r182 made filterSessionEntries the top OpenClaw self frame: 233 to 1751 samples, inclusive selectSessionEntries samples/rpm 8.27 to 25.2, and main-thread busy 37% to 57% despite lower traffic. All 108 golden cases remain identical to the historical owner path. * chore(perf): remove retired session ordering benchmark registration
What Problem This Solves
Large
sessions.listinventories repeatedly derive the same pin and activity facts while sorting and filtering, and sharing checks allocate two wrapper objects for each selected row.User Impact
Session lists do less repeated work while preserving ordering, pagination, filters, aliases, and viewer-specific disclosure. No configuration, schema, or protocol changes are required.
Why This Change Was Made
The resident row projection already owns revision-bound selection facts, bounded top-k selection, and ordered views maintained on writes. This change adds readonly sort facts to that existing snapshot, carries it through selection, and compares it directly. It removes per-comparison tuple allocation and repeated pin/key normalization and activity calculation. Sharing authorization consumes the role and capability resolved in the same synchronous frame, avoiding per-row parameter spreads; live profile and source-authority checks remain intact.
The alias lookup fallback remains because it serves a real alias contract. Request-bound sharing/profile preparation also remains: it revalidates the requester and operator authority after asynchronous preparation and before synchronous consumption. This change does not introduce cross-request sharing-policy reuse or change the fallback profile/alias snapshot lifetime. There is no new ordering cache or cross-viewer authorization cache. The small runtime LOC increase is the readonly tuple/caller contract and four prepared scalar facts needed to preserve all three sorts and canonical pin eligibility across revision changes. Measurement includes that preparation cost.
Evidence
Current head
6b95f3571458cf858a8608264bd8dfc25519fac4is rebased onto main41b9f21f382010852c4d564c8b5902e7ff614707. The original four changes remain patch-equivalent; a reviewed harness-only follow-up permitssessions.list --capture-responseswithout allocation or CPU profiling. This avoids repeating the already-collected attribution profile when retrying a golden capture. Changed-file formatting and lint pass, and the follow-up review is scoped-clean. Current-head CI is fully green: run 39633857638 succeeded, and the exact-head rollup has all required checks passing. The refreshed Gateway acceptance measurements are complete and pass the declared v5 rule.Historical exact-head PR CI run 39591225531 passed all 84 jobs on
566c11e8; its combined CI/security publisher run 39592258789 passed too. Those results are retained as prior-head evidence, not current-head success.Measurement sources are pinned to baseline
41b9f21f382010852c4d564c8b5902e7ff614707and candidate6b95f3571458cf858a8608264bd8dfc25519fac4, with identical committed measurement support on both. Source hashes and dependency versions were verified; the changed acpx setup closure was rebuilt once and staged identically. Retained synthetic fixtures were brought to current config and credential readiness through the existing owners before capture. All four fixtures pass current config validation and credential readiness. Preparation stayed sequential and within the sandbox.The strict golden comparison passed for all 20 representative list requests, with 100 RPCs completed on each revision. Both normalized response sets have SHA-256
59a854f2964ffcf84d4c3d2a4f6a22f92a093c0ad4cd6720b83c0f0e0a7fe4a4. Only the documented top-levelts, process-localrowsRevision, and exact fixture-root prefix are excluded; row clocks, IDs, order, filters, and payload fields remain unchanged. The successful baseline capture was retained across candidate setup recovery, and both result files identify the expected exact revisions. The candidate's single attribution CPU-profile pass is complete. The earlier baseline CPU profile remains historical attribution only and is not used for a current-head timing claim. Both concurrent landing pairs completed successfully on their first attempts.Reset accounting is a precondition for interpreting promotion/GC: compare completed work and reset boundaries on both sides, discard mismatches unless a common aligned window can be recovered. For this
sessions.listworkload,sessionResetsis omitted from JSON because it is a memory-soak-only field. Each side performs two setup reset RPCs (parent plus one child) before warmup; the measured list branch bypasses turn cohorts and performs zero measured resets. The result checker requires one measured sample and 100,000 completed list RPCs per side, 25,000 warmup operations, zero measured streams/turns, and no other measured RPC methods. Actual per-side counts are recorded below; both pairs passed this comparability check.Acceptance: identical selected keys and normalized JSON payloads for 20 representative requests; exactly two concurrent combined allocation/GC/diagnostic A/B pairs with 16 CPUs per side, swapping interleaved CPU sets under the shared
acquire-slot.shadmission helper (slot B: evens 64–94 / odds 65–95; slot A: evens 96–126 / odds 97–127). Record the actual slot per pair; a pair stays within one slot, while the two pairs may use different slots; target two minutes warmup and eight minutes measurement per side (equivalent operation count for sessions.list); gate on main-isolate trace promotion MB/RPC, total GC seconds/minute (minor + major), event-loop tail, and sessions.list RPC tail under the lead's final v5 rule (2026-10-21). For each gated metric, use the mean of the two paired percentage deltas,100 × (B − A) / A. Stop if that mean is adverse by at least 20%, or the same metric is adverse by at least 10% in both pairs. p99 requires at least 1,000 samples per side; otherwise use p95 with at least 200 per side and report p99 as context. Insufficient samples or missing percentiles require more workload; they never pass by omission. Per-side percentile counts and major-GC collection counts appear below. Separate major GC with fewer than 50 collections is context; total GC carries the gate. CPU, p50, minor/major GC, and sampled allocation remain reported context. This list-only workload has no turn cohorts or other measured RPCs. Passing also requires lower mean allocation or promotion because the runtime change is not a net deletion. Heap samples include collected objects. The 100-RPC golden capture uses a deterministic list/filter/projection clock through a fixture-only loader at the existing read-clock sites, and supplies the candidate's single CPU-profile pass under its acquired guarded slot; baseline capture omits profiling because its one attribution pass is already retained as historical context. Lifecycle, worker, and authority clocks remain real. That profile is for attribution only; all timed landing runs use the ordinary uninstrumented entry point and real time. Preparation is sequential on CPUs 0–63; CPU and I/O weights are 10, memory is capped at 64 GiB, and the shared production guard may abort a pair. Owner microbenchmarks run interleaved A/B without the quiet lock.The decision uses the mean of swapped pairs because of SMT placement bias. On this host logical CPU N and N+64 share a physical core; contiguous halves exposed each side to different sibling-block load. The lead’s 2026-10-21 SMT addendum reports sign reversals in four of five decided comparisons (lanes 1541, 1544, 1548, and 1535). Interleaved placement distributes sibling-block load, and the swapped-pair mean cancels residual placement bias. No landing pair in this lane ran before that addendum. The later either-slot addendum preserves interleaving and v5. The driver checks the shared deployment blackout schedule before queueing, after acquisition and after guard admission, reserving 10 minutes for the golden phase and 20 minutes for a pair. No runs are allowed during 2026-10-21 12:35–13:00Z or 13:55–14:55Z; the shared guard remains active throughout each run.
Completed Gateway measurements
Baseline
41b9f21f382010852c4d564c8b5902e7ff614707; candidate6b95f3571458cf858a8608264bd8dfc25519fac4. Both pairs used slot B: pair 1 baseline even / candidate odd CPUs, pair 2 swapped. Both completed on their first attempts with guard success and all four processes exiting 0. The raw heap totals, main-isolate trace windows, and all 38 evidence-manifest file hashes were independently verified. Figures use decimal MB.Decision: passes v5 with a 1.722% mean sampled-allocation reduction. Promotion rises 10.053% on the paired mean (3.680% and 16.427% individually); this is below the 20% mean stop and is not at least 10% in both pairs. The other gated means are also below the declared thresholds. This is not a promotion, GC, CPU, or latency win. The allocation reduction supplies the required measured win for the +24-line runtime change; no net-simplification exception is used.
All gated p99 values have at least 1,000 samples per side. Major GC alone is context: pair 2 baseline has only 44 major collections, and its large separate-major percentage change is not used as a stop under v5. Total GC remains gated.
sessionResetsandcompletedTurnsare not emitted by this list-only scenario; zero measured resets/turns is source-derived and corroborated by the measured RPC map and zero stream/tool counts, rather than an invented JSON field. Both sides have one uninterrupted measured round. The operation-count equivalent ran for 352.925/358.478 seconds in pair 1 and 399.075/400.351 seconds in pair 2. Across these two windows, allocation median / window-p95 is 2.537795 / 2.539362 MB/RPC before and 2.494092 / 2.500140 after; with only two windows that window-p95 is the maximum, not a population-tail estimate. Client RPC p99 above is based on 100,000 samples per window.Reproduction per side:
node --import ./scripts/tsx.mjs scripts/perf/transcript-broadcast-measure.ts --entry src/entry.ts --state-dir <isolated-fixture> --port <owned-port> --mock-port <owned-mock-port> --clients 1 --runs 1 --operations 100000 --warmup-operations 25000 --rounds 1 --heap-sampling-interval 524288 --scenario sessions.list --row-mode sidebar --limit 200 --capture-responses --start-at <shared-epoch-ms> --revision <exact-sha> --allocations --trace-gc --diagnostics, within the declared guarded per-side resource envelope. No additional CPU profiles were run for these pairs.The measured response size is 180,016 versus 180,021 bytes because the isolated candidate fixture-root spelling is five bytes longer. The fixed-clock 20-request golden removes only that exact top-level root prefix and the declared process-local envelope fields, and matches byte for byte.
Owner probe: 5,000 mixed rows, top 200, all three sorts; five interleaved A/B process pairs, five samples per process (25 per revision). The owner batches ran on CPUs 64–95 before the slot-B addendum; subsequent prep first used CPUs 32–63 under the earlier rule; all further prep uses CPUs 0–63 under the SMT rule. Values below are medians/p95 of the five batch medians; percentage changes are paired batch changes. Base
a6f48263b7129212127a9876938c158208a25152.The selected 200 keys are byte-identical for every sort. Cold preparation does more work once per revision; the table reports that cost explicitly. A sum of separately measured preparation and one-sort batch medians is 4.72→5.04 ms and 6.22→6.59 MB for 5,000 rows (+6.81% paired CPU, +5.73% allocation). This is an estimate, not a directly measured cold RPC. Reuse across three sorts amortizes CPU but still adds about 2.86% cold allocation; Gateway promotion/GC gates remain mandatory. A count-only Gateway pass confirms warm cached lists perform zero comparisons on both revisions, with 1,807.35 versus 1,806 key-normalization calls/RPC. Warm Gateway results therefore measure the sharing/allocation portion, not the sorting speedup. All five interleaved owner process pairs selected byte-identical keys. The 20-request golden comparison and both concurrent Gateway pairs passed their declared acceptance checks.
Focused proof: 166 behavior/consumer tests passed across selection, sharing, filters, search, snooze, session-ID resolution, resident resolution, TUI consumers, and the shared Control UI fixture. They cover pin eligibility after child/root transitions, archive rematerialization, sentinel ties, fresh profile aliases, and mutation authority. The profiling helper passes all 9 tests; two import-closure guard files pass 22 tests. The export-name collision guard, changed-file oxfmt, and scoped lint passed. Independent reviews of the runtime change, consumer/type cutover, and measurement support returned scoped-clean. Pre-rebase PR CI passed behavior, UI/e2e, production types, lint, architecture, source contracts, and security-fast; the inherited tooling type failure from that head is documented below. No Testbox/Crabbox lease or broad local validation was used.
Reproduce with the committed
scripts/perf/session-list-order-measure.ts(and separate--count-workpass) andscripts/perf/transcript-broadcast-measure.ts --scenario sessions.list --row-mode sidebar --limit 200 --allocations --capture-responsesagainst identical synthetic team-shape fixtures. Golden normalization is restricted to top-levelts, the process-local randomrowsRevisiontoken, and the exact isolated fixture-root prefix in top-levelpath; row identities, clocks, ordering, filters, and payload fields remain unchanged.The team-shape fixture disables plugins. This change measures the sessions.list row pipeline and makes no plugin invocation, hook, tool, API, or reload performance claim. The two concurrent Gateway pairs are complete. This is a modest sampled-allocation win with higher promotion and slightly higher GC/latency, within the explicitly declared v5 thresholds; no latency or promotion improvement is claimed.
Core runtime delta: +24 lines (112 added, 88 removed). The existing revision snapshot gains four readonly scalar facts, and readonly triples carry them through existing owners; no extra cache or invalidation system was introduced. The requested whole-change filter (
git diff --stat origin/main...HEAD -- ':!*.test.ts' ':!*test-support*' ':!docs/*') totals +214 lines (333 added, 119 removed), including the committed owner benchmark, measurement support, its README, and the shared UI synthetic fixture. That proof machinery accounts for the additional growth outside the runtime cutover.Measurement support: sessions.list response-only capture can omit profiling, while other RPC scenarios retain their profiling admission requirement. RPC warmup can use a smaller request count than the measured round, and the existing heap profiler accepts a sampling-interval override. This permits one uninterrupted eight-minute-class round at 512 KiB sampling; stopping multiple short samples would force GC between them and distort the promotion/GC gate. Existing defaults are unchanged. The focused profiling helper test file passes all 9 tests and the support change received an independent scoped-clean review.
CI history: the earlier head
ef2cf502had an inherited tooling-type error inci-changed-node-test-plan.test.ts(identical diagnostics on its exact main base, runs 39563876151 and 39563487228), plus GitHub installation API rate limits in analysis/upload jobs. Those remain historical failed results; they are not labeled successful scans. The required integration of landed presentation changes prompted the rebase. Current-head CI run 39633857638 completed successfully; the live rollup for6b95f3571458cf858a8608264bd8dfc25519fac4has all required checks passing. No CI rerun or update-branch was used to chase green.