Skip to content

fix(slack): guard directory cursor pagination against repeated cursors - #120445

Merged
steipete merged 1 commit into
openclaw:mainfrom
wanyongstar:fix/slack-directory-pagination-guard
Aug 8, 2026
Merged

steipete merged 1 commit into
openclaw:mainfrom
wanyongstar:fix/slack-directory-pagination-guard

Conversation

@wanyongstar

Copy link
Copy Markdown
Contributor

Summary

fix(slack): route directory users.list/conversations.list pagination through the shared repeated-cursor guard so a looping next_cursor cannot hang directory queries

What Problem This Solves

Slack directory queries (listSlackDirectoryPeersLive, listSlackDirectoryGroupsLive — used by directory lookup and channel self-checks) paginate the Slack Web API with a hand-rolled do/while that follows response_metadata.next_cursor until 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 the members/channels arrays 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 in resolve-users.ts and resolve-channels.ts. directory-live.ts is 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 for conversations.list.
  • Compare extensions/slack/src/cursor-pages.ts:20-38 — collectSlackCursorPages keeps a seenCursors set (throw on repeat) and enforces SLACK_CURSOR_PAGE_LIMIT.

Minimal reproduction: stub only the network wire to return { ok: true, members: [], response_metadata: { next_cursor: "SAME_CURSOR_FOREVER" } } for every users.list call — the real listSlackDirectoryPeersLive keeps issuing requests indefinitely (the proof below stops it at 501 calls with a harness cap). See the Evidence section below.

Root Cause

  • The unguarded loops predate the current history root (the file arrives unchanged at the boundary).
  • Violated invariant: every cursor pagination loop over external API data must terminate even when the cursor stream is pathological — repeated cursors are a protocol violation and must fail fast; endless distinct cursors must hit a page bound. The shared helper encodes exactly this contract, but these two call sites were never migrated to it.
  • Trigger condition: a Slack workspace (or a proxy between gateway and Slack) whose users.list/conversations.list responses repeat a non-empty next_cursor, then any directory query.

Why This Fix

  • Option A (chosen): replace both hand-rolled loops with 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, and params.limit slicing are untouched.
  • Option B: add a local repeated-cursor set and page cap inside directory-live.ts — rejected: it forks the guard into a second implementation that can drift (the repo's own comment in cursor-pages.ts calls this backstop "deliberately" shared).
  • Option C: leave the loops and document that directory queries can hang — rejected: an unbounded await inside a user-facing lookup is a liveness bug, not a doc issue.

User Impact

  • Affected scenario: Slack directory queries against a workspace/proxy that returns repeating or endless next_cursor values.
  • Before: the query paginates forever (in the proof, 501 sequential API calls with no end until the harness cap), memory grows with the accumulated arrays, and the caller never gets an answer.
  • After: the query fails fast with Slack cursor pagination repeated a cursor after 2 pages, surfacing the upstream misbehavior instead of hiding it.
  • Behavior change: none for healthy workspaces — the honest multi-page control in the proof resolves with identical results before and after.

Evidence

No mocked modules: the proof runs the real listSlackDirectoryPeersLive/listSlackDirectoryGroupsLive with 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.ts and cursor-pages.ts are byte-identical between the main checkout used below and the current PR base.

Before (on main)

$ node --import tsx proof-slack-directory-pagination.mjs   # main: bare do/while, no cursor guard
S1 peers, repeated next_cursor: RESOLVED after 501 API call(s)
BAD  S1: loop only ended because the proof cap stopped the cursor at 500
S2 groups, repeated next_cursor: RESOLVED after 501 API call(s)
BAD  S2: loop only ended because the proof cap stopped the cursor at 500
S3 control, honest two-page users.list: RESOLVED after 2 API call(s)
   entries: ["user:U1","user:U2"]
BEHAVIOR: FAIL - directory pagination spins on a repeated Slack cursor
exit=1

After (with fix)

$ node --import tsx proof-slack-directory-pagination.mjs   # HEAD: collectSlackCursorPages guards both loops
S1 peers, repeated next_cursor: REJECTED after 2 API call(s)
   error: Slack cursor pagination repeated a cursor after 2 pages
S2 groups, repeated next_cursor: REJECTED after 2 API call(s)
   error: Slack cursor pagination repeated a cursor after 2 pages
S3 control, honest two-page users.list: RESOLVED after 2 API call(s)
   entries: ["user:U1","user:U2"]
BEHAVIOR: PASS - repeated cursors fail fast; honest paginated directories still resolve
exit=0

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 tests rejects a repeated users.list cursor instead of paginating forever and rejects 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.ts passed; git diff --check passed.
  • Manual verification (the proof above):
    1. On main, both loops only stop because the proof harness cuts the cursor off at 500 pages -- FAIL.
    2. With the fix, both fail fast at 2 calls with the shared guard's repeated-cursor error, and the honest two-page control is unchanged -- PASS.

Note: proof and tests were run with Node 24.19.0.

@openclaw-barnacle openclaw-barnacle Bot added channel: slack Channel integration: slack size: S labels Aug 8, 2026
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.
@wanyongstar
wanyongstar force-pushed the fix/slack-directory-pagination-guard branch from 657d830 to 4993b54 Compare August 8, 2026 04:21
@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. P2 Normal backlog priority with limited blast radius. labels Aug 8, 2026
@clawsweeper

clawsweeper Bot commented Aug 8, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed August 8, 2026, 12:47 AM ET / 04:47 UTC.

ClawSweeper review

What this changes

The PR replaces Slack directory user and channel pagination loops with the existing bounded repeated-cursor guard and adds endpoint-level regression tests.

Regression provenance

Possible regression — probable (reproduction; reviewed change). No predecessor PR is attributed.

Merge readiness

⚠️ Ready for maintainer review - 1 item remains

No 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
Reviewed head: 4993b540f2e99f19b4d08da97080b9213d1d023a

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused canonical repair with strong boundary-oriented proof and no actionable correctness finding.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (terminal): The PR body records before/after behavior through the real directory functions and Slack Web API client with the cursor fault injected at the fetch boundary, including a healthy two-page control.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (terminal): The PR body records before/after behavior through the real directory functions and Slack Web API client with the cursor fault injected at the fetch boundary, including a healthy two-page control.
Evidence reviewed 6 items Current-main defect: Both live directory functions continue until a cursor becomes empty, with no repeat detection or page ceiling.
Canonical repair owner: The existing Slack-local helper normalizes cursors, rejects repeats, and enforces a 10,000-page ceiling.
Sibling contract: The same users.list and conversations.list request shapes already use the shared helper in Slack allowlist resolution.
Findings None None.
Security None None.

How this fits together

Slack’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]
Loading

Before merge

  • Complete next step (P2) - No repair-lane action is needed: the submitted branch already contains the narrow mechanical repair and has no actionable review finding.
Agent review details

Security

None.

PR surface

Source -13, Tests +67. Total +54 across 2 files.

View PR surface stats
Area Files Added Removed Net
Source 1 17 30 -13
Tests 1 67 0 +67
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 2 84 30 +54

Review metrics

Metric Value Why it matters
Production vs test LOC production +17/-30 (net -13); tests +67/-0 The patch removes duplicated pagination control flow while adding focused endpoint regressions.

Technical review

Best 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.

Labels

Label changes:

  • add P2: A pathological Slack response can indefinitely stall a live directory lookup, but the failure is limited to that channel workflow.
  • add proof: sufficient: Contributor real behavior proof is sufficient. The PR body records before/after behavior through the real directory functions and Slack Web API client with the cursor fault injected at the fetch boundary, including a healthy two-page control.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🦞 diamond lobster and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (terminal): The PR body records before/after behavior through the real directory functions and Slack Web API client with the cursor fault injected at the fetch boundary, including a healthy two-page control.

Label justifications:

  • P2: A pathological Slack response can indefinitely stall a live directory lookup, but the failure is limited to that channel workflow.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🦞 diamond lobster and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (terminal): The PR body records before/after behavior through the real directory functions and Slack Web API client with the cursor fault injected at the fetch boundary, including a healthy two-page control.
  • proof: sufficient: Contributor real behavior proof is sufficient. The PR body records before/after behavior through the real directory functions and Slack Web API client with the cursor fault injected at the fetch boundary, including a healthy two-page control.

Evidence

What I checked:

Likely related people:

  • joshavant: Current-main blame attributes both live directory loops to this commit, which also introduced the adjacent shared cursor guard. (role: feature author and recent area contributor; confidence: high; commits: 5cc2fa624925; files: extensions/slack/src/directory-live.ts, extensions/slack/src/cursor-pages.ts)
  • Peter Steinberger: History identifies a prior Slack cyclic-pagination repair that established the related invariant for sibling paths. (role: related pagination repair contributor; confidence: medium; commits: 50a97288dd03; files: extensions/slack/src/cursor-pages.ts, extensions/slack/src/resolve-users.ts, extensions/slack/src/resolve-channels.ts)

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

@steipete

steipete commented Aug 8, 2026

Copy link
Copy Markdown
Contributor

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Aug 8, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Command router queued. I will update this comment with the next step.

@steipete
steipete merged commit 16ab7e8 into openclaw:main Aug 8, 2026
94 checks passed
@steipete

steipete commented Aug 8, 2026

Copy link
Copy Markdown
Contributor

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Aug 9, 2026
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

channel: slack Channel integration: slack P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: S status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants