Skip to content

fix(cursor): page user spend by the top-level totalPages - #9381

Open
ShivamSharma43 wants to merge 1 commit into
apache:mainfrom
ShivamSharma43:fix/cursor-spend-pagination
Open

ShivamSharma43 wants to merge 1 commit into
apache:mainfrom
ShivamSharma43:fix/cursor-spend-pagination

Conversation

@ShivamSharma43

Copy link
Copy Markdown
Contributor

Summary

CollectUserSpend paged POST /teams/spend with nextPostPage. That function was written for filtered-usage-events and stops unless the response has pagination.hasNextPage: true. The spend endpoint has no pagination object. Per the Admin API docs ("Get Spending Data"), it returns teamMemberSpend, subscriptionCycleStart, totalMembers and a top-level totalPages. Because hasNextPage always decoded as false, the collector stopped after page 1. With pageSize 100, teams with more than 100 members lost the spend of every member past the first page.

Changes:

  • tasks/user_spend_collector.go: new nextSpendPage reads the top-level totalPages. It requests the next page until the current page reaches totalPages, and stops right away when totalPages is 0 (no members). CollectUserSpend now uses it. nextPostPage is unchanged for usage events and daily usage, which do return pagination.hasNextPage.
  • tasks/user_spend_collector_test.go: tests that pages continue from 1 to 2 to 3 when totalPages is 3 and stop on the last page. Also covers single-page and empty responses.

Does this close any open issues?

Closes #9379

Screenshots

N/A

Other Information

  • go test ./plugins/cursor/...: pass.
  • gofmt and golangci-lint run ./plugins/cursor/...: clean.
  • No open PR touches the cursor plugin.
  • Suggested label: pr-type/bug-fix.
  • AI assistance disclosure: this change was prepared with the help of Claude Code (Claude Opus 5.5), and I reviewed the diff. The commit carries a Generated-by: trailer per the ASF generative tooling guidance.

🤖 Generated with Claude Code

CollectUserSpend used nextPostPage, which stops unless the response
has pagination.hasNextPage. POST /teams/spend has no pagination
object; it reports totalMembers and a top-level totalPages. So the
collector always stopped after the first page, and teams with more
than 100 members lost the spend of everyone past the first page.

Add nextSpendPage, which reads totalPages and stops when the current
page reaches it, and use it for the spend collector. Usage events and
daily usage keep nextPostPage.

Closes apache#9379

Generated-by: Claude Code (Claude Opus 5.5)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Shivam Sharma <192242476+ShivamSharma43@users.noreply.github.com>
Copilot AI balanced review requested due to automatic review settings November 11, 2026 19:38

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.

[Bug][Cursor] User spend collector stops after the first page

2 participants