Skip to content

Fix bugs in GenerationalUtf8Cache constructor and access-time handling#11323

Open
dougqh wants to merge 4 commits intomasterfrom
dougqh/utf8-cache-fixes
Open

Fix bugs in GenerationalUtf8Cache constructor and access-time handling#11323
dougqh wants to merge 4 commits intomasterfrom
dougqh/utf8-cache-fixes

Conversation

@dougqh
Copy link
Copy Markdown
Contributor

@dougqh dougqh commented May 8, 2026

What Does This Do

Fixes three bugs and a misleading comment in the UTF-8 caches.
None of these issues impacted how the cache is currently used, but could pose a problem in the future.

  • GenerationalUtf8Cache.getUtf8(String, long accessTimeMs) captured this.accessTimeMs into a local and used that for entry timestamps, silently ignoring the supplied parameter — directly contradicting its Javadoc.
  • GenerationalUtf8Cache(int edenCapacity, int tenuredCapacity) sized the eden array using tenuredCapacity instead of edenCapacity. The existing test only exercised the single-arg constructor, so this was unobserved.
  • refreshAcessTime renamed to refreshAccessTime (typo). No other callers exist in the repo.
  • The "If we get here, then we're evicting the LRU" comment in lfuInsert (both SimpleUtf8Cache and GenerationalUtf8Cache) was misleading — those paths evict the LFU.

Motivation

Clean-up

Test plan

  • ./gradlew :communication:test — passes, including the new regression tests
    • GenerationalUtf8CacheTest.getUtf8_perCallAccessTime_overridesField — fails on master, passes after the fix.
    • GenerationalUtf8CacheTest.capacity_twoArg — fails on master, passes after the fix.
  • ./gradlew :communication:spotlessCheck
  • CI: verify across JDK matrix

🤖 Generated with Claude Code

- getUtf8(value, accessTimeMs) was capturing this.accessTimeMs and using
  that for entry timestamps, silently ignoring the parameter contrary
  to its Javadoc.
- The two-arg constructor sized the eden array using tenuredCapacity
  instead of edenCapacity.
- Rename refreshAcessTime to refreshAccessTime (no other callers).
- Correct misleading "evicting the LRU" comments in the LFU paths of
  both SimpleUtf8Cache and GenerationalUtf8Cache.

Adds regression tests for both bugs.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@dougqh dougqh added comp: core Tracer core tag: ai generated Largely based on code generated by an AI or LLM type: bug Bug report and fix labels May 8, 2026
@dougqh dougqh marked this pull request as ready for review May 8, 2026 13:45
@dougqh dougqh requested a review from a team as a code owner May 8, 2026 13:45
@dougqh dougqh requested a review from mcculls May 8, 2026 13:45
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: dd779943f8

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".


/** Updates access time to the @link {@link System#currentTimeMillis()} */
public void refreshAcessTime() {
public void refreshAccessTime() {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Restore the old refreshAcessTime method

Renaming this public method removes the refreshAcessTime() symbol from the published GenerationalUtf8Cache class. Any external or out-of-tree code compiled against the previous communication artifact that calls the misspelled method will now fail with NoSuchMethodError at runtime (or fail source compilation) even though the implementation could remain as a deprecated forwarding alias to refreshAccessTime().

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Contributor Author

@dougqh dougqh May 8, 2026

Choose a reason for hiding this comment

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

My choice - as described by Claude...

Decided not to keep the deprecated alias. GenerationalUtf8Cache lives in datadog.communication.serialization and is internal to the agent — not a documented public API. grep across the repo confirms there are no callers outside this class itself, and the package isn't shipped as a stable extension point. Carrying a misspelled forwarding method just to hedge against hypothetical out-of-tree compilation isn't worth the API surface debt.

return baseString + valueSuffix;
}

static long lookupEdenLastUsedMs(GenerationalUtf8Cache cache, String value) throws Exception {
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I'd prefer to make the fields package visible rather than use reflection in the tests.

dougqh and others added 3 commits May 8, 2026 09:54
- Restore refreshAcessTime as a deprecated forwarding alias to
  preserve binary compatibility for any existing callers compiled
  against the prior artifact.
- Drop reflection in GenerationalUtf8CacheTest by making the eden
  and tenured entry arrays package-visible.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Keep only the corrected refreshAccessTime method.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp: core Tracer core tag: ai generated Largely based on code generated by an AI or LLM type: bug Bug report and fix

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants