Skip to content

fix: bound dedupe cache with MAX_INFLIGHT=200 and 30s TTL#835

Merged
RUKAYAT-CODER merged 1 commit into
rinafcode:mainfrom
EmeditWeb:API-dedupe-cache
Jun 29, 2026
Merged

fix: bound dedupe cache with MAX_INFLIGHT=200 and 30s TTL#835
RUKAYAT-CODER merged 1 commit into
rinafcode:mainfrom
EmeditWeb:API-dedupe-cache

Conversation

@EmeditWeb

Copy link
Copy Markdown
Contributor

Summary

Bounded the in-flight deduplication cache to prevent unbounded memory growth when requests hang indefinitely.

Changes

  • src/lib/api/dedupe.ts

    • Added MAX_INFLIGHT = 200 — rejects new dedupe entries when the map reaches 200 entries
    • Added DEDUPE_TTL_MS = 30_000 — each entry gets a 30-second timeout that rejects the promise and removes the entry automatically
    • Clears the TTL timer when a request completes normally (success or error)
    • Updated cancelDedupe and clearDedupeCache to also clean up pending timers
  • src/lib/api/__tests__/dedupe.test.ts (new)

    • 12 tests covering:
      • Basic deduplication behavior (unchanged after refactor)
      • MAX_INFLIGHT limit enforcement
      • TTL eviction and post-eviction new requests
      • Timer cleanup on successful completion
      • Multi-entry independent eviction

Acceptance Criteria

  • The map never holds more than MAX_INFLIGHT entries simultaneously
  • Entries older than the TTL are evicted even if the associated request never resolved
  • Existing deduplication behavior is unchanged for requests that complete within the TTL

Closes #734

- Add MAX_INFLIGHT=200 constant; reject new entries when the cache is full
- Add DEDUPE_TTL_MS=30_000; auto-evict stale entries via setTimeout
- Clear TTL timer on normal completion/error
- Update cancelDedupe and clearDedupeCache to clean up pending timers
- Add comprehensive test suite covering size limit, TTL eviction,
  timer cleanup, and backward-compatible dedup behavior

Close rinafcode#734
@drips-wave

drips-wave Bot commented Jun 29, 2026

Copy link
Copy Markdown

@EmeditWeb Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

@RUKAYAT-CODER

Copy link
Copy Markdown
Contributor

Thank you for contributing to the project.

@RUKAYAT-CODER RUKAYAT-CODER merged commit 99d0f2f into rinafcode:main Jun 29, 2026
4 checks passed
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.

[Performance] API dedupe cache has no size limit or TTL — potential unbounded memory growth

2 participants