Skip to content

improve(sessions): reduce repeated reads during session updates - #149537

Merged
steipete merged 3 commits into
mainfrom
codex/sqlite-compaction-entry-reuse-0915
Sep 16, 2026
Merged

steipete merged 3 commits into
mainfrom
codex/sqlite-compaction-entry-reuse-0915

Conversation

@steipete

@steipete steipete commented Sep 16, 2026 •

Copy link
Copy Markdown
Contributor

Related: #146197

What Problem This Solves

Compaction, Goal edits, and parent forks repeatedly fetch session metadata within the same write transaction.

User Impact

These operations perform fewer SQLite reads, including fetching less prompt data during Goal edits. There is no user-visible behavior or configuration change. Authority checks, callback ordering, rollback, identity publication, and transaction boundaries remain unchanged. No latency improvement is claimed.

Why This Change Was Made

The existing entry writer accepts a canonical previous entry. Reuse the entry captured after the operation's callbacks and authority checks, preserving the separate previous-entry argument used for merging and provenance.

Evidence

Measured through the real owners on the observed writable handle:

Operation Prepared executions Returned rows Returned UTF-8 TEXT
Normal compaction 64→61 30→28 1,657→1,430 bytes
Incognito compaction 61→58 27→25 1,777→1,530 bytes
Goal edit with a 64-KiB saved prompt 23→20 13→11 264,539→198,406 bytes
Parent fork and skip cases Three fewer per successful call Two fewer 268 fewer bytes, or 158 for reused-child reset
  • Focused proof passed 35 compaction/sibling tests, 56 Goal owner/policy/RPC/chat tests, and 24 parent-fork/caller tests. The original implementations fail the added fetch budgets. Callback-time writes, refusals, replay, reopened state, and rollback are covered.
  • The parent regression counts full-row fetches: nine originally, at most eight with reuse. Separate diagnostics confirmed that the root-validation and ACP-provenance projections remain. The earlier broad-classifier failures are retained; the ceiling was not increased.
  • Independent review of the complete six-file candidate against refreshed main found no actionable P0–P2 findings. Formatting and diff checks pass. Thirty selected static checks pass, including core and all 19 core-test typecheck groups, targeted lint, database-first, import-cycle, and security guards. Hosted CI run 35053493110 passed for head 679287bd9bcc6f804087e01e1e35d46543d112d7, including both Windows jobs. Native preparation verified that hosted evidence without rerunning local gates.
  • Runtime proof is retained from the pre-refresh candidate; current production bytes are unchanged, and the two subsequent test-formatting deltas were inspected. Counters exclude native exec and other handles. State comparisons preserve complete within-run rollback/reopen checks; generated identities are not claimed byte-identical across independent runs.

Historical CI at the old compaction-only head failed the alias fixture. The refreshed base includes #149520's single late dependency-link call and #149558's idempotent helper repair; the successful new-head CI is recorded above.

@steipete steipete self-assigned this Sep 16, 2026
@clawsweeper

clawsweeper Bot commented Sep 16, 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 16, 2026 00:09
@clawsweeper

clawsweeper Bot commented Sep 16, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed September 16, 2026, 12:24 AM ET / 04:24 UTC (Revision 4).

ClawSweeper review

What this changes

Reuses freshly read session metadata during compaction, Goal edits, and parent forks, with regression coverage for read budgets and preserved state.

Merge readiness

✅ Ready for maintainer review

Keep open: this remains a useful, bounded optimization absent from current main. Source review found no actionable defects, and the recorded owner-flow measurements support the claimed reduction in reads.

Priority: P2
Reviewed head: 679287bd9bcc6f804087e01e1e35d46543d112d7

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused reuse of an established writer contract, supported by useful owner-flow measurements and meaningful regression coverage.
Proof confidence 🐚 platinum hermit (4/6) Sufficient (live_output): Recorded real SQLite owner-flow measurements exercise compaction, Goal mutation, and parent fork/skip operations and show fewer executions, rows, and payload bytes with preserved rollback and reopened state. The body retains the pre-refresh proof with unchanged production bytes; focused tests and reviewed-head CI supplement it.
Patch quality 🦞 diamond lobster (5/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (live_output): Recorded real SQLite owner-flow measurements exercise compaction, Goal mutation, and parent fork/skip operations and show fewer executions, rows, and payload bytes with preserved rollback and reopened state. The body retains the pre-refresh proof with unchanged production bytes; focused tests and reviewed-head CI supplement it.
Evidence reviewed 9 items Existing snapshot contract: The entry writer already accepts a canonical row revalidated inside the write transaction, with null representing absence. Reuse preserves its existing creation-stamp, sandbox, public-share, collaboration, and generation handling.
Compaction freshness: Compaction retains post-append authority checks and reads the session entry afterward; the patch passes that same entry to the existing writer without intervening callbacks or asynchronous work.
Parent callback ordering: Fork writes capture canonical identity after the patch callback; skip writes capture it after their commit guard. The separate previousEntry remains the lifecycle-selected merge/provenance input.
Findings None None.
Security None None.

How this fits together

OpenClaw’s session storage receives conversation updates and persists metadata and transcripts in SQLite. These operations feed subsequent session reads, Goal controls, and child conversations.

flowchart TD
  A[Compaction, Goal edit, or parent fork] --> B[Existing session operation owner]
  B --> C[Check authority and read current state]
  C --> D[Reuse canonical session snapshot]
  D --> E[Existing SQLite entry writer]
  E --> F[Commit state and publish results]
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source +9, Tests +183. Total +192 across 6 files.

View PR surface stats
Area Files Added Removed Net
Source 3 12 3 +9
Tests 3 217 34 +183
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 6 229 37 +192

Review metrics

Metric Value Why it matters
Measured Goal-edit payload 264,539 → 198,406 TEXT bytes The reported owner-flow measurement demonstrates reduced materialization with a 64-KiB saved prompt, without claiming lower latency.

Technical review

Best possible solution:

Keep canonical snapshot reuse inside the existing transaction owners, preserving validation, callback ordering, and the separate provenance inputs.

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

Not applicable as a functional bug report; source confirms redundant hydration, and the recorded before/after owner measurements quantify it. This review did not execute tests.

Is this the best way to solve the issue?

Yes. Passing freshly captured canonical entries through an existing writer option is a narrow solution that avoids introducing another cache or persistence owner.

AGENTS.md: found and applied where relevant.

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

Labels

Label justifications:

  • P2: This is a bounded session-storage efficiency improvement with measured savings and no intended user-visible behavior change.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🦞 diamond lobster.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (live_output): Recorded real SQLite owner-flow measurements exercise compaction, Goal mutation, and parent fork/skip operations and show fewer executions, rows, and payload bytes with preserved rollback and reopened state. The body retains the pre-refresh proof with unchanged production bytes; focused tests and reviewed-head CI supplement it.
  • proof: sufficient: Contributor real behavior proof is sufficient. Recorded real SQLite owner-flow measurements exercise compaction, Goal mutation, and parent fork/skip operations and show fewer executions, rows, and payload bytes with preserved rollback and reopened state. The body retains the pre-refresh proof with unchanged production bytes; focused tests and reviewed-head CI supplement it.

Evidence

What I checked:

Likely related people:

  • unknown: The claimed source-line change could not be verified from bounded local history. (role: source history unknown; confidence: low)
  • Peter Steinberger: Raw commit 3648942 adds src/config/sessions/session-accessor.sqlite-compaction.ts:42 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 3648942f0fc6; files: src/config/sessions/session-accessor.sqlite-compaction.ts)

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 (3 earlier review cycles)
  • reviewed 2026-09-16T00:15:39.117Z sha 969cb58 :: needs maintainer review before merge. :: none
  • reviewed 2026-09-16T01:13:17.938Z sha 969cb58 :: needs maintainer review before merge. :: none
  • reviewed 2026-09-16T04:05:22.228Z sha 679287b :: needs maintainer review before merge. :: none

@openclaw-barnacle openclaw-barnacle Bot added size: S maintainer Maintainer-authored PR labels Sep 16, 2026
@clawsweeper clawsweeper Bot added 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. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Sep 16, 2026
@steipete steipete changed the title improve(sessions): reduce repeated compaction reads improve(sessions): reduce repeated reads during session updates Sep 16, 2026
@steipete
steipete merged commit 3af348c into main Sep 16, 2026
211 checks passed
@steipete
steipete deleted the codex/sqlite-compaction-entry-reuse-0915 branch September 16, 2026 04:28
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

steipete added a commit that referenced this pull request Sep 16, 2026
Reuse the entry already read in the current write transaction when capturing
previous session identity. Preserve the other lookup keys, current authority
checks, post-write identity reads, and canonical certification.

This resolves the interaction between #149537 and #149388 without changing the
existing query budget. The unchanged test reproduces on their combined main
state; all 38 Goal, identity, and canonical-validation tests pass after repair.
steipete added a commit that referenced this pull request Sep 16, 2026
* fix(cron): normalize current-session completion payloads

* fix(cron): account for completed interim retry prompts

* fix(cron): preserve final context after retry accounting

* refactor(cron): centralize stale delivery policy

* fix(cron): clear stale billing after context-only retries

* fix(sessions): reuse the admitted entry during Goal edits

Reuse the entry already read in the current write transaction when capturing
previous session identity. Preserve the other lookup keys, current authority
checks, post-write identity reads, and canonical certification.

This resolves the interaction between #149537 and #149388 without changing the
existing query budget. The unchanged test reproduces on their combined main
state; all 38 Goal, identity, and canonical-validation tests pass after repair.

* refactor(ui): simplify chat pane callbacks

Keep the existing progress-dismiss and agent-change callbacks as explicit void expressions, preserving their undefined returns and side effects. This brings the renderer back within its existing max-lines limit after #149384 without changing UI behavior.

* fix(ci): accept file paths in extension packing fixtures
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 17, 2026
…claw#149537)

* perf(sessions): reuse validated entry during compaction

* perf(sessions): reuse captured entries for goals and parent forks

---------

Co-authored-by: Peter Steinberger <[email protected]>
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 17, 2026
…49697)

* fix(cron): normalize current-session completion payloads

* fix(cron): account for completed interim retry prompts

* fix(cron): preserve final context after retry accounting

* refactor(cron): centralize stale delivery policy

* fix(cron): clear stale billing after context-only retries

* fix(sessions): reuse the admitted entry during Goal edits

Reuse the entry already read in the current write transaction when capturing
previous session identity. Preserve the other lookup keys, current authority
checks, post-write identity reads, and canonical certification.

This resolves the interaction between openclaw#149537 and openclaw#149388 without changing the
existing query budget. The unchanged test reproduces on their combined main
state; all 38 Goal, identity, and canonical-validation tests pass after repair.

* refactor(ui): simplify chat pane callbacks

Keep the existing progress-dismiss and agent-change callbacks as explicit void expressions, preserving their undefined returns and side effects. This brings the renderer back within its existing max-lines limit after openclaw#149384 without changing UI behavior.

* fix(ci): accept file paths in extension packing fixtures
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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: M 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