Skip to content

feat(chat): native session scroll-back with offset paging and import-aware history - #105688

Merged
steipete merged 5 commits into
mainfrom
feat/native-chat-scrollback
Jul 12, 2026
Merged

steipete merged 5 commits into
mainfrom
feat/native-chat-scrollback

Conversation

@steipete

Copy link
Copy Markdown
Contributor

What Problem This Solves

Native OpenClaw sessions had no scroll-back: chat.history returned a single recent tail window and the Control UI offered no way to reach older messages. Catalog (Claude Code / Codex) sessions already got automatic scroll-back in #105209; native sessions — the far more common case — did not.

Closes #105127.

Why This Change Was Made

Unify the older-history experience across native and catalog sessions using the same UI machinery (IntersectionObserver top sentinel, spinner row, viewport anchoring, bounded cursor guards) landed in #105209, backed by a new offset paging contract on chat.history.

Server:

  • chat.history accepts offset and returns {hasMore, nextOffset, totalMessages} (ChatHistoryPagination); offset pages read strictly-older transcript slices without re-materializing the whole session.
  • Cursor advance is strict: when replaying the oldest partially-budgeted record cannot advance the cursor, the record is skipped past (omission reported via existing diagnostics) instead of returning a non-advancing cursor the UI would read as exhaustion.
  • CLI-bound sessions (claude-cli imports) keep their terminal snapshot contract: one full local read per snapshot load, stable imported message IDs, and completeSnapshot withheld when byte caps truncate the response (honest signal for the deferred opaque-snapshot-cursor follow-up, [Feature]: snapshot-cursor paging for oversized imported CLI transcripts in chat.history #105644).
  • Fixed an infinite recursion when the recent tail window incorporates CLI imports but the full local read dedupes them all: ignoreCliSessionImports now gates the import resolver itself, so the re-entry terminates in local-only paging.

UI:

  • Native sessions reuse the catalog scroll-back path: shared top sentinel + spinner + anchor-preserving prepend, with olderOffsetsSeen guarding against cursor loops and message identity dedupe on prepend.

User Impact

Scrolling up in any native session now automatically loads older messages with a loading indicator, without reloading the session. Bound Claude CLI sessions no longer risk a gateway-pegging infinite loop on a realistic dedupe layout.

Evidence

  • node scripts/run-vitest.mjs src/gateway/server.chat.gateway-server-chat-b.test.ts ui/src/pages/chat/chat-pane.test.ts ui/src/e2e/claude-sessions.e2e.test.ts — green (126 + 27 + 2 tests).
  • Negative proof for the recursion fix: with the resolver gate reverted, the new regression test (chat.history terminates when the full local read dedupes every claude-cli import) spins the gateway at ~100% CPU indefinitely; with the fix it passes.
  • Strict-cursor regression tests prove nextOffset > offset for pathological multi-sibling records and eventual access to the oldest record.
  • Linux Testbox: gateway + chat-pane suites green; claude-sessions E2E green on retry after one cold-setup timeout (exact unchanged rerun 2/2).
  • Autoreview: the earlier recursion finding is fixed with negative proof; the two remaining findings are consciously rejected as the scoped [Feature]: snapshot-cursor paging for oversized imported CLI transcripts in chat.history #105644 tradeoff: (a) byte-truncated imported snapshots stay terminal — on main bound sessions already return one merged tail with hasMore: false, so this branch strictly widens reachable history and adds the honest withheld-completeSnapshot signal; (b) one full local-transcript read per snapshot load mirrors the complete external JSONL scan the import reader already performs on main (same O(N) class, once per load, not per page — the per-page O(N²) variant was reverted). Both get the proper fix via the opaque snapshot cursor in [Feature]: snapshot-cursor paging for oversized imported CLI transcripts in chat.history #105644.

@openclaw-barnacle openclaw-barnacle Bot added app: web-ui App: web-ui gateway Gateway runtime size: XL maintainer Maintainer-authored PR labels Jul 12, 2026

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: e3adff9794

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +3502 to +3504
...(historyPage.responseOffset !== undefined ? { offset: historyPage.responseOffset } : {}),
...(hasMore ? { nextOffset } : {}),
...(hasMore !== undefined ? { hasMore } : {}),
...(historyPage.totalMessages !== undefined
? { totalMessages: historyPage.totalMessages }
hasMore,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Return offset on first paginated history page

When callers make the normal first-page chat.history request without offset, this now emits hasMore/nextOffset but still omits offset; the agent-facing sessions history tool only preserves pagination when result.offset or a requested offset is present (src/agents/tools/sessions-history-tool.ts:235-237), so agents calling sessions.history without explicitly guessing offset: 0 cannot discover or request the older pages that this change exposes. Include offset: 0 on paginated first-page responses, or update that consumer alongside this contract change.

Useful? React with 👍 / 👎.

@clawsweeper clawsweeper Bot added rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. P2 Normal backlog priority with limited blast radius. labels Jul 12, 2026
@clawsweeper

clawsweeper Bot commented Jul 12, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs real behavior proof before merge. Reviewed July 12, 2026, 4:54 PM ET / 20:54 UTC.

Summary
Adds offset-paged native chat history, import-aware transcript handling, and automatic Control UI scroll-back with deduplication and viewport anchoring.

PR surface: Source +336, Tests +1032, Other -2. Total +1366 across 17 files.

Reproducibility: yes. Source inspection gives a high-confidence path: a default agent-tool request has no offset, the network response omits it, and the embedded sibling exposes paging only after an offset is already supplied.

Review metrics: 1 noteworthy metric.

  • History Response Contract: 5 pagination fields coordinated. offset, nextOffset, hasMore, totalMessages, and completeSnapshot now jointly affect network gateway, embedded gateway, agent-tool, and Control UI behavior.

Stored data model
Persistent data-model change detected: serialized state: src/gateway/cli-session-history.test.ts, serialized state: src/gateway/server.chat.gateway-server-chat-b.test.ts, serialized state: src/gateway/session-transcript-readers.ts, serialized state: ui/src/pages/chat/chat-pane.ts, vector/embedding metadata: ui/src/e2e/claude-sessions.e2e.test.ts, vector/embedding metadata: ui/src/pages/chat/chat-pane.ts. Confirm migration or upgrade compatibility proof before merge.

Root-cause cluster
Relationship: fixed_by_candidate
Canonical: #105127
Summary: This PR is the candidate implementation for the canonical native scroll-back issue; oversized imported-snapshot paging remains a distinct partial-overlap follow-up.

Members:

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

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

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

Rank-up moves:

  • [P1] Fix both first-page pagination paths with focused sessions_history and embedded gateway regression coverage.
  • [P1] Add redacted real web UI chat proof showing older native history, the loading indicator, and stable viewport anchoring.

Proof guidance:

  • [P1] Needs real behavior proof before merge: Automated gateway, unit, mocked-browser, CI, and Testbox evidence is supplemental only; add redacted after-fix proof from a real native Control UI session, then update the PR body to trigger review or ask a maintainer to comment @clawsweeper re-review.

Mantis proof suggestion
The supported web UI chat lane can directly provide the missing real native-session scroll-back, spinner, and viewport-anchoring proof. A maintainer can ask Mantis to capture proof by posting this exact PR comment:

@openclaw-mantis web UI chat proof: reproduce native-session scroll-back, capture the spinner and older-message prepend, and verify the viewport remains anchored with redacted evidence.

Risk before merge

  • [P1] Network and embedded runtime modes currently expose different history reachability through the same sessions_history tool contract.
  • [P1] Oversized imported CLI transcripts remain terminal when the response byte cap truncates them, so users still cannot reach omitted imported history until the snapshot-cursor follow-up lands.

Maintainer options:

  1. Fix Contract, Accept Bounded Imports (recommended)
    Synchronize first-page paging across gateway modes, add real UI proof, and explicitly accept the linked oversized-import limitation.
  2. Require Complete Imported Paging
    Pause this branch until the snapshot-cursor design removes the terminal truncation boundary.

Next step before merge

  • [P1] Both blocking defects have narrow mechanical contract-and-test repairs; after those repairs, the protected-label imported-snapshot boundary still requires maintainer acceptance.

Maintainer decision needed

  • Question: May this PR ship while oversized CLI-import snapshots remain terminal until [Feature]: snapshot-cursor paging for oversized imported CLI transcripts in chat.history #105644?
  • Rationale: The branch deliberately improves regular native sessions without making byte-truncated imported history fully reachable, which affects persisted session-history behavior and requires maintainer intent rather than reviewer inference.
  • Likely owner: steipete — He introduced and merged the adjacent scroll-back behavior and is the strongest feature-history owner for deciding the intended completion boundary.
  • Options:
    • Accept Scoped Limitation (recommended): Fix both first-page contract defects, add real native UI proof, and merge while keeping the snapshot-cursor follow-up open.
    • Require Snapshot Paging: Hold this PR until oversized imported transcript history can be paged without repeated full materialization.

Security
Cleared: The patch changes application logic and tests without adding dependencies, action refs, permissions, secrets handling, package-resolution changes, lifecycle hooks, or downloaded code.

Review findings

  • [P2] Return offset on the first paginated history page — src/gateway/server-methods/chat.ts:3502-3504
  • [P2] Keep embedded chat.history paging in sync — src/gateway/server-methods/chat.ts:3503-3505
Review details

Best possible solution:

Use one discoverable first-page pagination contract across network gateway, embedded gateway, agent-tool serialization, and Control UI; add real native-session UI proof, then explicitly accept the bounded imported-snapshot limitation or complete the linked cursor work first.

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

Yes. Source inspection gives a high-confidence path: a default agent-tool request has no offset, the network response omits it, and the embedded sibling exposes paging only after an offset is already supplied.

Is this the best way to solve the issue?

No, not yet. Offset paging plus the shared scroll-back UI is the right general direction, but the contract is incomplete across sibling runtime paths and the imported-history boundary needs explicit maintainer acceptance.

Full review comments:

  • [P2] Return offset on the first paginated history page — src/gateway/server-methods/chat.ts:3502-3504
    A default sessions_history call sends no offset, and this response still omits offset even when hasMore and nextOffset are present. The consumer only preserves paging when it sees a response or requested offset, so agents cannot discover older pages; return offset: 0 or update the consumer contract alongside this change.
    Confidence: 0.99
  • [P2] Keep embedded chat.history paging in sync — src/gateway/server-methods/chat.ts:3503-3505
    Embedded sessions route sessions_history through the sibling stub, which still exposes paging only after callers already provide an offset. A first embedded read therefore cannot discover older native history. This path was unchanged at the earlier reviewed head; apologies for the late discovery, but it needs the same first-page contract and focused coverage.
    Confidence: 0.98
    Late finding: first raised on code an earlier review cycle already covered.

Overall correctness: patch is incorrect
Overall confidence: 0.98

AGENTS.md: found and applied where relevant.

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

Label changes

Label changes:

  • add merge-risk: 🚨 session-state: The patch changes which persisted transcript history is reachable while retaining a terminal truncation boundary for oversized imported sessions.

Label justifications:

  • P2: This is a normal-priority user-visible history feature and reliability improvement with bounded chat and agent-tool impact.
  • merge-risk: 🚨 compatibility: The changed chat.history response semantics currently diverge between network and embedded callers and can break pagination discovery for existing agent-tool consumers.
  • merge-risk: 🚨 session-state: The patch changes which persisted transcript history is reachable while retaining a terminal truncation boundary for oversized imported sessions.
  • 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: Automated gateway, unit, mocked-browser, CI, and Testbox evidence is supplemental only; add redacted after-fix proof from a real native Control UI session, then update the PR body to trigger review or ask a maintainer to comment @clawsweeper re-review.
Evidence reviewed

PR surface:

Source +336, Tests +1032, Other -2. Total +1366 across 17 files.

View PR surface stats
Area Files Added Removed Net
Source 11 458 122 +336
Tests 5 1037 5 +1032
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 1 0 2 -2
Total 17 1495 129 +1366

Acceptance criteria:

  • [P1] node scripts/run-vitest.mjs src/gateway/server.chat.gateway-server-chat-b.test.ts.
  • [P1] node scripts/run-vitest.mjs src/agents/tools/sessions-history-tool.test.ts src/agents/tools/embedded-gateway-stub.test.ts.
  • [P1] node scripts/run-vitest.mjs ui/src/pages/chat/chat-pane.test.ts ui/src/e2e/claude-sessions.e2e.test.ts.

What I checked:

Likely related people:

  • steipete: Authored and merged the current-main external-session scroll-back implementation reused by this branch, including cursor progress guards and viewport anchoring. (role: introduced adjacent behavior and merger; confidence: high; commits: 842f8f3ee92c, ae55e76721c8, b8342b854e41; files: ui/src/pages/chat/chat-pane.ts, ui/src/pages/chat/chat-thread.ts, ui/src/e2e/claude-sessions.e2e.test.ts)
  • Vincent Koc: The latest broad current-main refactor touching the central gateway, CLI-history, and chat-pane surfaces appears in commit c0f0107. (role: recent area contributor; confidence: medium; commits: c0f0107a5c84; files: src/gateway/server-methods/chat.ts, src/gateway/cli-session-history.ts, src/gateway/cli-session-history.claude.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 (2 earlier review cycles)
  • reviewed 2026-07-12T20:37:01.027Z sha e3adff9 :: needs real behavior proof before merge. :: [P2] Return offset on the first paginated history page
  • reviewed 2026-07-12T20:47:03.241Z sha 667ff21 :: needs real behavior proof before merge. :: [P2] Return offset on the first paginated history page

@openclaw-barnacle openclaw-barnacle Bot added the scripts Repository scripts label Jul 12, 2026

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 667ff210c7

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines 3503 to +3505
...(hasMore ? { nextOffset } : {}),
...(hasMore !== undefined ? { hasMore } : {}),
...(historyPage.totalMessages !== undefined
? { totalMessages: historyPage.totalMessages }
hasMore,
totalMessages: pagination.totalMessages,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Keep embedded chat.history paging in sync

When OpenClaw runs in embedded mode, sessions_history is routed through createEmbeddedCallGateway (src/agents/openclaw-tools.ts:458-576), but that sibling chat.history implementation still only returns hasMore/nextOffset when the caller already supplied offset (src/agents/tools/embedded-gateway-stub.ts:461-468). A first sessions_history read in embedded mode therefore cannot discover older native messages even though this gateway path now advertises first-page pagination; mirror the new first-page pagination contract there as well.

Useful? React with 👍 / 👎.

@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. 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. and removed rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Jul 12, 2026
@steipete
steipete merged commit 238c797 into main Jul 12, 2026
383 of 390 checks passed
@steipete
steipete deleted the feat/native-chat-scrollback branch July 12, 2026 20:58
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Jul 13, 2026
…aware history (openclaw#105688)

* feat(chat): native session scroll-back with import-aware history paging

* fix(chat): page imported session history

* fix(chat): restore terminal import snapshots

* fix(chat): gate cli import resolver on ignore flag to stop history recursion

* fix(chat): correct scroll-back types and drop orphaned recent-messages reader
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

app: web-ui App: web-ui 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.

[Feature]: native chat scroll-back (offset paging + import-aware history) to unify with catalog auto-load

1 participant