Skip to content

perf(sessions): bound history reads and stabilize cursor paging - #146770

Merged
steipete merged 1 commit into
mainfrom
codex/session-history-window-reads
Sep 13, 2026
Merged

steipete merged 1 commit into
mainfrom
codex/session-history-window-reads

Conversation

@steipete

@steipete steipete commented Sep 13, 2026 •

Copy link
Copy Markdown
Contributor

Related: #146607

What Problem This Solves

Session-history polling and recovery repeat SQLite work and decode discarded rows, while concurrent appends, branch changes, or resets can invalidate cursor pages.

User Impact

History polling does less work, recovery reads fewer payloads, and cursor pages remain consistent during concurrent history changes. Existing retryable projection errors reject changed continuation windows. No migration or operator action is required.

Why This Change Was Made

Directional reads now request only the required neighbors through shared SQLite/archive range logic. Display deltas reuse their validated snapshot and skip history reconstruction when no events were selected. Cursor selection and the initial page share one snapshot; later reads retain the original upper boundary and validate the source, reset, and newest selected row before loading payloads.

The same recent-read owner preserves byte limits and oversized-newest behavior for cursors at the head, without an extra payload probe. Duplicate range/projection logic and per-row temporary arrays were removed.

Empty or byte-blocked deltas intentionally no longer validate unrelated historical marker/reset payloads. Requested payload errors and admission fences remain enforced. No schema, retention, durability, or public RPC fields change.

Evidence

The guarded recovery tail decoded 694 → 350 payloads and took 5.184 → 4.041 ms (22% less time), including four additional continuity queries. Marker-heavy idle polling returned 1,003 → 1 SQLite rows and took 4.782 → 0.019 ms. Interior SSE paging used 13 → 7 statements with identical payloads.

These are warm synthetic measurements on Node 24.21.0 / SQLite 3.53.4 against bd002c80a15f01cc3ecc37401d4599f5e8d092bf: same process and canonical SQLite owner, 13 frozen baseline modules, shared unchanged dependencies, 100 warmups, and 32 alternating batches of 50 reads. Times below are medians of per-read batch averages, not individual-request percentiles. The 2,000-message full-reader guard used 3 warmups and 12 single-read rounds. Measurements use this fixed base; the history implementation and recorded source hashes remain unchanged after refreshing onto main.

Controls were roughly flat: centered-anchor median time/CPU increased 5%/7%, and several upper batch quantiles worsened. Nonempty marker-heavy delta CPU was unchanged despite fewer statements. These results do not establish cold-open, whole-RPC/browser, or universal tail-latency improvements.

All paired measurements (baseline → candidate)
Case Median ms/read SQLite read statements Decoded payloads
recent-control 0.343 → 0.353 8 → 8 20 → 20
page-control 0.251 → 0.244 8 → 8 20 → 20
full-reader-2000-guard 9.133 → 6.638 7 → 7 2000 → 2000
tail-ordinary-control 0.672 → 0.651 8 → 8 61 → 61
anchor-centered 0.791 → 0.834 8 → 8 203 → 203
anchor-older 0.930 → 0.562 8 → 8 203 → 102
anchor-newer 1.015 → 0.606 8 → 8 203 → 102
anchor-older-at-start 0.900 → 0.186 8 → 8 202 → 7
anchor-newer-at-end 0.872 → 0.168 8 → 8 203 → 6
anchor-historical-centered-first 2.161 → 2.209 14 → 13 201 → 201
anchor-historical-older 2.074 → 1.827 14 → 14 202 → 101
anchor-historical-newer 2.170 → 1.707 14 → 13 202 → 101
recovery-context 3.575 → 2.643 24 → 24 609 → 306
recovery-tail-with-continuity 5.184 → 4.041 39 → 43 694 → 350
display-delta-ordinary-nonempty 0.140 → 0.115 7 → 4 20 → 20
display-delta-ordinary-empty 0.055 → 0.019 5 → 1 0 → 0
display-delta-ordinary-byte-blocked 0.071 → 0.045 5 → 2 0 → 0
raw-delta-empty 0.038 → 0.027 4 → 3 0 → 0
display-delta-markers-nonempty 5.523 → 5.247 9 → 6 20 → 20
display-delta-markers-empty 4.782 → 0.019 6 → 1 0 → 0
display-delta-markers-byte-blocked 4.627 → 0.044 6 → 2 0 → 0
sse-interior-cursor 0.451 → 0.286 13 → 7 21 → 21
sse-past-head-cursor 4.080 → 3.730 14 → 8 421 → 421

Directional cases compare identical retained neighbors with the former centered-read-and-slice path; centered public anchor behavior is unchanged. Ordinary and recovery-tail outputs match except for the explicitly validated private read-window metadata. Past-head SSE decodes exactly the same 421 payloads, with no extra probe.

Error probes verify the same requested malformed-JSON failure and required-byte hint, and that an oversized newest message excludes malformed older JSON while decoding exactly one payload on both implementations.

@clawsweeper

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

@openclaw-barnacle openclaw-barnacle Bot added gateway Gateway runtime size: XL maintainer Maintainer-authored PR labels Sep 13, 2026
@steipete
steipete marked this pull request as ready for review September 13, 2026 05:36
@steipete
steipete requested a review from a team as a code owner September 13, 2026 05:36
@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 13, 2026
@clawsweeper

clawsweeper Bot commented Sep 13, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed September 13, 2026, 5:52 AM ET / 09:52 UTC (Revision 7).

ClawSweeper review

What this changes

Session-history reads reuse SQLite snapshots, fetch only needed neighboring messages, and validate page continuity across concurrent transcript changes.

Merge readiness

✅ Ready for maintainer review

The PR remains useful: current main still computes cursor offsets separately from page selection. No blocking defect was found, and the current diff plus compatibility discussion resolve the previous migration concern.

Priority: P2
Reviewed head: 3f5b482f329aeab5a52efe549be1752e569471f0

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused owner-level repair with useful actual-reader measurements, substantial regression coverage, and no identified blocking defect.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (live_output): Recorded paired runs exercise the actual SQLite history and Gateway-tail owners with unchanged output checks, error probes, and measured reductions in decoded payloads and returned rows. The evidence supports the bounded backend claims; tests provide additional race coverage.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (live_output): Recorded paired runs exercise the actual SQLite history and Gateway-tail owners with unchanged output checks, error probes, and measured reductions in decoded payloads and returned rows. The evidence supports the bounded backend claims; tests provide additional race coverage.
Evidence reviewed 8 items Verified patch boundary: The test merge records the pinned main commit followed by the exact PR head as its parents. Its changes against main contain only the supplied session-history paths; the profiler, sidebar, and other base-only changes are not introduced by this PR.
Current main still needs the cursor repair: Current main reads totalMessages, calculates an offset, and subsequently awaits the tail read. The candidate instead passes beforeSeq into page selection and retains the selected snapshot boundary for continuation.
Continuity metadata is transient: TranscriptReadWindow contains source, reset boundary, and anchor coordinates. Its inspected production callers pass these facts between history reads; no persistence, schema installer, public RPC envelope, or configuration writer is changed.
Findings None None.
Security None None.

How this fits together

The Gateway reads session transcripts from SQLite or retained archives, then projects them into chat-history pages and streaming updates. These readers determine which messages clients receive while conversations continue changing.

flowchart TD
  A[History request and cursor] --> B[Gateway history reader]
  B --> C[SQLite snapshot or archive]
  C --> D[Bounded page selection]
  D --> E[Continuation validation]
  E --> F[Chat display projection]
  F --> G[History page or stream update]
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source +294, Tests +676. Total +970 across 21 files.

View PR surface stats
Area Files Added Removed Net
Source 12 679 385 +294
Tests 9 729 53 +676
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 21 1408 438 +970

Review metrics

Metric Value Why it matters
Production versus regression coverage Production net +294 lines; tests and support net +676 lines Production growth supports shared range selection and continuity validation, with most net growth devoted to regression coverage.
Public and persistent surface 0 new configuration keys, public RPC fields, or schema changes The continuation facts stay within a logical read and require no state migration.

Technical review

Best possible solution:

Keep bounded selection and continuity checks in the existing transcript readers while preserving archive behavior, byte limits, and public cursor semantics.

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

Yes, from source: current main separates cursor offset calculation from page selection, allowing intervening appends to shift the window. The storage-backed race cases exercise that boundary; this review did not execute them.

Is this the best way to solve the issue?

Yes. Reusing the validated snapshot and existing recent-read owner addresses the race and redundant work without adding a parallel reader or changing persistent contracts.

AGENTS.md: found and applied where relevant.

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

Labels

Label justifications:

  • P2: This is a bounded history-performance and paging-correctness improvement without evidence of an urgent production outage.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🦞 diamond lobster 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): Recorded paired runs exercise the actual SQLite history and Gateway-tail owners with unchanged output checks, error probes, and measured reductions in decoded payloads and returned rows. The evidence supports the bounded backend claims; tests provide additional race coverage.
  • proof: sufficient: Contributor real behavior proof is sufficient. Recorded paired runs exercise the actual SQLite history and Gateway-tail owners with unchanged output checks, error probes, and measured reductions in decoded payloads and returned rows. The evidence supports the bounded backend claims; tests provide additional race coverage.

Evidence

What I checked:

  • Verified patch boundary: The test merge records the pinned main commit followed by the exact PR head as its parents. Its changes against main contain only the supplied session-history paths; the profiler, sidebar, and other base-only changes are not introduced by this PR. (197eefbbf0b2)
  • Current main still needs the cursor repair: Current main reads totalMessages, calculates an offset, and subsequently awaits the tail read. The candidate instead passes beforeSeq into page selection and retains the selected snapshot boundary for continuation. (src/gateway/session-history-state.ts:94, a8a9114fb787)
  • Continuity metadata is transient: TranscriptReadWindow contains source, reset boundary, and anchor coordinates. Its inspected production callers pass these facts between history reads; no persistence, schema installer, public RPC envelope, or configuration writer is changed. (src/sessions/transcript-read-window.ts:1, 3f5b482f329a)
  • Compatibility concern resolved: The maintainer compatibility statement at perf(sessions): bound history reads and stabilize cursor paging #146770 (comment) explicitly addresses schemas, defaults, archives, ID-less rows, configured stores, and read fences. Source inspection agrees that this is a query/read-continuity change without a stored-data migration. The storage guide exempts bounded read-only query improvements that preserve persistent contracts. Public docs: docs/reference/database-schemas/storage-changes.md. (docs/reference/database-schemas/storage-changes.md, 3f5b482f329a)
  • Production-boundary regression coverage: The added tests invoke SessionHistorySseState and canonical SQLite readers while injecting appends, equal-length branch changes, and resets between reads. Separate coverage preserves archive paging, ID-less rows, multi-page recovery, and oversized-newest byte limits. Tests were inspected, not executed during this read-only review. (src/gateway/session-history-reads.test.ts:24, 3f5b482f329a)
  • Recorded actual-reader measurements: The supplied PR body, captured under sourceRevision 5b98596adb9288f62fc49786ed82d859d6f0abdb78933eaaa9500fac0271ef3e, reports 23 paired actual-reader cases on Node 24.21.0 and SQLite 3.53.4. Recovery decoded 694 versus 350 payloads; marker-heavy idle polling returned 1,003 versus 1 rows. Output equality and error probes accompany the measurements. These are warm synthetic backend results, not whole-browser latency claims. The prepared image manifest references the related Browser-dashboard PR and is not evidence for these history changes. (3f5b482f329a)

Likely related people:

  • steipete: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • jalehman: 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.

History

Review history (6 earlier review cycles)
  • reviewed 2026-09-13T06:07:25.339Z sha 1dd06950bd952fa5d43d4b9d6d125eb2798ef437 :: blocked before merge. :: none
  • reviewed 2026-09-13T06:36:49.636Z sha ad71bf9d0bd3506c97c95b862d78cafacecebade :: blocked before merge. :: none
  • reviewed 2026-09-13T07:03:41.592Z sha 4f44b8664886eb79cb193bdf3c56ad4ee265c28e :: blocked before merge. :: none
  • reviewed 2026-09-13T07:36:58.244Z sha 4f44b8664886eb79cb193bdf3c56ad4ee265c28e :: blocked before merge. :: none
  • reviewed 2026-09-13T08:09:53.951Z sha b639d761c2a9369c1d9835078751de2245158776 :: blocked before merge. :: none
  • reviewed 2026-09-13T08:31:26.112Z sha 7ae1a2d29eb75c8f57ed8dbad7110441bebb0da4 :: blocked before merge. :: none

@openclaw-barnacle openclaw-barnacle Bot added the scripts Repository scripts label Sep 13, 2026
@steipete

steipete commented Sep 13, 2026 •

Copy link
Copy Markdown
Contributor Author

Maintainer compatibility review is complete. The final diff adds no runtime configuration keys, changes no defaults, and changes no SQLite schema, retention policy, transcript format, or public RPC field. Existing archive, reset-window, ID-less transcript, configured-store, and read-fence behavior is covered by the recorded tests. No state migration or operator action is needed.

The continuation metadata is transient read state. It validates the selected source, reset boundary, and original newest row during one logical history read; it is neither persisted nor added to public RPC envelopes.

All temporary CI and profiler prerequisites were dropped after the canonical repairs landed on main (#146702/#146672, #146862/#146803, and #146861). This PR now changes only session-history code and tests. Its 21 files and all 14 recorded benchmark hashes remain unchanged. Current CI and integration evidence are in the PR body.

@steipete
steipete force-pushed the codex/session-history-window-reads branch 2 times, most recently from 4f44b86 to b639d76 Compare September 13, 2026 08:02
@openclaw-barnacle openclaw-barnacle Bot added the app: web-ui App: web-ui label Sep 13, 2026
@steipete
steipete force-pushed the codex/session-history-window-reads branch from 7ae1a2d to a69b75f Compare September 13, 2026 08:51
@openclaw-barnacle openclaw-barnacle Bot removed the app: web-ui App: web-ui label Sep 13, 2026
Reuse validated delta snapshots, share directional range selection, and avoid decoding discarded recovery neighbors. Keep cursor selection in the page snapshot and validate continuation windows across branch or reset changes.

Validated with 279 focused tests, affected type and lint checks, independent P2 review, and 23 paired benchmark cases. Guarded recovery decoded 694 to 350 payloads and took 22% less time in warm synthetic measurements.
@steipete
steipete force-pushed the codex/session-history-window-reads branch from 49c14e8 to 3f5b482 Compare September 13, 2026 09:44
@openclaw-barnacle openclaw-barnacle Bot removed the scripts Repository scripts label Sep 13, 2026
@steipete steipete changed the title improve: bound history reads and stabilize cursor paging perf(sessions): bound history reads and stabilize cursor paging Sep 13, 2026
@steipete
steipete merged commit 0ee3503 into main Sep 13, 2026
194 of 195 checks passed
@steipete
steipete deleted the codex/session-history-window-reads branch September 13, 2026 10:06
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

vincentkoc added a commit that referenced this pull request Sep 13, 2026
* refs/heads/temp/pr-146883: (159 commits)
  fix: retain route ownership while discovering conversations (#146927)
  refactor: reuse plugin fixture shell runner (#146920)
  fix(worker): stop preparing disabled live previews (#146896)
  fix(runtime): support Bun across tooling suite (#146807)
  chore(i18n): refresh native locales (#146924)
  perf(secrets): limit expiry metadata to transient credentials (#146882)
  fix(ui): preserve queued refreshes during session discovery (#146535)
  test(ui): wait for quiet scrolling and close named file tabs (#146836)
  fix(ui): prevent Usage hour filters from freezing during DST (#146919)
  test(ui): share browser page cleanup across layout fixtures (#146805)
  ci: balance complete PR runtime test groups (#146916)
  improve(infra): reduce scheduling work for session notice bursts (#146818)
  improve: prepare Gateway skill commands asynchronously (#146812)
  improve(agents): skip unused assistant delivery parsing (#146858)
  improve(ui): reuse date formatters across timestamp lists (#146789)
  fix(tests): isolate installer and Docker shell snippets (#146897)
  test(heartbeat): share explicit channel configuration fixtures (#146853)
  fix: retain conversation reply claims through write admission (#146866)
  perf(sessions): bound history reads and stabilize cursor paging (#146770)
  fix(ui): let slow dashboard downloads finish before recovery (#146881)
  ...
vincentkoc added a commit that referenced this pull request Sep 13, 2026
* refs/heads/temp/pr-146833: (43 commits)
  fix(memory): preserve newer indexes and disclose automatic rebuild costs (#146908)
  fix: retain route ownership while discovering conversations (#146927)
  refactor: reuse plugin fixture shell runner (#146920)
  fix(worker): stop preparing disabled live previews (#146896)
  fix(runtime): support Bun across tooling suite (#146807)
  chore(i18n): refresh native locales (#146924)
  perf(secrets): limit expiry metadata to transient credentials (#146882)
  fix(ui): preserve queued refreshes during session discovery (#146535)
  test(ui): wait for quiet scrolling and close named file tabs (#146836)
  fix(ui): prevent Usage hour filters from freezing during DST (#146919)
  test(ui): share browser page cleanup across layout fixtures (#146805)
  ci: balance complete PR runtime test groups (#146916)
  improve(infra): reduce scheduling work for session notice bursts (#146818)
  improve: prepare Gateway skill commands asynchronously (#146812)
  improve(agents): skip unused assistant delivery parsing (#146858)
  improve(ui): reuse date formatters across timestamp lists (#146789)
  fix(tests): isolate installer and Docker shell snippets (#146897)
  test(heartbeat): share explicit channel configuration fixtures (#146853)
  fix: retain conversation reply claims through write admission (#146866)
  perf(sessions): bound history reads and stabilize cursor paging (#146770)
  ...
vincentkoc added a commit that referenced this pull request Sep 13, 2026
…ssion-list-roster-batch-20260913

* commit 'f513c0f345f7f2514c49ccfbc00adc3f78b9a755': (46 commits)
  chore(i18n): refresh native locales (#146924)
  perf(secrets): limit expiry metadata to transient credentials (#146882)
  fix(ui): preserve queued refreshes during session discovery (#146535)
  test(ui): wait for quiet scrolling and close named file tabs (#146836)
  fix(ui): prevent Usage hour filters from freezing during DST (#146919)
  test(ui): share browser page cleanup across layout fixtures (#146805)
  ci: balance complete PR runtime test groups (#146916)
  improve(infra): reduce scheduling work for session notice bursts (#146818)
  improve: prepare Gateway skill commands asynchronously (#146812)
  improve(agents): skip unused assistant delivery parsing (#146858)
  improve(ui): reuse date formatters across timestamp lists (#146789)
  fix(tests): isolate installer and Docker shell snippets (#146897)
  test(heartbeat): share explicit channel configuration fixtures (#146853)
  fix: retain conversation reply claims through write admission (#146866)
  perf(sessions): bound history reads and stabilize cursor paging (#146770)
  fix(ui): let slow dashboard downloads finish before recovery (#146881)
  fix: share Doctor lifecycle coordination with SQLite workers (#146714)
  fix: retain native session model provenance (#146801)
  fix: settle embedded transcript repairs before session cleanup (#146842)
  feat(macos): improve agent navigation and chat layout (#146531)
  ...
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 14, 2026
…claw#146770)

Reuse validated delta snapshots, share directional range selection, and avoid decoding discarded recovery neighbors. Keep cursor selection in the page snapshot and validate continuation windows across branch or reset changes.

Validated with 279 focused tests, affected type and lint checks, independent P2 review, and 23 paired benchmark cases. Guarded recovery decoded 694 to 350 payloads and took 22% less time in warm synthetic measurements.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

gateway Gateway runtime 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: XL 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