Skip to content

fix(message): bound trace request cache - #3298

Open
tju-yxq wants to merge 1 commit into
apache:rocketmq-studiofrom
tju-yxq:codex/trace-cache-bound
Open

fix(message): bound trace request cache#3298
tju-yxq wants to merge 1 commit into
apache:rocketmq-studiofrom
tju-yxq:codex/trace-cache-bound

Conversation

@tju-yxq

@tju-yxq tju-yxq commented Sep 5, 2026

Copy link
Copy Markdown

What changed

Message Explorer deduplicates trace lookups in a page-local Map, but successful promises were retained indefinitely. A long investigation session with many distinct messages could therefore keep every resolved trace response referenced until the page was destroyed.

This change replaces the unbounded map with a small LRU promise cache:

  • cap retained trace requests at 32 entries;
  • refresh recency when an existing trace is reopened;
  • evict the least-recently-used entry when the cap is exceeded;
  • keep in-flight request de-duplication unchanged;
  • continue removing rejected requests so a failed lookup can be retried;
  • add focused tests for capacity validation, LRU eviction, replacement, deletion, and cleanup.

The cache is page-local and does not alter trace query results or server-side history recording.

Closes #3297

Validation

  • npm test -- boundedPromiseCache.test.ts --run — 4 tests passed
  • npm test -- MessagePageAsyncState.test.tsx MessagePage.test.tsx --run — 27 tests passed
  • npm run lint -- --quiet — 0 errors; 10 existing warnings remain elsewhere in the tree
  • npm run build — passed
  • git diff --check — passed

The GitHub Actions status is not being described as green here; the checks above are local validation on this branch.

@RockteMQ-AI RockteMQ-AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Summary

This PR replaces the unbounded Map used for trace request caching with a well-implemented LRU cache (BoundedPromiseCache) capped at 32 entries. This prevents memory leaks during long investigation sessions where many distinct messages are explored.

Strengths:

  • Clean LRU implementation using Map insertion order
  • Proper recency refresh on get() (delete + re-set)
  • Good test coverage: capacity validation, eviction, replacement, deletion, cleanup
  • Correct handling of rejected promises (removed from cache to allow retry)
  • Proper input validation (maxEntries must be positive integer)

No blocking issues found. The implementation is solid and follows best practices.


*Automated review by *

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.

2 participants