Repository navigation
fix(toolset): keep a timed-out 429 on GET /accounts fatal to a fan-out - #403
Merged
Merged
Conversation
When GET /accounts times out while a 429 is being retried, the toolset throws a 429 StackOneAPIError whose cause is the raw TimeoutError. isRateLimitFailure only treats a 429 as a rate limit when its cause is a StreamableHTTPError, RateLimitTimeoutError or HttpRateLimitError, so this error did not count. An end-user lookup that hit it was rewrapped as the original refusal, and fetchTools skipped the account and returned a partial catalog instead of failing with the 429. Wrap the cause in RateLimitTimeoutError, as the MCP session already does for the same case, and add a regression test that fails without the fix. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Co-authored-by: Guillaume Lebedel <10488548+glebedel@users.noreply.github.com>
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
commit: |
…counts paths - Add rateLimitTimeoutError() so the MCP session and the accounts lookup build the same StackOneAPIError (status 429, RateLimitTimeoutError cause) from one place instead of two copies - Stop exporting RateLimitTimeoutError, which only the helper constructs - Fix the isRateLimitFailure doc line to describe what it checks - Assert the full error message in the end-user lookup timeout test Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Co-authored-by: Guillaume Lebedel <10488548+glebedel@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
When
GET /accountstimed out while a 429 was being retried, the toolset threw a 429StackOneAPIErrorwhose cause was the rawTimeoutError.isRateLimitFailureonly treats a 429 as a rate limit when the cause is aStreamableHTTPError,RateLimitTimeoutErrororHttpRateLimitError, so the end-user lookup rewrapped it as the original refusal,fetchToolsskipped the account, and the caller got a partial catalog. The accounts lookup and the MCP session now build that error through one helper,rateLimitTimeoutError(), so both carry aRateLimitTimeoutErrorcause and stay fatal to a fan-out.src/mcp-client.ts: newrateLimitTimeoutError(request, timeout, cause).RateLimitTimeoutErrorstays unexported, as onmain(only the helper builds it, and neither is exported fromsrc/index.ts). TheisRateLimitFailuredoc line now says "a request" instead of "an MCP request", since it also covers the accounts lookup.src/toolsets.ts:fetchAccountsthrowsrateLimitTimeoutError(...)on a timeout after a 429. The message text is unchanged.src/end-user-id.test.ts: regression test "stays fatal to a fan-out when the lookup times out while a 429 is retried". Onmainit fails with a 4-tool partial catalog; here it passes and asserts the full message.Dogfood on a local stack
mainand this head (360b0ff) were built withpnpm buildand run against a local HTTP server built from the repo'smocks/mcp-server.ts./mcprefusesacc1without its end user (400, like the API's account guard). With throttling on,GET /accountsanswers one 429 withRetry-After: 0and then stalls. The client isnew StackOneToolSet({ accountIds: ['acc1', 'acc2'], timeout: 1000 }).fetchTools().Throttled,
main(the bug: a partial catalog):Throttled, this PR:
Control, no throttling: both builds resolve the same 4 tools (
acc1_tool_1, acc1_tool_2, acc2_tool_1, acc2_tool_2), so only the throttled path changes.Test plan
pnpm vitest run --project root: 41 files, 1315 passed, no type errorspnpm vitest run src/end-user-id.test.ts src/rate-limit.test.ts src/mcp-client.test.ts: 157 passedpnpm lint: pass (only the existing knip hints)Rate limit and failure
No new calls, retries or timers. The accounts lookup keeps its existing retry budget (4 attempts,
Retry-Afterhonoured) and the toolsettimeout. The only change is which error a timeout during that retry produces: the fan-out now fails with a 429 instead of returning fewer tools.Gates
.claude/rules/*.release-pleasenot applied: no release in scope/forge:forgesrc/rate-limit.test.ts:84, kept as the suite's test pattern)/security-review/code-reviewPost-merge validation
Library: ships with the next release-please release. After publishing, run the same throttled scenario against the published package; the signal is a 429
StackOneAPIErrorinstead of a shorter tool list. Regression signal: a fan-out failing with 429 when/accountswas not throttled.Requested by guillaume@stackone.com in Slack (repo audit thread).
🤖 Generated with Claude Code