Skip to content

perf(gateway): batch running-candidate row selections - #185148

Merged
steipete merged 3 commits into
mainfrom
steipete/coldload-running-candidate-selections
Oct 27, 2026
Merged

steipete merged 3 commits into
mainfrom
steipete/coldload-running-candidate-selections

Conversation

@steipete

@steipete steipete commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

Draft: final integration proof blocked by AWS capacity. Current head bb464ce456d6badca01ee1e2751a775c07980c28, base 5856b6ba3e512a9ffb4dcd151a941414011ccf26. It preserves the newly landed partition and collector-presentation benchmark changes. Detached review of the complete integrated branch is clean through P2. The complete performance/test results below belong to the explicitly named prior head, not the integrated head.

The requested AWS c7a.4xlarge allocation was rejected for quota; Crabbox substituted t3.small on lease cbx_653dbbcc0324. The lease was stopped before checkout or tests; no measurements from that instance are used. Required remaining proof: focused integration/type/lint checks, collector-mode smoke, randomized equivalence, 11 interleaved replay pairs and the ten-minute-per-revision Gateway harness on one fixed c7a.4xlarge, then ready-state exact-head CI. No merge is authorized.

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-candidate selections per list. These selections came from looping over candidate identities, including IDs/keys resolving to the same logical session. Both ownerRunningCandidateKeys and 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-metrics task 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, fixed c7a.4xlarge, Node 26.12.1. Baseline ce069f9f837471069b3a35df1e7c05953ea792ab; candidate 44f8ba7053afcb7ee1c1566f31c16b0c0e9324df. 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]:

Metric Baseline Candidate
Running-candidate selections/list 4.0000 [4.0000, 4.0000] 0.9375 [0.9375, 0.9375]
Whole-list thread CPU, ms/list 2.2358 [2.2191, 2.2581] 2.2408 [2.2318, 2.2518]

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.

Pair Selection delta/list Whole-list CPU delta, ms/list
1 -3.0625 +0.042088
2 -3.0625 -0.036659
3 -3.0625 -0.026031
4 -3.0625 +0.015293
5 -3.0625 +0.004977
6 -3.0625 -0.023815
7 -3.0625 +0.026065
8 -3.0625 +0.054116
9 -3.0625 -0.007679
10 -3.0625 -0.030761
11 -3.0625 -0.071634

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.

Metric Baseline Candidate Paired delta
Running-candidate selections/min 842.653 171.237 -671.416
All running-candidate selections / completed list 7.1194 1.4467 -5.6726
List-handler mean, ms 13.060 13.072 +0.012
Partition-cache hits/list 13.0742 13.0759 +0.0017
Partition-cache misses/list 14.0972 14.2592 +0.1620
Main thread CPU, % 9.781 9.418 -0.363
GC, seconds/min 0.2534 0.1975 -0.0559
Event-loop p99, ms 33.489 34.046 +0.557
List p99, ms 50.031 43.410 -6.621
Native post-GC old generation, MiB 592.706 600.267 +7.561
Worker heap, MiB 1015.942 1036.429 +20.487
RSS, MiB 2989.621 2962.570 -27.051
Completed turns 40 40 +0
Completed lists 1183 1183 +0
Workers sampled 32 31 -1

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.list stage-CPU metric is not exported by this harness.

Scrape windows: 594.622s / 594.613s, with 1173 / 1173 server list completions.

Running-candidate task Baseline calls Candidate calls
other 8288 0
sessions.list 63 9
work-metrics 0 1688

Separate temporary stack attribution on baseline 4c2a27148307b98006e3a7276b0d79c6b5a8c50d found 816/816 unattributed calls in server-work-metrics active-only preparation; two named sessions.list calls came through the owner-count facet. Those caller modules are unchanged between that attribution baseline and this baseline. The current timed candidate exposes work-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:

File Tests passed Wall time, s
sessions-read-owner-counts.test.ts 3 53.55
session-row-selection.test.ts 8 55.92
server-work-metrics.test.ts 1 52.03
sessions-read-active.test.ts 15 69.06
team-shape-stress.test.ts 26 5.24

node scripts/check-changed.mjs passed 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.

@clawsweeper

clawsweeper Bot commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@openclaw-barnacle openclaw-barnacle Bot added gateway Gateway runtime scripts Repository scripts size: S labels Oct 26, 2026
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Oct 26, 2026
@clawsweeper

clawsweeper Bot commented Oct 26, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs changes before merge.

What this changes

This 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.

  • Before: The row selector is entered eight times.
  • After: One selection resolves all eight identities while retaining physical competitors.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) The runtime change is focused, but the new replay cannot evaluate its intended candidate fan-out and the experiment remains explicitly held.
Proof confidence 🌊 off-meta tidepool Not applicable: This maintainer-authored experiment is outside the ordinary contributor proof gate; its session-selection owner change has no completed replay or shipped Gateway evidence, and the author explicitly leaves those results pending.
Patch quality 🦐 gold shrimp (3/6) 1 actionable review finding remain.

Product

Kind: Performance · Worth it: Yes · Fix scope: Complete
User problem: Repeated session-selection preparation can compete with signed-in dashboard session-list and activity presentation work.
Reason: The maintainer has authorized a narrow experiment with a declared acceptance rule, and the implementation reuses the existing owner without introducing another cache.

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
Reviewed head: 121a2dda5b0c20308c7874d8f07a399341fa016d

Before merge

  • Exercise multiple candidate identities in the new replay mode (P2) - With --running-candidates, this case requests owner counts, but read() supplies no Gateway context, so prepareProjectedSessionList never creates projectRun and omits its direct-run key/ID candidates. All eight synthetic children also share parent.key as their requester, and the seeded historical runs are settled. The remaining requester and projected-ancestor sets therefore collapse to at most one candidate: baseline already performs zero or one selection per list, leaving no fan-out for batching to reduce by the declared 50%. Supply a representative production context or seed several distinct candidate roots before using this mode to accept or reject the optimization.

Findings

  • [P2] Exercise multiple candidate identities in the new replay mode — scripts/perf/session-prepared-list-measure.ts:163-169

Tests

  • Missing end-to-end proof: Completed paired replay and real Gateway stress results showing reduced candidate selections with unchanged running/attention output, plus base-red/head-green regression results, remain pending.
Agent review details

How this fits together

Gateway 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]
Loading

Technical review

Best 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:

  • [P2] Exercise multiple candidate identities in the new replay mode — scripts/perf/session-prepared-list-measure.ts:163-169
    With --running-candidates, this case requests owner counts, but read() supplies no Gateway context, so prepareProjectedSessionList never creates projectRun and omits its direct-run key/ID candidates. All eight synthetic children also share parent.key as their requester, and the seeded historical runs are settled. The remaining requester and projected-ancestor sets therefore collapse to at most one candidate: baseline already performs zero or one selection per list, leaving no fan-out for batching to reduce by the declared 50%. Supply a representative production context or seed several distinct candidate roots before using this mode to accept or reject the optimization.
    Confidence: 0.97

Overall correctness: patch is incorrect
Overall confidence: 0.94

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 31bd47773b7c.

Provenance checked

  • Candidate identity and physical-competitor selection keeps the original intent (fix(gateway): avoid rebuilding archived session rows during refreshes #151574: Retain cold metadata and all physical competitors so federation precedes downstream filtering; the batched path preserves that ordering.)
  • Sparse live owner counts keeps the original intent (39aee7d: Refresh running counts from live candidates and descendant activity at the response boundary instead of projecting every counted row.)
  • Selection attribution keeps the original intent (cee236c: Attribute selection work using bounded caller and selection-kind counters without per-selection diagnostic events.)
  • Diagnostic work publication keeps the original intent (f277bdf: Publish live counts from existing owners after changes, with coalescing and demand-bound lifecycle; this PR adds attribution while retaining that lifecycle.)

Testing

Proof path: none.

Security

None.

Evidence

Acceptance criteria:

  • Run node --expose-gc --import ./scripts/tsx.mjs scripts/perf/session-prepared-list-measure.ts --state-dir --running-candidates --mode timing on baseline and candidate with the same repaired fixture; verify the baseline exercises multiple candidate selections.
  • Run node scripts/run-vitest.mjs src/gateway/server-methods/sessions-read-owner-counts.test.ts src/gateway/session-row-selection.test.ts --maxWorkers=1.
  • Verify equivalent response digests using the replay's existing --mode verify and --golden controls.
  • Run scoped script lint/type checks and git diff --check.

What I checked:

Likely related people:

  • Peter Steinberger: Raw commit cee236c adds src/gateway/session-row-scope.ts:417 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: cee236c9e989; files: src/gateway/session-row-scope.ts)

PR surface

Source +5, Tests +9, Other +25. Total +39 across 9 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 5 38 33 +5
Tests 3 20 11 +9
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 1 25 0 +25
Total 9 83 44 +39

Review metrics

Metric Value Why it matters
Benchmark control 1 new flag: --running-candidates This selects a developer replay workload and does not add a shipped Gateway configuration option.

Labels

Label changes:

  • add P2: This is a bounded session-list performance experiment with a concrete benchmark defect and no demonstrated urgent production regression.
  • add rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🌊 off-meta tidepool and patch quality is 🦐 gold shrimp.
  • add status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action.

Label justifications:

  • P2: This is a bounded session-list performance experiment with a concrete benchmark defect and no demonstrated urgent production regression.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🌊 off-meta tidepool and patch quality is 🦐 gold shrimp.
  • status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action.

Rating scale

6/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.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only. Repair and merge execution lanes are retired.

Reviewed October 26, 2026, 7:28 PM ET / 23:28 UTC.

@steipete
steipete force-pushed the steipete/coldload-running-candidate-selections branch 2 times, most recently from 29b16b3 to 44f8ba7 Compare October 27, 2026 01:52
@steipete steipete changed the title experiment(control-ui): batch running-candidate selections [do not merge] perf(gateway): batch running-candidate row selections Oct 27, 2026
@steipete
steipete marked this pull request as ready for review October 27, 2026 03:28
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-27T04:58:26.929194Z bb464ce Draft marked ready
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@steipete
steipete marked this pull request as draft October 27, 2026 04:02
@steipete
steipete force-pushed the steipete/coldload-running-candidate-selections branch from 44f8ba7 to bb464ce Compare October 27, 2026 04:51
@steipete
steipete marked this pull request as ready for review October 27, 2026 04:56
@steipete
steipete merged commit f44c62d into main Oct 27, 2026
218 of 219 checks passed
@steipete
steipete deleted the steipete/coldload-running-candidate-selections branch October 27, 2026 05:21
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 28, 2026
…#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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

gateway Gateway runtime P2 Normal backlog priority with limited blast radius. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. scripts Repository scripts size: S status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant