feat(messages): add since parameter to get_messages API and MCP tool#154
Open
tlongwell-block wants to merge 1 commit intomainfrom
Open
feat(messages): add since parameter to get_messages API and MCP tool#154tlongwell-block wants to merge 1 commit intomainfrom
since parameter to get_messages API and MCP tool#154tlongwell-block wants to merge 1 commit intomainfrom
Conversation
Adds forward pagination to the channel messages endpoint, enabling agents to poll for new messages since a given timestamp. Mirrors the existing `before` parameter pattern. When `since` is provided without `before`, results are ordered oldest-first (ASC) for chronological consumption. When both are provided or only `before`, ordering remains newest-first (DESC). Changes: - sprout-db: add since_cursor param to get_channel_messages_top_level - sprout-relay: add since query param to GET /api/channels/:id/messages - sprout-mcp: add since field to GetMessagesParams, update tool description Naming follows NIP-01 convention (since/until) and matches the existing get_feed tool's since parameter. No schema changes or new indexes needed. Codex CLI review: 7/10, SQL injection safe, bind order correct, ORDER BY logic correct. One pre-existing pattern noted (invalid timestamps silently ignored, consistent with existing before behavior).
wesbillman
approved these changes
Mar 22, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Adds forward pagination to the channel messages endpoint, enabling agents to poll for new messages since a given timestamp. Mirrors the existing
beforeparameter pattern.Motivation
Agent orchestration in Sprout requires polling for new messages. Without
since, agents must re-read the entire recent message window on every poll and diff against what they've already seen. Withsince, the polling loop becomes clean and stateless:This is the per-channel equivalent of
get_feed's existingsinceparameter.Changes
sprout-db/src/thread.rssince_cursorparam toget_channel_messages_top_level;AND e.created_at > $Nclause; conditional ORDER BY (ASC when since-only)sprout-db/src/lib.rssprout-relay/src/api/messages.rssince: Option<i64>toListMessagesParams; parse and pass to DBsprout-mcp/src/server.rssince: Option<i64>toGetMessagesParams; update tool description; add to query builderNo schema changes. No new indexes. The existing
idx_events_channel_createdcovers both directions.Behavior
sincewithoutbefore: returns messages created strictly after the timestamp, ordered oldest-first (ASC) for chronological consumptionbeforewithoutsince: existing behavior, newest-first (DESC)sinceandbefore: bounded window, newest-first (DESC)Naming
Uses
sinceto match:since/until)get_feedtool (sinceparameter)subscriptionstable (filter_since/filter_untilcolumns)Review
Codex CLI review: 9/10, APPROVE
Residual note from reviewer: invalid out-of-range timestamps are silently treated as
None(pre-existing pattern frombefore, not introduced here).