Skip to content

Put the response status and headers on the error the backoff reads - #13287

Open
unolife wants to merge 1 commit into
continuedev:mainfrom
unolife:annotate-llm-errors-with-status-and-headers
Open

unolife wants to merge 1 commit into
continuedev:mainfrom
unolife:annotate-llm-errors-with-status-and-headers

Conversation

@unolife

@unolife unolife commented Sep 17, 2026

Copy link
Copy Markdown

calculateDelay in core/llm/utils/retry.ts looks for

error.headers["retry-after"] ||
error.headers["x-ratelimit-reset"] ||
error.headers["ratelimit-reset"] || ...

so a retry waits exactly as long as the provider asked rather than guessing.

Nothing ever put them there. parseError builds its error from the response and keeps only the text — no status, no headers — so that branch could not fire and every rate limit fell through to exponential backoff.

What changed

parseError now annotates whatever it built with the response's status and a lower-cased plain-object copy of its headers.

  • Lower-cased because that is how Headers yields them, and how the reader spells the names it checks first.
  • A plain object because the reader uses bracket access, which returns undefined on a Headers instance regardless of casing.
  • Left unset when the response carried none — an empty object reads as "the provider answered with no limits"; absent says it never answered.

No behaviour changes on its own. This only makes the existing header path reachable, and puts the limit within reach of anything else that wants it.

Testing

jest llm/index.test.ts189 passed, including three new cases covering the Retry-After round trip, the lower-casing, and the absent-headers case.

`calculateDelay` in core/llm/utils/retry.ts looks for
`error.headers["retry-after"]`, `["x-ratelimit-reset"]` and friends so a retry
waits exactly as long as the provider asked. Nothing ever put them there:
`parseError` builds its error from the response and keeps only the text, so that
branch could not fire and every rate limit fell through to exponential backoff —
a guess, when the provider had already said the answer.

`parseError` now annotates whatever it built with the response's `status` and a
lower-cased plain-object copy of its headers. Lower-cased because that is how
`Headers` yields them and how the reader spells the names it checks first, and a
plain object because the reader uses bracket access, which returns undefined on
a `Headers` instance.

Headers are left unset when the response carried none: an empty object reads as
"the provider answered with no limits", and absent says it never answered.

No behaviour changes on its own — this only makes the existing header path
reachable.

Verified: `jest llm/index.test.ts` — 189 passed, including three new cases.
@unolife
unolife requested a review from a team as a code owner September 17, 2026 07:47
@unolife
unolife requested review from sestinj and removed request for a team September 17, 2026 07:47
@github-actions

Copy link
Copy Markdown
Contributor


Thank you for your submission, we really appreciate it. Like many open-source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution. You can sign the CLA by just posting a Pull Request Comment same as the below format.


I have read the CLA Document and I hereby sign the CLA


You can retrigger this bot by commenting recheck in this Pull Request. Posted by the CLA Assistant Lite bot.

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.

1 participant