Skip to content

improve(gateway): load session history faster without duplicate readers - #129114

Merged
steipete merged 2 commits into
mainfrom
codex/session-history-owner-cleanup
Aug 25, 2026
Merged

steipete merged 2 commits into
mainfrom
codex/session-history-owner-cleanup

Conversation

@steipete

@steipete steipete commented Aug 25, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Resolves a problem where long conversations did unnecessary work every time users opened or paged session history, while duplicate HTTP, SSE, and SQLite reader implementations made reset handling, sparse histories, and future changes harder to keep consistent.

Why This Change Was Made

History now has one Gateway-owned raw-snapshot path for REST and SSE, one canonical transcript reader for array/source reads, and one supported SQLite history lookup/anchor implementation. Ordinary conversations reuse the existing authoritative event/message counters to skip impossible compaction/reset scans. No SQLite tables, indexes, schema versions, persisted projections, or transcript copies are added.

The change removes 204 production lines and 84 test lines. Existing reset archives, cursor pagination, compaction markers, heartbeat boundaries, hidden-message backfill, SSE streaming, authorization, and complete-history requests keep their current contracts.

User Impact

Session history opens and pages faster without storing duplicate messages. On the existing 816 MiB database containing 1,361,203 transcript events, a 50-message page from a million-message session improved from 0.436 ms to 0.235 ms, approximately 1.9 times faster, and remains effectively constant across 1,000 to 1,000,000 messages.

Evidence

  • 223 focused tests passed across live listening Gateway HTTP/SSE flows, REST pagination, reset archives, branch rebuilds, sparse hidden-message backfill, SQL query plans, and a 100,000-message SQLite fixture.
  • The existing lightweight 128-transcript-row SQLite smoke benchmark remains fast and reports approximately 0.050 ms query p95 with database integrity intact.
  • Production typecheck, both affected config/Gateway test typecheck shards, targeted lint, dead-export scan, schema-version guard, database-first guard, runtime-sidecar guard, import-cycle check, and independent structured review passed.
  • The unrelated whole-tree test typecheck on this linked checkout encounters an existing Control UI dependency mismatch: main requests pako 3.0.1 while the shared local dependency tree resolves an untyped pako 1.0.11. Exact-head CI installs the lockfile-defined dependency set.

Related: #128844 #128964 #129047

@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: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. 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 25, 2026, 4:09 AM ET / 08:09 UTC.

ClawSweeper review

What this changes

This PR unifies Gateway REST and SSE session-history loading behind one raw-snapshot path and removes duplicate SQLite history-reader exports.

Merge readiness

⚠️ Ready for maintainer review - 2 items remain

Keep open for normal maintainer review. The previous changelog finding was addressed, and the current source centralizes the history snapshot boundary without a concrete correctness finding; current-main and live GitHub rechecks were blocked by unavailable repository objects/network access.

Priority: P2
Reviewed head: a2b595a4c077128ae2e818fa5ce29beba0d068cd

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) The net-negative consolidation and focused contract coverage are sound on the reviewed head, with current-main and exact-head CI rechecks still unavailable locally.
Proof confidence 🌊 off-meta tidepool Not applicable: The repository context identifies this as a maintainer-authored PR; its body additionally reports real Gateway HTTP/SSE coverage.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: The repository context identifies this as a maintainer-authored PR; its body additionally reports real Gateway HTTP/SSE coverage.
Evidence reviewed 6 items Single snapshot owner: The new raw-snapshot function selects the full-history reader for unbounded requests and the bounded indexed tail for paginated requests, retaining reset-archive fallback in both paths.
HTTP and SSE caller: The HTTP endpoint obtains one raw snapshot, uses it for REST projection, and seeds the SSE state from that same snapshot after authorization.
Canonical reader seam: The session reader now delegates public message reads through the source-aware reader, which owns history-event projection and reset-archive fallback.
Findings None None.
Security None None.

Live Verification

Command: pnpm test src/gateway/sessions-history-http.test.ts

Result: FAIL (partial) — step 2 expect_output Test Files: expected terminal output was not visible within 30 seconds: "Test Files"

pnpm test src/gateway/sessions-history-http.test.ts
runner@runnervm76f27:/tmp/clawsweeper-live-proof-129114-fsHKEm/target$ pnpm test src/gateway/sessions-history-http.test.ts
$ node --import tsx scripts/test-projects.mts src/gateway/sessions-history-http.test.ts
[test] starting test/vitest/vitest.e2e.config.ts
pnpm test src/gateway/sessions-history-http.test.ts

 RUN  v4.1.10 /tmp/clawsweeper-live-proof-129114-fsHKEm/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 (48%)
  - rolldown-plugin-dts:generate (22%)
  - rolldown-plugin-dts:fake-js (20%)
See https://rolldown.rs/reference/InputOptions.checks#plugintimings for more details.

[tsdown-build] invocation 1/11 finished in 4.6s
[tsdown-build] invocation 2/11 finished in 21.5s






























Assertions:

  • FAIL expect_output: Test Files

How this fits together

Gateway history reads indexed session transcripts and returns paginated chat history over HTTP or live SSE updates. The shared snapshot feeds display projection, cursors, reset-archive fallback, and stream refreshes.

flowchart LR
  A[Indexed transcript events] --> B[History event reader]
  B --> C[Gateway raw snapshot]
  C --> D[HTTP history response]
  C --> E[SSE history state]
  D --> F[Chat clients]
  E --> F
Loading

Before merge

  • Resolve merge risk (P1) - The review environment could not re-read current main, complete prior-review continuity history, or live GitHub comments/checks because the partial clone and GitHub API remote were unreachable.
  • Complete next step (P2) - No discrete repair finding was identified; this protected maintainer PR needs normal exact-head validation and maintainer handling.
Agent review details

Security

None.

PR surface

Source -204, Tests -84. Total -288 across 11 files.

View PR surface stats
Area Files Added Removed Net
Source 6 72 276 -204
Tests 5 73 157 -84
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 11 145 433 -288

Review metrics

Metric Value Why it matters
Production versus tests production +72/-276 (net -204); tests +73/-157 (net -84) The targeted Gateway and session-reader change is net-negative in both production and test code, consistent with consolidating duplicate paths.

Stored data model

Persistent data-model change detected: serialized state: src/config/sessions/session-accessor.sqlite-active-events.test.ts, serialized state: src/config/sessions/session-accessor.sqlite-active-events.ts, serialized state: src/config/sessions/session-accessor.sqlite-history-events.test.ts, serialized state: src/config/sessions/session-accessor.sqlite-history-events.ts, serialized state: src/config/sessions/session-accessor.sqlite-message-cut.test.ts, serialized state: src/gateway/session-history-state.ts, and 8 more. Confirm migration or upgrade compatibility proof before merge.

Merge-risk options

Maintainer options:

  1. Decide the mitigation before merge
    Keep the single Gateway-owned snapshot boundary, then confirm it against current main and exact-head CI before merge.
  2. Pause or close
    Do not merge this PR until maintainers decide whether the risk is worth taking.

Technical review

Best possible solution:

Keep the single Gateway-owned snapshot boundary, then confirm it against current main and exact-head CI before merge.

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

Not applicable: this is a consolidation/performance PR, not a standalone bug report with a new failing reproduction to establish here.

Is this the best way to solve the issue?

Yes: source inspection shows the snapshot owner is the narrowest place to unify complete and bounded history reads while preserving the existing reader seam and fallback behavior.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 84dfcf27a3ce.

Labels

Label changes:

  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • remove rating: 🦐 gold shrimp: Current PR rating is rating: 🐚 platinum hermit, so this older rating label is no longer current.

Label justifications:

  • P2: This changes user-visible Gateway history reads and merits normal maintainer review, without evidence of an urgent current regression.
  • 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 repository context identifies this as a maintainer-authored PR; its body additionally reports real Gateway HTTP/SSE coverage.

Evidence

What I checked:

  • Single snapshot owner: The new raw-snapshot function selects the full-history reader for unbounded requests and the bounded indexed tail for paginated requests, retaining reset-archive fallback in both paths. (src/gateway/session-history-state.ts:89, a2b595a4c077)
  • HTTP and SSE caller: The HTTP endpoint obtains one raw snapshot, uses it for REST projection, and seeds the SSE state from that same snapshot after authorization. (src/gateway/sessions-history-http.ts:227, a2b595a4c077)
  • Canonical reader seam: The session reader now delegates public message reads through the source-aware reader, which owns history-event projection and reset-archive fallback. (src/gateway/session-transcript-readers.ts:252, a2b595a4c077)
  • Focused contract coverage: Existing focused tests cover bounded SSE refreshes, cursor pages, reset archives, sparse/silent tails, and history-event boundaries. (src/gateway/session-history-state.test.ts:628, a2b595a4c077)
  • History provenance limitation: Current-line blame reaches the shallow checkout boundary at the PR head, so deeper local provenance could not be reconstructed. (src/gateway/session-history-state.ts:89, a2b595a4c077)
  • Current-main check unavailable: The checkout could not materialize the supplied current-main SHA or prior reviewed SHA because its promisor remote was unreachable; no current-main or release claim is made.

Likely related people:

  • steipete: The supplied related merged history PRs and this PR's commits place this contributor on the same Gateway history-owner work. (role: recent Gateway-history contributor; confidence: high; commits: 9ddffe9afe52, a99317ef97af, 110b7474b42b; files: src/gateway/session-history-state.ts, src/gateway/sessions-history-http.ts, src/config/sessions/session-accessor.sqlite-history-events.ts)

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

  • Re-run the current-main comparison and exact-head CI check once repository-object and GitHub access are available.

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 (1 earlier review cycle)
  • reviewed 2026-08-25T07:37:45.230Z sha 9ddffe9 :: needs changes before merge. :: [P3] Remove the release-owned changelog entry

@steipete
steipete merged commit a19da06 into main Aug 25, 2026
228 checks passed
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

@steipete
steipete deleted the codex/session-history-owner-cleanup branch August 25, 2026 08:18
@clawsweeper clawsweeper Bot added rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. and removed rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. labels Aug 25, 2026
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Aug 26, 2026
…rs (openclaw#129114)

* perf(gateway): consolidate session history readers

* chore: leave changelog to release generation
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