Repository navigation
feat: cover hard conditions and camera tilt in the detector replay - #506
Merged
Merged
Conversation
The frame recipe adds patterned surfaces, hard shadows, sleeves, glare, motion blur, a hand over a corner, and empty patterned surfaces, each in four tilt buckets from a camera pose. The scorer gates each condition and tilt bucket, and reports each metric by border colour. Refs #496
Reilley64
marked this pull request as ready for review
October 21, 2026 05:17
Reilley64
added a commit
that referenced
this pull request
Oct 21, 2026
Part of #495 ## Summary The Detector workflow has a new `replay` job. It runs `bun run detector:replay` on a `macos-15` runner, with the PR's base branch as `--base`. The branch and the merge base run in the same job, so Vision and the hardware are the same on both sides. A missed bar fails the job, and the job summary shows the table under a "Detector replay" heading. ```text Detector workflow fixtures bun run detector:test (unchanged) module xcodebuild for the Simulator (unchanged) + replay + restore the card images (cache key: detector/cards.json) + restore the textures (cache key: detector/textures.json) + restore the frames (cache key: detector/frames.sha256) + bun run detector:replay --base origin/<base branch, or main when run by hand> + append "## Detector replay" and comparison.md to the job summary, even when a bar fails ``` The timing is less noisy now. Before, the replay ran all 60 frames on the merge base, then all 60 on the branch, and took the p95 of those 60 calls. ```diff detector:replay - card-detector frames <every frame> base first, then branch - Mac timing = p95 of 60 calls + card-detector step <every frame and clip frame> base and branch start together and read their frames once + round 1: every frame and clip frame; rounds 2 and 3: the frames + for each of them + detect on base and on branch, back to back + swap which side goes first on each frame and each round + outlines and clips from the first round + Mac timing = p95 over frames of each frame's median time over the rounds ``` - `step` is a new mode of the macOS detector command. It reads frame indices on its input and writes one JSON line for each. `frames` stays for use by hand. - `--rounds <n>` sets the number of rounds. The default is 3. - The merge base on `spec/493-detector-replay` has a command without `step`. So the fallback rule now reads: "when the merge base has no detector command with the `step` mode, build the branch's command with the merge base's detector files". Before, the rule was "no detector command". - `comparison.md` now starts with the commits, the base ref, and the number of rounds. - The workflow also runs on changes to `apps/mobile/test/scanner-evidence/detector/**` and to the automatic capture rule in `apps/mobile/src/scan/capture.ts`, which the clips use. - The job caches the card images, the textures, and the rendered frames. - The README describes how CI runs the replay and how a PR shows its table. A PR that changes the card detector copies the table from the job summary under a "Detector replay" heading, and links the run. ## Evidence **A missed bar fails the job.** I planted the regression from #502 on a throwaway branch: `outwardness <` in `CardEdgeRefiner.swift`, so the edge refiner picks the innermost lines. Then I ran the workflow by hand: [run 39546178053](https://github.com/Reilley64/mtgscan/actions/runs/39546178053). The replay job failed with exit code 1, and the job summary got the table and the list of failing outlines. I deleted the branch after the run. The fixtures job failed too, as it should. | Condition | Metric | Merge base | Branch | Bar | Result | | --- | --- | --: | --: | --- | --- | | plain | Detection rate | 21 of 30 | 21 of 30 | not lower by more than 1 | pass | | plain | Corner error median | 0.01 mm | 9.99 mm | not worse by more than 0.1 mm | fail | | plain | Corner error p90 | 0.07 mm | 11.55 mm | not worse by more than 0.5 mm | fail | | plain | Inside outlines | 1 | 18 | no new one | fail | | plain | Size error, width x height | 0.00 mm x -0.00 mm | 4.14 mm x 5.62 mm | reported | | | empty-plain | False outlines | 0 | 0 | zero | pass | | | Mac timing p95 | 67.1 ms | 66.8 ms | at most 1.2 times the merge base | pass | **Job time, with the 1,080 frames from #506 and the 20 clips from #497.** The workflow timeout is 30 minutes. | Run | Frames | Frames cache | Replay job | | --- | --- | --- | --: | | [PR, final head](https://github.com/Reilley64/mtgscan/actions/runs/39578379495) | 1,080 and 20 clips | hit | 10 min 6 s | | [PR](https://github.com/Reilley64/mtgscan/actions/runs/39573404410) | 1,080 and 20 clips | miss | 8 min 36 s | | [by hand](https://github.com/Reilley64/mtgscan/actions/runs/39573456606) | 1,080 and 20 clips | miss | 12 min 32 s | | [by hand](https://github.com/Reilley64/mtgscan/actions/runs/39576758186) | 1,080 and 20 clips | hit, 25 s to restore | 11 min 16 s | | [PR](https://github.com/Reilley64/mtgscan/actions/runs/39552916165) | 1,080 | miss | 9 min 16 s | | [by hand](https://github.com/Reilley64/mtgscan/actions/runs/39555007902) | 1,080 | miss | 11 min 56 s | | [by hand](https://github.com/Reilley64/mtgscan/actions/runs/39556431307) | 1,080 | hit, 42 s to restore | 10 min 16 s | | first PR run | 60 | miss | 1 min 42 s | - The runner rendered every frame, clip frame, and photo with the same bytes as `frames.sha256`. The replay checks the hashes on every run, also after a cache restore. A mismatch fails the job and names the first frame that differs. - The frames cache holds the frames, the clip frames, and the photos, 1.9 GB. The textures from #506 have their own cache, keyed by `detector/textures.json`. - The detector calls take most of the job: 3 rounds of the 1,080 frames and one round of the clip frames, on both sides. One call takes 45 to 100 ms on the runner. Without the cache, the render takes about 1.5 minutes. - Clip frames run once, in the first round. Only the frames count for Mac timing. **Timing noise.** Vision is about 20 times slower on the runner than on an M3. One detector call takes 60 to 100 ms there. These are CI runs with the same detector code on both sides. The first 7 used the first 60 frames: | Run | Rounds | Merge base | Branch | Ratio | | --- | --: | --: | --: | --: | | [PR, first push](https://github.com/Reilley64/mtgscan/actions/runs/39546152968) | 5 | 57.8 ms | 59.7 ms | 1.03 | | [planted run](https://github.com/Reilley64/mtgscan/actions/runs/39546178053) | 5 | 67.1 ms | 66.8 ms | 1.00 | | [PR, second push](https://github.com/Reilley64/mtgscan/actions/runs/39548592954) | 3 | 98.6 ms | 96.4 ms | 0.98 | | [by hand](https://github.com/Reilley64/mtgscan/actions/runs/39548853311) | 3 | 71.5 ms | 70.7 ms | 0.99 | | [by hand](https://github.com/Reilley64/mtgscan/actions/runs/39549088491) | 3 | 67.9 ms | 64.6 ms | 0.95 | | [by hand](https://github.com/Reilley64/mtgscan/actions/runs/39549379328) | 3 | 92.7 ms | 86.2 ms | 0.93 | | [by hand](https://github.com/Reilley64/mtgscan/actions/runs/39549715695) | 3 | 71.9 ms | 72.0 ms | 1.00 | | [PR, 1,080 frames](https://github.com/Reilley64/mtgscan/actions/runs/39552916165) | 3 | 64.1 ms | 64.0 ms | 1.00 | | [by hand, 1,080 frames](https://github.com/Reilley64/mtgscan/actions/runs/39555007902) | 3 | 82.8 ms | 84.9 ms | 1.03 | | [by hand, 1,080 frames](https://github.com/Reilley64/mtgscan/actions/runs/39556431307) | 3 | 76.3 ms | 76.2 ms | 1.00 | | [PR, with clips](https://github.com/Reilley64/mtgscan/actions/runs/39573404410) | 3 | 46.3 ms | 46.0 ms | 0.99 | | [PR, final head](https://github.com/Reilley64/mtgscan/actions/runs/39578379495) | 3 | 71.1 ms | 71.7 ms | 1.01 | | [by hand, with clips](https://github.com/Reilley64/mtgscan/actions/runs/39573456606) | 3 | 83.6 ms | 85.8 ms | 1.03 | | [by hand, with clips](https://github.com/Reilley64/mtgscan/actions/runs/39576758186) | 3 | 86.0 ms | 88.8 ms | 1.03 | On my M3, busy with other work, 10 runs of each method with the same detector code gave these ratios: | Method | Lowest | Highest | Over 1.2 | | --- | --: | --: | --: | | Before: base pass, then branch pass, p95 of 60 calls | 0.71 | 1.70 | 1 of 10 | | Interleaved, 1 round | 0.59 | 1.05 | 0 | | Interleaved, 3 rounds | 0.96 | 1.04 | 0 | | Interleaved, 5 rounds | 0.96 | 1.04 | 0 | **Scorer tests** (`test/detector-replay.test.ts`, 19 tests with those from #506 and #497). Two are new: ```text one slow round does not fail the Mac timing bar when the other rounds hold steady base [4, 4, 4] ms, branch [4, 40, 4] ms -> 4.0 ms against 4.0 ms, pass a branch slower than 1.2 times the merge base on most rounds fails the Mac timing bar base [4, 4, 4] ms, branch [4, 5, 5] ms -> 5.0 ms against 4.0 ms, fail ``` - Mutation: timing from the first round only turns the second test red. - Mutation: timing from the slowest round turns the first test red. - `bun run detector:test` (14 tests), `typecheck`, and `lint` pass locally. Local replay of this branch against `origin/spec/493-detector-replay`, with the clips (Apple M3, macOS 27.0.1, Xcode 26.3): every bar passes, Mac timing p95 6.5 ms against 6.5 ms, and the clip table matches #497's numbers. The run took 2 min 7 s with the frames already rendered. ## Merge Danger **Door:** two-way The job, the `step` mode, and the rounds are tooling. `ios/Detector` and the app do not change. **Blast Radius:** CI Every detector PR now runs the replay, and a missed bar blocks it. The runner's macOS gives other numbers than macOS 27 on the M3, such as 21 of 30 plain frames detected at no tilt against 22. Both sides run in the same job, so the comparison holds. The job now takes 8.5 to 12.5 minutes. Each new PR saves 1.9 GB of frames to the Actions cache, because PRs share no cache. Both commands hold every frame buffer in memory, about 1.5 GB each with 1,080 frames, plus 14 MB for each photo.
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.
Part of #496
Summary
The detector replay now covers the known weak spots of the card detector. Each frame comes from a camera pose with a tilt angle and a focal length, so the replay can split frames by tilt.
detector/frames.py conditions plain, empty-plain + patterned, shadow, sleeve, glare, motion-blur, hand, empty-patterned + tilt buckets: 0, 0-7.5, 7.5-15, 15-25 degrees, 30 frames each per condition + labels.json: + tiltBucket (tiltDegrees and intrinsicMatrix were already there) +detector/textures.json # 12 Poly Haven textures, CC0, with page and download detector/score.ts - bars per condition + bars per condition and tilt bucket + reported: per condition and border colour, per border colour and tilt bucket replayTable - one row per bar + one row per condition and tilt bucket, merge base → branch in each cellplain-000toplain-029andempty-plain-000toempty-plain-029) keep the same bytes. Onlylabels.jsonchanges in their part offrames.sha256.Evidence
Before (#494): 2 conditions, 60 frames, every frame flat.
After:
bun run detector:replayon this branch againstorigin/main(a6fcfaf), on an Apple M3 with macOS 27.0.1 and Xcode 26.3. Every bar passes. The table onmainshows the known weak spots:mainThe full table
Card frames by condition and tilt in degrees, merge base → branch:
Empty frames:
Card frames by condition and border colour, reported:
Card frames by border colour and tilt, reported:
The whole run:
Bars for each condition and tilt:
Every bar passes.
base.jsonandbranch.jsonexcept timing.aspectRatioTolerance0.02 to 0.012 inCardQuadGeometry.swift), ran the replay once, then reverted it. The replay exited 1. 20 of the 28 condition and tilt rows failed, and 8 passed:plainat 0 and 0-7.5,patterned,sleeve,motion-blur, andhandat 0, andglareat 0 and 0-7.5. The list named 29 new inside outlines.test/detector-replay.test.ts, 9 tests, 4 new): bars per condition and tilt bucket, inside outlines per border colour and tilt bucket, one table row per condition and tilt bucket, and rows per condition and border colour.typecheck,lint, and the changed test file pass locally.Merge Danger
Door: two-way
The recipe, the scorer, and the table change.
ios/Detectorand the app do not change.Blast Radius: tooling
The replay renders 18 times as many frames, so it takes longer and needs 1.6 GB for the frames. It downloads 12 textures, about 11 MB, from Poly Haven once. Once #505 lands, its frame cache holds the frames. Its cache does not hold the textures yet.