fix(diff): Count extra comp pixels when compare image is larger than base#170
Merged
Conversation
e9bcf0e to
40ad40b
Compare
40ad40b to
df7dd20
Compare
Contributor
Author
|
Updated the test to use a new |
Contributor
Author
|
(I can work around this in the short term but it involves me only running in CLI mode until this is merged, but for sure hope we can move back to server mode if this is merged!) |
NicoHinderling
added a commit
to getsentry/sentry
that referenced
this pull request
Apr 13, 2026
…ch bug odiff server mode has a stdin buffer reuse bug that causes non-deterministic false match=True results. Switch to CLI mode (one subprocess per comparison) until the upstream fix lands. All server-mode code is commented out for easy revert once dmtrKovalenko/odiff#170 is released in odiff-bin. Also derives changed pixel count from the diff mask histogram instead of parsing odiff stdout, which is more reliable.
NicoHinderling
added a commit
to getsentry/sentry
that referenced
this pull request
Apr 13, 2026
…ch bug (#112829) Switch snapshot image comparison from odiff server mode to CLI mode (one subprocess per comparison) to work around a non-deterministic false match bug caused by stdin buffer reuse in server mode. The upstream fix is at dmtrKovalenko/odiff#170. All server-mode code is commented out (not deleted) for easy revert once the fix is released in odiff-bin. Also changes pixel counting from parsing odiff stdout (which varied across versions) to counting non-zero pixels from the diff mask via PIL histogram — more reliable and version-independent.
dmtrKovalenko
approved these changes
Apr 16, 2026
NicoHinderling
added a commit
to getsentry/sentry
that referenced
this pull request
Apr 17, 2026
odiff-bin v4.3.8 ships the upstream fix for the server-mode stdin buffer reuse bug (dmtrKovalenko/odiff#170), so we can drop the CLI-mode fallback introduced in #112829 and go back to using server mode. Also: - Pin odiff-bin to exact 4.3.8 (no caret) in package.json and CI - Point _find_odiff_binary() at node_modules/odiff-bin/bin/odiff.exe; v4.3.8's post-install only chmods this path, while raw_binaries/ ship without the execute bit - Extract _fetch_batch_images helper in tasks.py to avoid per-iteration closure rebinding inside the batch loop Co-Authored-By: Claude <noreply@anthropic.com>
NicoHinderling
added a commit
to getsentry/sentry
that referenced
this pull request
Apr 20, 2026
) Reverts the odiff CLI-mode workaround (#112829) now that odiff-bin v4.3.8 ships the upstream fix for the server-mode stdin buffer reuse bug ([dmtrKovalenko/odiff#170](dmtrKovalenko/odiff#170)). Snapshot comparison goes back to using server mode — one persistent subprocess per batch instead of spawning one per comparison. ### Dependency pin `odiff-bin` is pinned to exact `4.3.8` (no caret) in `package.json`, `pnpm-lock.yaml`, and the CI workflow. Exact pin keeps dev / prod / CI in lockstep with minimal machinery. ### Bonus fix — binary resolution `_find_odiff_binary()` now points at `node_modules/odiff-bin/bin/odiff.exe` instead of `raw_binaries/odiff-<platform>`. v4.3.8's `post_install.js` only sets the execute bit on `bin/odiff.exe`; the raw binaries ship without `+x`, which was causing `PermissionError` on fresh installs. Despite the `.exe` suffix, this is the package's cross-platform entrypoint on all OSes. ### Minor cleanup Extracted `_fetch_batch_images` helper in `tasks.py` so the per-batch closure / lock / cache setup lives in one place instead of being rebuilt inside every loop iteration. Co-authored-by: Claude <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
compareDifferentLayoutsnow counts extra comp columns (per row) and extra comp rows when the compare image is larger than the base — previously these pixels were silently ignored, causing falsematch: truefor images where comp is wider or tallermax(base.width, comp.width) × max(base.height, comp.height)fordiffPercentageso it stays ≤100%Root cause
compareDifferentLayoutshad asymmetric handling: it counted extra pixels whenbase > compbut completely ignored extra pixels whencomp > base. For example, comparing a 200×200 base against a 300×200 compare image would ignore the 100 extra columns entirely, producingdiff_count == 0.This bug affects both CLI and server mode. The race condition from #169 (thread-safe allocator) is also theoretically present in CLI, but since the process exits immediately after one comparison, the overlapping memory never gets a chance to cause observable damage. In server mode, the corrupted allocations compound across requests. This dimension bug, however, is fully deterministic — it reproduces 100% of the time in both modes for any image pair where the compare image is larger than the base.
Why the
diffPercentagedenominator also changesCounting extra comp pixels in
diff_countwithout changing the denominator produces >100% percentages (e.g. 400% for a 4×4 base vs 8×8 compare). This would break downstream consumers that assume percentage is bounded at 100%.For example, Argos (a major consumer of odiff) computes
score = diffPercentage / 100and stores it with a database constraint ofmaximum: 1. A >100% percentage would fail validation and crash. Argos itself avoids this by resizing images to matching dimensions before diffing, but other consumers may not.The tradeoff: changing the denominator from
base.width × base.heighttomax(base.width, comp.width) × max(base.height, comp.height)(the bounding box) means the percentage changes for different-dimension image pairs. For same-dimension images (the vast majority of real-world usage), the denominator is identical and behavior is unchanged.Isolated test results (server mode, 100 runs × 11 pairs = 1100 comparisons)
The 100/1100 remaining with ThreadSafeAllocator alone are all from
width_change.png(200×200 vs 300×200) — the exact bug this PR fixes. The dimension fix alone does not help with the race condition (still 45.3% on a smaller test set).Depends on
This PR depends on #169 (thread-safe allocator fix) and should be reviewed/merged after it.
Test plan
zig build test-allpasses (updated expectations for layout diff tests)diffPercentagestays ≤100% — uses bounding box denominator