Skip to content

M1: Add composite DB index and getMessagesPaginated()#21562

Merged
Jasonnnz merged 1 commit into
feature/msg-paginationfrom
swarm/msg-pagination/task-1
Mar 25, 2026
Merged

M1: Add composite DB index and getMessagesPaginated()#21562
Jasonnnz merged 1 commit into
feature/msg-paginationfrom
swarm/msg-pagination/task-1

Conversation

@Jasonnnz
Copy link
Copy Markdown
Contributor

@Jasonnnz Jasonnnz commented Mar 25, 2026

Summary

  • Adds composite DB index idx_messages_conversation_created_at on messages(conversation_id, created_at) for efficient paginated history queries
  • Adds getMessagesPaginated() with limit+1 sentinel pattern for server-side cursor pagination
  • Adds getLastAssistantTimestampBefore() for interface diff seeding

Part of #21550.

Test plan

  • Verify migration creates index without error on fresh DB
  • Verify getMessagesPaginated() with limit=undefined returns all messages in ASC order with hasMore: false
  • Verify getMessagesPaginated() with a limit returns correct slice with sentinel-based hasMore
  • Verify getMessagesPaginated() with beforeTimestamp filters correctly
  • Verify getLastAssistantTimestampBefore() returns correct timestamp or 0

Generated with Claude Code


Open with Devin

…istory pagination

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@Jasonnnz Jasonnnz self-assigned this Mar 25, 2026
Copy link
Copy Markdown

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

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: 65a6cec0bb

ℹ️ 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 thread assistant/src/memory/conversation-crud.ts
Copy link
Copy Markdown
Contributor

@devin-ai-integration devin-ai-integration Bot left a comment

Choose a reason for hiding this comment

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

Devin Review found 1 potential issue.

View 2 additional findings in Devin Review.

Open in Devin Review

Comment thread assistant/src/memory/conversation-crud.ts
@Jasonnnz
Copy link
Copy Markdown
Contributor Author

Re: tie-breaker cursor — this is explicitly scoped out as a follow-up hardening task. monotonicNow() guarantees strictly increasing timestamps within a process run, making same-millisecond collisions extremely unlikely. The deleted #9246 implementation had this — will be restored as a follow-up.

Re: no callers — correct, these are introduced ahead of M2 (#21553) which wires them into handleListMessages. Part of #21550.

@Jasonnnz Jasonnnz merged commit ac3b6fe into feature/msg-pagination Mar 25, 2026
6 checks passed
@Jasonnnz Jasonnnz deleted the swarm/msg-pagination/task-1 branch March 25, 2026 18:05
Jasonnnz added a commit that referenced this pull request Mar 25, 2026
* feat: add composite DB index and getMessagesPaginated() for message history pagination (#21562)

Co-authored-by: Vellum Assistant <assistant@vellum.ai>
Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* M2: Wire pagination into handleListMessages HTTP endpoint (#21569)

* feat: wire server-side pagination into handleListMessages HTTP endpoint

Part of #21550

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* fix: gate pagination fields behind isPaginated and regenerate openapi spec

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: Vellum Assistant <assistant@vellum.ai>
Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* M3: Client-side safety fixes for pagination edge cases (#21565)

* fix: remove trim-after-pagination and add 60s safety timeout for stuck loading state

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* fix: use minimal state clear instead of resetMessagePagination() on timeout

Replace resetMessagePagination() in the 60s timeout handler with a
targeted clear of isLoadingMoreMessages + loadMoreTimeoutTask. This
preserves the user's scroll position, historyCursor, and hasMoreHistory
so they can retry by scrolling up, rather than collapsing the visible
window.

Also update doc comments to reflect the 30s/60s two-stage timeout
behavior and the accepted misclassification tradeoff.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: Vellum Assistant <assistant@vellum.ai>
Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* test: add pagination test suite for handleListMessages (#21578)

Part of #21550. Adds 9 test cases covering backward compatibility, cursor
pagination, strict exclusivity, hasMore logic, metadata correctness, empty
conversations, and input validation.

Co-authored-by: Vellum Assistant <assistant@vellum.ai>
Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* fix: remove duplicate guard let self in timeout closure (non-optional after first unwrap)

---------

Co-authored-by: Vellum Assistant <assistant@vellum.ai>
Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant