MergeStorydemo-repofeature/retry

Retry temporary failures with exponential backoff

WeatherClient.getForecast now retries network errors, 429 and 5xx through a new withRetry helper, with full-jitter backoff and support for Retry-After. Other 4xx errors still fail at once.

Watch the video on YouTube

What to review

Why you can trust this video

23 of 23 narration lines cite evidence from the change.

Each line points at files, hunks, symbols, commits or tests of this change, and MergeStory checks every reference before it renders the video. Open a chapter to see what its lines rely on.

The mission1 line
  • The weather client now retries temporary failures on its own. Commit ea92200: Retry temporary failures with exponential backoffsrc/retry.tsTask description
The problem2 lines
  • When the API is busy, forecasts fail with 429, 503 or a network error. Callers retry by hand. Task description
  • The task: retry those failures with exponential backoff, and respect Retry-After. Task descriptionWeatherClient.getForecast (src/client.ts:46-66)
Where the change lives2 lines
  • The retry loop lives in a new helper, withRetry, so other calls can use it later. src/retry.tswithRetry (src/retry.ts:27-43)Implementation notes
  • getForecast sends every request through it, and loadConfig reads three new retry settings. src/client.ts:45-67WeatherClient.getForecast (src/client.ts:46-66)src/config.ts:9-16loadConfig (src/config.ts:8-16)
The retry loop3 lines
  • withRetry fills in defaults from DEFAULT_RETRY, then runs the operation in a loop. withRetry (src/retry.ts:27-43)DEFAULT_RETRY (src/retry.ts:8)src/retry.ts:1-43
  • On a final error, or after the last allowed retry, it throws the error. withRetry (src/retry.ts:27-43)src/retry.ts:1-43
  • Otherwise it waits: afterMs if the decision has one, or else backoffDelay. withRetry (src/retry.ts:27-43)src/retry.ts:1-43
The retry policy3 lines
  • The defaults: three retries, a 250 millisecond base delay and a four second cap. DEFAULT_RETRY (src/retry.ts:8)Check the changed timeout, retry or interval valuessrc/retry.ts:1-43
  • isRetryableStatus accepts only 429 and 5xx. isRetryableStatus (src/retry.ts:17-19)src/retry.ts:1-43
  • backoffDelay picks a random wait below a limit that doubles each time. That is full jitter. backoffDelay (src/retry.ts:22-25)src/retry.ts:1-43Implementation notes
What is retried, and what is not3 lines
  • retryDecision retries a WeatherError only for 429 and 5xx. A 404 fails at once. retryDecision (src/client.ts:31-37)src/client.ts:9-41Implementation notes
  • A TypeError means fetch got no response, so it is retried as a network error. retryDecision (src/client.ts:31-37)src/client.ts:9-41
  • retryAfterMs reads Retry-After, in seconds or as a date. That wait replaces the backoff. retryAfterMs (src/client.ts:22-28)src/client.ts:9-41Implementation notes
One request during an outage3 lines
  • Before, the first failure went straight back to the caller. src/client.ts:45-67
  • Now, in the first new test, no response means a backoff wait, and a 503 waits as Retry-After says. test/retry.test.ts:1-49src/client.ts:9-41src/retry.ts:1-43
  • The third attempt returns the forecast. test/retry.test.ts:1-49src/client.ts:45-67
What to review4 lines
  • The timeout applies per attempt, so the worst case grows with every retry. Implementation notessrc/client.ts:45-67
  • A long Retry-After is used as sent, without the maxDelayMs cap. Implementation notessrc/retry.ts:1-43
  • Timeouts are not retried, but any TypeError is, even one from a bug. Implementation notesretryDecision (src/client.ts:31-37)src/client.ts:9-41
  • And WeatherError and WeatherConfig changed shape, so check the callers. Confirm callers still match the changed signaturesWeatherError.constructor (src/client.ts:14-18)WeatherConfig (src/config.ts:3-6)
Wrap up2 lines
  • Temporary failures now retry with jittered backoff. Other 4xx errors fail at once. WeatherClient.getForecast (src/client.ts:46-66)retryDecision (src/client.ts:31-37)src/retry.ts:1-43
  • The coding agent reports that npm test passed. Test run: npm test (passed, reported by the caller)test/retry.test.ts:1-49

What the video could not confirm

How it was made

Storyboard
Written by a coding agent.
Voice
Kokoro (local)
Generated
2026-11-11
Commit
ea92200