Skip to content

Fix defects found in review of the scripted commands - #2

Merged
shellbear merged 1 commit into
mainfrom
fix/scripted-review
Nov 28, 2026
Merged

shellbear merged 1 commit into
mainfrom
fix/scripted-review

Conversation

@shellbear

Copy link
Copy Markdown
Owner

Why

An independent review of #1 finished after it was merged and found real defects in the scripted commands. None has shipped: main is ahead of the last release (0.2.1). This fixes all of the confirmed ones.

What was wrong, and what happens now

Finding Before Now
render --out <dataset folder> Overwrote the source images with downscaled, drawn-on copies Refused, exit 64, however the folder is spelled (symlink, case, trailing slash)
annotate and stdin Read stdin whenever it wasn't a terminal, so inside a while read loop it swallowed the loop's input stdin is read only with --from -. An image with no boxes and no --negatives is a usage error rather than a silent no-op
Image names in annotate A.JPG created a second entry beside a.jpg; annotations.json was accepted as an image A name must be what a directory listing returns: image extension, spelled as stored, not hidden, directly in the folder
Negative width or height Silently flipped positive Refused
Box smaller than a pixel Saved as width 0 and re-added on every run, so add was not idempotent Refused
--image-size on an unreadable image Ignored; numbers written unscaled Reported as a problem
--mode replace with an empty box list Cleared the image, so detect | annotate --mode replace wiped labels wherever the detector found nothing "No boxes" is a no-op in both modes unless --negatives is given
Corrupt annotations.json Exit 64 with a usage banner Exit 1; validate reports invalid-annotations-file as JSON
--image a.jpg with one box object Rejected Accepted
Code fence on a single line Not stripped Stripped
Replacing an image's boxes with the same boxes Reported written: true and rewrote the file No change reported, file untouched

One behaviour change to be aware of

Clearing an image now takes --mode replace --negatives; --mode replace alone with an empty list does nothing. I think that is the right default (a detector that finds nothing should never delete labels), but it is a deliberate change to what #1 did.

What the review found sound

No regressions in the four rewritten format files (loader, writer, indent sniffing, directory listing), no concurrency problems in concurrentMap or the duplicate check, and the coordinate-convention arithmetic produced the expected numbers in every combination tried.

How it was checked

  • swift test: 175 tests, 0 failures (9 new, one per finding).
  • scripts/smoke-scripted.sh now has a check per command-level finding, including that render leaves the source image byte-identical and that a while read loop runs every iteration.
  • Every recipe in docs/agents.md was re-run against the rebuilt binary and saves the same coordinates as before.
  • Timings on 10,000 images are unchanged (stats 0.2 s, annotate 0.1 s, validate 0.5 s).

Not addressed

  • A dataset path that is itself a symlink lists no images in stats, validate and render. The reviewer confirmed the old code behaved the same way, so it is not a regression; it deserves its own fix.

🤖 Generated with Claude Code

A review of the merged scripted commands turned up defects, one destructive:

- render --out <dataset folder> overwrote the source images with downscaled,
  drawn-on copies. It is now refused (exit 64), however the folder is spelled.
- annotate read stdin whenever it wasn't a terminal, so inside a
  'while read' loop it swallowed the loop's input. stdin is now read only
  with --from -; naming an image with no boxes and no --negatives is a usage
  error instead of a silent no-op.
- For up to 256 named images annotate checked existence only, so A.JPG created
  a second entry beside a.jpg and annotations.json was accepted as an image.
  Names must now match what a listing returns: an image extension, spelled as
  stored, not hidden, directly in the folder.
- A negative width or height was silently flipped positive by CGRect. Refused.
- A box under one pixel rounded to zero on disk and was re-added on every
  run, breaking idempotency. Refused.
- --image-size (and an entry's width/height) was ignored when the image could
  not be read, writing unscaled numbers. Now a reported problem.
- An image supplied with no boxes was cleared in replace mode without
  --negatives, so 'detect | annotate --mode replace' wiped labels wherever the
  detector found nothing. 'No boxes' is now a no-op in both modes unless
  --negatives is given; an image whose every box was refused is left alone.
- A corrupt annotations file exited 64 with a usage banner. It is a dataset
  problem: exit 1, and validate reports it as invalid-annotations-file.
  Unparseable --from content is exit 1 as well.
- With --image, a single box object is accepted, and a code fence on one line
  is stripped.
- Records hold the 2-decimal values the file will hold, so replacing an
  image's boxes with the same boxes no longer reports a change.

Each has a unit test, and the smoke test gained a check per command-level
finding. Help text, the skill and docs/agents.md describe the new behaviour.
@shellbear
shellbear merged commit f0cb874 into main Nov 28, 2026
2 checks passed
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