Skip to content

fix(cursor): accept numeric strings in spendLimitUsage - #155

Closed
Itstommy10 wants to merge 1 commit into
onllm-dev:mainfrom
Itstommy10:fix/cursor-flexible-spend-limit
Closed

Itstommy10 wants to merge 1 commit into
onllm-dev:mainfrom
Itstommy10:fix/cursor-flexible-spend-limit

Conversation

@Itstommy10

Copy link
Copy Markdown
Contributor

Summary

Cursor's usage endpoint returns some spendLimitUsage fields as strings instead of numbers (seen on a Free account: "pooledLimit":"0"). Because CursorSpendLimitUsage declares them as int, decoding the whole usage response failed and Cursor polling never stored data:

Failed to fetch Cursor quotas error="cursor: fetch usage: json: cannot unmarshal string into Go struct field CursorSpendLimitUsage.spendLimitUsage.pooledLimit of type int"

This adds a custom UnmarshalJSON for CursorSpendLimitUsage that accepts the integer fields as JSON numbers, numeric strings, empty strings or null (empty/null/non-numeric decode as 0). The struct fields and all call sites stay int, so nothing else changes.

Test plan

  • New tests: numbers, numeric strings, empty/null, float, nested in the usage response
  • go vet ./internal/api/ and go test ./internal/api/
  • Verified against a real Free account: polling now completes (Cursor poll complete account_type=individual plan_name=Free quota_count=2)

Cursor returns some spendLimitUsage fields as strings (e.g. pooledLimit
"0" on free accounts), which made the whole usage response fail to
decode with "cannot unmarshal string into ... pooledLimit of type int".
Decode the integer fields from numbers, numeric strings, empty strings
or null.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@codecov

codecov Bot commented Oct 22, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 74.35897% with 10 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
internal/api/cursor_types.go 74.35% 5 Missing and 5 partials ⚠️

📢 Thoughts on this report? Let us know!

@prakersh

Copy link
Copy Markdown
Contributor

Thanks a lot for digging into this and sending a fix, @Itstommy10, and for checking it against a real Free account. That confirmation is really useful.

The same issue was reported as #151, and the fix landed on main in #153 and ships in v2.14.14. It adds string-tolerant decoders for every numeric field in the Cursor responses, not just spendLimitUsage, and also handles "", null, decimals (rounded), and NaN, Inf and overflow. A field that can't be read now drops only the quota it defines, with a warning, instead of being stored as 0. Main also has a regression test for a Free account with a string pooledLimit.

Because main already defines UnmarshalJSON on CursorSpendLimitUsage and the fields are no longer plain int, this branch would not compile after a rebase, so I am closing it as superseded. If you still see a Cursor decode error on v2.14.14, please open an issue with the log line and a redacted payload and we will take a look. Thanks again!

@prakersh prakersh closed this Oct 22, 2026
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