Skip to content

fix: deduplicate concurrent models.dev fetch requests#282

Merged
BYK merged 1 commit into
mainfrom
fix/memoize-models-dev-fetch
May 13, 2026
Merged

fix: deduplicate concurrent models.dev fetch requests#282
BYK merged 1 commit into
mainfrom
fix/memoize-models-dev-fetch

Conversation

@BYK
Copy link
Copy Markdown
Owner

@BYK BYK commented May 13, 2026

Summary

  • fetchModelData() cached the resolved result (TTL-based) but not the in-flight promise, so concurrent calls before the first resolved each fired a separate HTTP request to models.dev/api.json
  • Added promise memoization via an inflightFetch module-level variable — concurrent callers now share a single in-flight request
  • Observable symptom was duplicate log lines at startup: models.dev: loaded data for 75 models across anthropic, openai repeated 6 times at the same timestamp

fetchModelData() cached the resolved result but not the in-flight promise,
so concurrent calls before the first resolved each fired a separate HTTP
request. Store the pending promise in a module-level variable and return
it for subsequent callers until settlement.
@BYK BYK force-pushed the fix/memoize-models-dev-fetch branch from 081b367 to 4b53716 Compare May 13, 2026 09:43
@BYK BYK merged commit c43f30b into main May 13, 2026
7 checks passed
@BYK BYK deleted the fix/memoize-models-dev-fetch branch May 13, 2026 09:47
This was referenced May 13, 2026
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