Skip to content

Report unreadable image imports instead of failing silently - #124

Merged
vycdev merged 10 commits into
vycdev:developfrom
officialasishkumar:fix/issue-107-corrupt-image-feedback
Nov 7, 2026
Merged

vycdev merged 10 commits into
vycdev:developfrom
officialasishkumar:fix/issue-107-corrupt-image-feedback

Conversation

@officialasishkumar

Copy link
Copy Markdown
Contributor

Choosing or dropping a file labelled image/* that cannot be decoded (for example plain text saved as .png) showed no feedback. It also replaced the current image in app state. handleFiles invalidated the swatches and pushed the broken object URL into history. CanvasPreview then failed to load it and only cleared its loaded flag. The old pixels stayed on screen, but undo, swatches, and later operations pointed at an image that did not exist.

handleFiles now decodes the file before touching any state:

  • An unreadable file revokes its object URL and leaves the current image, undo history, and swatches untouched. A dismissible, localized notice appears at the bottom of the 2D preview, clear of the preview toolbar and the size badge.
  • Non-image files use the same notice instead of a blocking alert(). The next successful import clears it.
  • The notice stores the error kind and file name, not a translated string, so it follows language changes.
  • A request counter commits only the latest pick or drop if decodes overlap.
  • The resize path shares the same decodeImage helper instead of its inline copy.

The three new strings are added to all 12 locales, and there is an Unreleased changelog entry.

Fixes #107.

Validation:

  • New tests/e2e/image-import-error.spec.ts (@smoke): after a valid 1000×835 import, a corrupt PNG and then a text file each show the notice. The 1000×835 image is kept, dismissal works, one Undo returns to the starter image with Undo then disabled (no history entry for failed files), and a later valid import clears the notice. The spec fails on current develop (no notice appears) and passes with this change.
  • tests/e2e/image-reimport.spec.ts: passed.
  • npx eslint src --max-warnings=0, npx tsc -b, npm run check:i18n, and Prettier on changed files: passed.
  • tests/e2e/i18n.spec.ts under playwright.i18n.config.ts: 16 passed, 1 failed. The failing test, desktop release notes switch languages…, times out the same way on unmodified develop in my environment.

Choosing or dropping a file whose MIME type is image/* but whose bytes
cannot be decoded (for example a text file renamed to .png) went
straight into the image history. `CanvasPreview` then failed to load it
and only cleared its loaded flag, so the user saw no feedback and the
old pixels stayed on screen even though the app state now pointed at the
broken URL: swatches had been invalidated, the undo stack had gained an
entry, and later operations ran against an image that did not exist.

`handleFiles` now decodes the file before touching any state. An
unreadable file revokes its object URL, leaves the current image, undo
history, and swatches untouched, and shows a dismissible, localized
notice at the bottom of the 2D preview (clear of the preview toolbar).
Non-image files use the same notice instead of a blocking browser
alert, and the next successful import clears it. The notice stores the
error kind and file name rather than a translated string so it follows
language changes while open. A request counter ensures only the most
recent pick or drop is committed if decodes overlap.

The resize path already decoded through an inline promise; it now
shares the same `decodeImage` helper.

Add the three new strings to all 12 locales and a browser regression
that imports a corrupt PNG and a text file after a valid image, checks
the notice, the retained image, the unchanged undo history, dismissal,
and that a successful import clears the error.

Fixes vycdev#107
@chatgpt-codex-connector

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

Copy link
Copy Markdown

Codex Review Summary

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

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-03T10:35:17.143112Z 9368546 PR opened
ℹ️ 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: 936854630a

ℹ️ 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 src/App.tsx Outdated
Comment on lines +615 to +616
const image = await decodeImage(url);
if (request !== imageImportRequestRef.current) {

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 Invalidate pending imports after image edits

If a large image takes time to decode, the editor remains interactive while this await is pending. The request token advances only when another file is selected, so if the user clears, undoes, or crops the current image during this gap, the pending import still completes and replaces that later result. Invalidate pending imports when other image-changing actions occur or gate completion on the image state remaining unchanged.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Note

🤖 Claude Opus 5.5 responding on behalf of Victor Sandu

Fixed in 336d29f. useImageHistory runs onBeforeSet on every set, clear, undo, and redo, and App now passes a callback there that advances the import token. Any image change during a pending import therefore cancels it: Remove image, Undo/Redo, crop, resize, bake, dedither, touch-up, swatch edits, and quantize. A cancelled import revokes its object URL and shows no notice.

The new e2e test image edits made while an import is being checked cancel that import holds createImageBitmap, then undoes or removes the image while the import is pending. It checks that the import is discarded and the history is unchanged. Each phase fails without the fix and passes with it.

An <img> still loads a truncated or partly damaged raster file and shows
only the rows it could decode, so such files replaced the current image
with a partial one and no notice. After the <img> decode succeeds,
handleFiles now also requires createImageBitmap to accept the file.
SVGs skip that check because Chrome's createImageBitmap does not accept
SVG blobs.

The decode error said "Your current image was kept" even when there was
no current image. Add an imageDecodeFailedNoImage variant without that
sentence in all 12 locales. Removing the image also clears the notice.

Mention the behavior in the Loading Images guide in all 12 languages and
fold the changes into the existing changelog entry.

Extend the browser regression with a truncated PNG (and its effect on
undo history), the no-image wording after Remove image, and valid JPEG
and SVG imports.
vycdev and others added 7 commits November 4, 2026 21:18
handleFiles awaits the decode and createImageBitmap checks before it
commits, and the editor stays interactive meanwhile. The request token
only advanced on another file pick or drop, so Remove image, Undo, Redo,
crop, resize, bake, dedither, touch-up, swatch edits, or quantize during
that gap were overwritten when the import finished.

Pass a callback that advances the token as useImageHistory's
onBeforeSet, which runs on every set, clear, undo, and redo. A cancelled
import revokes its object URL and shows no notice, as before.

Add a browser regression that holds createImageBitmap, then undoes or
removes the image while the import is pending, and checks that the
import is discarded and the history is unchanged.
Quantize and dedither commit their result through image history, which
cancels any pending import. A file chosen or dropped while one of them
ran was therefore discarded without any notice once it finished. Disable
Choose file, the file input, and the drop zone while they run instead.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
WebKit, used by the macOS and Linux desktop apps, decodes truncated files
to a partial image in both <img> and createImageBitmap, so the
createImageBitmap check only caught them in Chrome. Check the file
structure for its end marker first: PNG must reach IEND, JPEG must reach
EOI after its scans, and WebP must match its RIFF size. Other formats
are still left to the decoder.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The notice read the live image to decide whether to say the current
image was kept, and stayed open through undo, redo, and edits. After
Remove image, a failed import, and Undo, it claimed an image had been
kept. Record the image on screen when the import fails, word the notice
from it, and close the notice once the image changes.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Some platforms and desktop WebViews report an empty File.type for valid
images, which the main import rejected as "Please upload an image file".
Move the Stack Matrix photo picker's isImageFile helper, which falls back
to the extension, into src/lib and use it for the main import too.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Undo and redo called onBeforeSet from inside their setPast/setFuture
updaters, which React may run later or twice. Pending image imports now
rely on it for cancellation, so call it in the handler instead, and skip
it when there is nothing to undo or redo.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The cats fixtures recorded the SHA-256 of profile.kfil from a CRLF
checkout, so the immutability check only passed on Windows with
core.autocrlf=true. Mark .kfil files and performance fixture JSON as
-text so every platform checks out the committed bytes, record the LF
hash, and document that archived results hold the CRLF form. Cached
multi-head preparation accepts either line-ending form of the same
committed profile so archived evidence stays usable.

Closes vycdev#130

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@vycdev

vycdev commented Nov 7, 2026

Copy link
Copy Markdown
Owner

Note

🤖 Claude Opus 5.5 responding on behalf of Victor Sandu

Thanks for this, @officialasishkumar. I reviewed it and pushed a few fixes to your branch, one commit each, then merged the latest develop:

  • 8ec0c54 Refuse imports while quantize or dedither is running. Their result goes through image history, which cancels a pending import, so a file dropped during Apply was discarded with no notice. Choose file, the file input, and the drop zone are now disabled while they run.
  • 85da057 Detect truncated PNG, JPEG, and WebP files on every engine. WebKit (used by the macOS and Linux desktop apps) decodes truncated files partially in both <img> and createImageBitmap, so the check only worked in Chrome. The new src/lib/imageTruncation.ts checks for the format's end marker first. Your truncated-PNG test failed in WebKit before this change and passes after it.
  • 5d8060e Tie the notice to the image it was shown for. The "current image was kept" wording read the live image, so after Remove image, a failed import, and Undo, it wrongly said an image had been kept. The notice now closes once the image changes.
  • e75f25d Recognize images without a MIME type by extension, reusing the Stack Matrix isImageFile helper (moved to src/lib/imageFile.ts).
  • 7d209fb Call onBeforeSet in the undo/redo handlers rather than inside the state updaters, which React may run later or twice.

Each fix has a regression test that fails without it. The follow-ups that didn't belong in this PR are in #131 (repeated decoding), #132 (shared image-loading helper), and #133 (moving import handling into a hook and validating Stack Matrix photos the same way).

@vycdev

vycdev commented Nov 7, 2026

Copy link
Copy Markdown
Owner

Added 078e2f0 to this branch. It fixes #130, which is unrelated to the image-import changes. It's here so both land in develop with one merge.

Problem: cats captured observations and artifact hashes remain immutable failed on macOS and Linux. The recorded SHA-256 of tests/assets/performance/8-colors-frontlit-2026-08-26/profile.kfil (42b7259d…) came from a Windows checkout with core.autocrlf=true, which converted the file to CRLF. The committed file uses LF and hashes to 0df2f266….

Changes:

  • .gitattributes: *.kfil and tests/assets/performance/**/*.json are now -text, so every platform checks out the committed bytes.
  • The four case.json fixtures record the LF profile hash. The observation-hash constant in tests/optimizerEvidence.test.ts is updated to match. The observed results are unchanged.
  • tests/benchmark/multiHeadAppearance.ts: --prepare accepts saved results whose profile hash is either the LF or the CRLF form of the committed profile. Both hashes come from the actual file, so a different profile is still rejected. Archived results recorded on Windows stay usable.
  • tests/benchmark/results/cats-exact/2026-11-01/ is left untouched because its manifest locks those hashes. tests/benchmark/cats-exact-reproducibility.md now explains that 42b7259d… is the CRLF form of the same file, and how to refresh an existing Windows clone.
  • CHANGELOG: added to the Unreleased "Cats Exact benchmark reproducibility" entry.

Verified locally on macOS (no GitHub checks run for PRs into develop):

  • npm test: 1,102 pass, 0 fail, 1 skipped
  • npm run lint, npx tsc --noEmit, npm run build
  • AppImage update tests and scripts/check-release-notes.mjs
  • Simulated core.autocrlf=true checkout: profile.kfil stays LF and hashes to 0df2f266…

#130 needs to be closed by hand after merge, because Closes #130 only takes effect on main.

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.

2 participants