Skip to content

improve(sessions): reduce allocations when creating and listing sessions - #146310

Merged
steipete merged 2 commits into
mainfrom
codex/memory-next-sessions
Sep 12, 2026
Merged

steipete merged 2 commits into
mainfrom
codex/memory-next-sessions

Conversation

@steipete

@steipete steipete commented Sep 12, 2026 •

Copy link
Copy Markdown
Contributor

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

  • 86 tests passed across creation snapshots, read-only accessors, large session-row selections, and participant identity. Type-aware lint, formatting, and git diff --check passed.
  • Canonical P2 review completed scoped-clean with no findings.
  • Synthetic SQLite proof: 1,000 sessions, 100 reads per case; complete participant values, insertion order, and input ownership are checked, alongside creation-snapshot contracts and list counts.
Sessions with participants Projection sampled allocation Creation snapshot sampled allocation Full-list sampled allocation
0% 35.40 → 20.92 MB (−40.9%) 206.45 → 190.99 MB (−7.5%) −1.3%
10% 51.67 → 38.48 MB (−25.5%) 222.33 → 208.16 MB (−6.4%) −1.2%
100% 178.42 → 171.32 MB (−4.0%) 352.16 → 350.42 MB (−0.5%) Effectively flat

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.ts gate 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.

@clawsweeper

clawsweeper Bot commented Sep 12, 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 12, 2026 18:38
@openclaw-barnacle openclaw-barnacle Bot added size: XS maintainer Maintainer-authored PR labels Sep 12, 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: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Sep 12, 2026
@clawsweeper

clawsweeper Bot commented Sep 12, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed September 12, 2026, 3:16 PM ET / 19:16 UTC (Revision 3).

ClawSweeper review

What this changes

The 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
Reviewed head: f23306961bff3be9942c52c2f5d1cd80d4d34208

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused, behavior-preserving optimization with useful bounded proof and no actionable findings.
Proof confidence 🐚 platinum hermit (4/6) Sufficient (live_output): The supplied component measurements exercise the changed SQLite projection and creation/list paths, while the isolated Linux Gateway follow-up records successful real responses, tool flows, and durable transcript checks after the combined changes. Functional evidence is sufficient for this bounded optimization; the cancelled paired run and combined measurements do not establish per-PR latency or retained-memory gains.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (live_output): The supplied component measurements exercise the changed SQLite projection and creation/list paths, while the isolated Linux Gateway follow-up records successful real responses, tool flows, and durable transcript checks after the combined changes. Functional evidence is sufficient for this bounded optimization; the cancelled paired run and combined measurements do not establish per-PR latency or retained-memory gains.
Evidence reviewed 7 items Introduced change and preserved semantics: The independently inspected merge-base-to-head diff contains the participant-loop optimization and QA selector correction. The existing projection already returns the original entry when participant records are empty; copying the Map and replacing existing values preserves insertion order without changing input entries, query selection, or eager identity decoding.
Current main still needs the optimization: The fetched main revision still constructs intermediate arrays and visits every entry through the projection helper. The merged selector repair does not implement this central optimization. Release-source inspection could not complete because a required Git object was unavailable; no shipped-fix claim is made.
Production callers preserve ownership: The complete entry-cache, selected-row reader, and summary modules were inspected. They supply ordinary Maps of parsed SessionEntry objects; the creation-snapshot reader consumes the same cache owner. No new persistence, authorization, configuration, or dependency contract is introduced.
Findings None None.
Security None None.

How this fits together

OpenClaw’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]
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source +2, Other 0. Total +2 across 2 files.

View PR surface stats
Area Files Added Removed Net
Source 1 8 6 +2
Tests 0 0 0 0
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 1 1 1 0
Total 2 9 7 +2

Review metrics

None.

Technical review

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

Labels

Label justifications:

  • P2: This is a bounded session-performance improvement with measured allocation savings and no established urgent user-facing regression.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (live_output): The supplied component measurements exercise the changed SQLite projection and creation/list paths, while the isolated Linux Gateway follow-up records successful real responses, tool flows, and durable transcript checks after the combined changes. Functional evidence is sufficient for this bounded optimization; the cancelled paired run and combined measurements do not establish per-PR latency or retained-memory gains.
  • proof: sufficient: Contributor real behavior proof is sufficient. The supplied component measurements exercise the changed SQLite projection and creation/list paths, while the isolated Linux Gateway follow-up records successful real responses, tool flows, and durable transcript checks after the combined changes. Functional evidence is sufficient for this bounded optimization; the cancelled paired run and combined measurements do not establish per-PR latency or retained-memory gains.

Evidence

What I checked:

  • Introduced change and preserved semantics: The independently inspected merge-base-to-head diff contains the participant-loop optimization and QA selector correction. The existing projection already returns the original entry when participant records are empty; copying the Map and replacing existing values preserves insertion order without changing input entries, query selection, or eager identity decoding. (src/config/sessions/session-accessor.sqlite-participant-projection.ts:121, f23306961bff)
  • Current main still needs the optimization: The fetched main revision still constructs intermediate arrays and visits every entry through the projection helper. The merged selector repair does not implement this central optimization. Release-source inspection could not complete because a required Git object was unavailable; no shipped-fix claim is made. (src/config/sessions/session-accessor.sqlite-participant-projection.ts:121, 6b92ac80b5ab)
  • Production callers preserve ownership: The complete entry-cache, selected-row reader, and summary modules were inspected. They supply ordinary Maps of parsed SessionEntry objects; the creation-snapshot reader consumes the same cache owner. No new persistence, authorization, configuration, or dependency contract is introduced. (src/config/sessions/session-accessor.sqlite-entry-cache.ts:156, f23306961bff)
  • Existing contract coverage: Inspected complete creation-snapshot and session-row test modules covering participant projection beyond SQLite’s parameter limit, empty selections, retained participant values, snapshot consistency, and detached cache payloads. The PR reports 86 passing focused tests; tests were not executed during this read-only review. (src/config/sessions/session-accessor.creation-snapshot.test.ts:64, f23306961bff)
  • Previous prerequisite resolved: GitHub REST confirms fix(qa): select the renamed diagnostics browser test #146323 merged at 2026-09-12T19:09:46Z. Current main contains its selector, which matches the executable diagnostics test. This satisfies the prior review’s explicit dependency-order blocker. (qa/scenarios/ui/control-ui-health-status-models.yaml:28, 35b237db14bf)
  • Bounded component and live evidence: The complete supplied PR body records 1,000-session SQLite comparisons across 0%, 10%, and 100% participant density, checking values, order, and ownership. Its isolated Linux Gateway follow-up reports eight real provider responses, two tool flows, and independent SQLite verification after shutdown. These observations cover the session workflows but combine two optimizations. The linked Testbox workflow is marked cancelled, consistent with the disclosed incomplete ordinary paired validation; it is not treated as a blanket PASS. Prepared screenshots were inspected and belong to the related diagnostics UI change, not allocation proof. Captured context sourceRevision: 7e091c27fa47b7d445d9fa267a4d79251c13acfade649193d23c25297b2edf56.

Likely related people:

  • unknown: The claimed source-line change could not be verified from bounded local history. (role: source history unknown; 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.

History

Review history (2 earlier review cycles)
  • reviewed 2026-09-12T18:44:08.757Z sha 1f82a25801593edf5b406a78f39962b7cc34ee3d :: needs maintainer review before merge. :: none
  • reviewed 2026-09-12T19:01:57.111Z sha f233069 :: needs changes before merge. :: none

@steipete
steipete force-pushed the codex/memory-next-sessions branch from 1f82a25 to f233069 Compare September 12, 2026 18:56
@clawsweeper clawsweeper Bot added the proof: sufficient ClawSweeper judged the real behavior proof convincing. label Sep 12, 2026
@steipete
steipete merged commit d142640 into main Sep 12, 2026
201 of 203 checks passed
@steipete
steipete deleted the codex/memory-next-sessions branch September 12, 2026 19:25
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 13, 2026
…ons (openclaw#146310)

* fix(qa): select the renamed diagnostics browser test

* improve(sessions): reduce allocation when projecting participants
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

extensions: qa-lab maintainer Maintainer-authored PR P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: XS status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant