Skip to content

perf(chat): bound history pages and reuse recovery cursors - #165897

Merged
steipete merged 1 commit into
mainfrom
steipete/perf-micro-chat-history-page-bytes-20260919
Oct 6, 2026
Merged

steipete merged 1 commit into
mainfrom
steipete/perf-micro-chat-history-page-bytes-20260919

Conversation

@steipete

@steipete steipete commented Oct 6, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Chat history recovery and backscroll can repeatedly transfer multi-megabyte pages, including history the caller already checked.

User Impact

Ordinary history pages are smaller, and repeated outbox delivery checks resume from the existing transcript cursor. Transcript storage and visible UI behavior are unchanged; older messages remain available through pagination. No new configuration or protocol version.

Why This Change Was Made

The previous default allowed 1,000-entry requests to return roughly 4.7 MB. Initial chat loads already request a smaller budget and ordinary refreshes already use a delta cursor, but outbox recovery requested a full page on every check, including its second idle verification.

Use a 512 KiB default response target for ordinary pages and deltas, preserving the existing 6 MiB hard ceiling. Source-row projections stay together because numeric offsets cannot resume within one row. Anchored reads keep their previous budget because they have no continuation, and error-recovery lookahead retains its existing read budget independently of response sizing.

The outbox owner now retains the existing revision-backed cursor for the exact connection, scope, physical session and queued submission version. Every request still reads fresh session state and input custody. Resets clear the watermark before fetching a new tail. Legacy submissions without exact receipts search the former 1,000-message / 6 MiB message-and-activity window before accepting a negative tail cursor. Shared history reconciliation preserves distinct projected siblings across page overlaps; the temporary inspected window is bounded.

Production LOC: +291 net (+352 / −61), excluding tests and docs. Growth preserves concrete existing contracts: raw-row numeric cursor compatibility; legacy delivery proof outside the smaller first page; and connection/submission/session invalidation. The unconditional full-page reader is replaced, not retained as a competing path. Existing host reconciliation moves into its projection module to keep the outbox owner within its line cap.

Evidence

The staged gate passed on the authorized Linux rig after Testbox admission exceeded 20 minutes. Measurements passed on that rig. Current-head focused validation passed on Blacksmith Testbox tbx_01m47dk1eefxqtfm3pfa5v46ez, provider blacksmith-testbox, profile openclaw-check. The synthetic rig uses 640 messages of roughly 7 KB each, the real history handler and storage workers, Gateway frame serializer and a loopback WebSocket, with nine warm measured calls per variant. Baseline and candidate use the same checkout base.

Linux rig, Node 26.8.1: 40 warmups for each path, then nine measured samples per variant; candidate ran before baseline. Main-thread CPU uses process.threadCpuUsage(), and its total is the median of per-call phase sums.

Measurement Original full page Bounded full page Repeated cursor read
Response bytes 4,633,114 522,667 1,245
Assembly elapsed time 91.57 ms 206.06 ms 33.90 ms
Frame serialization elapsed time 0.70 ms 0.35 ms 0.17 ms
Synchronous WebSocket send elapsed time 1.37 ms 0.63 ms 0.36 ms
Main-thread CPU: assembly + frame + send 9.56 ms 8.74 ms 8.49 ms

Every sampled full frame had exactly the listed byte count. Full pages were 88.7% smaller and unchanged refetches avoided 99.97% of the bytes. The unchanged cursor response already existed; the outbox now uses it. The shared rig showed substantial elapsed-time and scheduling variation between passes, so no latency improvement is claimed. Direct main-thread CPU improved only about 8.6% for full pages / 11.3% for repeats in this run: the 80% main-thread target is not established.

Focused Testbox validation passed 228 tests in eight files, plus three expected failing negative controls, in 3m19s total command time. The run verified all 14 source hashes against the published head before execution and after restoring the controls. Restoring the smaller read budget lost anchored siblings and exposed a recovered error; ignoring activity bytes inspected 18,941,250 bytes instead of staying within the bounded fixture window.

Costs for changed test files, each run as pnpm test <file> --maxWorkers=1:

File Passed Wall time Reported test execution
ui/src/pages/chat/chat-outbox-transient-recovery.test.ts 26 5.41 s 0.118 s
src/gateway/server-methods/chat-history-request-budget.test.ts 5 47.20 s 15.937 s
src/gateway/server-methods/chat-history-pages.test.ts 5 10.30 s 0.061 s

The RPC/worker budget tests exercise real storage, projection and serialization because helper-only checks cannot detect the paging and recovery regressions. The remaining 192 tests cover chat send, pending-input pagination, send deadlines, history cursors and history-worker errors via node scripts/run-vitest.mjs <focused files> --maxWorkers=1. These costs are measured on Testbox; hosted CI test costs are unavailable because the dependency audit cancelled that run.

Independent Codex review: scoped-clean through P2. node scripts/check-changed.mjs --staged passed on the Linux rig (exit 0, approximately 64 minutes), including all 27 core-test type graphs, UI/core typechecks, dead-code scans, changed-file lint and source/storage guards. The native command suppresses its timing table on success unless --timed is set; no checks were repeated merely to produce a table. No focused validation remains pending.

Hosted CI blocker: run 37399958211 failed security-fast / Audit production dependencies on GHSA-68fv-2mgg-jv7q, which flags source-map-js >=1.0.0 <1.2.2. The failure cancelled the other CI lanes. This PR changes no dependency files; verified main 381b1e05d7f0fa572fdf085e7714d4f90864d4b5 still pins [email protected], and its lockfile blob is identical to this branch (5ef4235547392dcc35175fecd449052fb0c6dbaf). The dependency owner needs to land the fix on main, after which this branch can rebase. No audit exception or dependency change is included here.

Limits: the same ordinary workload meets the <1 MB page and <2 KB unchanged targets. An indivisible projected group or anchored request can still exceed 1 MB under the preserved hard ceiling. JSON encoding already runs in a worker; authorization, session and receipt work remains per request. The measurements do not establish the 80% main-thread target.

A bounded 50-minute read-only production log sample contained 41 responses above 2 MB (182.7 MB total), including six responses of exactly 4,597,151 bytes on one uninterrupted Control UI connection. That sample does not reconcile the campaign aggregate of 120. Production logs omit history parameters and session keys. Repeated identical page sizes on an uninterrupted connection are consistent with outbox recovery, but exact session/caller attribution remains unproven. No production deployment is included.

Use a smaller response target without shortening history recovery reads or
splitting readable source-row projections. Reuse existing transcript cursors
for outbox recovery while preserving fresh custody and legacy delivery proof.

The synthetic full page drops from 4,633,114 to 522,667 bytes; unchanged
refetches return 1,245 bytes. The 80% main-thread target is not established.
@clawsweeper

clawsweeper Bot commented Oct 6, 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 October 6, 2026 01:35
@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation app: web-ui App: web-ui gateway Gateway runtime labels Oct 6, 2026
@steipete
steipete enabled auto-merge (squash) October 6, 2026 01:40
@steipete
steipete merged commit 50f38c6 into main Oct 6, 2026
164 of 207 checks passed
@steipete
steipete deleted the steipete/perf-micro-chat-history-page-bytes-20260919 branch October 6, 2026 01:46
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 6, 2026
…165897)

Use a smaller response target without shortening history recovery reads or
splitting readable source-row projections. Reuse existing transcript cursors
for outbox recovery while preserving fresh custody and legacy delivery proof.

The synthetic full page drops from 4,633,114 to 522,667 bytes; unchanged
refetches return 1,245 bytes. The 80% main-thread target is not established.
steipete added a commit that referenced this pull request Oct 6, 2026
50f38c6 (#165897) intentionally changed ordinary history responses to
a 512 KiB target and documented continuation through nextOffset. The old
single-request assertion measured scrolling through all 900 messages under
the previous 6 MiB policy from #152979; it did not measure opening a chat.

Match older requests to committed pagination steps, check contiguous
coverage and bounded nonempty responses, and allow at most one staged
successor. Assert that all three startup samples issue no older-history
requests. Preserve the ordered transcript, initial-tail, identity, Home,
avatar, and cache assertions.

The real Gateway reproduces the old failure with eight requests for eight
backscroll steps. Startup remains one reply with 59 messages and 260,813 history bytes. The
updated file passes locally, as do type-aware/boundary lint, its test-type
graph, formatting, full local check-changed, and independent P2 review. No production or dependency
changes; security-fast's source-map-js advisory (#165918) is inherited.

Testbox-congestion exception: the lease timed out after 15 minutes queued,
before sync or execution. Use the authorized ready-PR fallback; three
Linux real-Gateway runs and the complete owning UI e2e config remain unrun.
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 7, 2026
815d4c3 (openclaw#165897) intentionally changed ordinary history responses to
a 512 KiB target and documented continuation through nextOffset. The old
single-request assertion measured scrolling through all 900 messages under
the previous 6 MiB policy from openclaw#152979; it did not measure opening a chat.

Match older requests to committed pagination steps, check contiguous
coverage and bounded nonempty responses, and allow at most one staged
successor. Assert that all three startup samples issue no older-history
requests. Preserve the ordered transcript, initial-tail, identity, Home,
avatar, and cache assertions.

The real Gateway reproduces the old failure with eight requests for eight
backscroll steps. Startup remains one reply with 59 messages and 260,813 history bytes. The
updated file passes locally, as do type-aware/boundary lint, its test-type
graph, formatting, full local check-changed, and independent P2 review. No production or dependency
changes; security-fast's source-map-js advisory (openclaw#165918) is inherited.

Testbox-congestion exception: the lease timed out after 15 minutes queued,
before sync or execution. Use the authorized ready-PR fallback; three
Linux real-Gateway runs and the complete owning UI e2e config remain unrun.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

app: web-ui App: web-ui docs Improvements or additions to documentation gateway Gateway runtime size: XL

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant