Skip to content

fix(slack): keep paginating past short pages until next_cursor is empty - #9465

Open
ShivamSharma43 wants to merge 1 commit into
apache:mainfrom
ShivamSharma43:fix/slack-short-page-pagination
Open

ShivamSharma43 wants to merge 1 commit into
apache:mainfrom
ShivamSharma43:fix/slack-short-page-pagination

Conversation

@ShivamSharma43

Copy link
Copy Markdown
Contributor

Summary

The Slack collectors can stop paginating too early and silently skip channels, messages and thread replies.

collectChannel (conversations.list), collectChannelMessage (conversations.history) and collectThread (conversations.replies) pass the requested limit (100, 100 and 50) as the ApiCollector PageSize. With GetNextPageCustomData set, ApiCollector.fetchPagesSequentially returns as soon as a page has fewer items than PageSize, before GetNextPageCustomData looks at the cursor:

if count < collector.args.PageSize {
	return nil
}

Slack's pagination docs say: "It's possible to receive fewer results than your specified limit, even when there are additional results to retrieve", and that only an empty next_cursor means there are no further results. So when Slack returns a short page with a non-empty response_metadata.next_cursor, the rest of the channel list, the channel history or the thread is not collected, and the subtask still succeeds.

Changes:

  • tasks/api_client.go: slackCollectorPageSize = 1 is passed as PageSize, so ApiCollector never ends the collection on a short page and only an empty next_cursor does. This is the same approach as the claude_code and cursor collectors (PageSize: 1 plus their own limit query parameter). The number of items asked from Slack is still sent as limit. The three copies of the cursor logic are replaced by getSlackNextCursor and setSlackCursorQuery.
  • tasks/*_collector.go: the ApiCollectorArgs are built in newChannelCollectorArgs, newChannelMessageCollectorArgs and newThreadCollectorArgs, so they can be tested with a mock API client.
  • collectThread no longer sends offset: conversations.replies has no such parameter, and the value came from Pager.Skip, which now grows by 1 per page.

Does this close any open issues?

No issue is open for this. The bug is described above.

Screenshots

N/A

Other Information

  • New pagination_test.go runs each collector's ApiCollectorArgs through ApiCollector against a fake Slack API that serves three short pages (2, 1 and 3 items, next_cursor set on the first two). It checks that all three pages are requested with the right cursor and limit, and that all 6 items are saved. With the old PageSize (the limit), only the first page is requested and the test fails.
  • go test ./plugins/slack/..., go vet ./plugins/slack/..., gofmt and golangci-lint run ./plugins/slack/... are clean (mocks generated with mockery v3.9.0 as in make mock). Not run against a live Slack workspace.
  • Not covered here: ApiCollector.fetchAsync returns before calling the pagination handler when a page has no items, so a page with zero items and a non-empty next_cursor still ends the collection. Fixing that needs a change in the shared helper.
  • Suggested label: pr-type/bug-fix.
  • This PR was prepared with AI assistance (Claude Code). The commit carries a Co-Authored-By: trailer.

🤖 Generated with Claude Code

The Slack collectors (conversations.list, conversations.history and
conversations.replies) passed the requested `limit` as the ApiCollector
PageSize. With GetNextPageCustomData set, ApiCollector stops as soon as
a page has fewer items than PageSize, before looking at the cursor.
Slack documents that a page can have fewer results than `limit` while
more results remain, and that only an empty next_cursor marks the end,
so channels, messages and thread replies after a short page were
silently not collected.

Give ApiCollector a PageSize of 1 (the same approach as the claude_code
and cursor plugins) and keep sending the real page size as `limit`, so
only an empty response_metadata.next_cursor ends the collection. The
three collectors now share getSlackNextCursor and setSlackCursorQuery,
and their ApiCollectorArgs are built in functions that the new test
runs against a fake Slack API. The unused `offset` parameter sent to
conversations.replies (which has no such parameter) is dropped, as it
was derived from the pager.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Copilot AI balanced review requested due to automatic review settings November 27, 2026 15:47

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

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.

2 participants