Skip to content

improve(gateway): bound visible history page reads - #110457

Closed
jalehman wants to merge 3 commits into
openclaw:josh/clawdbot-d02.1.9.1.40-db6-generation-cursorsfrom
jalehman:clawdbot-d02.1.9.1.40-db6.7/visible-http-sse-history
Closed

jalehman wants to merge 3 commits into
openclaw:josh/clawdbot-d02.1.9.1.40-db6-generation-cursorsfrom
jalehman:clawdbot-d02.1.9.1.40-db6.7/visible-http-sse-history

Conversation

@jalehman

Copy link
Copy Markdown
Contributor

Parent stack: #110374 must land first. This draft is based directly on josh/clawdbot-d02.1.9.1.40-db6-generation-cursors and contains only the visible HTTP/SSE history follow-up.

What Problem This Solves

Deep GET /sessions/:sessionKey/history pages and SSE history refreshes currently materialize and deserialize the full transcript before returning a small visible page. A 50-message request against a 100,000-event active transcript therefore incurs latency and memory proportional to total transcript size.

Why This Change Was Made

Visible JSON and SSE reads now share one internal cursor/read owner backed by the existing session_transcript_active_events projection and indexed keyset access from #108851. The opaque cursor is session-scoped, generation-aware, direction-aware, and anchored to a stable active event; raw delta cursors remain separate. The change does not add a projection, offset scan, schema version, or alter chat.history.

The shipped numeric HTTP cursor remains accepted for one upgrade window. Unsupported fallback reads preserve the caller's cursor instead of silently restarting the page.

User Impact

Operators with deep session histories receive small HTTP history pages and SSE refreshes with bounded work. New appends do not invalidate paging toward older messages, while branch replacement or generation changes reset the visible snapshot instead of continuing from a stale anchor.

Evidence

Correctness and validation

  • Focused accessor, state, query-plan, HTTP JSON, and SSE tests passed on Blacksmith Testbox (39 focused assertions total across the exercised files).
  • Path-scoped pnpm check:changed passed formatting, boundary/API guards, core and test typechecks, lint, database-first guards, and import-cycle checks.
  • Mandatory autoreview completed clean after addressing its cursor compatibility and fallback findings.
  • Thermonuclear maintainability review and Martian completion checks passed.
  • Exact parent e84b451c93dfce204ff049924be0538b6ab0b6d4 reproduces 10 stale sequence-value assertions in the full HTTP test file. The child-specific cursor, replacement, append, compatibility, and SSE cases pass, and this child preserves the parent's actual wire sequence semantics.

Apples-to-apples benchmark

Same Blacksmith machine (ip-172-31-64-123), Linux x64, Node v24.18.0; deterministic 100,000-event linear active assistant transcript; 64-character text; page size 50; raw window 1,020; 3 warmups; 12 measured runs. Both sides exercise the production HTTP handler and SSE state owner using the same measurement code.

Baseline: current origin/main at c1b78839e288936bd165dc8932fabfee8af7543c
Candidate: 7bc4bbec59cb45be5b74fe000605074debbbde86

Scenario Metric Main Candidate Result
HTTP JSON median latency 925.839 ms 16.442 ms 56.3x faster
HTTP JSON p95 latency 945.240 ms 19.744 ms 47.9x faster
HTTP JSON events deserialized 100,000 1,020 98.98% fewer
HTTP JSON median heap delta 108,697,288 B 12,731,952 B 88.3% lower
SSE refresh/page median latency 890.436 ms 10.105 ms 88.1x faster
SSE refresh/page p95 latency 916.514 ms 10.783 ms 85.0x faster
SSE refresh/page events deserialized 100,000 1,020 98.98% fewer
SSE refresh/page median heap delta 80,958,856 B 11,354,336 B 86.0% lower

Median RSS delta was 14,725,120 B (HTTP) and 10,866,688 B (SSE) on main versus 0 B in both candidate scenarios. Process peak RSS was 645,916 KiB on main and 609,732 KiB on the candidate.

EXPLAIN QUERY PLAN on the candidate reports:

SEARCH active USING INDEX idx_agent_transcript_active_messages
  (session_id=? AND message_position>? AND message_position<?)
SEARCH event USING INDEX sqlite_autoindex_transcript_events_1
  (session_id=? AND seq=?)

No full transcript scan or temporary B-tree is used. Raw benchmark output is reproducible with:

node --expose-gc --import tsx scripts/bench-session-history-http.ts

@openclaw-barnacle openclaw-barnacle Bot added gateway Gateway runtime scripts Repository scripts size: XL maintainer Maintainer-authored PR labels Jul 18, 2026
@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. 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. P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. labels Jul 18, 2026
@clawsweeper

clawsweeper Bot commented Jul 18, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs real behavior proof before merge. Reviewed July 18, 2026, 11:57 AM ET / 15:57 UTC.

Summary
The PR routes visible gateway HTTP and SSE history pages through a shared bounded SQLite active-projection reader and replaces newly emitted numeric HTTP continuation cursors with opaque generation-aware cursors.

PR surface: Source +295, Tests +363, Other +436. Total +1094 across 10 files.

Reproducibility: yes. source-reproducible: the supplied benchmark and changed reader paths describe a 100,000-event transcript whose visible HTTP/SSE page previously materialized the full transcript. Exact-head live reproduction evidence is still missing.

Review metrics: 1 noteworthy metric.

  • Gateway cursor contract: 1 response-cursor representation changed. New pages emit opaque generation-aware cursors instead of the current numeric representation, so upgrade behavior requires explicit review.

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/gateway/session-history-state.ts, serialized state: src/gateway/session-history-visible-reader.ts, serialized state: src/gateway/sessions-history-http.test.ts, serialized state: src/gateway/sessions-history-http.ts, and 7 more. Confirm migration or upgrade compatibility proof before merge.

Merge readiness
Overall: 🦪 silver shellfish
Proof: 🦪 silver shellfish
Patch quality: 🦐 gold shrimp
Result: blocked until real behavior proof is added.

Overall follows the weaker of proof and patch quality, so missing proof can cap an otherwise strong patch.

Rank-up moves:

  • [P1] Land or replace the required parent foundation, then rebase this branch onto current main.
  • Attach redacted exact-head terminal output or logs for HTTP and SSE paging, including numeric upgrade input, opaque cursors, append stability, and replacement reset.
  • Obtain maintainer confirmation of the external cursor transition contract.

Proof guidance:

  • [P1] Needs real behavior proof before merge: The body gives benchmark and test claims, but its concrete benchmark candidate predates the reviewed head and no redacted exact-head live HTTP/SSE output, runtime log, recording, or artifact demonstrates the final cursor and reset behavior. Add that evidence after the parent lands, redacting private endpoints, IP addresses, and credentials; updating the PR body should trigger re-review, or a maintainer can comment @clawsweeper re-review. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.

Risk before merge

  • [P1] Merging changes the observable HTTP continuation-cursor contract from newly emitted numeric values to opaque, session- and generation-bound values; clients, bookmarks, or integrations that persist cursors need an explicitly accepted transition contract.
  • [P1] The current branch cannot be evaluated as a standalone main-bound change until feat: bound transcript reads across replacements #110374 lands or is replaced by an equivalent merged foundation.
  • [P1] The supplied performance evidence targets an earlier candidate commit rather than the current head, so it does not yet prove the final cursor/reset behavior in a live HTTP and SSE flow.

Maintainer options:

  1. Prove and document the cursor transition (recommended)
    After the parent lands, rebase and attach redacted exact-head HTTP and SSE output covering legacy numeric input, opaque continuation, append stability, and generation-reset behavior.
  2. Adopt the new contract deliberately
    Accept opaque response cursors as the supported gateway contract and explicitly own any compatibility impact for clients that persist returned cursors.
  3. Split the compatibility decision
    Pause this branch if maintainers want the bounded read optimization without changing the externally visible cursor representation yet.

Next step before merge

  • [P1] This stacked draft needs maintainer resolution of its public cursor compatibility policy plus contributor-provided exact-head real behavior proof; neither is a safe mechanical repair task.

Maintainer decision needed

  • Question: Should the gateway HTTP history endpoint adopt opaque generation-aware nextCursor values now, with legacy numeric inputs accepted only for the stated upgrade window?
  • Rationale: This is a public compatibility choice for existing HTTP consumers, not a mechanical implementation detail; the PR’s tests can validate the selected policy but cannot choose the supported transition duration or contract.
  • Likely owner: steipete — They authored the merged bounded-history foundation and are the strongest history signal for the gateway cursor compatibility decision.
  • Options:
    • Accept bounded transition (recommended): Approve opaque emitted cursors while preserving numeric cursor input for a defined transition window, then require exact-head upgrade and live HTTP/SSE proof.
    • Preserve numeric emitted cursors: Keep emitting numeric cursors and use the opaque cursor only internally until a separately approved API transition is designed.
    • Pause API change: Keep the bounded reader work but defer cursor-contract changes until an owner defines versioning or documented client migration behavior.

Security
Cleared: The shown diff changes gateway/session TypeScript, tests, a benchmark, and Knip registration; it does not add a dependency, workflow, publishing path, secret access, or new privilege boundary.

Review details

Best possible solution:

After the parent foundation lands, rebase this branch and retain one canonical visible-history reader with a documented, tested cursor transition that proves both an upgraded numeric cursor and the new opaque cursor in HTTP and SSE flows.

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

Yes, source-reproducible: the supplied benchmark and changed reader paths describe a 100,000-event transcript whose visible HTTP/SSE page previously materialized the full transcript. Exact-head live reproduction evidence is still missing.

Is this the best way to solve the issue?

Unclear: sharing one active-projection reader is a maintainable direction, but the public numeric-to-opaque cursor transition needs owner approval and exact-head upgrade proof before this can be called the best solution.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 7bded09b6175.

Label changes

Label changes:

  • add merge-risk: 🚨 session-state: Cursor anchoring and generation resets determine whether active transcript history pages remain gap-free across appends and replacements.

Label justifications:

  • P2: This is a bounded performance and pagination improvement with meaningful but non-emergency gateway compatibility implications.
  • merge-risk: 🚨 compatibility: The PR changes newly emitted HTTP continuation cursors while retaining numeric input only temporarily.
  • merge-risk: 🚨 session-state: Cursor anchoring and generation resets determine whether active transcript history pages remain gap-free across appends and replacements.
  • rating: 🦪 silver shellfish: Overall readiness is 🦪 silver shellfish; proof is 🦪 silver shellfish and patch quality is 🦐 gold shrimp.
  • status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask. Needs real behavior proof before merge: The body gives benchmark and test claims, but its concrete benchmark candidate predates the reviewed head and no redacted exact-head live HTTP/SSE output, runtime log, recording, or artifact demonstrates the final cursor and reset behavior. Add that evidence after the parent lands, redacting private endpoints, IP addresses, and credentials; updating the PR body should trigger re-review, or a maintainer can comment @clawsweeper re-review. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
Evidence reviewed

PR surface:

Source +295, Tests +363, Other +436. Total +1094 across 10 files.

View PR surface stats
Area Files Added Removed Net
Source 5 414 119 +295
Tests 3 371 8 +363
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 2 436 0 +436
Total 10 1221 127 +1094

What I checked:

Likely related people:

  • steipete: Authored the merged active-projection and bounded-history foundation that this PR explicitly reuses. (role: merged foundation author; confidence: high; commits: 7d71d7cf6b3c, 3b3104257b3d; files: src/config/sessions/session-accessor.sqlite-active-events.ts, src/gateway/sessions-history-http.ts)
  • jalehman: Authored the still-open generation-aware cursor foundation on which this stacked PR depends. (role: parent-stack author; confidence: high; commits: cc2648284a1b; files: src/config/sessions/session-accessor.sqlite-active-events.ts, src/gateway/session-history-state.ts)
What the crustacean ranks mean
  • 🦀 challenger crab: rare, exceptional readiness with strong proof, clean implementation, and convincing validation.
  • 🦞 diamond lobster: very strong readiness with only minor maintainer review expected.
  • 🐚 platinum hermit: good normal PR, likely mergeable with ordinary maintainer review.
  • 🦐 gold shrimp: useful signal, but proof or patch confidence is still limited.
  • 🦪 silver shellfish: thin signal; proof, validation, or implementation needs work.
  • 🧂 unranked krab: not merge-ready because proof is missing/unusable or there are serious correctness or safety concerns.
  • 🌊 off-meta tidepool: rating does not apply to this item.

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.

How this review workflow works
  • 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.
Review history (4 earlier review cycles)
  • reviewed 2026-07-18T06:05:27.464Z sha 7bc4bbec59cb45be5b74fe000605074debbbde86 :: needs maintainer review before merge. :: none
  • reviewed 2026-07-18T14:15:08.049Z sha c05bd044dbe0e48ae74e1c90aade04f82d15569a :: needs real behavior proof before merge. :: none
  • reviewed 2026-07-18T14:35:54.163Z sha a87874c285c297e63b8c2b06c24924340ac0f64b :: needs real behavior proof before merge. :: none
  • reviewed 2026-07-18T15:15:26.571Z sha 1699baa042a98f22d0f1944217ff2d8d6f2b2bd2 :: needs real behavior proof before merge. :: none

@jalehman
jalehman force-pushed the josh/clawdbot-d02.1.9.1.40-db6-generation-cursors branch from e84b451 to b628667 Compare July 18, 2026 14:04
@jalehman
jalehman force-pushed the clawdbot-d02.1.9.1.40-db6.7/visible-http-sse-history branch from 7bc4bbe to c05bd04 Compare July 18, 2026 14:11
@clawsweeper clawsweeper Bot added rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. and removed proof: sufficient ClawSweeper judged the real behavior proof convincing. 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 Jul 18, 2026
@jalehman
jalehman force-pushed the josh/clawdbot-d02.1.9.1.40-db6-generation-cursors branch from b628667 to cf8eeb1 Compare July 18, 2026 14:28
@jalehman
jalehman force-pushed the clawdbot-d02.1.9.1.40-db6.7/visible-http-sse-history branch from c05bd04 to a87874c Compare July 18, 2026 14:32
@jalehman
jalehman force-pushed the josh/clawdbot-d02.1.9.1.40-db6-generation-cursors branch from cf8eeb1 to 7ff4bab Compare July 18, 2026 14:37
@jalehman
jalehman force-pushed the clawdbot-d02.1.9.1.40-db6.7/visible-http-sse-history branch 2 times, most recently from b86b8b6 to 1699baa Compare July 18, 2026 15:11
@clawsweeper clawsweeper Bot added the merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. label Jul 18, 2026
@jalehman
jalehman force-pushed the josh/clawdbot-d02.1.9.1.40-db6-generation-cursors branch 2 times, most recently from cb90b46 to 69e4633 Compare July 18, 2026 18:34
@jalehman
jalehman force-pushed the clawdbot-d02.1.9.1.40-db6.7/visible-http-sse-history branch from 1699baa to 089687a Compare July 18, 2026 18:41
@jalehman
jalehman deleted the branch openclaw:josh/clawdbot-d02.1.9.1.40-db6-generation-cursors July 18, 2026 18:41
@jalehman jalehman closed this Jul 18, 2026
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 merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. P2 Normal backlog priority with limited blast radius. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. scripts Repository scripts size: XL status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant