Skip to content

fix(chat): faster, reliable older history and live updates - #128964

Merged
steipete merged 1 commit into
mainfrom
codex/faster-shared-chat-history
Aug 25, 2026
Merged

steipete merged 1 commit into
mainfrom
codex/faster-shared-chat-history

Conversation

@steipete

Copy link
Copy Markdown
Contributor

Related: #128844, #128810

What Problem This Solves

Fixes an issue where users paging backward through chat history could receive a 500 error, unnecessary transcript-wide reads, or inconsistent turn boundaries when newer unrelated transcript events were malformed or filtered. Long sessions containing many silent entries also performed repeated projection work across HTTP, server-sent events, WebSocket chat, and embedded history.

Why This Change Was Made

Read explicitly limited older pages through the existing indexed transcript scanner, using the authoritative logical display-sequence count to derive the bounded offset. Carry the already prepared display projection across the shared history boundary, grow sparse scans adaptively, and remove superseded projection and transcript-reader wrappers. Reset archives and events sharing a display sequence keep their existing semantics.

This is a follow-up to #128844 and #128810: the transcript remains the single source of truth. There are no transcript copies, new SQLite tables, schema-version changes, protocol changes, or configuration changes. Production code shrinks by 44 lines while regression coverage grows.

User Impact

Older chat pages load without traversing unrelated newer transcript content, HTTP and live event streams consistently preserve turn boundaries, and silent-entry-heavy history is substantially faster. A 4,040-entry representative sparse transcript drops from 41 projection passes and 83,640 projected rows to 13 passes and 25,620 rows, improving approximately 94 ms to 25 ms (about 3.7x faster).

Evidence

  • 659 tests passed against the current main baseline, including real listening Gateway HTTP, authenticated bearer access, revocation, WebSocket history, SSE streaming and refresh, reset archives, SQLite query plans, embedded-agent history, and the TUI.
  • The live HTTP regression first reproduces an older-page 500 by poisoning an unrelated newest SQLite transcript row, then proves the repaired owner returns 200 with the requested older page.
  • Real Gateway HTTP and SSE regressions both confirm filtered-heartbeat overread retains the same turn-boundary metadata.
  • Eight real Chromium browser suites passed all 46 history-recovery, session-management, geometry, disclosure, redaction, messaging, and streaming checks. Browser suites exercise the real UI with mocked Gateway transport; the listening-Gateway suites above exercise the real backend transports.
  • Independent structured review returned clean. Focused TypeScript, formatting, lint, dead-export, import-cycle, database-first, and unchanged-schema checks passed.
Production: +129/-173 (net -44)
Tests:      +167/-130 (net +37)
SQLite:     no new tables; no schema changes

@clawsweeper

clawsweeper Bot commented Aug 25, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

@openclaw-barnacle openclaw-barnacle Bot added gateway Gateway runtime size: L maintainer Maintainer-authored PR labels Aug 25, 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 Aug 25, 2026
@clawsweeper

clawsweeper Bot commented Aug 25, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed August 24, 2026, 9:59 PM ET / August 25, 2026, 01:59 UTC.

ClawSweeper review

What this changes

The PR bounds paginated HTTP and SSE chat-history reads, carries the shared display projection forward, and removes superseded projection wrappers.

Merge readiness

⚠️ Ready for maintainer review - 1 item remains

This PR remains necessary: current main still sends every limited cursor request through a full transcript read. The proposed shared bounded scanner covers that gap across HTTP and SSE; no blocking patch defect was found in the reviewed paths.

Priority: P2
Reviewed head: 33b732cbf48ed5d9e39477050ef25a27170aa008

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) The patch follows the existing transcript-reader contract, uses a shared owner boundary, and adds meaningful real-transport regression coverage.
Proof confidence 🌊 off-meta tidepool Not applicable: The PR is authored by a repository member, so the external-contributor proof gate does not apply; its body nevertheless describes real listening-Gateway HTTP and SSE regressions.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: The PR is authored by a repository member, so the external-contributor proof gate does not apply; its body nevertheless describes real listening-Gateway HTTP and SSE regressions.
Evidence reviewed 6 items Current-main gap: Current main bounds only the initial limited page; any cursor request leaves the bounded path and reads complete history.
Bounded cursor implementation: The PR converts the public display-sequence cursor to the transcript reader's newest-relative offset, then uses the same bounded scanner for the requested page.
Reader contract: The underlying page reader treats offset as newest-relative and exposes the logical total, matching the PR's cursor-to-offset calculation.
Findings None None.
Security None None.

Live Verification

Command: pnpm test src/gateway/sessions-history-http.test.ts --testNamePattern "supports cursor pagination over direct REST"

Result: FAIL (partial) — step 2 expect_output supports cursor pagination over direct REST: expected terminal output was not visible within 30 seconds: "supports cursor pagination over direct REST"

pnpm test src/gateway/sessions-history-http.test.ts --testNamePattern "supports cursor pagination over direct REST"
runner@runnervm76f27:/tmp/clawsweeper-live-proof-128964-rAb8Hr/target$ pnpm test src/gateway/sessions-history-http.test.ts --testNamePattern "supports cursor pa
gination over direct REST"
$ node --import tsx scripts/test-projects.mts src/gateway/sessions-history-http.test.ts --testNamePattern 'supports cursor pagination over direct REST'
pnpm test src/gateway/sessions-history-http.test.ts --testNamePattern "supports cursor pagination over direct REST"
[test] starting test/vitest/vitest.e2e.config.ts

 RUN  v4.1.10 /tmp/clawsweeper-live-proof-128964-rAb8Hr/target

[openclaw] Building TypeScript (dist is stale: missing_private_qa_dist - private QA dist entry missing).
[openclaw] Building bundled plugin assets.
[canvas] build: node scripts/bundle-a2ui.mjs
[diffs] build: node --import tsx ../../scripts/build-diffs-viewer-runtime.mts curated
[diffs-language-pack] build: node --import tsx ../../scripts/build-diffs-viewer-runtime.mts full
[discord] build: node --import tsx ../../scripts/build-discord-activity-sdk.mts
  - tsdown:deps (49%)
  - rolldown-plugin-dts:generate (21%)
  - rolldown-plugin-dts:fake-js (18%)
See https://rolldown.rs/reference/InputOptions.checks#plugintimings for more details.

[tsdown-build] invocation 1/11 finished in 4.4s
[tsdown-build] invocation 2/11 finished in 21.0s





























Assertions:

  • FAIL expect_output: supports cursor pagination over direct REST

How this fits together

Gateway history reads transcript events from the agent SQLite store, projects visible chat turns, and returns pages through HTTP, SSE, WebSocket, and embedded-chat paths. The changed shared scanner supplies the bounded raw window and display projection used by HTTP snapshots and SSE refreshes.

flowchart LR
  A[SQLite transcript events] --> B[Transcript reader]
  B --> C[Bounded history scanner]
  C --> D[Display projection]
  D --> E[HTTP history page]
  D --> F[SSE refresh]
  D --> G[Other chat transports]
Loading

Before merge

  • Complete next step (P2) - This active maintainer PR needs normal exact-head CI and merge review, not a separate automated repair lane.
Agent review details

Security

None.

PR surface

Source -44, Tests +37. Total -7 across 10 files.

View PR surface stats
Area Files Added Removed Net
Source 6 129 173 -44
Tests 4 167 130 +37
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 10 296 303 -7

Review metrics

Metric Value Why it matters
Production vs test delta production -44 net; tests +37 net The repair removes redundant production wrappers while adding boundary coverage for cursor pages, malformed newer rows, silent tails, and SSE.

Stored data model

Persistent data-model change detected: serialized state: src/gateway/session-history-state.test.ts, serialized state: src/gateway/session-history-state.ts, serialized state: src/gateway/session-history-tail.ts, serialized state: src/gateway/session-transcript-readers.ts, serialized state: src/gateway/sessions-history-http.test.ts, serialized state: src/gateway/sessions-history-http.ts, and 5 more. Confirm migration or upgrade compatibility proof before merge.

Root-cause cluster

Relationship: canonical
Canonical: #128964
Summary: This PR is the remaining bounded-cursor follow-up to the merged shared-history work.

Members:

Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything.

Technical review

Best possible solution:

Land the shared bounded cursor path after exact-head Gateway regressions and required CI are green, preserving the existing unbounded response only when no limit is requested.

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

Yes, from source: the focused HTTP regression creates an older cursor, corrupts an unrelated newer transcript row, and verifies the older page remains readable; it has not been executed in this read-only review.

Is this the best way to solve the issue?

Yes. Reusing the existing indexed transcript reader and one bounded display-projection flow is the narrowest owner-boundary repair; retaining the current full read for limited cursor pages would leave the reported scale and malformed-newer-row failure path intact.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 3c7143d65040.

Labels

Label changes:

  • add P2: The PR repairs Gateway chat-history pagination and live refresh behavior with a limited but user-visible blast radius.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: The PR is authored by a repository member, so the external-contributor proof gate does not apply; its body nevertheless describes real listening-Gateway HTTP and SSE regressions.

Label justifications:

  • P2: The PR repairs Gateway chat-history pagination and live refresh behavior with a limited but user-visible blast radius.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: The PR is authored by a repository member, so the external-contributor proof gate does not apply; its body nevertheless describes real listening-Gateway HTTP and SSE regressions.

Evidence

What I checked:

Likely related people:

  • steipete: Authored the merged bounded cross-transport history refactor and the current cursor-page follow-up. (role: feature owner and recent area contributor; confidence: high; commits: a99317ef97af, 33b732cbf48e; files: src/gateway/session-history-state.ts, src/gateway/session-history-tail.ts, src/gateway/sessions-history-http.ts)
  • Ayaan Zaidi: Recently maintained the shared chat-history projection behavior adjacent to the bounded scanner. (role: recent adjacent contributor; confidence: medium; commits: 5238648a3b8e; files: src/gateway/session-history-state.ts, src/gateway/session-history-tail.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.

@steipete
steipete merged commit 110b747 into main Aug 25, 2026
243 checks passed
@steipete
steipete deleted the codex/faster-shared-chat-history branch August 25, 2026 02:18
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

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. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: L 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