Skip to content

fix(toolset): keep a timed-out 429 on GET /accounts fatal to a fan-out - #403

Merged
glebedel merged 2 commits into
mainfrom
s2d2/audit-accounts-429-timeout
Nov 11, 2026
Merged

glebedel merged 2 commits into
mainfrom
s2d2/audit-accounts-429-timeout

Conversation

@glebedel

@glebedel glebedel commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

Summary

When GET /accounts timed out while a 429 was being retried, the toolset threw a 429 StackOneAPIError whose cause was the raw TimeoutError. isRateLimitFailure only treats a 429 as a rate limit when the cause is a StreamableHTTPError, RateLimitTimeoutError or HttpRateLimitError, so the end-user lookup rewrapped it as the original refusal, fetchTools skipped 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 a RateLimitTimeoutError cause and stay fatal to a fan-out.

  • src/mcp-client.ts: new rateLimitTimeoutError(request, timeout, cause). RateLimitTimeoutError stays unexported, as on main (only the helper builds it, and neither is exported from src/index.ts). The isRateLimitFailure doc line now says "a request" instead of "an MCP request", since it also covers the accounts lookup.
  • src/toolsets.ts: fetchAccounts throws rateLimitTimeoutError(...) 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". On main it fails with a 4-tool partial catalog; here it passes and asserts the full message.

Dogfood on a local stack

main and this head (360b0ff) were built with pnpm build and run against a local HTTP server built from the repo's mocks/mcp-server.ts. /mcp refuses acc1 without its end user (400, like the API's account guard). With throttling on, GET /accounts answers one 429 with Retry-After: 0 and then stalls. The client is new StackOneToolSet({ accountIds: ['acc1', 'acc2'], timeout: 1000 }).fetchTools().

Throttled, main (the bug: a partial catalog):

[server] POST /mcp acc1 without end user -> 400
[server] GET /accounts #1 -> 429 Retry-After: 0
[server] GET /accounts #2 -> (stalls)
[@stackone/ai] GET http://127.0.0.1:4799/accounts was rate limited (429) on attempt 1 of 4; retrying in 0s
[@stackone/ai] Skipping account that failed to list tools ... acc1: MCP request to http://127.0.0.1:4799/mcp failed with 400 Bad Request: ...
[main] RESOLVED with 2 tools: acc2_tool_1, acc2_tool_2

Throttled, this PR:

[server] POST /mcp acc1 without end user -> 400
[server] GET /accounts #1 -> 429 Retry-After: 0
[server] GET /accounts #2 -> (stalls)
[@stackone/ai] GET http://127.0.0.1:4799/accounts was rate limited (429) on attempt 1 of 4; retrying in 0s
[pr] REJECTED StackOneAPIError status=429: Listing accounts at http://127.0.0.1:4799/accounts was rate limited (429) and timed out after 1s while retrying

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 errors
  • pnpm vitest run src/end-user-id.test.ts src/rate-limit.test.ts src/mcp-client.test.ts: 157 passed
  • pnpm 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-After honoured) and the toolset timeout. 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

Gate Result Head
Repo skills None in repo (Nix-managed, gitignored). Read .claude/rules/*. release-please not applied: no release in scope 360b0ff
/forge:forge Ran: shared the duplicated error construction into one helper, dropped an export only the helper needs. Meter vs 08c356a: comment lines 0 → 1 (a stale doc line corrected; one doc comment removed, net 0), longest block 1, type escapes 0, copies 1 → 1 (the msw 429 handler idiom also at src/rate-limit.test.ts:84, kept as the suite's test pattern) 360b0ff
Security scan (security-reviewer agent + Aikido) No findings. Aikido: no open critical/high issue is in a changed file 360b0ff
Codex security pass No findings (error message and cause carry no credentials) 360b0ff
/security-review Pass 08c356a, no behaviour change since
/code-review 7 findings: 2 fixed (shared helper, full-message assertion), 5 declined with reasons 08c356a, refactor applied in 360b0ff
Dogfood Above, local stack, both builds 360b0ff
CI Green 360b0ff
Review threads 0 unresolved 360b0ff

Post-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 StackOneAPIError instead of a shorter tool list. Regression signal: a fan-out failing with 429 when /accounts was not throttled.

Requested by guillaume@stackone.com in Slack (repo audit thread).

🤖 Generated with Claude Code

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>
@glebedel
glebedel requested a review from a team as a code owner November 10, 2026 20:34
@glebedel glebedel self-assigned this Nov 10, 2026
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 10, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-10T20:35:27.052471Z 08c356a PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@pkg-pr-new

pkg-pr-new Bot commented Nov 10, 2026 •

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/StackOneHQ/stackone-ai-node/@stackone/ai@403

commit: 360b0ff

…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>
@glebedel
glebedel merged commit f5e99c8 into main Nov 11, 2026
32 checks passed
@glebedel
glebedel deleted the s2d2/audit-accounts-429-timeout branch November 11, 2026 09:10
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