Skip to content

fix(gateway): keep session history pageable after hidden tails - #124120

Merged
steipete merged 1 commit into
mainfrom
fix/autoqa-refill-session-history-outcomes-v2
Aug 15, 2026
Merged

steipete merged 1 commit into
mainfrom
fix/autoqa-refill-session-history-outcomes-v2

Conversation

@steipete

Copy link
Copy Markdown
Contributor

Related: #121386

What Problem This Solves

Fixes an issue where HTTP/SSE session-history clients could be told that no older conversation existed when a bounded raw transcript tail contained only hidden rows, even though visible SQLite history remained earlier in the session.

Why This Change Was Made

The raw bounded tail owns the pagination boundary even when display projection removes every row. The shared session-history projector now keeps hasMore true and derives the existing nextCursor from the first raw sequence, without exposing hidden rows or changing the HTTP/SSE response shape.

The existing ClawSweeper review recommends also consolidating the separate embedded-history path. Maintainer scope for this PR explicitly preserves the two-file HTTP/SSE repair; the embedded path is not claimed fixed here and should remain tracked separately rather than being silently bundled.

Production LOC: +3/-4 (net -1). Tests: +46/-0. CHANGELOG.md is intentionally unchanged; release generation owns changelog updates.

User Impact

External HTTP/SSE history clients can page past an all-hidden tail and recover older visible conversation rows. Visible-row behavior, hidden-row filtering, retention, storage, configuration, and protocol shape are unchanged.

Evidence

  • Before: a real SQLite transcript with one visible row followed by 40 NO_REPLY rows returned messages: [], hasMore: false, and no cursor for ?limit=1.
  • After: REST and SSE return the same hidden first page with hasMore: true and nextCursor: "2"; requesting that cursor returns the older visible row.
  • Blacksmith Testbox: https://github.com/openclaw/openclaw/actions/runs/31875210575
    • src/gateway/session-history-state.test.ts: 26/26 passed.
    • src/gateway/sessions-history-http.test.ts: 84/84 passed, including invalid cursor/limit bounds, archive rollover, pagination, SSE refresh, and cleanup siblings.
    • Changed gate passed: format, core production/test types, focused lint, storage/database-first guards, native schema-version guard, and zero runtime import cycles.
  • Fresh autoreview: no accepted/actionable findings.
  • git diff --check: clean.

@clawsweeper

clawsweeper Bot commented Aug 15, 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: S maintainer Maintainer-authored PR labels Aug 15, 2026
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Aug 15, 2026
@clawsweeper

clawsweeper Bot commented Aug 15, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed August 15, 2026, 5:03 AM ET / 09:03 UTC.

ClawSweeper review

What this changes

Repairs Gateway session-history pagination so an all-hidden bounded transcript tail still returns a cursor to older visible SQLite history for HTTP and SSE clients.

Regression provenance

Possible regression — suspected (reviewed change). No predecessor PR is attributed.

Merge readiness

⚠️ Ready for maintainer review - 1 item remains

Keep open. Current main still suppresses the continuation cursor when a bounded raw tail projects to no visible rows; this focused shared-projector repair corrects REST and SSE without changing response shape.

Priority: P2
Reviewed head: 9ad4b7991f41fb54e6319f5adf451e49a6a3150e

Review scores

Measure Result What it means
Overall readiness 🦞 diamond lobster (5/6) A focused, net-negative owner-boundary repair with direct transport-level regression coverage.
Proof confidence 🦞 diamond lobster (5/6) ✨ media proof bonus Sufficient (linked_artifact): The PR body provides after-fix REST and SSE results from a real SQLite Gateway harness plus a linked Blacksmith Testbox run.
Patch quality 🦞 diamond lobster (5/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (linked_artifact): The PR body provides after-fix REST and SSE results from a real SQLite Gateway harness plus a linked Blacksmith Testbox run.
Evidence reviewed 6 items Current-main defect: The bounded-tail continuation branch requires at least one projected visible message, so an all-hidden tail leaves hasMore false and omits nextCursor despite older raw rows.
Shared HTTP and SSE owner: Both REST and SSE pass the bounded raw rows and total count into the same snapshot projector, so the changed owner covers both transports.
Authoritative cursor sequence: SQLite history projection attaches the stored sequence to each transcript entry; the fallback cursor therefore uses an authoritative raw-row watermark rather than an array position.
Findings None None.
Security None None.

How this fits together

Gateway session-history reads a bounded SQLite transcript tail, projects displayable messages, and returns a REST or SSE page. Clients use the returned cursor to request older conversation rows.

flowchart LR
A[SQLite transcript] --> B[Bounded raw tail]
B --> C[History projection]
C --> D{Visible rows?}
D --> E[REST history page]
D --> F[SSE history event]
B --> G[Continuation cursor]
G --> E
G --> F
Loading

Before merge

  • Complete next step (P2) - No repair lane is needed: this protected maintainer PR has a concrete patch and should proceed through normal exact-head CI and maintainer review.
Agent review details

Security

None.

PR surface

Source -1, Tests +46. Total +45 across 2 files.

View PR surface stats
Area Files Added Removed Net
Source 1 3 4 -1
Tests 1 46 0 +46
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 2 49 4 +45

Review metrics

Metric Value Why it matters
Production versus test LOC production +3/-4 (net -1); tests +46/-0 The repair is net-negative production code, while the added boundary test covers both transport responses and cursor recovery.

Stored data model

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

Root-cause cluster

Relationship: fixed_by_candidate
Canonical: #121386
Summary: This PR is the focused candidate fix for the HTTP/SSE portion of the canonical session-history report; embedded history remains separate 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 HTTP/SSE projector repair after exact-head CI; retain the separate embedded-history duplication under #121386.

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

Yes—high-confidence source reproduction is encoded by the added real Gateway/SQLite harness scenario: current main leaves the empty bounded page without a continuation cursor.

Is this the best way to solve the issue?

Yes—the shared snapshot projector is the narrow owner for both HTTP and SSE; altering the embedded duplicate would address a separate remaining surface tracked in the linked issue.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 11bcc0eb4985.

Labels

Label changes:

  • add P2: This corrects an externally observable session-history pagination dead end with limited known blast radius.
  • add proof: sufficient: Contributor real behavior proof is sufficient. The PR body provides after-fix REST and SSE results from a real SQLite Gateway harness plus a linked Blacksmith Testbox run.
  • add rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🦞 diamond lobster and patch quality is 🦞 diamond lobster.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (linked_artifact): The PR body provides after-fix REST and SSE results from a real SQLite Gateway harness plus a linked Blacksmith Testbox run.

Label justifications:

  • P2: This corrects an externally observable session-history pagination dead end with limited known blast radius.
  • rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🦞 diamond lobster and patch quality is 🦞 diamond lobster.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (linked_artifact): The PR body provides after-fix REST and SSE results from a real SQLite Gateway harness plus a linked Blacksmith Testbox run.
  • proof: sufficient: Contributor real behavior proof is sufficient. The PR body provides after-fix REST and SSE results from a real SQLite Gateway harness plus a linked Blacksmith Testbox run.

Evidence

What I checked:

  • Current-main defect: The bounded-tail continuation branch requires at least one projected visible message, so an all-hidden tail leaves hasMore false and omits nextCursor despite older raw rows. (src/gateway/session-history-state.ts:177, 11bcc0eb4985)
  • Shared HTTP and SSE owner: Both REST and SSE pass the bounded raw rows and total count into the same snapshot projector, so the changed owner covers both transports. (src/gateway/sessions-history-http.ts:192, 11bcc0eb4985)
  • Authoritative cursor sequence: SQLite history projection attaches the stored sequence to each transcript entry; the fallback cursor therefore uses an authoritative raw-row watermark rather than an array position. (src/gateway/session-transcript-message.ts:34, 11bcc0eb4985)
  • Boundary regression coverage: The added Gateway-harness case writes the transcript, verifies JSON and SSE expose cursor 2 from an empty first page, then follows it to the older visible row; it would fail at the current-main visible-message gate. (src/gateway/sessions-history-http.test.ts:1071, 9ad4b7991f41)
  • History provenance: Blame ties the current guard to the session-history-state introduction; the local shallow/promisor history cannot safely establish a predecessor PR for regression attribution. (src/gateway/session-history-state.ts:177, 2e806ef0e2c9)
  • Release status: No checked-out release tag contains the PR head, so this remains an unreleased repair rather than behavior already available to users. (9ad4b7991f41)

Likely related people:

  • Ayaan Zaidi: Current-main blame attributes the bounded-tail continuation condition to the session-history-state introduction. (role: feature introducer; confidence: high; commits: 2e806ef0e2c9; files: src/gateway/session-history-state.ts)
  • steipete: Previously landed bounded live session-history behavior and authored this focused repair. (role: recent area contributor; confidence: high; commits: d976c2ea829e, 9ad4b7991f41; files: src/gateway/session-history-state.ts, src/gateway/sessions-history-http.test.ts)
  • Galin Iliev: Earlier history work addressed paging beyond truncated tails in the same Gateway area. (role: adjacent pagination contributor; confidence: medium; commits: dc575d148a7c; files: src/gateway/session-history-state.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

Copy link
Copy Markdown
Contributor Author

ClawSweeper next step is satisfied: exact-head CI is green at 9ad4b7991f41fb54e6319f5adf451e49a6a3150e, maintainer landing approval is explicit, native review artifacts validate as READY FOR /prepare-pr, and fresh autoreview reports no actionable findings.

The stored-data-model warning is not applicable here: this PR changes no SQLite schema, migration, retention, serialized field, or HTTP/SSE response shape. It only supplies the existing nextCursor/hasMore continuation metadata from the authoritative raw-row sequence when projection hides the whole bounded tail. The separate embedded-history path remains outside this PR and remains tracked in #121386.

@steipete
steipete merged commit 5419a70 into main Aug 15, 2026
194 checks passed
@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. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. size: S 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