Repository navigation
fix(mp3): make the decode stack watermark reproducible (#4106) - #4114
Conversation
The metric landed on exact-but-different values on different CI runners while the decoder was byte-identical -- 1736 and 3336 for the retired Helix backend, each exact, one reproduced on a re-run. #4105 demoted it to informational as a stopgap. The issue asked for the mechanism to be instrumented rather than reasoned about, so that is what this does. **It was glibc.** `watermark.cpp` forwarded the decoder's `memcpy`/`memmove`/ `memset` to libc, so glibc's own frames sat inside the measured window. The metric is the deepest byte *anything* disturbed, and glibc's block-move implementations are large and differ between builds and CPU dispatch paths. Measured, not inferred, in this order: - Dumped every disturbed span. Dense and contiguous to depth 2696, locally deterministic at 2952 across runs -- so not noise. - Tested the obvious suspect first and it was wrong: forcing different `mem*` variants via `GLIBC_TUNABLES` (`-AVX2_Usable`, `-SSE4_1,-SSSE3`) moved the number not at all. - Instrumented the decoder with `-finstrument-functions` and recorded the minimum stack pointer per function entry. Deepest decoder frame is `mp3d_DCT_II` at 1896 -- 800 bytes shallower than the paint reported, so something below the decoder was being counted. - Replaced the libc forwarders with plain loops: 2952 -> 2056, and every span below ~1800 vanished. That is the ~900 bytes, and it is glibc's. The harness now uses its own loops. The pointers are `volatile` so loop-idiom recognition cannot call `memcpy` right back and silently restore the variance -- a guarantee from the standard rather than a build flag someone can drop. Verified the only remaining libc `mem*` call in the binary is the paint itself in `startWatermark`, which runs before the measured window and above it. Measuring glibc was also measuring the wrong thing: the 2 KiB budget is an MCU budget, and no MCU links a vectorised `memcpy`. Two independent instruments now corroborate each other. The compiler-derived callgraph says 2032 and the live watermark says 2056 -- a 24-byte gap that is the audit call boundary. Before the fix they disagreed by 664 bytes. So the metric is gated again: `INFORMATIONAL_METRICS` is now empty and the ledger row is 2056. Five consecutive runs identical, unchanged under every `GLIBC_TUNABLES` setting tried, and `LEDGER:PASS` end to end. Closes #4106 Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01ByD5ZKrnFJuchjRmPiQdd5
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Team Run ID: 📒 Files selected for processing (3)
Included review availability: Your plan provides up to 8 included reviews per hour; 7 remain after this review. 📝 WalkthroughWalkthroughThe watermark harness replaces libc memory calls with volatile byte loops. The audit now regression-gates ChangesCodec memory watermark
Estimated code review effort: 2 (Simple) | ~10 minutes Merge Risk: ⚪ Minimal · up to This PR makes the CI memory measurement deterministic and restores regression gating without changing production behavior or public interfaces. No actionable merge-blocking risk remains beyond normal checks and review. 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
Full details: Docstring CoverageExplanation Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 3 functions across 2 files. (1 skipped: 1 unsupported.)
✨ Finishing Touches 💡 1📝 Generate docstrings 💡
🧪 Generate unit tests (beta)
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. Comment |
The decode stack watermark gave exact-but-different answers on different CI runners while the decoder was byte-identical — 1736 and 3336 for the retired Helix backend, each exact, one reproduced on a re-run. #4105 demoted it to informational as a stopgap. The issue asked for the mechanism to be instrumented rather than reasoned about, so that is what this does.
It was glibc
ci/codec_memory/watermark.cppforwarded the decoder'smemcpy/memmove/memsetto libc. The metric is "the deepest byte anything disturbed", so glibc's own block-move frames sat inside the measured window — and those are large and differ between glibc builds and CPU dispatch paths.How I got there, including the wrong turn
memcpyvariants per CPU — that shape explains "exact but host-dependent" perfectly. Forcing variants withGLIBC_TUNABLES(-AVX2_Usable,-AVX2_Usable,-AVX_Usable,-SSE4_1,-SSSE3) moved the number not at all. Hypothesis dead.-finstrument-functions, recording the minimum stack pointer at every function entry. Deepest decoder frame:mp3d_DCT_IIat depth 1896 — 800 bytes shallower than the paint was reporting. So the decoder was being charged for something below itself.The fix
The harness uses its own loops. The pointers are
volatileso loop-idiom recognition cannot turn them back into amemcpycall and silently restore the variance — a guarantee from the standard rather than a build flag someone can drop later. I verified the only remaining libcmem*call in the linked binary is the paint itself instartWatermark, which runs before the measured window and above it.Measuring glibc was also measuring the wrong thing: the 2 KiB budget this audit enforces is an MCU budget, and no MCU links a vectorised
memcpy— newlib's is a word loop much like these.Why I trust the new number
The two independent instruments now corroborate each other:
24 bytes is the audit call boundary. That 664-byte disagreement was the bug visible in the ledger the whole time, and nobody had chased it.
Validation
GLIBC_TUNABLESsetting tried.LEDGER:PASSend to end, all other metrics byte-identical.INFORMATIONAL_METRICSis now empty and the metric is gated again like every other one — the stopgap is no longer needed. The set is kept (empty, documented) rather than deleted, so re-demoting a metric later doesn't require reinventing the mechanism.Closes #4106
Summary by CodeRabbit
Bug Fixes
Documentation