Skip to content

fix(gateway): keep same-sequence history rows reachable - #124145

Merged
steipete merged 2 commits into
mainfrom
fix/autoqa-refill-history-sequence-cursor-v2
Aug 15, 2026
Merged

steipete merged 2 commits into
mainfrom
fix/autoqa-refill-history-sequence-cursor-v2

Conversation

@steipete

Copy link
Copy Markdown
Contributor

Related: #121386
Related: #124120

What Problem This Solves

Fixes an issue where HTTP/SSE session-history clients could permanently miss a visible row when display projection produced several rows with the same transcript sequence and a page limit split that sequence group.

Why This Change Was Made

The existing public cursor addresses transcript sequences, not individual projected rows. The shared REST/SSE paginator now closes each tentative page over every included sequence group, including interleaved message-tool result/mirror rows, while preserving display order and the existing cursor and response shape.

This is a focused continuation of the hidden-tail repair in #124120. Issue #121386 remains broader embedded-history context and is not closed or claimed fully resolved here.

Production LOC: +20/-1 (net +19). Tests: +202/-18. The original contiguous-run repair was +9 production LOC, but independent review found a valid two-send projection shaped as seq 3 result, seq 4 result, seq 3 mirror, seq 4 mirror; the extra closure logic is required to satisfy the full sequence-group invariant rather than only adjacent siblings.

No protocol, HTTP/SSE schema, SQLite schema, migration, retention, config, security, release, or deployment surface changes. CHANGELOG.md and docs are intentionally unchanged; this body carries release-note context and the public API contract is unchanged.

AI-assisted; maintainer-reviewed.

User Impact

External session-history clients can follow the existing sequence cursor without duplicate, skipped, looping, or hidden rows. A page may exceed its requested row limit only when needed to keep an indivisible sequence group reachable.

Evidence

  • Pre-fix against b37b048: the strengthened owner regression failed 1/26 because the newest limit=1 page returned only the seq-4 mirror and stranded the interleaved seq-3/seq-4 siblings.
  • Post-fix state owner suite: 26/26 passed.
  • Real SQLite + isolated Gateway REST/SSE suite: 85/85 passed on Blacksmith Testbox run 31877896740.
    • The first page preserves the interleaved seq-3 and seq-4 result/mirror groups and returns cursor 3.
    • Following cursors reconstructs all six visible row identities in display order with no duplicate, skip, or loop.
    • REST and initial SSE identities/cursors match; NO_REPLY remains hidden.
    • fix(gateway): keep session history pageable after hidden tails #124120's all-hidden-tail continuation regression remains green.
  • Source-blind behavior validation: all six REST/SSE contract clauses passed; 85/85 tests, exit 0.
  • Projection sibling suite: 21/21 passed.
  • Changed gate passed: formatting, core production/test types, focused lint, and changed guards.
  • Explicit storage/architecture guards passed: database-first legacy stores, session accessor, transcript reader, synchronous SQLite transaction boundary, SQLite schema baseline, native schema version, and zero runtime import cycles.
  • Fresh autoreview: no accepted/actionable findings; patch correctness 0.98.
  • 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.

@steipete
steipete marked this pull request as ready for review August 15, 2026 10:14
@openclaw-barnacle openclaw-barnacle Bot added gateway Gateway runtime size: M maintainer Maintainer-authored PR labels Aug 15, 2026
@steipete steipete self-assigned this Aug 15, 2026
@clawsweeper clawsweeper Bot added merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. 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 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, 6:20 AM ET / 10:20 UTC.

ClawSweeper review

What this changes

The PR makes REST and SSE session-history pages include all visible projected rows connected to an included transcript sequence, even when those rows are interleaved.

Merge readiness

⚠️ Ready for maintainer review - 3 items remain

Keep this maintainer-owned PR open for the explicit public-pagination compatibility decision and normal exact-head merge checks. Current main still splits interleaved same-sequence rows, and the branch’s owner and HTTP/SSE tests cover the intended repair without a concrete implementation defect found.

Priority: P2
Reviewed head: e263e41a862720bfbe343416e5a690725f0f7bd4
Owner decision: Required. See Decision needed.

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) The patch has focused owner and real Gateway boundary coverage and no concrete correctness finding, with one explicit compatibility decision remaining.
Proof confidence 🌊 off-meta tidepool Not applicable: Repository context identifies this as a maintainer PR; its body additionally links an after-fix isolated Gateway REST/SSE Testbox run.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: Repository context identifies this as a maintainer PR; its body additionally links an after-fix isolated Gateway REST/SSE Testbox run.
Evidence reviewed 5 items Current-main behavior: Current main takes a strict trailing row window; when a projected sequence appears earlier and later in display order, the earlier row can be excluded while the cursor advances past it.
Proposed owner-boundary repair: The branch closes the tentative page over repeated and transitively interleaved sequence groups before deriving the existing sequence cursor.
Gateway entry points: The shared snapshot builder feeds both direct JSON history and initial SSE state, so repairing the paginator covers the two advertised transports through one owner.
Findings None None.
Security None None.

How this fits together

Gateway session-history endpoints project SQLite transcript records into display rows and paginate them with a transcript-sequence cursor. REST and SSE consumers use that cursor to retrieve older history, so each cursor page must leave no included sequence group unreachable.

flowchart LR
  A[SQLite transcript] --> B[Display projection]
  B --> C[Rows with transcript sequences]
  C --> D[Sequence cursor paginator]
  D --> E[REST history page]
  D --> F[SSE history event]
Loading

Decision needed

Question Recommendation
Should the public session-history endpoint permit a page to exceed its requested limit when that is required to keep a sequence-addressed group reachable? Adopt indivisible sequence pages: Keep this repair and make the bounded-overflow rule part of the endpoint’s maintained pagination contract.

Why: The existing cursor identifies transcript sequences rather than projected rows, so a strict row cap and complete group reachability cannot both be guaranteed without a new cursor contract.

Before merge

  • Resolve merge risk (P1) - A request with limit=1 can now return several rows to keep a sequence group reachable; clients treating limit as a strict response-size cap need the endpoint contract explicitly confirmed.
  • Resolve merge risk (P1) - This bug repair adds net 19 production lines; the interleaved-group regression demonstrates why a contiguous-only adjustment is insufficient, but the closure loop should remain the single canonical pagination policy.
Agent review details

Security

None.

PR surface

Source +19, Tests +184. Total +203 across 3 files.

View PR surface stats
Area Files Added Removed Net
Source 1 20 1 +19
Tests 2 202 18 +184
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 3 222 19 +203

Review metrics

Metric Value Why it matters
Production vs test delta production +20/-1 (net +19); tests +202/-18 (net +184) The added production closure loop is justified by the noncontiguous sequence-group regression, while both owner and real Gateway transport coverage expand.

Stored data model

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

Merge-risk options

Maintainer options:

  1. Confirm group-overflow pagination (recommended)
    Accept sequence groups as indivisible and record that a response may exceed limit only to prevent an unreachable cursor group.
  2. Require a strict-cap cursor redesign
    Pause this PR if consumers must always receive no more rows than requested, because that requires a distinct compatible cursor contract.

Technical review

Best possible solution:

Retain sequence-group closure and explicitly establish that history limit is a target row window that may expand for an indivisible sequence group, rather than introducing a competing cursor format.

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

Yes, from source: current main’s strict trailing-row slice in src/gateway/session-history-state.ts:148 strands earlier rows when the same sequence is interleaved, and the branch supplies owner and SQLite-backed REST/SSE regression scenarios for that shape.

Is this the best way to solve the issue?

Unclear pending the public contract choice: sequence-group closure is the narrowest repair under the existing sequence cursor, but allowing a page to exceed limit is an externally visible pagination decision.

AGENTS.md: found and applied where relevant.

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

Labels

Label changes:

  • add P2: This repairs a bounded edge case in external session-history pagination without evidence of an urgent default-path outage.
  • add merge-risk: 🚨 compatibility: The patch intentionally permits responses to contain more rows than the caller’s limit, which may affect clients that use it as a strict page-size bound.
  • 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: Repository context identifies this as a maintainer PR; its body additionally links an after-fix isolated Gateway REST/SSE Testbox run.

Label justifications:

  • P2: This repairs a bounded edge case in external session-history pagination without evidence of an urgent default-path outage.
  • merge-risk: 🚨 compatibility: The patch intentionally permits responses to contain more rows than the caller’s limit, which may affect clients that use it as a strict page-size bound.
  • 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: Repository context identifies this as a maintainer PR; its body additionally links an after-fix isolated Gateway REST/SSE Testbox run.

Evidence

What I checked:

Likely related people:

  • steipete: Direct commit metadata attributes the immediately preceding session-history cursor repair and both commits in this continuation to Peter Steinberger; the PR metadata maps that history to steipete. (role: recent area contributor; confidence: high; commits: 5419a70618bf, 21462dd2d88a, e263e41a8627; files: src/gateway/session-history-state.ts, src/gateway/sessions-history-http.ts)

Rank-up moves

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

  • Confirm and record the public limit overflow rule before merging.

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 commented Aug 15, 2026 •

Copy link
Copy Markdown
Contributor Author

Maintainer decision (now explicitly confirmed): adopt indivisible sequence pages.

For this endpoint, limit is a target projected-row window rather than a strict response-size cap. A page may exceed it only when necessary to keep every row sharing an included transcript sequence reachable through the existing public sequence cursor. A strict cap would require a different compatible cursor contract.

The +19 production LOC is accepted. The smaller contiguous-run implementation was proven incomplete for valid interleaving (seq 3 result, seq 4 result, seq 3 mirror, seq 4 mirror); the landed loop remains the single canonical REST/SSE pagination policy.

This supersedes the earlier automation correction. No protocol shape, HTTP/SSE schema, SQLite schema, migration, config, security, release, or deployment changed.

@steipete
steipete merged commit 7e09412 into main Aug 15, 2026
255 checks passed
@steipete
steipete deleted the fix/autoqa-refill-history-sequence-cursor-v2 branch August 15, 2026 10:30
@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 merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. P2 Normal backlog priority with limited blast radius. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: M 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