Repository navigation
fix(slack): guard directory cursor pagination against repeated cursors - #120445
Conversation
listSlackDirectoryPeersLive/listSlackDirectoryGroupsLive hand-rolled do/while loops with no repeated-cursor detection and no page bound, while every other users.list/conversations.list consumer goes through collectSlackCursorPages. A Slack API or proxy edge that keeps returning the same non-empty next_cursor made directory queries paginate forever, growing the member/channel arrays without bound. Both loops now go through collectSlackCursorPages, which throws on a repeated cursor and caps total pages.
657d830 to
4993b54
Compare
|
Codex review: needs maintainer review before merge. Reviewed August 8, 2026, 12:47 AM ET / 04:47 UTC. ClawSweeper reviewWhat this changesThe PR replaces Slack directory user and channel pagination loops with the existing bounded repeated-cursor guard and adds endpoint-level regression tests. Regression provenancePossible regression — probable (reproduction; reviewed change). No predecessor PR is attributed. Merge readinessNo blocking findings. This focused PR is still necessary: current main retains two unbounded Slack directory loops, while the patch routes both through the established shared guard without changing their request options or result shaping. Priority: P2 Review scores
Verification
How this fits togetherSlack’s live directory adapter fetches paginated users and channels from the Slack Web API for directory lookup and channel checks. The resulting records flow to CLI and gateway callers after filtering and limiting. flowchart LR
A[Directory lookup] --> B[Slack live directory adapter]
B --> C[Slack API pages]
C --> D[Shared cursor guard]
D --> E[Filtered users or channels]
E --> F[CLI and gateway callers]
Before merge
Agent review detailsSecurityNone. PR surfaceSource -13, Tests +67. Total +54 across 2 files. View PR surface stats
Review metrics
Technical reviewBest possible solution: Merge the two remaining live-directory consumers onto the Slack-local shared guard, retaining the existing caller-visible bounded failure behavior. Do we have a high-confidence way to reproduce the issue? Yes, at source level: return the same non-empty next_cursor from users.list or conversations.list and current main repeats the request indefinitely; the PR body also records this through the real directory and Slack-client path. Is this the best way to solve the issue? Yes. Reusing the existing Slack-local cursor collector is the narrowest maintainable fix because sibling consumers of the same endpoints already use it and filtering, ranking, and limits remain unchanged. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against 68e37772452c. LabelsLabel changes:
Label justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
|
|
@clawsweeper re-review |
|
🦞👀 Command router queued. I will update this comment with the next step. |
|
Merged via squash.
|
openclaw#120445) listSlackDirectoryPeersLive/listSlackDirectoryGroupsLive hand-rolled do/while loops with no repeated-cursor detection and no page bound, while every other users.list/conversations.list consumer goes through collectSlackCursorPages. A Slack API or proxy edge that keeps returning the same non-empty next_cursor made directory queries paginate forever, growing the member/channel arrays without bound. Both loops now go through collectSlackCursorPages, which throws on a repeated cursor and caps total pages.
Summary
fix(slack): route directory users.list/conversations.list pagination through the shared repeated-cursor guard so a looping next_cursor cannot hang directory queriesWhat Problem This Solves
Slack directory queries (
listSlackDirectoryPeersLive,listSlackDirectoryGroupsLive— used by directory lookup and channel self-checks) paginate the Slack Web API with a hand-rolleddo/whilethat followsresponse_metadata.next_cursoruntil it comes back empty. Slack documents an empty cursor as the only normal termination signal, but nothing guards the abnormal ones: if the API (or an intermediate proxy, gateway, or SDK edge) keeps returning the same non-empty cursor — or endless distinct cursors — the loop never exits, and themembers/channelsarrays grow without bound. The directory request hangs forever while memory climbs.This is not hypothetical hardening of an unreachable path: the repository already treats unbounded cursor pagination as a real failure mode.
extensions/slack/src/cursor-pages.ts(collectSlackCursorPages) exists precisely for this invariant — it throws on a repeated cursor and caps total pages — and it is already used for the same two endpoints inresolve-users.tsandresolve-channels.ts.directory-live.tsis the only consumer of these endpoints that still hand-rolls the loop.Code evidence: in
extensions/slack/src/directory-live.ts(main, before this fix):extensions/slack/src/directory-live.ts:101-111—do { users.list(...) } while (cursor)with no repeated-cursor detection and no page cap.extensions/slack/src/directory-live.ts:147-159— the identical pattern forconversations.list.extensions/slack/src/cursor-pages.ts:20-38—collectSlackCursorPageskeeps aseenCursorsset (throw on repeat) and enforcesSLACK_CURSOR_PAGE_LIMIT.Minimal reproduction: stub only the network wire to return
{ ok: true, members: [], response_metadata: { next_cursor: "SAME_CURSOR_FOREVER" } }for everyusers.listcall — the reallistSlackDirectoryPeersLivekeeps issuing requests indefinitely (the proof below stops it at 501 calls with a harness cap). See the Evidence section below.Root Cause
users.list/conversations.listresponses repeat a non-emptynext_cursor, then any directory query.Why This Fix
collectSlackCursorPages— the guard the repo already built and tested for this exact invariant, already used on the same endpoints elsewhere. The change deletes code and aligns all consumers on one behavior; item collection, filtering, ranking, andparams.limitslicing are untouched.directory-live.ts— rejected: it forks the guard into a second implementation that can drift (the repo's own comment incursor-pages.tscalls this backstop "deliberately" shared).User Impact
next_cursorvalues.Slack cursor pagination repeated a cursor after 2 pages, surfacing the upstream misbehavior instead of hiding it.Evidence
No mocked modules: the proof runs the real
listSlackDirectoryPeersLive/listSlackDirectoryGroupsLivewith the real Slack lookup client (createSlackLookupClient→@slack/web-api); only the network wire (globalThis.fetch, the exact boundary where Slack/proxy data enters) is stubbed. The stub repeats one non-empty cursor but stops offering it after 500 calls (a proof-harness cap, not a code path) so the run terminates; S3 is an honest two-page directory control.directory-live.tsandcursor-pages.tsare byte-identical between the main checkout used below and the current PR base.Before (on main)
After (with fix)
Tests and Validation
node node_modules/vitest/vitest.mjs run extensions/slack/src/directory-live.test.ts extensions/slack/src/cursor-pages.test.ts-- 9/9 tests passed, including the new regression testsrejects a repeated users.list cursor instead of paginating foreverandrejects a repeated conversations.list cursor instead of paginating forever(both fail fast after exactly 2 API calls) plus the advancing-cursor control.pnpm exec oxfmt --check extensions/slack/src/directory-live.ts extensions/slack/src/directory-live.test.tspassed;git diff --checkpassed.Note: proof and tests were run with Node 24.19.0.