Repository navigation
feat(cli): carry 429 retry timing in the CLI and mcpdo error envelopes - #2795
Conversation
#2772) A throttled request now classifies as `rate_limited` with exit code 10, and the envelope lifts `method`, `retryAfter` and `retryAfterMs` off the annotated error's data, so a script can wait and re-run without parsing the prose message. Absent fields are omitted, matching the envelope's other optional fields. mcpdo's daemon error body only carried code/message/exitCode, which is why its envelope lacked even `status`; it now relays `status` and the rate-limit fields across the socket, sanitizing the header text on the client side. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: cliffhall <[email protected]>
There was a problem hiding this comment.
🟡 Changes recommended
Retry headers bypass secret redaction, streaming subscription errors lose metadata, and overflowing delays serialize as null.
3 open issues
What changed in this PR
This PR exposes structured HTTP 429 retry information in the shared CLI error envelope and carries it across mcpdo’s daemon connection, building on the rate-limit annotations from #2737.
Changes:
- Adds
rate_limitedclassification, exit code10, and optional method and retry-timing fields. - Relays HTTP status and retry metadata through mcpdo’s daemon protocol.
- Documents the envelope and adds shared fixtures, unit tests, and end-to-end coverage.
| File | Description |
|---|---|
core/cli/error-handler.ts |
Classifies 429 responses and preserves retry metadata. |
clients/mcpdo/src/daemon/server.ts |
Sends structured error fields over the daemon socket. |
clients/mcpdo/src/daemon/protocol.ts |
Defines the additional daemon error fields. |
clients/mcpdo/src/daemon/client.ts |
Rebuilds relayed envelopes and sanitizes header text. |
clients/mcpdo/__tests__/rate-limit-envelope.test.ts |
Tests daemon relay and end-to-end error output. |
clients/cli/README.md |
Documents exit code 10 and retry fields. |
clients/cli/__tests__/rate-limit-envelope.test.ts |
Tests parsed, malformed, and missing retry headers. |
clients/cli/__tests__/helpers/throttling-server.ts |
Provides a shared HTTP 429 test server. |
clients/cli/__tests__/error-handler.test.ts |
Tests classification, field validation, and pre-classified errors. |
Review effort: Balanced
| // before it reaches a terminal via the shared error handler. | ||
| sanitizeText(response.error.message), | ||
| { code: response.error.code }, | ||
| relayedEnvelope(response.error), |
There was a problem hiding this comment.
Fixed in bfead90 — streamDaemon's setup-refusal path now builds its envelope with relayedEnvelope, same as callDaemon. Added a regression test: a socket server refuses a stream with a rate_limited body and the rejected CliExitCodeError keeps status, method, retryAfter and retryAfterMs.
…streams (#2772) - retryAfter is server text kept verbatim when malformed, so it now goes through the envelope's URL redaction like message. - A delta-seconds header too long for a double parses to Infinity, which serialized as null; retryAfterMs is now included only when finite. - streamDaemon's setup-refusal path rebuilt only `code`; it now uses relayedEnvelope, so a throttled resources/subscribe keeps its fields. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: cliffhall <[email protected]>
|
Copilot round 1 — all three findings fixed in bfead90 (replied in each thread):
|
|
Copilot review loop closed: round 2 was clean — "Approval recommended", no inline comments, no new findings. The one item it still lists as open (stream subscription metadata) is the round-1 thread, fixed in bfead90 ( |
Exit code 10 was taken on v2/main by LOAD_THRESHOLD_EXCEEDED (#2745); RATE_LIMITED moves to 11. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: cliffhall <[email protected]>


Closes #2772
What changed
The one-shot CLI and mcpdo JSON error envelopes now keep the structured rate-limit data that #2737 attaches to a throttled request's error:
{"error":{"code":"rate_limited","message":"Rate limited by the server (HTTP 429) on tools/list. …","cause":"…","status":429,"method":"tools/list","retryAfter":"30","retryAfterMs":30000}}core/cli/error-handler.ts(shared by both CLIs): a 429 now classifies asrate_limited. The handler readsmethod,retryAfterandretryAfterMsofferror.dataand checks each one's type before using it.retryAfteris the header exactly as the server sent it, so a malformed value still shows up.retryAfterMsappears only when the header parsed. A missing header leaves both fields out instead of emittingnull, the same way the envelope already handlescause,statusandurl. The 429 check runs before the unreachable pattern, because a throttled error's message includes the server's response body, which could match that pattern by accident.DaemonErrorBodyused to carry onlycode,messageandexitCode. That is why mcpdo's envelope had nostatusat all. The daemon now also sendsstatusand the rate-limit fields over the socket. The client rebuilds them into theCliExitCodeErrorenvelope and sanitizes the server-suppliedretryAftertext the same way it sanitizes the message.Decision: a dedicated code and exit code
The issue left this open. I added
rate_limitedwith exit code11(EXIT_CODES.RATE_LIMITED;10was taken byLOAD_THRESHOLD_EXCEEDED, #2745, while this PR was open) instead of keepingerror/1. A 429 is the one failure where the right response is "wait, then run the same command again", and the envelope now says how long. With exit 1, a script would have to read stderr just to tell throttling apart from a real failure, and the exit-code map exists to save callers from doing that. Codes 7–10 already set the precedent of one code per failure class a caller would act on differently.Tests
The issue asked for tests in both CLIs, because each client sends its output a different way:
clients/cli/__tests__/rate-limit-envelope.test.ts: end to end against a small HTTP server that answers 429. It covers a parsed header, a malformed header, and no header, all throughrunCli.clients/cli/__tests__/error-handler.test.ts: unit tests for the classification, wrong-type and non-objectdata, an unannotated 429, the unreachable-pattern precedence, and the pre-classified relay path.clients/mcpdo/__tests__/rate-limit-envelope.test.ts: the daemon side of the relay (both the classified and the pre-classified branch), the client-side rebuild including sanitization, and a fullconnect→tools/listrun through the auto-spawned daemon.clients/cli/__tests__/helpers/throttling-server.ts). mcpdo's tests already import CLI test helpers.npm run local:gatepassed.🤖 Generated with Claude Code