GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — feat(session): bi-directional cursor-based pagination (#6548) by CasualDeveloper · Pull Request #8535 · anomalyco/opencode

Conversation

@CasualDeveloper

@CasualDeveloper CasualDeveloper commented Jan 14, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

Issue for this PR

Closes #6548
Closes #28257
Closes #30587

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

Adds bidirectional cursor pagination for session messages across the server, app, TUI, experimental HttpApi routes, and generated SDK/OpenAPI types.

This keeps large sessions usable by loading bounded message windows, using RFC 8288 Link headers for older/newer pages, and preserving revert/restore correctness through server-backed revert preview metadata when boundary messages are outside the loaded page.

It also resolves two open issues rooted in the TUI's single-page history load:

  • [FEATURE]: TUI scroll buffer should not truncate old messages — breaks fork from history #30587: scrolling up now pages older history on demand instead of stopping at a hard limit, so fork-from-history works in long sessions.
  • /Undo command does not work if last user message gets out of visible session history #28257: /undo now walks older pages to find the last user message when trailing agent output fills the loaded window.

Scope: v1

This PR targets the current (v1) architecture on dev, where the TUI loads a single limit: 100 page and stops. The v2 branch redesigns the API with cursor pagination built in (message.list with limit/order/cursor), so v2 will solve this differently by design. Until v2 ships, this PR is the working solution for v1 releases, and the branch is kept rebased on dev for anyone building from it.

How did you verify your code works?

Verified locally on the current branch (rebased on dev):

  • bun typecheck in packages/opencode, packages/app, packages/tui, packages/core, and packages/sdk/js
  • bun test test/session/revert-compact.test.ts test/session/messages-pagination.test.ts test/server/httpapi-session.test.ts test/server/session-messages.test.ts test/util/parse-link-header.test.ts in packages/opencode (98 pass)
  • bun test --preload ./happydom.ts ./src/context/server-session.test.ts ./src/context/revert-page.test.ts ./src/pages/session/timeline/model.test.ts ./src/pages/session/timeline/projection.test.ts in packages/app (108 pass)
  • bun test test/util/pagination-helpers.test.ts test/cli/cmd/tui/sync.test.tsx in packages/tui (29 pass)
  • Regenerated OpenAPI and SDK surfaces (bun run generate in packages/client, ./packages/sdk/js/script/build.ts)
  • git diff --check dev..HEAD

Screenshots / recordings

Not included. This changes session loading/scroll behavior rather than visual styling; the behavior is covered by the targeted tests above.

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

process: human-driven and reviewed, with agentic assistance from anthropic/claude-fable-5.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

sim590, bitmensch, evan-goode, and troyliu0105 reacted with heart emoji ry2009, arsham, alberti42, scottsut, vxkc, sim590, csrl, and jasontyping reacted with rocket emoji
All reactions
  • ❤️ 4 reactions
  • 🚀 8 reactions
@github-actions

github-actions Bot commented Jan 14, 2026

Copy link
Copy Markdown
Contributor

The following comment was made by an LLM, it may be inaccurate:

Potential Duplicate Found

PR #6656: "session: paginate message loading"

  • URL: session: paginate message loading #6656
  • Relationship: This PR explicitly supersedes session: paginate message loading #6656 (as noted in the description). The current PR feat(session): bi-directional cursor-based pagination (#6548) #8535 implements the same cursor-based pagination feature but with significant improvements including bi-directional cursors, proper RFC 5005 Link headers, memory bounding, LRU caching, and additional test coverage.

This is not a duplicate in the traditional sense—it's a more complete implementation that builds upon and replaces the earlier approach.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@CasualDeveloper CasualDeveloper changed the title feat(session): add bi-directional cursor-based pagination for messages feat(session): bi-directional cursor-based pagination (#6548) Jan 14, 2026
@CasualDeveloper CasualDeveloper mentioned this pull request Jan 14, 2026
[FEATURE]: Paginated message loading for long sessions #6548
Closed
1 task done
@CasualDeveloper

CasualDeveloper commented Jan 14, 2026

Copy link
Copy Markdown
Contributor Author

@rekram1-node hi Aiden, would appreciate your feedback on how I implemented pagination, per your suggestion! :)

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@ry2009

ry2009 commented Jan 14, 2026

Copy link
Copy Markdown
Contributor

Glad I could help kickstart this, I have been a little busy to continue my OSS journey right now. I haven't personally looked through the code in depth (just did a skim) but 1k line changes seems like a lot for one PR (might be better to split it if you can) but once again maybe the code is super clean and simple -- I just haven't sifted through deeply lol. Great work & good luck closing this!

CasualDeveloper reacted with heart emoji
All reactions
  • ❤️ 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@CasualDeveloper
CasualDeveloper force-pushed the feat/6548-message-pagination branch 6 times, most recently from 4f57718 to afe9c53 Compare January 15, 2026 06:35
@github-actions github-actions Bot mentioned this pull request Jan 15, 2026
feat(tui): load conversation and session history #8627
Closed
@CasualDeveloper
CasualDeveloper force-pushed the feat/6548-message-pagination branch 3 times, most recently from 4bd8bf6 to 34eea60 Compare January 15, 2026 17:21
This was referenced Jan 15, 2026
[BUG] Cannot scroll to beginning of long conversations (message limit hardcoded to 100) (#6138) #6137
Closed
feat(tui): add session_list_limit for session picker #6138
Closed
@github-actions github-actions Bot mentioned this pull request Jan 17, 2026
feat(session): add ts_before and breakpoint params to Session.messages API #8996
Closed
@ryanwyler ryanwyler mentioned this pull request Jan 17, 2026
feat(tui): load conversation and session history #8999
Closed
@CasualDeveloper
CasualDeveloper force-pushed the feat/6548-message-pagination branch from 34eea60 to 2c70c15 Compare January 17, 2026 05:23
@CasualDeveloper
CasualDeveloper force-pushed the feat/6548-message-pagination branch from 2c70c15 to adec748 Compare January 17, 2026 10:15
@CasualDeveloper
CasualDeveloper force-pushed the feat/6548-message-pagination branch from adec748 to 01e84ef Compare January 17, 2026 10:46
@github-actions github-actions Bot mentioned this pull request Jan 17, 2026
feat(util): Add bounded LRU cache utility #9141
Closed
3 tasks done
@CasualDeveloper
CasualDeveloper force-pushed the feat/6548-message-pagination branch from 01e84ef to ea25515 Compare January 18, 2026 18:59
@CasualDeveloper
CasualDeveloper force-pushed the feat/6548-message-pagination branch from ea25515 to 4cb0df1 Compare January 18, 2026 19:23
@CasualDeveloper
CasualDeveloper force-pushed the feat/6548-message-pagination branch 2 times, most recently from 2f40327 to 686e602 Compare February 25, 2026 21:47
@CasualDeveloper
CasualDeveloper force-pushed the feat/6548-message-pagination branch from 686e602 to d12668b Compare March 8, 2026 15:07
@alberti42

alberti42 commented Mar 8, 2026

Copy link
Copy Markdown
Contributor

Is there any update on this PR? Where is it hanging? I use it daily. Thank you, @CasualDeveloper, for this super useful extension. So often, I need to fork from the first message..

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@CasualDeveloper
CasualDeveloper force-pushed the feat/6548-message-pagination branch from d12668b to fb9cc15 Compare March 8, 2026 18:50
@CasualDeveloper

CasualDeveloper commented Mar 10, 2026

Copy link
Copy Markdown
Contributor Author

Hi @alberti42, I think this one has been hanging because it's a big change and unfortunately I haven't had an opportunity to sit down with the maintainers to follow up and go over the work in this feature (I got swamped with real job stuff lol)

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@alberti42

alberti42 commented Mar 10, 2026

Copy link
Copy Markdown
Contributor

Yeah, I totally understand. Same here; sometimes there is really no time for fun projects like this one. Thank you a lot for the super important contribution.

The current implementation is no longer compatible with the main branch, right? I tried to rebase, but there were several conflicts. So, I stopped updating while waiting for this feature to be properly handled. I think some of the maintainers should help you or take over because this is a central must-have feature.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@github-actions github-actions Bot mentioned this pull request Mar 10, 2026
Add SQLite storage layer with FTS5 for memory-efficient data persistence #16913
Closed
4 of 6 tasks
@CasualDeveloper
CasualDeveloper force-pushed the feat/6548-message-pagination branch 2 times, most recently from 1c805dd to a86cd02 Compare March 27, 2026 07:19
Copilot AI reviewed Apr 10, 2026
View reviewed changes

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Pull request overview

Adds robust bi-directional, cursor-based pagination for session messages across the server/API, SDK, app, and TUI to make long sessions navigable while keeping message memory bounded.

Changes:

  • Implement before / after / oldest cursor pagination for session messages and emit RFC 8288 Link headers.
  • Update SDK types/client to support new pagination params + header-based navigation.
  • Wire TUI (and app prefetch/sync) to use boundary-aware loading with a capped in-memory message window; add/adjust regression tests.

Reviewed changes

Copilot reviewed 18 out of 18 changed files in this pull request and generated 10 comments.

Show a summary per file
File Description
packages/sdk/openapi.json Adds after/oldest query params and documents Link pagination response header.
packages/sdk/js/src/v2/gen/types.gen.ts Regenerates request types to include after/oldest for session messages.
packages/sdk/js/src/v2/gen/sdk.gen.ts Regenerates SDK client to send after/oldest query params.
packages/opencode/src/util/link-header.ts Adds RFC 8288 Link header parsing utilities for rel URLs + query param extraction.
packages/opencode/src/session/message-v2.ts Implements bidirectional cursor pagination in storage layer (before/after/oldest) and updates streaming to use new cursors.
packages/opencode/src/session/index.ts Adjusts DB import set (minor refactor).
packages/opencode/src/server/routes/session.ts Extends /session/:sessionID/message to validate new params and return RFC 8288 Link headers for prev/next pages.
packages/opencode/src/cli/cmd/tui/util/pagination.ts Adds TUI pagination helper utilities (ordering, insertion, eviction, edge hints, error normalization).
packages/opencode/src/cli/cmd/tui/routes/session/index.tsx Updates TUI session view to support boundary-aware loading and new scroll behavior, plus minor UI tweaks.
packages/opencode/src/cli/cmd/tui/context/sync.tsx Implements cursor-based message paging state, capped message windowing (500), and load older/newer/jump behaviors using Link headers.
packages/opencode/src/cli/cmd/tui/context/keybind.tsx Hardens keybind parsing for non-string config values.
packages/opencode/test/util/parse-link-header.test.ts Adds unit tests for new Link header parsing utilities.
packages/opencode/test/cli/tui/pagination-helpers.test.ts Adds unit tests for TUI pagination helper/edge-state logic.
packages/opencode/test/session/messages-pagination.test.ts Reworks session pagination regression tests for new cursor semantics and ordering rules.
packages/opencode/test/server/session-messages.test.ts Updates server API tests to validate Link header pagination (prev/next), param validation, and limit boundary behavior.
packages/opencode/test/server/session-select.test.ts Refactors request/auth helper usage for endpoint tests.
packages/app/src/pages/layout.tsx Switches app-side prefetch cursor extraction from X-Next-Cursor to parsing Link header (rel=prev).
packages/app/src/context/sync.tsx Switches app-side sync cursor extraction from X-Next-Cursor to parsing Link header (rel=prev).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread packages/opencode/src/server/instance/session.ts Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread packages/opencode/src/server/instance/session.ts Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread packages/opencode/src/session/index.ts Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread packages/opencode/src/cli/cmd/tui/routes/session/index.tsx Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread packages/opencode/src/cli/cmd/tui/routes/session/index.tsx Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread packages/opencode/src/cli/cmd/tui/routes/session/index.tsx Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread packages/opencode/test/server/session-select.test.ts Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread packages/opencode/test/server/session-select.test.ts Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread packages/opencode/test/server/session-messages.test.ts Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread packages/opencode/test/session/messages-pagination.test.ts Resolved

Uh oh!

There was an error while loading. Please reload this page.

@CasualDeveloper

CasualDeveloper commented Apr 14, 2026

Copy link
Copy Markdown
Contributor Author

Fork updated to sync with dev (as of cb1a500).

alberti42 reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@sim590 sim590 mentioned this pull request Apr 18, 2026
[FEATURE]: Timeline dialog should load all session messages, not just those in memory #23346
Closed
1 task done
@Electricitysheep Electricitysheep mentioned this pull request May 8, 2026
[FEATURE]: Add page-based navigation for browsing conversation history in TUI #26327
Closed
1 of 6 tasks
@Davids048

Davids048 commented May 11, 2026

Copy link
Copy Markdown

Hi, thank you very much for building this feature. It is very important for long context works. Is there any update on the progress of this feature?

alberti42 reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@CasualDeveloper

CasualDeveloper commented May 13, 2026

Copy link
Copy Markdown
Contributor Author

Hi, thank you very much for building this feature. It is very important for long context works. Is there any update on the progress of this feature?

for now i've just been keeping updated in my local fork of opencode, regularly rebasing and refactoring as needed to make it work on dev

you might need to manually set up my fork as a source and pull the same way if you really needed it

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@alberti42

alberti42 commented May 13, 2026

Copy link
Copy Markdown
Contributor

@Davids048 I am doing exactly this, and I am very thankful that @CasualDeveloper keeps rebasing. I have a few other branches of mine with fixes, and usually I rebase them every time there is an update from this feature.

I am not sure why OpenCode does not help here to push it through. It is nearly a dealbreaker for me not being able to get back to the beginning of a given chat.

They probably have many other projects they are currently following.

CasualDeveloper reacted with heart emoji
All reactions
  • ❤️ 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@CasualDeveloper

CasualDeveloper commented May 13, 2026

Copy link
Copy Markdown
Contributor Author

@alberti42 thanks for the compliment! :D

i think it's probably because the feature is so huge and the team is busy with refactoring a lot of stuff everywhere else lol

alberti42 reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@github-actions github-actions Bot mentioned this pull request Jun 15, 2026
📊 AI CLI 工具社区动态日报 2026-06-15 jasonalang/big_model_radar#91
Open
@coderabbitai coderabbitai Bot mentioned this pull request Jun 16, 2026
Fix stream/run turn-completion detection (empty exit, run timeout) colinmollenhour/occtl#4
Merged
@github-actions github-actions Bot mentioned this pull request Jul 8, 2026
fix(app): render cold-loaded session timelines #35928
Closed
@coderabbitai coderabbitai Bot mentioned this pull request Jul 9, 2026
analyze: add Opencode cost tracking (Go, Zen, standalone API) aiosbrain/aios-workspace#205
Merged
@github-actions github-actions Bot mentioned this pull request Jul 9, 2026
📊 AI CLI 工具社区动态日报 2026-07-09 96loveslife/big_model_radar#130
Open
@CasualDeveloper

CasualDeveloper commented Jul 9, 2026

Copy link
Copy Markdown
Contributor Author

Fork updated to sync with dev (as of 77429f5).

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@github-actions github-actions Bot mentioned this pull request Jul 9, 2026
📊 AI CLI 工具社区动态日报 2026-07-09 litang9/big_model_radar#179
Open
This was referenced Jul 17, 2026
📊 AI CLI 工具社区动态日报 2026-07-18 litang9/big_model_radar#225
Open
📊 AI CLI 工具社区动态日报 2026-07-19 zx0828/big_model_radar#273
Open
@github-actions github-actions Bot mentioned this pull request Aug 8, 2026
📊 AI CLI 工具社区动态日报 2026-08-09 litang9/big_model_radar#336
Open
@CasualDeveloper
feat(session): add paginated message history
cbf31e9
Rework V2 message pagination onto durable sequence cursors that only advertise
real older/newer pages, returning bounded projection context and a revert
preview with the first page. Extend the V1 messages endpoint with after/oldest
paging and a bounded revert preview endpoint. Move app revert, restore, and
undo flows onto server-backed previews so they stay correct beyond the loaded
window, and give the TUI bidirectional history windows with revert-aware
hydration and live-tail reconciliation.
@coderabbitai coderabbitai Bot mentioned this pull request Aug 21, 2026
fix(opencode): wait for session completion Waishnav/devspace#217
Merged
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

Copilot code review Copilot
Copilot review effort
Applies to this pull request for everyone.Learn more about Copilot code review.
Copilot left review comments
@adamdotdevin adamdotdevin Awaiting requested review from adamdotdevin
@Hona Hona Awaiting requested review from Hona
@Brendonovich Brendonovich Awaiting requested review from Brendonovich

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

[FEATURE]: TUI scroll buffer should not truncate old messages — breaks fork from history /Undo command does not work if last user message gets out of visible session history [FEATURE]: Paginated message loading for long sessions

Uh oh!

There was an error while loading. Please reload this page.

6 participants

@CasualDeveloper @ry2009 @NamedIdentity @alberti42 @Davids048
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.