Repository navigation
improve: reduce CPU work when listing sessions - #156221
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 real behavior proof before merge. Reviewed September 23, 2026, 2:30 AM ET / 06:30 UTC. ClawSweeper reviewWhat this changesReuses 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 Review scores
Verification
How this fits togetherThe 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]
Before merge
Agent review detailsSecurityNone. PR surfaceSource +6, Tests +49. Total +55 across 4 files. View PR surface stats
Review metrics
Technical reviewBest 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. LabelsLabel changes:
Label justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
|
|
Merged via squash auto-merge.
|
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
sessions.listhandler 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.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 callsselectRows()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-filecheck-changedlane 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.