Repository navigation
perf(gateway): batch running-candidate row selections - #185148
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 changes before merge. What this changesThis PR batches running-candidate lookups through the existing session-row selector and attributes diagnostic selections to work metrics. Example: A session list has eight distinct running-candidate identities.
Review scores
ProductKind: Performance · Worth it: Yes · Fix scope: Complete Merge readiness⛔ Needs changes before merge - 1 item remains Keep this maintainer-authored experiment open and unmerged as requested; the new benchmark needs correction before it can evaluate the batching change. Priority: P2 Before merge
Findings
Tests
Agent review detailsHow this fits togetherGateway session lists and diagnostic publishers consume live activity identities, resolve resident session rows, and apply existing federation and visibility policies before producing results. flowchart LR
A[Live activity owners] --> B[Candidate identities]
B --> C[Session row selector]
C --> D[Physical competitors]
D --> E[Federation and visibility]
E --> F[Session lists and metrics]
Technical reviewBest possible solution: Retain the existing selector owner and correct the replay fixture to exercise multiple candidate identities before judging the experiment. Do we have a high-confidence way to reproduce the issue? Current-main source establishes repeated per-identity selections, and the benchmark's missing context and shared requester establish its qualification defect without executing target code. Is this the best way to solve the issue? Batching at the existing row owner is a focused approach that preserves competitor expansion and removes the superseded loops, but the supplied replay cannot establish its intended benefit. Full review comments:
Overall correctness: patch is incorrect AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 31bd47773b7c. Provenance checked
TestingProof path: none. SecurityNone. EvidenceAcceptance criteria:
What I checked:
Likely related people:
PR surfaceSource +5, Tests +9, Other +25. Total +39 across 9 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 26, 2026, 7:28 PM ET / 23:28 UTC. |
29b16b3 to
44f8ba7
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. |
44f8ba7 to
bb464ce
Compare
…#185148) Team r233b counted ~5,608/min running-candidate selections with task="other" plus ~1,640/min (about 8 per list) from sessions.list: the list owner resolved running candidates by issuing one exact selection per candidate session id or key (handed over from the memory session's ownerRunningCandidateKeys trace). The row selector now accepts the candidate identity set in one query (candidateSessionIdsOrKeys) and resolves all of them in a single selection pass; an empty candidate set short-circuits. The work-metrics refresh runs under a named main-thread task so it no longer counts as "other". Measured on the Team-shaped replay (11 pairs, AWS c7a.4xlarge, prior head; this head is a rebase only): running-candidate selections per list 4 -> 0.94 (-76.6%, 11/11), per minute 842.65 -> 171.24 (-79.7%); list CPU flat. 53 tests including a baseline regression that fails on main; 320 equivalence comparisons; exact-head CI green; autoreview clean through P2. Runtime +5 LOC.
What Problem This Solves
The cold-load campaign recorded a 14-state reload sequence for a signed-in dashboard deep link. This change targets repeated server-side row selections feeding session lists and running/attention presentation.
A sampled operator workload averaged roughly eight
running-candidateselections per list. These selections came from looping over candidate identities, including IDs/keys resolving to the same logical session. BothownerRunningCandidateKeysand active-only list preparation entered the selection owner separately for each identity. Fan-out follows the candidate identity set, rather than the partition or owner count. Readiness awaits can legitimately require another fresh selection, so the batch boundary is one synchronous prepared read.Why This Change Was Made
Pass the complete candidate set to the existing row selector. Resolve IDs/keys together, union logical keys before gathering physical competitors, and prepare/acquire once. Preserve federation precedence, visibility, and active-run presentation through their existing owners. Empty candidate sets require no selection.
Delete both superseded per-identity loops and the separate metric-kind argument. Add the bounded
work-metricstask label for the diagnostic work publisher.No retained running-candidate cache is introduced. Restart/recovery and terminal-outcome precedence remain with the existing run-state owners. No schema, configuration, protocol, or stored-shape changes are needed.
User Impact
Reduce repeated selection work while producing the same session-list and running/attention data. The measured primary is selection work; no first-paint timing improvement is claimed.
Evidence
AWS Crabbox
cbx_a241bb66b927, fixedc7a.4xlarge, Node 26.12.1. Baselinece069f9f837471069b3a35df1e7c05953ea792ab; candidate44f8ba7053afcb7ee1c1566f31c16b0c0e9324df. Both revisions installed with the frozen lockfile and fully built before measuring, with no later rebase. All data is synthetic.Owner replay: 11 interleaved pairs
10,800 sessions, independent live parent sessions, 352 measured lists after 48 warmup lists, 33 run-state updates per list. Odd pairs baseline/candidate; even pairs candidate/baseline. Values are median [Q1, Q3]:
Selection work falls 76.56%, better in 11/11 pairs, passing the predeclared ≥50% / ≥9-of-11 gate. Whole-list CPU passes the campaign's secondary no-regression gate (median change +0.22%); paired CPU median delta is -0.007679 ms/list. CPU improves in 6/11 pairs; the full distribution and all signed deltas are shown here. Every pair has identical initial/final response fingerprints. Separate verify-mode responses also match, including running-owner totals checked against independent live-parent fixture facts.
Real Gateway: one ten-minute pair
team-shape-stress.ts --mode timing --minutes 10 --pairs 1, baseline then candidate on the same instance, 10,800 sessions and 65 clients. Counter deltas use the first/last Prometheus scrape and normalize against server list completions in that same window. Running-candidate totals sum all task labels, including the background publisher; normalization by list completions does not imply all calls occurred inside the list handler.The steady-state primary falls 79.68%. Both runs have zero RPC errors and zero stalls. Secondary results from this single macro pair are directional and inconclusive under the paired/IQR rule. Worker-heap samples contain different live worker counts. These results do not establish a broad CPU or memory improvement. List p99 is interpreted with the harness's documented ±120 ms A/A noise. Whole-list thread CPU is measured in the owner replay; a
sessions.liststage-CPU metric is not exported by this harness.Scrape windows: 594.622s / 594.613s, with 1173 / 1173 server list completions.
othersessions.listwork-metricsSeparate temporary stack attribution on baseline
4c2a27148307b98006e3a7276b0d79c6b5a8c50dfound 816/816 unattributed calls inserver-work-metricsactive-only preparation; two namedsessions.listcalls came through the owner-count facet. Those caller modules are unchanged between that attribution baseline and this baseline. The current timed candidate exposeswork-metrics, and the all-label totals above ensure relabeling cannot count as savings.Behavior and checks
The randomized equivalence pass compared 320 batched reads with independently recomputed scalar unions through the real row owner across 3371 starts, 3322 finishes, 3339 aborts, and 17 projection recreations with cleared live claims. It uses the canonical terminal-outcome builder. This tests the batched selection cutover; no incremental run-state cache or new recovery owner exists.
The counter regression fails on the baseline and passes on the candidate. Existing full-RPC owner/visibility/delegation and active-list tests pass. Each focused file ran separately with
pnpm test <file> --maxWorkers=1; command wall times include startup:sessions-read-owner-counts.test.tssession-row-selection.test.tsserver-work-metrics.test.tssessions-read-active.test.tsteam-shape-stress.test.tsnode scripts/check-changed.mjspassed on the pinned candidate.Detached Codex autoreview is clean through P2, including the rebased proposal and final benchmark change.
Prior-head CI passed: run 40444372417, exact head
44f8ba7053afcb7ee1c1566f31c16b0c0e9324df. Broad CI on the integrated draft head has not run; draft checks skip those jobs.Production LOC
Production diff with the campaign exclusions: +92 / −37 = +55 lines on the current integrated head, comprising +5 runtime and +50 benchmark lines. Runtime growth adds the internal batch query contract and bounded diagnostic task label while deleting both per-identity execution paths and the separate metric-kind argument. Test/support changes are excluded from that count.