Skip to content

Fix the flaky red badge: compare figures by content, not bytes - #1

Merged
ASM-21 merged 1 commit into
mainfrom
claude/figure-check-tolerance
Nov 30, 2026
Merged

ASM-21 merged 1 commit into
mainfrom
claude/figure-check-tolerance

Conversation

@ASM-21

@ASM-21 ASM-21 commented Nov 30, 2026

Copy link
Copy Markdown
Owner

Before: the README badge has been red since Nov 29. The only failing step was "Committed figures are exactly what the code produces": tariff-explorer/figures/01_regime_bill_curves.png came out 141094 -> 141097 bytes. I re-ran CI on the same commit (4071c1e) today with the same runner image (ubuntu-26 20261111.635), Python 3.12.16 and identical matplotlib 3.10.8 / numpy 2.4.4 / pandas 2.3.3 / pillow 12.1.1, and it passed. A one-off workflow on a scratch branch also regenerated every figure on a runner and found none that differed. So the figures are current and the check itself is flaky.

After: tools/check_figures.py replaces git diff --exit-code. A regenerated figure fails if its size changes or if more than 25 pixels move by more than 16/255 on any channel. It still catches the case the check exists for: its self-test shows a corrected title moves 2,081 pixels and a single swapped digit in a 10 pt label ("$1,234" to "$1,243") moves 202. The git diff --stat line still prints, and the upload-on-failure step is unchanged. The three study READMEs now say figures are "checked against the code in CI" instead of "byte-for-byte".

How: Pillow and numpy, both already pinned through matplotlib. I couldn't run check_bundle.py or update_manifest.py --check locally (they import pandapower), so this PR's CI run is the real test.

Cleanup for you: the scratch branch claude/ci-rendered-figure is still on GitHub because branch deletion is blocked from my side. It holds only the one-off workflow; delete it from the branches page.


Generated by Claude Code

Commit 4071c1e failed the figure step on Nov 29 (one PNG, 3 bytes) and
passed it on Nov 30 with the same runner image and pins, so byte
equality is not stable even in CI. tools/check_figures.py still fails on
any content change (a swapped digit in a 10 pt label moves ~200 pixels)
and passes antialiasing noise (25 pixels or fewer), with a self-test.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@ASM-21
ASM-21 marked this pull request as ready for review November 30, 2026 21:50
@ASM-21
ASM-21 merged commit 171db00 into main Nov 30, 2026
1 check passed
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 30, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-30T21:53:49.530607Z 905d551 Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

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

Copy link
Copy Markdown

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: 905d551160

ℹ️ About Codex in GitHub

Your team has set up Codex to 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 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread tools/check_figures.py


def changed_figures() -> list[str]:
out = _git("diff", "--name-only", "--", "*/figures/*.png").decode().split()

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 Include staged figure changes in the comparison

When a contributor stages regenerated PNGs before running this documented checker, git diff compares the worktree to the index, while git ls-files --others omits staged files. changed_figures() can therefore be empty and the check falsely succeeds without inspecting the staged image. CI currently runs from a clean checkout, but the local check should include staged changes when comparing against HEAD.

Useful? React with 👍 / 👎.

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.

1 participant