Skip to content

perf(gateway): retain cold session list selections - #166405

Merged
steipete merged 1 commit into
mainfrom
steipete/perf-micro-reconnect-storm-sessions-list-20260919
Oct 7, 2026
Merged

steipete merged 1 commit into
mainfrom
steipete/perf-micro-reconnect-storm-sessions-list-20260919

Conversation

@steipete

@steipete steipete commented Oct 7, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Cold sessions.list pages repeat full-roster selection while their selected display rows materialize. Each display-only publication retires the cached principal/filter view even when selection metadata is unchanged.

User Impact

Cold list requests retain their shared selection across row-preparation slices. Different principals and filters keep separate views, and each response still authorizes and presents current rows synchronously.

Why This Change Was Made

Use the projection's existing selection revision plus row-context identity for list views. Keep the broader sharing revision unchanged for authorization receipts and asynchronous read fences. Existing request/row-read coalescing stays with its owners; this adds no cache, configuration, or schema.

Production LOC: −5 (session-row-presentation.ts: 3 additions, 8 deletions).

Evidence

A six-request cold-owner benchmark over 5,000 synthetic sessions, calibrated to 562,014-byte responses, ran three fresh projections per version on one Blacksmith Testbox, candidate first:

Measurement Before After
Median burst request latency 453.7 ms 416.4 ms
Median main-thread CPU per burst 345.9 ms 300.6 ms
Full-roster selections per burst 2–3 1

Calibration used the committed benchmark with labels ending in "界".repeat(324) and process.threadCpuUsage() around the six-request burst. The committed opt-in fixture uses larger, 781 KB responses. These are small samples, not p99 estimates. One calibrated candidate cold-owner burst reached 530.8 ms.

The real Gateway restart rig used two fresh processes per version, 5,000 synthetic sessions, six concurrent sidebar lists and 560,465-byte responses. All requests were below 500 ms: baseline 99–188 ms, candidate 116–256 ms. It did not reproduce the reported multi-second production stall or establish an end-to-end speedup. Gateway startup already awaits initial roster materialization before exposing the request context. The cold-owner probe isolates metadata-ready/display-cold rebuilding. This PR removes that independently reproduced selection amplification; the production stall and possible later invalidation or worker contention remain investigation gaps.

Validation:

  • blacksmith-testbox, lease tbx_01m4a2b6sdmm3nk4rmv15es9t2: baseline regression fails specifically with 3 selections instead of 1; candidate passes. Focused serialization, viewer, presentation and list-page suites: 18 passed (node scripts/run-vitest.mjs … --maxWorkers=1). Combined command: 168.2 s.
  • Same lease: reversed-order calibrated benchmarks, 6 passed, command 55.1 s. An initial temporary-driver quoting error was corrected before those tests ran.
  • pnpm test src/gateway/session-list-serialization.test.ts --maxWorkers=1: 4 passed, 3.14 s test time / 41.05 s command wall time (30.79 s inside the test wrapper). New regression: 1.60 s. The large benchmark is opt-in (OPENCLAW_DB_WORKER_BENCH=1), not ordinary CI test work.
  • Authorized Linux rig fallback after Testbox queueing: node scripts/check-changed.mjs --staged, exit 0; all 27 core test typecheck groups, lint, dead-code and required guards passed. Baseline and candidate runtime builds and isolated Gateway restart runs also passed.
  • Independent Codex review: scoped-clean through P2. Rebase preserved the reviewed patch byte-for-byte (git range-diff reports equality).

Measurements and the changed-file gate used base 7880834c1961. The branch was then rebased without conflicts onto 27ba9720f2c5. Exact-head CI passed for 3f6c2159f2db, including Node tests and typechecks. Selected Node CI jobs took 84–296 s each; per-file CI timing was not exported. The fresh-head Testbox lease remained queued and was stopped after CI verified the rebased head; it supplied no additional test result. All task leases and rig checkouts are cleaned up.

Keep principal-scoped list views on the selection revision so display-only materialization does not repeatedly filter the roster. Preserve sharing revisions for authorization receipts and refresh views on selection or context publication.
@clawsweeper

clawsweeper Bot commented Oct 7, 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 size: S labels Oct 7, 2026
@steipete
steipete marked this pull request as ready for review October 7, 2026 02:52
@steipete
steipete enabled auto-merge (squash) October 7, 2026 02:55
@clawsweeper

clawsweeper Bot commented Oct 7, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed October 6, 2026, 10:57 PM ET / October 7, 2026, 02:57 UTC.

ClawSweeper review

What this changes

The Gateway reuses principal-specific session-list selections while cold display rows materialize, with regression coverage and an opt-in benchmark.

Merge readiness

✅ Ready for maintainer review

This remains a useful, focused optimization absent from current main. No introduced correctness defect was found; the evidence supports reduced selection work without establishing a fix for the broader production stall.

Priority: P2
Reviewed head: 3f6c2159f2db74429a77e31bc7a47a990c3cff6c

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused owner-level simplification with meaningful regression coverage and carefully bounded runtime evidence.
Proof confidence 🐚 platinum hermit (4/6) Sufficient (live_output): Reported production-owner/database-worker benchmarks show selection amplification removed, and isolated real Gateway restart runs exercise concurrent serialized session-list responses after the change. This supports the narrow optimization, not a claimed end-to-end speedup; the patch changes no stored-data contract.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (live_output): Reported production-owner/database-worker benchmarks show selection amplification removed, and isolated real Gateway restart runs exercise concurrent serialized session-list responses after the change. This supports the narrow optimization, not a claimed end-to-end speedup; the patch changes no stored-data contract.
Evidence reviewed 8 items Verified introduced scope: The pinned merge-base-to-head diff changes selection-cache invalidation and adds focused regression and benchmark coverage; it does not change sharing receipts, configuration, dependencies, or persisted formats.
Still necessary on current main: Fetched main still keys publication lists on sharingRevision, which display-row materialization retires. The branch switches this to the existing selection revision and retains row-context identity.
Selection invalidation owner: Materialization preserves selection identity unless board membership changes; replacement invalidates selection when generation, board membership, or stored entry metadata changes. Projection removal and topology publication also invalidate selection.
Findings None None.
Security None None.

How this fits together

The Gateway turns session metadata and a caller's visibility policy into paginated session lists. Its projection prepares selected display rows before presenting and serializing responses.

flowchart TD
  A[Session metadata] --> B[Session projection]
  C[Caller and list filters] --> D[Principal-specific selection]
  B --> D
  D --> E[Prepare selected display rows]
  E --> F[Current policy and row presentation]
  F --> G[Serialized session list]
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source -5, Tests +180. Total +175 across 3 files.

View PR surface stats
Area Files Added Removed Net
Source 1 3 8 -5
Tests 2 181 1 +180
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 3 184 9 +175

Review metrics

Metric Value Why it matters
Selection amplification Reported 2–3 full-roster selections reduced to 1 per six-request burst This directly measures the work the patch intends to eliminate.
Production versus test growth Production −5 net lines; tests +180 net lines The implementation simplifies the existing owner; added coverage includes an opt-in large benchmark.

Technical review

Best possible solution:

Keep selection reuse within the existing projection owner while preserving current principal policy, metadata invalidation, and synchronous row presentation.

Do we have a high-confidence way to reproduce the issue?

Yes, for selection amplification: current main retires cached selections during display-only materialization, and the reported baseline regression observes three selections instead of one. The broader multi-second production stall remains unconfirmed.

Is this the best way to solve the issue?

Yes. Using the existing metadata-selection revision removes unnecessary invalidation without adding another cache owner or changing authorization receipts.

AGENTS.md: found and applied where relevant.

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

Labels

Label changes:

  • add P2: This is a bounded session-list performance improvement; available evidence does not establish an urgent production availability regression.
  • add proof: sufficient: Contributor real behavior proof is sufficient. Reported production-owner/database-worker benchmarks show selection amplification removed, and isolated real Gateway restart runs exercise concurrent serialized session-list responses after the change. This supports the narrow optimization, not a claimed end-to-end speedup; the patch changes no stored-data contract.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.

Label justifications:

  • P2: This is a bounded session-list performance improvement; available evidence does not establish an urgent production availability regression.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.
  • proof: sufficient: Contributor real behavior proof is sufficient. Reported production-owner/database-worker benchmarks show selection amplification removed, and isolated real Gateway restart runs exercise concurrent serialized session-list responses after the change. This supports the narrow optimization, not a claimed end-to-end speedup; the patch changes no stored-data contract.

Evidence

What I checked:

  • Verified introduced scope: The pinned merge-base-to-head diff changes selection-cache invalidation and adds focused regression and benchmark coverage; it does not change sharing receipts, configuration, dependencies, or persisted formats. (src/gateway/session-row-presentation.ts:101, 3f6c2159f2db)
  • Still necessary on current main: Fetched main still keys publication lists on sharingRevision, which display-row materialization retires. The branch switches this to the existing selection revision and retains row-context identity. (src/gateway/session-row-presentation.ts:101, c48607980ace)
  • Selection invalidation owner: Materialization preserves selection identity unless board membership changes; replacement invalidates selection when generation, board membership, or stored entry metadata changes. Projection removal and topology publication also invalidate selection. (src/gateway/session-row-projection-revisions.ts:102, 3f6c2159f2db)
  • Principal and current-policy separation: Each presentation recomputes sharing policy; its list key includes principal, aliases, scopes, policy, and filters. Membership is read through the current projection, while sharingRevision remains unchanged as the broader publication fence. (src/gateway/session-sharing-read.ts:363, 3f6c2159f2db)
  • Real consumer boundary: The list owner reselects through exact-row preparation and then presents rows and invokes the response consumer synchronously. Clock-sensitive and transient queries bypass retained selection. (src/gateway/session-utils-list.ts:534, 3f6c2159f2db)
  • Focused regression and existing revocation coverage: The added regression exercises six real session-list handler calls across cold row slices, checks one selection, and verifies a second principal and changed page limit remain separate. Existing serialization coverage changes a viewer's role and verifies the next list excludes foreign sessions. (src/gateway/session-list-serialization.test.ts:26, 3f6c2159f2db)

Likely related people:

  • Peter Steinberger: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

@steipete
steipete merged commit 9a2106e into main Oct 7, 2026
186 checks passed
@steipete
steipete deleted the steipete/perf-micro-reconnect-storm-sessions-list-20260919 branch October 7, 2026 03:02
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 7, 2026
Keep principal-scoped list views on the selection revision so display-only materialization does not repeatedly filter the roster. Preserve sharing revisions for authorization receipts and refresh views on selection or context publication.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

gateway Gateway runtime size: S

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant