Skip to content

feat: cover hard conditions and camera tilt in the detector replay - #506

Merged
Reilley64 merged 1 commit into
spec/493-detector-replayfrom
ticket/496
Oct 21, 2026
Merged

Reilley64 merged 1 commit into
spec/493-detector-replayfrom
ticket/496

Conversation

@Reilley64

@Reilley64 Reilley64 commented Oct 21, 2026 •

Copy link
Copy Markdown
Owner

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 cell
  • The frame set has 9 conditions x 4 tilt buckets x 30 frames, 1,080 frames in all. Each condition, border colour, and tilt bucket has 10 frames.
  • The 60 frames from #494 (plain-000 to plain-029 and empty-plain-000 to empty-plain-029) keep the same bytes. Only labels.json changes in their part of frames.sha256.
  • Patterned surfaces are half procedural: high-contrast stripes, checks, a grid, dots, text, or a clutter of rectangles. The other half are CC0 photo textures from Poly Haven, scaled and turned at random. The pattern lies on the table plane, so it takes the camera pose too.
  • The bars are the same as in #494. They now apply to each condition and tilt bucket, so the new metrics take part in the gate that ci: run the detector replay in the Detector workflow #505 runs in CI.
  • The list of failing outlines now gives each frame's tilt bucket and border colour.

Evidence

Before (#494): 2 conditions, 60 frames, every frame flat.

After: bun run detector:replay on this branch against origin/main (a6fcfaf), on an Apple M3 with macOS 27.0.1 and Xcode 26.3. Every bar passes. The table on main shows the known weak spots:

Weak spot On main
Inside outlines rise with tilt on black-bordered cards 3, 12, 17, and 39 of 70 frames in the 0, 0-7.5, 7.5-15, and 15-25 degree buckets
Outlines on the sleeve edge Size error -1.08 x -1.14 mm at no tilt, about the sleeve margin
Low detection rate on patterned surfaces 61 of 120 frames, against 82 of 120 on plain surfaces. For black and white borders, 56 of 80 against 73 of 80.
No false outlines on empty surfaces 0 of 240 empty plain and patterned frames
The full table

Card frames by condition and tilt in degrees, merge base → branch:

Condition Tilt Detection rate Corner error median Corner error p90 Inside outlines Size error, width x height Result
plain 0 22 of 30 → 22 of 30 0.01 mm → 0.01 mm 0.07 mm → 0.07 mm 1 → 1 0.00 x 0.00 mm → 0.00 x 0.00 mm pass
plain 0-7.5 18 of 30 → 18 of 30 0.01 mm → 0.01 mm 0.02 mm → 0.02 mm 0 → 0 0.00 x 0.00 mm → 0.00 x 0.00 mm pass
plain 7.5-15 21 of 30 → 21 of 30 0.01 mm → 0.01 mm 5.34 mm → 5.34 mm 8 → 8 0.00 x 0.00 mm → 0.00 x 0.00 mm pass
plain 15-25 21 of 30 → 21 of 30 3.04 mm → 3.04 mm 5.60 mm → 5.60 mm 12 → 12 0.00 x 0.01 mm → 0.00 x 0.01 mm pass
patterned 0 12 of 30 → 12 of 30 0.02 mm → 0.02 mm 4.65 mm → 4.65 mm 2 → 2 0.00 x 0.00 mm → 0.00 x 0.00 mm pass
patterned 0-7.5 17 of 30 → 17 of 30 0.05 mm → 0.05 mm 4.89 mm → 4.89 mm 4 → 4 0.00 x 0.00 mm → 0.00 x 0.00 mm pass
patterned 7.5-15 16 of 30 → 16 of 30 0.04 mm → 0.04 mm 8.70 mm → 8.70 mm 6 → 6 0.00 x 0.00 mm → 0.00 x 0.00 mm pass
patterned 15-25 16 of 30 → 16 of 30 4.19 mm → 4.19 mm 8.75 mm → 8.75 mm 12 → 12 1.81 x 1.48 mm → 1.81 x 1.48 mm pass
shadow 0 25 of 30 → 25 of 30 2.60 mm → 2.60 mm 4.84 mm → 4.84 mm 6 → 6 0.00 x 0.00 mm → 0.00 x 0.00 mm pass
shadow 0-7.5 24 of 30 → 24 of 30 0.19 mm → 0.19 mm 5.13 mm → 5.13 mm 3 → 3 -0.01 x -0.09 mm → -0.01 x -0.09 mm pass
shadow 7.5-15 26 of 30 → 26 of 30 1.84 mm → 1.84 mm 5.74 mm → 5.74 mm 6 → 6 0.00 x 0.00 mm → 0.00 x 0.00 mm pass
shadow 15-25 20 of 30 → 20 of 30 4.27 mm → 4.27 mm 5.92 mm → 5.92 mm 12 → 12 0.00 x 0.00 mm → 0.00 x 0.00 mm pass
sleeve 0 29 of 30 → 29 of 30 1.67 mm → 1.67 mm 2.29 mm → 2.29 mm 0 → 0 -1.08 x -1.14 mm → -1.08 x -1.14 mm pass
sleeve 0-7.5 26 of 30 → 26 of 30 1.50 mm → 1.50 mm 2.27 mm → 2.27 mm 2 → 2 -1.00 x -0.97 mm → -1.00 x -0.97 mm pass
sleeve 7.5-15 27 of 30 → 27 of 30 1.95 mm → 1.95 mm 3.30 mm → 3.30 mm 4 → 4 -0.73 x -0.84 mm → -0.73 x -0.84 mm pass
sleeve 15-25 25 of 30 → 25 of 30 3.32 mm → 3.32 mm 5.36 mm → 5.36 mm 16 → 16 0.00 x 0.00 mm → 0.00 x 0.00 mm pass
glare 0 22 of 30 → 22 of 30 0.02 mm → 0.02 mm 0.10 mm → 0.10 mm 1 → 1 0.00 x 0.00 mm → 0.00 x 0.00 mm pass
glare 0-7.5 22 of 30 → 22 of 30 0.02 mm → 0.02 mm 6.26 mm → 6.26 mm 4 → 4 0.00 x 0.00 mm → 0.00 x 0.00 mm pass
glare 7.5-15 24 of 30 → 24 of 30 0.04 mm → 0.04 mm 5.49 mm → 5.49 mm 8 → 8 0.00 x 0.00 mm → 0.00 x 0.00 mm pass
glare 15-25 20 of 30 → 20 of 30 3.47 mm → 3.47 mm 7.69 mm → 7.69 mm 13 → 13 0.00 x 0.00 mm → 0.00 x 0.00 mm pass
motion-blur 0 18 of 30 → 18 of 30 0.09 mm → 0.09 mm 3.98 mm → 3.98 mm 2 → 2 0.00 x 0.00 mm → 0.00 x 0.00 mm pass
motion-blur 0-7.5 19 of 30 → 19 of 30 0.45 mm → 0.45 mm 7.64 mm → 7.64 mm 6 → 6 0.00 x 0.01 mm → 0.00 x 0.01 mm pass
motion-blur 7.5-15 17 of 30 → 17 of 30 0.23 mm → 0.23 mm 7.84 mm → 7.84 mm 7 → 7 0.00 x 0.01 mm → 0.00 x 0.01 mm pass
motion-blur 15-25 17 of 30 → 17 of 30 6.58 mm → 6.58 mm 9.77 mm → 9.77 mm 14 → 14 2.01 x 3.92 mm → 2.01 x 3.92 mm pass
hand 0 22 of 30 → 22 of 30 0.01 mm → 0.01 mm 0.14 mm → 0.14 mm 0 → 0 0.00 x 0.00 mm → 0.00 x 0.00 mm pass
hand 0-7.5 24 of 30 → 24 of 30 0.01 mm → 0.01 mm 0.22 mm → 0.22 mm 2 → 2 0.00 x 0.00 mm → 0.00 x 0.00 mm pass
hand 7.5-15 25 of 30 → 25 of 30 0.14 mm → 0.14 mm 5.42 mm → 5.42 mm 10 → 10 0.00 x 0.00 mm → 0.00 x 0.00 mm pass
hand 15-25 23 of 30 → 23 of 30 4.27 mm → 4.27 mm 6.44 mm → 6.44 mm 15 → 15 0.00 x 1.81 mm → 0.00 x 1.81 mm pass

Empty frames:

Condition Tilt False outlines Result
empty-plain 0 0 → 0 pass
empty-plain 0-7.5 0 → 0 pass
empty-plain 7.5-15 0 → 0 pass
empty-plain 15-25 0 → 0 pass
empty-patterned 0 0 → 0 pass
empty-patterned 0-7.5 0 → 0 pass
empty-patterned 7.5-15 0 → 0 pass
empty-patterned 15-25 0 → 0 pass

Card frames by condition and border colour, reported:

Condition Border colour Detection rate Corner error median Corner error p90 Inside outlines Size error, width x height
plain black 37 of 40 → 37 of 40 0.01 mm → 0.01 mm 5.93 mm → 5.93 mm 10 → 10 0.00 x 0.00 mm → 0.00 x 0.00 mm
plain white 36 of 40 → 36 of 40 0.01 mm → 0.01 mm 4.48 mm → 4.48 mm 7 → 7 0.00 x 0.00 mm → 0.00 x 0.00 mm
plain borderless 9 of 40 → 9 of 40 0.43 mm → 0.43 mm 3.91 mm → 3.91 mm 4 → 4 0.01 x 0.02 mm → 0.01 x 0.02 mm
patterned black 27 of 40 → 27 of 40 0.05 mm → 0.05 mm 8.33 mm → 8.33 mm 8 → 8 0.00 x 0.00 mm → 0.00 x 0.00 mm
patterned white 29 of 40 → 29 of 40 0.04 mm → 0.04 mm 8.55 mm → 8.55 mm 13 → 13 0.00 x 0.00 mm → 0.00 x 0.00 mm
patterned borderless 5 of 40 → 5 of 40 3.01 mm → 3.01 mm 4.78 mm → 4.78 mm 3 → 3 0.03 x 1.48 mm → 0.03 x 1.48 mm
shadow black 39 of 40 → 39 of 40 3.37 mm → 3.37 mm 5.82 mm → 5.82 mm 11 → 11 -0.13 x -0.92 mm → -0.13 x -0.92 mm
shadow white 39 of 40 → 39 of 40 0.02 mm → 0.02 mm 5.74 mm → 5.74 mm 9 → 9 0.00 x 0.00 mm → 0.00 x 0.00 mm
shadow borderless 17 of 40 → 17 of 40 3.86 mm → 3.86 mm 5.08 mm → 5.08 mm 7 → 7 -0.37 x -1.09 mm → -0.37 x -1.09 mm
sleeve black 40 of 40 → 40 of 40 1.43 mm → 1.43 mm 3.48 mm → 3.48 mm 10 → 10 0.00 x 0.00 mm → 0.00 x 0.00 mm
sleeve white 39 of 40 → 39 of 40 2.23 mm → 2.23 mm 5.36 mm → 5.36 mm 8 → 8 -1.03 x -1.21 mm → -1.03 x -1.21 mm
sleeve borderless 28 of 40 → 28 of 40 1.84 mm → 1.84 mm 3.32 mm → 3.32 mm 4 → 4 -1.18 x -1.14 mm → -1.18 x -1.14 mm
glare black 39 of 40 → 39 of 40 0.01 mm → 0.01 mm 7.69 mm → 7.69 mm 10 → 10 0.00 x 0.00 mm → 0.00 x 0.00 mm
glare white 39 of 40 → 39 of 40 0.04 mm → 0.04 mm 4.33 mm → 4.33 mm 10 → 10 0.00 x 0.00 mm → 0.00 x 0.00 mm
glare borderless 10 of 40 → 10 of 40 2.56 mm → 2.56 mm 3.92 mm → 3.92 mm 6 → 6 0.02 x 1.26 mm → 0.02 x 1.26 mm
motion-blur black 32 of 40 → 32 of 40 1.07 mm → 1.07 mm 9.66 mm → 9.66 mm 15 → 15 0.01 x 0.01 mm → 0.01 x 0.01 mm
motion-blur white 35 of 40 → 35 of 40 0.45 mm → 0.45 mm 7.60 mm → 7.60 mm 13 → 13 0.00 x 0.00 mm → 0.00 x 0.00 mm
motion-blur borderless 4 of 40 → 4 of 40 0.59 mm → 0.59 mm 6.19 mm → 6.19 mm 1 → 1 0.00 x -0.01 mm → 0.00 x -0.01 mm
hand black 40 of 40 → 40 of 40 0.01 mm → 0.01 mm 4.57 mm → 4.57 mm 7 → 7 0.00 x 0.00 mm → 0.00 x 0.00 mm
hand white 40 of 40 → 40 of 40 0.01 mm → 0.01 mm 5.80 mm → 5.80 mm 14 → 14 0.00 x 0.00 mm → 0.00 x 0.00 mm
hand borderless 14 of 40 → 14 of 40 0.43 mm → 0.43 mm 6.44 mm → 6.44 mm 6 → 6 0.03 x 0.02 mm → 0.03 x 0.02 mm

Card frames by border colour and tilt, reported:

Border colour Tilt Detection rate Corner error median Corner error p90 Inside outlines Size error, width x height
black 0 65 of 70 → 65 of 70 0.03 mm → 0.03 mm 2.84 mm → 2.84 mm 3 → 3 0.00 x 0.00 mm → 0.00 x 0.00 mm
black 0-7.5 64 of 70 → 64 of 70 0.03 mm → 0.03 mm 6.26 mm → 6.26 mm 12 → 12 0.00 x 0.00 mm → 0.00 x 0.00 mm
black 7.5-15 64 of 70 → 64 of 70 0.04 mm → 0.04 mm 5.49 mm → 5.49 mm 17 → 17 0.00 x 0.00 mm → 0.00 x 0.00 mm
black 15-25 61 of 70 → 61 of 70 4.04 mm → 4.04 mm 8.59 mm → 8.59 mm 39 → 39 0.00 x 0.01 mm → 0.00 x 0.01 mm
white 0 65 of 70 → 65 of 70 0.02 mm → 0.02 mm 2.27 mm → 2.27 mm 5 → 5 0.00 x 0.00 mm → 0.00 x 0.00 mm
white 0-7.5 66 of 70 → 66 of 70 0.02 mm → 0.02 mm 3.84 mm → 3.84 mm 7 → 7 0.00 x 0.00 mm → 0.00 x 0.00 mm
white 7.5-15 66 of 70 → 66 of 70 0.09 mm → 0.09 mm 8.04 mm → 8.04 mm 23 → 23 0.00 x 0.00 mm → 0.00 x 0.00 mm
white 15-25 60 of 70 → 60 of 70 3.84 mm → 3.84 mm 7.60 mm → 7.60 mm 39 → 39 0.00 x 0.01 mm → 0.00 x 0.01 mm
borderless 0 20 of 70 → 20 of 70 1.72 mm → 1.72 mm 3.86 mm → 3.86 mm 4 → 4 -0.95 x -0.96 mm → -0.95 x -0.96 mm
borderless 0-7.5 20 of 70 → 20 of 70 1.46 mm → 1.46 mm 3.64 mm → 3.64 mm 2 → 2 -0.03 x -0.09 mm → -0.03 x -0.09 mm
borderless 7.5-15 26 of 70 → 26 of 70 2.22 mm → 2.22 mm 3.92 mm → 3.92 mm 9 → 9 0.00 x 0.00 mm → 0.00 x 0.00 mm
borderless 15-25 21 of 70 → 21 of 70 3.06 mm → 3.06 mm 6.19 mm → 6.19 mm 16 → 16 0.01 x 1.45 mm → 0.01 x 1.45 mm

The whole run:

Metric Merge base Branch Bar Result
Mac timing p95 4.5 ms 4.9 ms at most 1.2 times the merge base pass
Same detector code same same numbers same numbers pass

Bars for each condition and tilt:

  • Detection rate: not lower by more than 1
  • Corner error median: not worse by more than 0.1 mm
  • Corner error p90: not worse by more than 0.5 mm
  • Inside outlines: no new one
  • False outlines: zero

Every bar passes.

  • Run time. From nothing, with the card images downloaded: 2 minutes 33 seconds. Rendering the frames takes about 30 seconds of that on the M3 (8 cores), and the two builds and two detector runs about 70 seconds. With the frames already rendered, the replay takes 63 seconds. The frames take 1.6 GB on disk.
  • Same numbers. Two full runs gave the same base.json and branch.json except timing.
  • Planted regression. I tightened the aspect gate (aspectRatioTolerance 0.02 to 0.012 in CardQuadGeometry.swift), ran the replay once, then reverted it. The replay exited 1. 20 of the 28 condition and tilt rows failed, and 8 passed: plain at 0 and 0-7.5, patterned, sleeve, motion-blur, and hand at 0, and glare at 0 and 0-7.5. The list named 29 new inside outlines.
  • Mac timing. One run failed the Mac timing bar with the same detector code (5.8 ms against 13.7 ms). Another session was running the recognizer replay on the same Mac at a load average of about 14. The next run passed (4.5 ms against 4.9 ms). ci: run the detector replay in the Detector workflow #505 interleaves the two builds, which should remove most of this noise.
  • Scorer tests (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.
  • Mutation. Grouping the bars by condition alone turns 2 tests red.
  • typecheck, lint, and the changed test file pass locally.

Merge Danger

Door: two-way

The recipe, the scorer, and the table change. ios/Detector and 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.

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
Reilley64 marked this pull request as ready for review October 21, 2026 05:17
@Reilley64
Reilley64 merged commit 3992459 into spec/493-detector-replay Oct 21, 2026
9 checks passed
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.
@Reilley64
Reilley64 deleted the ticket/496 branch October 21, 2026 22:42
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