Implement UID-cursor pagination for search#18
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 2908ab6ae3
ℹ️ 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".
Sources/PostServer/PostServer.swift
Outdated
| var identifierSet: MessageIdentifierSet<UID>? | ||
| if let afterUid { | ||
| // Only search UIDs greater than the cursor | ||
| identifierSet = MessageIdentifierSet(UID(afterUid + 1)...) |
There was a problem hiding this comment.
Validate
afterUid before incrementing cursor
searchMessages is exposed as an @MCPTool, but the new cursor logic does afterUid + 1 directly. If a caller sends afterUid = Int.max (or any value near the bound), Swift integer overflow traps at runtime, which can terminate the daemon for a single malformed request. Please bound-check afterUid (and ideally constrain it to IMAP UID range) before computing the next value.
Useful? React with 👍 / 👎.
Sources/post/Commands/Search.swift
Outdated
| // Show next page hint | ||
| if let next = result.page.next { | ||
| print() | ||
| print("To see more: post search --server \(serverId) --mailbox \(mailbox) --limit \(limit) --after-uid \(next.afterUid)") |
There was a problem hiding this comment.
Include active filters in next-page hint
The plain-text pagination hint only includes --server, --mailbox, --limit, and --after-uid, so following the suggested command after a filtered search (for example --from, --subject, date bounds, or flag filters) fetches a different result set instead of the next page of the current query. This produces incorrect pagination guidance for users who rely on the printed command.
Useful? React with 👍 / 👎.
- P1: Validate afterUid bounds (0 to UInt32.max) to prevent overflow - P2: Include all active filters in plain-text next-page hint
Resolved conflicts by keeping review fixes (P1 + P2) from the feature branch.
Summary
Implements #13: UID-based cursor pagination for large search results using ESEARCH PARTIAL (RFC 9394).
Changes
--limitand--after-uidflags topost searchextendedSearch()with server-side pagination{ "total": 998, "messages": [...], "page": { "returned": 50, "hasMore": true, "next": { "afterUid": 64241 } } }SearchResult,SearchResultPage, andSearchResultNextmodelsSearchPaging.swifthelperTesting
Tested on
drobnik / Archive(998 messages in 2025):Verification
swift build -c releaseswift test(8/8 passing)--after-uidCloses #13