fix(api): in-flight request coalescing for /chart/:mint [BUG-107] - #223
fix(api): in-flight request coalescing for /chart/:mint [BUG-107]#223Morenikeoa wants to merge 1 commit into
Conversation
/chart/:mint's own cache Map had no in-flight de-dup, distinct from the already-fixed cache.ts/db-cache-fallback.ts coalescing (different cache entirely) and from issue dcccrypto#213 (which is about the limit param polluting the cache key — a different mechanism). On a miss, this route makes two sequential awaited fetch() calls to GeckoTerminal (getTopPool then fetchOhlcv) with no de-dup — concurrent requests for the same mint/timeframe/aggregate/limit key all miss together and each independently fire both upstream calls. GeckoTerminal is a third-party API with rate limits shared across this whole process, so duplicate concurrent calls risk exhausting that budget and degrading /chart for every mint, not just the one being requested. Extracted the miss-path into fetchAndCache() and added an `inflight` Map mirroring the proven coalescing pattern already in oracle-router.ts: only the first concurrent caller for a key runs fetchAndCache(); the rest await the same promise and the cache write happens once per miss-episode. Added a regression test: two concurrent requests for the same key result in exactly one pool-resolution call and one OHLCV call (not two of each), and both get the same candle data. Verified it fails against the pre-fix code (2 pool calls instead of 1) and passes against the fix. Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
|
@Princessdada is attempting to deploy a commit to the Khubair Nasir's projects Team on Vercel. A member of the Team first needs to authorize it. |
|
Warning Review limit reached
More reviews will be available in 46 minutes and 24 seconds. Learn how PR review limits work. Your organization has used up its prepaid credits, and credit purchases are no longer available. Enable the review add-on in the billing tab to keep reviews running — you're only billed for reviews past your plan's rate limits ($0.25/file). ⌛ How to resolve this issue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based credits. 🚦 How do rate limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please see our Fair Usage Limits Policy for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Problem
/chart/:mintkeeps its own separatecacheMap, distinct fromcache.ts/db-cache-fallback.ts(already fixed for in-flight de-dup) and fromadl.ts'sadlCache(issue #193). On a cache miss, the handler makes two sequential awaitedfetch()calls to GeckoTerminal —getTopPool(mint)thenfetchOhlcv(...)— with no in-flight de-duplication. Concurrent requests for the samemint:timeframe:aggregate:limitkey all miss together and each independently fire both upstream calls.Impact
GeckoTerminal is a third-party API consumed without an API key and rate-limited on egress, shared across this entire process for every mint. Duplicate concurrent calls for the same key risk exhausting that shared budget, which can degrade
/chartfor every mint being charted, not just the one whose concurrent requests caused the spike.This is distinct from open issue #213, which is about the
limitquery param being included in the cache key (causing many distinct keys for the same mint) — a different root cause than this one (no coalescing within a single key).Fix
Extracted the miss-path into
fetchAndCache()and added aninflightmap, mirroring the proven coalescing pattern already used inoracle-router.tsin this same repo: only the first concurrent caller for a given key actually callsfetchAndCache(); concurrent callers await the same promise instead of starting their own. The cache write happens once per miss-episode regardless of how many concurrent requests triggered it.Proof of Fix
New test: two concurrent requests for the same key result in exactly one pool-resolution fetch and one OHLCV fetch (not two of each), and both requests receive the same candle data.
Verified this is a genuine regression test: reverted just the source change and reran — failed with 2 pool-resolution calls instead of 1. Restored the fix and it passes.
tsc --noEmitclean (no separate lint script in this repo).Test Output
Full suite: 295/296 passed (294 baseline + 1 new). The 1 failure (
tests/sdk-smoke.test.ts) is pre-existing and unrelated — it asserts on an exact@percolatorct/sdkerror-message string that has drifted from the locally-resolved SDK version in this environment.Related
Found during a broader API audit. Distinct from open issue #213 (cache-key/limit-param fragmentation — a different root cause). No existing open issue/PR covers this specific coalescing gap.