fix(datasets): send HF token, retry only 429/5xx, honor Retry-After for cached file fetches - #78
Conversation
…or cached file fetches Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
Original prompt from Devin Bot
|
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
TL;DR
fetchCachedTextFile(the path tau-bench-airlinedb.jsonand the tau3 banking files take on a cache miss) now sendsHF_TOKENto huggingface.co, retries only on 429/5xx/transport errors, and honorsRetry-After. Follow-up to #75.What changed?
src/datasets/cached-file.tsCachedTextFileRequest.hfToken?: string. When omitted, the helper readsHF_TOKENthroughresolveHfToken()(same source as the generic HF rows loader). TheAuthorization: Bearerheader is sent only when the URL host ishuggingface.coor a subdomain, so the token never reaches the GitHub raw URLs used by tau3 banking.CachedFileError.retryAfterMs?: number, parsed from theretry-afterresponse header (delay-seconds or HTTP-date).isRetryableCachedFileFailure: retryCachedFileErroronly for status 429 or >= 500; always retryHttpClientError(transport / body read). A 404 or 403 now fails fast instead of burning the retry budget.files/<url>.json), so entries already in the GCS bucket stay valid.src/datasets/huggingface.tshfFetchRetrySchedule(config, isRetryable, retryAfterMs?): optional third parameter that overrides the computed backoff with the server-provided delay. Applied beforewithRetryAttemptLogging, sodelay_msin the retry log reflects the real wait. Existing callers are unaffected (defaults toundefined→ computed delay).src/datasets/cached-file.test.ts: non-retryable 404 makes exactly one request; 503 retries;retry-after: 1delays the retry by >= 900 ms; token header present only for huggingface.co and absent for an empty token; unit tests forisHuggingFaceUrlandparseRetryAfterMs. Existing cache-hit and 429-then-success tests still cover those paths.src/benchmarks/tau-bench-airline/airline.test.ts:ensureAirlineDatamakes no network request once the in-process copy is populated.Why?
Datadog APM, 7 days ending 2026-09-09, production bench-worker: 51,556 of 87,052 errored
RunActivity:runBenchmarkattempts (59%) failed withFailed to load airline data from HF: ... Failed to fetch db.json from HF (429). Each Temporal activity retries up to 5 times, so the same chunk keeps hitting the same 429.Burst amplification: the pre-#75 loader memoized
db.jsonin a module-level variable, which is per process. The worker pool runs one activity per Cloud Run instance and scales to roughly 1000 instances, so every scale-up wave is a burst of identical anonymousresolve/.../db.jsondownloads from fresh processes, with no shared cache, no backoff, and no token. Hugging Face rate-limits the anonymous burst, and the Temporal retry multiplies each 429 by five.#75 (merged, not yet pulled into openrouter-web) moved
db.jsononto the shared cache store and added backoff, which removes the steady-state burst. This PR closes the remaining gaps in that path so a cold-cache burst after a revision bump behaves like the generic HF loader:Retry-Afterfrom HF is honored instead of guessed.Searched existing PRs (last 90 days, harness and openrouter-web): #75 covers the cache-store routing; nothing covers the token, retry classification, or
Retry-After. openrouter-web #40710 was a direct subtree edit and is closed.How to test
bun run format:check bun run check bun run typecheck bun test bun run buildAll five pass locally (1434 tests, 0 failures). Targeted run:
bun test src/datasets/cached-file.test.ts src/benchmarks/tau-bench-airline/airline.test.tsExpected:
retry-aftertest logsdelay_ms: 1000in theRetrying after transient errorline; the 404 test logs no retry.Benchmark impact
None. Dataset content, revision pin, solver, and scorer are unchanged. Only the transport for fetching the environment file changes.
Reviewer focus
isRetryableCachedFileFailuretreats everyHttpClientErroras retryable. Transport errors and body-read failures are the only members of that union on this path.authorizationHeadershost check:huggingface.coand*.huggingface.coonly.hfFetchRetrySchedulethird parameter is additive; existing call sites pass two or fewer arguments.Follow-up
scripts/subtree-pull-bench-harness.shto pull #75 and this PR intopackages/bench-harness. Production still runs the pre-fix: cache tau environment files in the dataset cache store #75 loader until that lands; the Datadog figures above are all from that code.Retry-Aftermake that burst survivable; a cross-process lock is out of scope here.How to test in prod
Failed to fetch db.json from HF (429)/HTTP 429 for https://huggingface.co/datasets/abhinavpola/tau2-bench-verified-airline/....service:bench-worker resource_name:"RunActivity:runBenchmark" status:errorover the 24 h after deploy and search the error message for429. Success criterion: 429-tagged errors drop to near zero as a share ofRunActivity:runBenchmarkerrors (baseline 59%). Query: https://us5.datadoghq.com/apm/traces?query=service%3Abench-worker%20resource_name%3A%22RunActivity%3ArunBenchmark%22%20status%3Aerror%20%40error.message%3A%2A429%2Aservice:bench-worker "Retrying after transient error" "CachedFileError". Expected: sparse entries withdelay_msequal to the HFRetry-Aftervalue when present; no retries witherror_message: "HTTP 404 ...".gsutil ls gs://<bench dataset cache bucket>/dataset-cache/files/ | grep tau2-bench-verified-airlinereturns one object for the pinned revision790bdd0336f4e3386824ced48ee2a98a11058345(bucket name fromgoogle_storage_bucket.bench_dataset_cacheinservices/gcp-bench-worker/cloudrun/).RunActivity:runBenchmarkerrors stays at or above baseline, or newHTTP 401/HTTP 403errors for huggingface.co appear (indicates a badGCP_BENCHMARKING_HF_TOKEN).Checklist
[Used playbook: Google Developer Docs Style — Write or Review Docs]
Link to Devin session: https://openrouter.devinenterprise.com/sessions/0cc065effe934a91a31f6f7c7fa1fce2
Open in Devin Desktop: https://openrouter.devinenterprise.com/desktop/session/0cc065effe934a91a31f6f7c7fa1fce2?variant=devin
Requested by: @jamespsterling