Repository navigation
improve(sessions): reduce allocations when creating and listing sessions - #146310
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 maintainer review before merge. Reviewed September 12, 2026, 3:16 PM ET / 19:16 UTC (Revision 3). ClawSweeper reviewWhat this changesThe branch reduces temporary allocations when adding participant details to session results and corrects the diagnostics QA scenario’s test selector. Merge readiness✅ Ready for maintainer review The optimization remains useful and is absent from current main. No actionable defect was found, and the previous landing prerequisite is resolved by the merged QA repair. Priority: P2 Review scores
Verification
How this fits togetherOpenClaw’s session accessor combines stored session entries with SQLite participant records for creation snapshots, listings, and summaries. This change reduces intermediate allocations while preserving the returned entries and their order. flowchart TD
A[Session creation or listing] --> B[Read selected session entries]
B --> C[Copy ordered entry map]
D[SQLite participant records] --> E[Project entries with participants]
C --> E
E --> F[Session snapshots and results]
Before mergeNone. Agent review detailsSecurityNone. PR surfaceSource +2, Other 0. Total +2 across 2 files. View PR surface stats
Review metricsNone. Technical reviewBest possible solution: Keep participant projection in the existing session accessor and preserve its values, ordering, validation, and ownership while removing temporary allocations. Do we have a high-confidence way to reproduce the issue? Not applicable as a functional bug reproduction: this is a behavior-preserving optimization, supported by source inspection and reported component allocation measurements. Is this the best way to solve the issue? Yes. The change removes intermediate work in the existing owner without adding a cache, changing queries, or altering the persisted data contract. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 6b92ac80b5ab. LabelsLabel justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (2 earlier review cycles)
|
1f82a25 to
f233069
Compare
|
Merged via squash.
|
…ons (openclaw#146310) * fix(qa): select the renamed diagnostics browser test * improve(sessions): reduce allocation when projecting participants
Related: #145579
What Problem This Solves
Gateways with many sessions allocate temporary objects while preparing session creation and list results, including for sessions without recorded participants.
Why This Change Was Made
Copy the selected entries directly into the result Map, then project only entries with participant records. This removes intermediate arrays while preserving input order, entry ownership, eager validation, and query behavior.
User Impact
Session creation and listing produce less allocation pressure, especially when participants are absent or sparse. Results and persistent state remain unchanged.
Evidence
git diff --checkpassed.scoped-cleanwith no findings.Five alternating same-process timing rounds of 250 projections gave median elapsed times of 142.3 → 144.9 ms, 312.3 → 239.0 ms, and 1,170.2 → 1,084.5 ms respectively. Ranges overlap; no general latency improvement is claimed. Full-list savings are modest because saved payload parsing dominates. Highest sampled RSS in separate processes was about 728 → 704 MiB, while the paired timing run settled around 657 MiB for both versions; neither establishes a retained-memory reduction. These are bounded local measurements, not per-PR attribution from a live Gateway.
Combined live follow-up
A fixed 1,000-session workload on an isolated Linux Testbox exercised both changes together against main
7249a939db2c8d644a554ca286034df9a4b30c20. Both variants completed eight real OpenAI responses, two read-tool flows, and the same control-plane, UI, history, subscription, and session activity. Independent SQLite reads verified the eight final responses exactly once before cleanup and after shutdown. Tool flows were verified through RPC history and streaming evidence.Sampled allocations were 6.612 → 6.449 GB (−2.47%), peak RSS 2,121 → 2,037 MiB (−3.96%), and post-GC load heap 354.011 → 353.517 MB (essentially flat). Wall time was 48.75 → 50.92 seconds (+4.46%). These are one-pair descriptive observations for the combined changes, not per-PR causal or retained-memory claims.
The baseline required SIGKILL after the canonical two-second graceful teardown budget; the candidate exited cleanly. Captured logs do not establish the baseline shutdown phase or root cause, and baseline final provider counters were unavailable. Consequently ordinary paired validation did not pass, despite both functional workloads passing. The baseline was not replayed; the candidate ran once. Both owned Gateway groups and the Testbox lease are stopped, and all 30 downloaded evidence files match remote hashes. Raw credentialed heap snapshots remained remote. Testbox run.
The combined local
node scripts/check-changed.mjs -- src/skills/runtime/refresh.ts src/config/sessions/session-accessor.sqlite-participant-projection.tsgate passed, including core and all 18 test type graphs, dead-export scans, targeted lint, formatting, and source guards. Both independent canonical reviews and subsequent ClawSweeper reviews found no actionable issues. Initial hosted CI failed on an unrelated stale QA scenario selector introduced on main by #146207. The independently reviewed repair #146323 is now merged on main; this branch includes that correction, and its landing prerequisite is satisfied. The optimization patch and source hash are unchanged, verified by range-diff; the local and live measurements above apply to the original pinned baseline, not the refreshed full main tree.