You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Retry pagespeed_insights on transient PSI failures (#48)
The PSI API occasionally returns transient errors — HTTP 5xx bursts
when Google's backend is congested, rate-limit 429s under load, and
HTTP 200 responses where lighthouseResult.runtimeError is set because
Lighthouse itself crashed mid-audit (common on slow or JS-heavy
pages). Until now each of these would bubble straight up to the
caller as a tool error, failing the whole URL even though a single
retry would usually succeed.
Split the PSI fetch into a helper with a bounded retry loop (max 1
retry, 2s backoff). Retry triggers on:
- network/abort errors (fetch throws)
- HTTP 5xx or 429
- HTTP 200 but lighthouseResult.runtimeError present
Non-transient failures (4xx other than 429, malformed JSON) still
fail immediately. Worst-case added latency: one retry window
(~2s + one 90s PSI call) when the first attempt also hits its
timeout — still comfortable under the 120s budget callers allow.
Retries are logged to stdout so wrangler tail reveals flakiness
patterns when they happen.
Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
0 commit comments