Skip to content

improve: reduce CPU work when listing sessions - #156221

Merged
steipete merged 1 commit into
mainfrom
codex/session-selection-once
Sep 23, 2026
Merged

steipete merged 1 commit into
mainfrom
codex/session-selection-once

Conversation

@steipete

@steipete steipete commented Sep 23, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Warm session lists repeat the full visibility, ownership, and ordering selection three times, even when returning a small page from a large roster.

User Impact

Reduces main-thread CPU spent listing sessions while preserving the returned pages, current access checks, archive retention, and placement ordering. No configuration, schema, stored-data, or update changes.

Why This Change Was Made

The row-preparation owner now carries one selection through each synchronous preparation and response frame. It selects again after asynchronous preparation, so changes to membership, scopes, time filters, and session identity remain visible before responding. The redundant placement wrapper is removed, and its lifecycle tests exercise the production read boundary.

Evidence

  • The regression fails on the original code with 12 ownership projections for four visible sessions. The fixed test bounds that work to one pass and retains the existing page and sharing-role assertions.
  • An isolated benchmark through the registered sessions.list handler confirms three selection passes become one at 100, 1,000, and 5,000 sessions. At 5,000 sessions with a 100-row page, ownership projections fall from 15,000 to 5,000. Median main-thread CPU was 4.97 → 2.99 ms and wall time 5.17 → 2.82 ms across ten measured requests per run. Separate-process timings are illustrative; production latency improvement has not been measured.
  • Focused validation passed 45 existing tests plus the isolated benchmark, with one existing opt-in benchmark skipped. Coverage includes membership and owner changes during worker waits, placement invalidation, bounded concurrent admission, FIFO, queued disposal, archives, and private reads.

Per-file cost with pnpm test <file> --maxWorkers=1: viewer suite 51.180 s wall (5.206 s test time; 15.827 s cold worker compilation), placement lifecycle suite 19.122 s wall (21 ms test time). These measurements include concurrent local check load. The existing fixture supplies the page/access and lifecycle contracts; this change adds assertions without adding test cases.

Both changed suites passed in hosted CI: summed test-body times were 2.675 s for viewers and 0.011 s for placement lifecycle. CI does not expose standalone per-file wall time; the containing 62-file Gateway shard took 114.40 s.

Independent review completed. One stale-selection finding was rejected after tracing the post-await prepare() loop: it calls selectRows() before validating or consuming placement facts and repeats after every preparation await. The passing held-placement test revokes scopes, advances the clock, and changes visibility before releasing that wait. No accepted actionable review findings remain. The complete four-file check-changed lane passed, including production types, all 25 core test-typecheck shards, changed-file lint, dead-export scans, runtime import-cycle checks, and repository guards.

Behavior proof and review disposition

The completed exact-head ClawSweeper review reports no correctness or security findings. Its generic proof request records a not-applicable assessment despite recognizing the executed registered-handler benchmark. The applicable boundary proof is present above. Selected after-change benchmark fields at 5,000 stored synthetic sessions:

{"benchmark":"warm-session-selection","size":5000,"selectionPasses":1,"directOwnerVisits":5000}

The same registered handler and fixture performed three passes and 15,000 ownership projections before the change. Golden page, ordering and sharing-role assertions pass; held-placement and worker-wait cases prove scope, clock, visibility and current-fact changes are respected after awaits. The final source hashes match the passing proof.

Maintainer disposition: this is sufficient behavior proof for the internal synchronous selection optimization. No specific missing behavior was identified by the completed review. Transport and authentication handshakes are unchanged; the measurements do not claim production latency improvement. Current main introduces no overlap in either changed production owner.

@clawsweeper

clawsweeper Bot commented Sep 23, 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.

@steipete
steipete marked this pull request as ready for review September 23, 2026 05:35
@openclaw-barnacle openclaw-barnacle Bot added gateway Gateway runtime size: M labels Sep 23, 2026
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Sep 23, 2026
@clawsweeper

clawsweeper Bot commented Sep 23, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs real behavior proof before merge. Reviewed September 23, 2026, 2:30 AM ET / 06:30 UTC.

ClawSweeper review

What this changes

Reuses session selection within each synchronous preparation frame, removes a redundant placement wrapper, and updates performance and lifecycle coverage.

Merge readiness

⛔ Blocked before merge - 1 item remains

Keep open: this remains a useful performance improvement over current main, with no blocking correctness finding. The preparation loop refreshes selection after waits and preserves synchronous response authorization.

Priority: P2
Reviewed head: a8e7ebe53f5e89ef937f7be66a412506de8230b5

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) Recorded reviewer rating: A focused optimization with relevant regression coverage, reported benchmark results, and no identified blocking defect. Real behavior proof remains required by host policy.
Proof confidence 🌊 off-meta tidepool Recorded reviewer rating; Required by policy: the recorded not-applicable assessment does not satisfy the current PR proof policy. Put relevant after-change evidence in the main PR body, then request a fresh review with @clawsweeper re-review. Recorded reviewer context: The author is a verified repository administrator, so ordinary external-contributor proof is exempt. The supplied registered-handler benchmark supports the CPU claim, and inspected tests cover freshness and lifecycle behavior; neither was rerun here. No stored-data contract changes.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Required by policy Required by policy: the recorded not-applicable assessment does not satisfy the current PR proof policy. Put relevant after-change evidence in the main PR body, then request a fresh review with @clawsweeper re-review. Recorded reviewer context: The author is a verified repository administrator, so ordinary external-contributor proof is exempt. The supplied registered-handler benchmark supports the CPU claim, and inspected tests cover freshness and lifecycle behavior; neither was rerun here. No stored-data contract changes.
Evidence reviewed 8 items Introduced patch: Reviewed the pinned merge-base-to-head delta: selection reuse and wrapper removal are confined to the session preparation owner and its caller, with corresponding test changes.
Fresh selection after waits: The post-placement prepare loop calls selectRows before preparing selected rows and repeats after every preparation await. The warm path consumes its selection without an intervening yield. Membership readiness and exact-row assertions remain in the consuming frame.
Behavioral regression coverage: The changed viewer regression bounds ownership projections while retaining page, ordering, count, and sharing-role assertions. Existing held-placement coverage revokes admin scopes, changes visibility, advances the clock, and verifies only the permitted session remains; disposal prevents a response.
Findings None None.
Security None None.

How this fits together

The Gateway turns stored session metadata and current viewer permissions into ordered session-list pages. Its preparation layer gathers placement and membership facts before presenting and returning those pages.

flowchart TD
  A[Session list request] --> B[Current viewer and filters]
  B --> C[Select session page]
  C --> D{Facts ready?}
  D -->|No| E[Await preparation]
  E --> C
  D -->|Yes| F[Authorize and present synchronously]
  F --> G[Return session page]
Loading

Before merge

  • Add real behavior proof - Required by policy: the recorded not-applicable assessment does not satisfy the current PR proof policy. Put relevant after-change evidence in the main PR body, then request a fresh review with @clawsweeper re-review. Recorded reviewer context: The author is a verified repository administrator, so ordinary external-contributor proof is exempt. The supplied registered-handler benchmark supports the CPU claim, and inspected tests cover freshness and lifecycle behavior; neither was rerun here. No stored-data contract changes.
Agent review details

Security

None.

PR surface

Source +6, Tests +49. Total +55 across 4 files.

View PR surface stats
Area Files Added Removed Net
Source 2 66 60 +6
Tests 2 68 19 +49
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 4 134 79 +55

Review metrics

Metric Value Why it matters
Warm selection work 3 passes → 1 Source and the reported handler benchmark support eliminating repeated roster work without claiming production-wide latency gains.

Technical review

Best possible solution:

Keep selection reuse inside the existing preparation owner, refreshing after every asynchronous boundary while preserving page and access semantics.

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

Yes, source provides a high-confidence path: a warm session-list request repeats selection through placement preparation and ancestor consumption on current main. No execution was performed during this review.

Is this the best way to solve the issue?

Yes. Reusing the selection within a synchronous frame removes redundant work at its existing owner, while the post-await loop restores fresh viewer, clock, and session facts.

AGENTS.md: found and applied where relevant.

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

Labels

Label changes:

  • add P2: This is a bounded Gateway CPU optimization for session listing, without evidence of an urgent outage or regression.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit. This is the recorded reviewer rating; real behavior proof remains required by host policy.
  • add status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask. Required by policy: the recorded not-applicable assessment does not satisfy the current PR proof policy. Put relevant after-change evidence in the main PR body, then request a fresh review with @clawsweeper re-review. Recorded reviewer context: The author is a verified repository administrator, so ordinary external-contributor proof is exempt. The supplied registered-handler benchmark supports the CPU claim, and inspected tests cover freshness and lifecycle behavior; neither was rerun here. No stored-data contract changes.

Label justifications:

  • P2: This is a bounded Gateway CPU optimization for session listing, without evidence of an urgent outage or regression.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit. This is the recorded reviewer rating; real behavior proof remains required by host policy.
  • status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask. Required by policy: the recorded not-applicable assessment does not satisfy the current PR proof policy. Put relevant after-change evidence in the main PR body, then request a fresh review with @clawsweeper re-review. Recorded reviewer context: The author is a verified repository administrator, so ordinary external-contributor proof is exempt. The supplied registered-handler benchmark supports the CPU claim, and inspected tests cover freshness and lifecycle behavior; neither was rerun here. No stored-data contract changes.

Evidence

What I checked:

  • Introduced patch: Reviewed the pinned merge-base-to-head delta: selection reuse and wrapper removal are confined to the session preparation owner and its caller, with corresponding test changes. (src/gateway/session-row-placement-projection.ts:254, a8e7ebe53f5e)
  • Fresh selection after waits: The post-placement prepare loop calls selectRows before preparing selected rows and repeats after every preparation await. The warm path consumes its selection without an intervening yield. Membership readiness and exact-row assertions remain in the consuming frame. (src/gateway/session-row-placement-projection.ts:295, a8e7ebe53f5e)
  • Behavioral regression coverage: The changed viewer regression bounds ownership projections while retaining page, ordering, count, and sharing-role assertions. Existing held-placement coverage revokes admin scopes, changes visibility, advances the clock, and verifies only the permitted session remains; disposal prevents a response. (src/gateway/session-list-viewers.perf.test.ts:350, a8e7ebe53f5e)
  • Current-main necessity: Fetched main still contains repeated query selection in placement preparation and ancestor consumption. No merged replacement was established. The latest supplied release tag does not contain this placement-owner path, so it provides no evidence that this optimization has shipped. (src/gateway/session-row-placement-projection.ts:263, 5b77505b37f9)
  • Reported performance and validation: The captured PR body reports a registered sessions.list benchmark reducing ownership projections from 15,000 to 5,000 for 5,000 sessions, with illustrative median thread CPU of 4.97 to 2.99 ms. It explicitly disclaims measured production latency improvement and supplies focused test costs and hosted CI results. These runs were not independently repeated during this read-only review. (a8e7ebe53f5e)
  • Verified author role: GitHub's collaborator-permission endpoint identifies steipete as a repository administrator, establishing the trusted-author proof exemption despite the supplied CONTRIBUTOR association.

Likely related people:

  • steipete: 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 enabled auto-merge (squash) September 23, 2026 15:13
@steipete
steipete merged commit f6a3ed7 into main Sep 23, 2026
289 checks passed
@steipete
steipete deleted the codex/session-selection-once branch September 23, 2026 15:14
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash auto-merge.

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: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: M status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant