Skip to content

feat(#4840): found critical bug in caching mechanism for transpilation process#4845

Merged
yegor256 merged 1 commit into
objectionary:masterfrom
volodya-lombrozo:4840-cache-transpilation
Feb 2, 2026
Merged

feat(#4840): found critical bug in caching mechanism for transpilation process#4845
yegor256 merged 1 commit into
objectionary:masterfrom
volodya-lombrozo:4840-cache-transpilation

Conversation

@volodya-lombrozo

@volodya-lombrozo volodya-lombrozo commented Feb 2, 2026

Copy link
Copy Markdown
Member

This PR adds a few more tests that reveal the critical problem with the current caching mechanism.

Related to #4840

Summary by CodeRabbit

  • Bug Fixes & Improvements

    • Enhanced transpilation logging to include plugin version and cache metadata details
    • Improved cache directory resolution and parameter handling in the build pipeline
  • Tests

    • Added test coverage for transpilation behavior when cache is unavailable
    • Added test for cache-hit scenarios (currently disabled)

Copilot AI review requested due to automatic review settings February 2, 2026 12:04
@coderabbitai

coderabbitai Bot commented Feb 2, 2026

Copy link
Copy Markdown
Contributor
📝 Walkthrough

Walkthrough

The PR enhances the transpilation caching mechanism by introducing contextual metadata (plugin version, tail path, cache directory) into the transpilation logging and pipeline, and expands test coverage with new cache-behavior test cases.

Changes

Cohort / File(s) Summary
Transpilation Metadata Enhancement
eo-maven-plugin/src/main/java/org/eolang/maven/MjTranspile.java
Captures and propagates additional contextual metadata into transpilation flow: plugin version, tail path computation, and dedicated cache directory; extends logging output to include version, Tojo hash, and cache-related details; updates function parameters to pass new cache directory and tail path.
Caching Test Coverage
eo-maven-plugin/src/test/java/org/eolang/maven/FpDefaultTest.java
Adds two new test methods for cache scenarios: transpilesIfCacheMiss (active test verifying transpilation on cache miss) and doesNotTranspileIfCacheHitWhenCacheExistedBefore (disabled test for cache hit behavior); includes new imports for test utilities.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested reviewers

  • yegor256

Poem

🐰 Whiskers twitching with delight,
Cache and tail paths now shine bright,
Metadata flows through transpilation's dance,
Tests hop in to give coverage a chance!

🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 75.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main purpose of the PR—identifying and addressing a critical bug in the transpilation caching mechanism—which aligns with the PR objectives and the code changes made.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions

github-actions Bot commented Feb 2, 2026

Copy link
Copy Markdown
Contributor

🚀 Performance Analysis

All benchmarks are within the acceptable range. No critical degradation detected (threshold is 100%). Please refer to the detailed report for more information.

Click to see the detailed report
Test Base Score PR Score Change % Change Unit Mode
benchmarks.XmirBench.xmirToEO 176.083 169.066 -7.018 -3.99% ms/op Average Time

✅ Performance gain: benchmarks.XmirBench.xmirToEO is faster by 7.018 ms/op (3.99%)

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 Fix all issues with AI agents
In `@eo-maven-plugin/src/test/java/org/eolang/maven/FpDefaultTest.java`:
- Around line 358-360: The test uses FpDefaultTest.notExistedTarget(...) which
appends "tar/get.txt" and therefore hides the intended transpilation output
path; change the test to use the explicit expected output Path (the resolved
".../fibonacci.xmir") instead of calling notExistedTarget, and ensure its parent
directories are created before use (e.g., createParents on the Path or
Files.createDirectories(target.getParent())); update references to the variable
target and remove reliance on notExistedTarget to ensure the test actually
targets the fibonacci.xmir output.
- Line 405: The test currently ages the directory with
FpDefaultTest.makeOlder(cdir, 1000), which updates the directory mtime (and with
a positive shift can make it newer); instead, change the call to age the actual
cache file mtime into the past — locate the cache file path used in this test
(the cache filename variable or the File/Path pointing to the cache under cdir)
and call FpDefaultTest.makeOlder(cacheFilePath, -1000) (or otherwise pass a
negative shift) so the cache file itself is set to an older mtime and simulates
"cache older than source".

Comment on lines +358 to +360
final Path target = FpDefaultTest.notExistedTarget(
temp.resolve("target/eo/5-transpile/org/eolang/examples/fibonacci.xmir")
);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

Target path helper hides the intended transpilation output path.

notExistedTarget(...) appends tar/get.txt, so this test doesn’t actually use the .../fibonacci.xmir target and is less representative of real output paths. Consider using the explicit path (and ensure parent dirs exist).

Suggested fix
-        final Path target = FpDefaultTest.notExistedTarget(
-            temp.resolve("target/eo/5-transpile/org/eolang/examples/fibonacci.xmir")
-        );
+        final Path target =
+            temp.resolve("target/eo/5-transpile/org/eolang/examples/fibonacci.xmir");
+        Files.createDirectories(target.getParent());
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
final Path target = FpDefaultTest.notExistedTarget(
temp.resolve("target/eo/5-transpile/org/eolang/examples/fibonacci.xmir")
);
final Path target =
temp.resolve("target/eo/5-transpile/org/eolang/examples/fibonacci.xmir");
Files.createDirectories(target.getParent());
🤖 Prompt for AI Agents
In `@eo-maven-plugin/src/test/java/org/eolang/maven/FpDefaultTest.java` around
lines 358 - 360, The test uses FpDefaultTest.notExistedTarget(...) which appends
"tar/get.txt" and therefore hides the intended transpilation output path; change
the test to use the explicit expected output Path (the resolved
".../fibonacci.xmir") instead of calling notExistedTarget, and ensure its parent
directories are created before use (e.g., createParents on the Path or
Files.createDirectories(target.getParent())); update references to the variable
target and remove reliance on notExistedTarget to ensure the test actually
targets the fibonacci.xmir output.

Files.createDirectories(cachefile.getParent());
final String cached = "transpilation results from cache";
Files.write(cachefile, cached.getBytes(StandardCharsets.UTF_8));
FpDefaultTest.makeOlder(cdir, 1000);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

Age the cache file itself (and in the past) for this scenario.

makeOlder(cdir, 1000) updates the directory timestamp (and with a positive shift makes it newer). If the cache decision is based on the cache file’s mtime, this won’t simulate “cache older than source.” Set the cache file mtime to the past instead.

Suggested fix
-        FpDefaultTest.makeOlder(cdir, 1000);
+        Files.setLastModifiedTime(
+            cachefile,
+            FileTime.fromMillis(System.currentTimeMillis() - 1_000)
+        );
🤖 Prompt for AI Agents
In `@eo-maven-plugin/src/test/java/org/eolang/maven/FpDefaultTest.java` at line
405, The test currently ages the directory with FpDefaultTest.makeOlder(cdir,
1000), which updates the directory mtime (and with a positive shift can make it
newer); instead, change the call to age the actual cache file mtime into the
past — locate the cache file path used in this test (the cache filename variable
or the File/Path pointing to the cache under cdir) and call
FpDefaultTest.makeOlder(cacheFilePath, -1000) (or otherwise pass a negative
shift) so the cache file itself is set to an older mtime and simulates "cache
older than source".

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Adds additional coverage and diagnostics around the transpilation caching behavior to help reproduce and investigate issue #4840 (“transpilation doesn't use the cache”).

Changes:

  • Added new FpDefault cache behavior tests, including a disabled regression test documenting the timestamp-based cache problem.
  • Enhanced MjTranspile cache-miss debug logging and slightly refactored repeated expressions into locals.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 5 comments.

File Description
eo-maven-plugin/src/test/java/org/eolang/maven/FpDefaultTest.java Adds tests targeting transpilation cache miss/hit behavior and documents the suspected timestamp-based flaw.
eo-maven-plugin/src/main/java/org/eolang/maven/MjTranspile.java Improves cache-miss logging with version/hash/tail/cache-dir details to aid debugging cache decisions.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Files.createDirectories(cachefile.getParent());
final String cached = "transpilation results from cache";
Files.write(cachefile, cached.getBytes(StandardCharsets.UTF_8));
FpDefaultTest.makeOlder(cdir, 1000);

Copilot AI Feb 2, 2026

Copy link

Choose a reason for hiding this comment

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

In this disabled test, makeOlder(cdir, 1000) only changes the directory timestamp, but FpDefault compares the cache file timestamp (the path returned by CachePath, i.e., cachefile). This means the test setup may not reliably reproduce the intended “cache older than source” scenario when you later enable it. Consider explicitly setting cachefile (and/or source) lastModifiedTime to guarantee cachefile is older than source.

Suggested change
FpDefaultTest.makeOlder(cdir, 1000);
FpDefaultTest.makeOlder(cachefile, 1000);

Copilot uses AI. Check for mistakes.
* than the source files.
*/
@Test
@Disabled

Copilot AI Feb 2, 2026

Copy link

Choose a reason for hiding this comment

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

@Disabled is used without a reason string, which makes test reports harder to interpret. Consider adding a short explanation directly in the annotation (e.g., referencing #4840 / timestamp-based cache validation) so it’s visible without opening the Javadoc.

Suggested change
@Disabled
@Disabled("Disabled until #4840: implement proper timestamp-based cache validation")

Copilot uses AI. Check for mistakes.
Comment on lines +398 to +402
final Path cachefile = cdir
.resolve("1.0-SNAPSHOT")
.resolve("94641989dbaebef167cf67906a265d925bbb4e5b")
.resolve("org/eolang/examples/fibonacci.xmir");
Files.createDirectories(cachefile.getParent());

Copilot AI Feb 2, 2026

Copy link

Choose a reason for hiding this comment

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

Variable name cachefile is a compound name; per project guideline prefer a single-word noun for locals. Consider renaming it to something like cache/entry (and adjust usages) to keep naming consistent with the guideline.

Copilot generated this review using guidance from organization custom instructions.
Comment on lines 184 to +196
Logger.debug(
this,
"Transpiled %[file]s (%s) to %[file]s (%s) in %[ms]s (cache miss)",
"Transpiled %[file]s (%s) to %[file]s (%s) in %[ms]s (cache miss), version: %s, hash: %s, tail: %s, cache enabled: %b, cache dir: %[file]s",
source,
MjTranspile.info(source),
target,
MjTranspile.info(target),
System.currentTimeMillis() - start
System.currentTimeMillis() - start,
version,
hsh.get(),
tail,
this.cacheEnabled,
cdir

Copilot AI Feb 2, 2026

Copy link

Choose a reason for hiding this comment

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

The debug message always says “(cache miss)”, but this lambda can also run when caching is disabled (cache enabled: false). This can be misleading when diagnosing builds. Consider adjusting the wording to reflect both cases (e.g., “cache miss or disabled”) or emitting different messages depending on cacheEnabled.

Copilot uses AI. Check for mistakes.
Comment on lines +176 to 179
final String version = this.plugin.getVersion();
final Path tail = base.relativize(target);
final Path cdir = this.cache.toPath().resolve(MjTranspile.CACHE);
new FpDefault(

Copilot AI Feb 2, 2026

Copy link

Choose a reason for hiding this comment

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

Local name cdir is an abbreviated compound; per project guideline prefer a single-word noun for locals. Consider renaming to cache/dir (or similar) to avoid abbreviations and compound naming.

Copilot generated this review using guidance from organization custom instructions.
@volodya-lombrozo

Copy link
Copy Markdown
Member Author

@yegor256 I suggest rewriting the caching mechanism - it's full of bugs and it's hard to comprehend the logic behind of it.

@yegor256 yegor256 merged commit 7148c77 into objectionary:master Feb 2, 2026
32 of 33 checks passed
@0crat

0crat commented Feb 3, 2026

Copy link
Copy Markdown

@volodya-lombrozo Thanks for the contribution! You've earned +12 points for this: +16 as a basis, +5.35 for your 107 hits-of-code, but -4 for exceeding 100 hits-of-code and -5.35 to cap the HoC bonus at 16 points max. According to our policy, contributions over 100 hits-of-code get penalized to encourage smaller, more focused changes. Please keep them coming, but consider breaking larger contributions into smaller chunks! 🎯 Your running score is +272; don't forget to check your Zerocracy account too.

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.

4 participants