Backtestshugorun-20260930-140149#15267
Bump fileCacheEntryVersion in transform.ToMath
Our patch was judged on par with the merged fix.
In this judgment, Patch B = our agent, Patch A = the merged fix.
Both patches make the identical functional change in tpl/transform/transform.go: they bump fileCacheEntryVersion from "v1" to "v2". This changes the cache key prefix (tomath/v2/...), so cached output from KaTeX 0.16.21 is invalidated and regenerated with 0.18.4. That addresses the root cause in the issue. Neither patch adds tests, and both are minimally scoped. The only difference is that Patch B extends the comment to "e.g. KaTeX upgrades". This is a small documentation nicety that hints when to bump the version. It has no effect on behavior or risk and is too minor to count as a meaningful craft difference. The two patches are functionally equivalent.
The judge saw only the two patches, labelled A and B in random order, with issue links and version numbers removed. The reasoning above is shown verbatim.
Solve
25m 43s14 turns
Wall-clock time in the container
Full test suite
No new failures
3,753 passed · 99 skipped · 3,854 total
Contamination audit
Clean
No sign the agent saw the real fix
Patch size
2vs 2 merged
Changed lines, ours vs merged
The issue
View on GitHubIn ec52e638c we bumped KaTeX from 0.16.21 to 0.18.4. This produces different output.
I ran into this when testing the docs site, specifically the chem example.
The two patches
tpl/transform/transform.goindex 5c99b322c..edff5df9a 100644@@ -293,7 +293,7 @@ func (ns *Namespace) ToMath(ctx context.Context, args ...any) (template.HTML, er Warnings []string `json:"warnings,omitempty"` } - const fileCacheEntryVersion = "v1" // Increment on incompatible changes.+ const fileCacheEntryVersion = "v2" // Increment on incompatible changes, e.g. KaTeX upgrades. s := hashing.HashString(args...) key := "tomath/" + fileCacheEntryVersion + "/" + s[:2] + "/" + s[2:]
tpl/transform/transform.goindex 5c99b322c..f9d0dabb0 100644@@ -293,7 +293,7 @@ func (ns *Namespace) ToMath(ctx context.Context, args ...any) (template.HTML, er Warnings []string `json:"warnings,omitempty"` } - const fileCacheEntryVersion = "v1" // Increment on incompatible changes.+ const fileCacheEntryVersion = "v2" // Increment on incompatible changes. s := hashing.HashString(args...) key := "tomath/" + fileCacheEntryVersion + "/" + s[:2] + "/" + s[2:]
What the agent reported
I bumped the cache key version in transform.ToMath from v1 to v2, but I couldn't run any tests: the test environment can't download Go modules. So the diff has no test. I wrote a regression test but removed it, because I never saw it fail before the fix or pass after it.
What was wrong: ToMath saves its rendered output in a file cache, and the saved entries are named using fileCacheEntryVersion. That was still "v1" after ec52e638c upgraded KaTeX from 0.16.21 to 0.18.4. Sites with an existing cache, like the docs site and its chem example, kept getting the old 0.16.21 output.
What I changed: one line in tpl/transform/transform.go:296, "v1" → "v2". The comment now names KaTeX upgrades as a reason to bump it. Old cache entries are simply never looked up again. ToMath is the only code that uses KaTeX, and Markdown math also goes through it, so nothing else needed a bump.
Test evidence:
- Both runs of
./bt-test ./tpl/transform/ -run TestToMath, one before the fix and one after, endedFAIL github.com/gohugoio/hugo/tpl/transform [setup failed]. The report had 93 errors likelookup proxy.golang.org ... server misbehaving. Runninggo testdirectly fails the same way (Forbidden), and the local module cache is empty. - The removed test was
TestToMathStaleFileCacheEntry. It pre-writes a fake v1 cache entry containingSTALE_KATEX_0.16.21exactly where the cache would look for it. It then builds a page withtransform.ToMathand checks that the fake output is not served and real KaTeX output (<span class="katex"><math) is. - A reviewer traced the cache code and agreed the test should fail on v1 and pass on v2. That is from reading only, not from a run.
- The test is saved as a patch at
/tmp/tomath_stale_test.patch. Once modules are available, restore it withgit apply /tmp/tomath_stale_test.patchand run./bt-test ./tpl/transform/ -run TestToMathStaleFileCacheEntry.
Requirements:
- Bump
fileCacheEntryVersionintransform.ToMath: done (v1 → v2), but not verified by any test run. - KaTeX 0.16.21 → 0.18.4 changes output: the fix makes the cache ignore entries saved before the upgrade.
internal/warpc/katex.goonly uses the version number for the licence listing, not for caching. - Docs site chem example: covered by the same fix, since it renders through
ToMath. I didn't reproduce it because nothing can build here.
AGENTS.md and CLAUDE.md were already deleted before I started; I left them alone. Nothing is committed and no scratch files are in the repository.