Skip to content

fix(messages): resolve message ID cursors to sortKey - #40

Open
b-pm wants to merge 2 commits into
beeper:mainfrom
b-pm:fix/messages-cursor-sortkey
Open

b-pm wants to merge 2 commits into
beeper:mainfrom
b-pm:fix/messages-cursor-sortkey

Conversation

@b-pm

@b-pm b-pm commented Oct 2, 2026

Copy link
Copy Markdown

Summary

Fixes #39.

messages list (--before-cursor / --after-cursor), messages context (--id), and messages export were passing a message ID straight through as the Desktop API cursor. The API expects a sortKey (oldestCursor / newestCursor on pages), so ID-based paging returned wrong or empty windows.

This PR resolves a supplied cursor via messages.retrieve when chat + message ID are available, then uses that message’s sortKey. If retrieve 404s (value is already a sortKey) or sortKey is missing, the original value is passed through unchanged.

Flag help and docs/messages.md now describe cursor semantics (message ID or sortKey) instead of “message ID” alone.

Out of scope

Server-side Desktop API issues remain upstream and are not addressed here:

Test plan

  • Unit tests for resolveMessageCursor (ID → sortKey, sortKey passthrough on 404, missing retrieve / missing sortKey, unexpected errors)
  • Wiring coverage for list + context using the resolved sortKey as API cursor
  • bun test test/messages-cursor.test.ts (8 pass) — full monorepo bun install / bun test not run in this environment

Desktop API message list pagination expects sortKey as cursor, but
messages list/context/export were passing message IDs through unchanged.

Retrieve the message when chat+ID are available and use its sortKey;
pass through values that are already sortKeys (retrieve 404).

Fixes beeper#39
Copilot AI balanced review requested due to automatic review settings October 2, 2026 18:48
@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot review overview

🟡 Changes recommended

The wiring tests bypass the production commands and cannot detect regressions in their cursor handling.

Review effort: Balanced
Findings: 1 Medium severity

Open (1)
What changed in this PR

Fixes #39 by resolving message IDs to Desktop API sortKey cursors before pagination.

Changes:

  • Applies cursor resolution to list, context, and export.
  • Clarifies cursor semantics in help and documentation.
  • Adds resolver tests and simulated wiring checks.
File Description
packages/​cli/​test/​messages-cursor.test.ts Adds resolver and simulated wiring tests.
packages/​cli/​test/​fixtures/​fake-client.ts Adds optional message sortKey.
packages/​cli/​src/​lib/​resolve.ts Adds cursor resolution with passthrough fallbacks.
packages/​cli/​src/​commands/​messages/​list.ts Resolves pagination cursors and updates help.
packages/​cli/​src/​commands/​messages/​export.ts Resolves export cursors and updates help.
packages/​cli/​src/​commands/​messages/​context.ts Uses one resolved cursor for both directions.
packages/​cli/​docs/​messages.md Documents message ID and sortKey support.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread packages/cli/test/messages-cursor.test.ts Outdated

b-pm commented Oct 2, 2026

Copy link
Copy Markdown
Author

Copilot's wiring-test finding is valid. The implementation fix itself is in place, but the two wiring tests currently simulate the resolver/list sequence instead of invoking MessagesList / MessagesContext, so they would not catch a regression in command wiring. I’m treating that as the remaining item before this is merge-ready; the test should follow the existing local Bun.serve + bin/dev.js command pattern and assert the actual outgoing cursor plus one context lookup.

b-pm commented Oct 3, 2026

Copy link
Copy Markdown
Author

Addressed Copilot's wiring-test finding in cb0a1f7: the tests now launch the real messages list and messages context CLI commands against a local Bun.serve API stub. They assert the outgoing resolved sortKey cursor, both context directions, and exactly one target-message lookup. Please re-review the current head.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

messages list --before-cursor/--after-cursor and messages context pass a message ID where the API expects a sort key

2 participants