oficina / docs Public

Snapshot gate: other-ways flake on the Mac (Fable #161 finding 4) open

On branch fix/snapshot-other-ways-flake

other-ways flakes on the Mac snapshot gate: cause found and fixed. This is finding 4 of Fable's review on #161, and it is pre-existing on main. One commit, ac2a9c0, test-only; no picture changes. Not merged.

What flaked

other-ways (DocsSnapshots.swift:30) failed about one gate run in twenty under a light load, with 3761 and 5512 pixel diffs, always in both appearances of the same run.

I ran the gate in a loop under load with a live log of the text fields' frames. In the failing runs, a rounded text field in the kit's NativeSignInView (sometimes the account field, once the server field) was 30 pt tall instead of 24. It had that height from the first frame (about 50 ms) to the last (about 300 ms). So the kit isn't settling too early: the screen is built that way and stays that way.

Details:

  • The control size, font and first responder were identical in good and bad runs (controlSize large, 13 pt; no field focused).
  • I couldn't reproduce it with the screen alone in fresh windows: 30 processes, 0 cases.
  • It needs the gate's sequence under load. The rate was 0 of 40 runs idle, 2 of 40 runs with 3 busy processes, and worse alongside a CPU-bound session (Fable's run and mine both hit it then).

So the cause is in AppKit and SwiftUI's first build of the field. I can't fix that from Docs, so the fix is in the test.

The fix

RemountedOnScreen builds the screen's content once more inside its already-showing window, from a .task (never from init or body), and only that second build is drawn. Only other-ways uses it.

Proof

  • Under the same light load: 0 of 90 gate runs failed (a first batch of 50 and a final batch of 40, 180 renders), against 2 of 40 before.
  • 10 consecutive native/scripts/snapshots.sh compare mac runs: all green.
  • snapshots.sh compare iphone: green (32 images).

Not fixed here (noted for whoever picks it up)

Under heavy artificial load (40 busy processes on 10 cores), the library and library-empty screens fail every run. The cause is different: DocsWorkspace loads its list asynchronously, and under that load the kit's "two equal frames 50 ms apart" rule settles before the list arrives. That's the same class of problem the editor screens on #161 avoid by holding themselves unsettled until ready. It didn't fail in any run at normal or light load.

Hub CI at ac2a9c0: amadan ci status oficina/docs -branch fix/snapshot-other-ways-flake exit 0 (CI passed). Ready for review. Not merged.

Rebased onto main 198c1da (the iOS render-loop fix, #162) and force-pushed; head is now 364f4f4. No conflicts; the change is the same one commit.

  • 10 consecutive native/scripts/snapshots.sh compare mac runs at 364f4f4: all exit 0, docs snapshots (compare, 22 images) each time.
  • Hub CI at 364f4f4: amadan ci status oficina/docs -branch fix/snapshot-other-ways-flake exit 0 (CI passed).

Not merged.

Review of 364f4f4 by Claude Fable (model claude-fable-5-2): APPROVE. Read-only review with git show; I did not build or run the gate, so the 0-of-90 figure is the author's, not re-measured.

The change is test-only, one screen, pictures unchanged, and safe to merge. Three follow-ups, none blocking.

1. Does the remount hide a real production defect? Possibly a cosmetic one; record it against the kit.

  • The shipping app has the same first-build path. DocsAccountWindow.swift:71 shows DocsOtherWaysView directly when the stored route is server and no account is kept, so a person on that route gets it as the first build of a new window at launch, which is also a loaded moment.
  • The worst case is small. One field 6 pt taller inside a ScrollView, nothing clipped or unusable. Nobody has shown it happening in the app: the author got 0 of 30 with the screen alone in fresh windows, and it needed the gate's earlier screens in the same process plus load.
  • The gate no longer watches this screen's first build. That is an acceptable trade for one screen, but the finding should not live only in a test comment.
  • Follow-up in rastrillo/native, not here. The kit's own gate draws NativeSignInView three times (sign-in, sign-in-waiting, sign-in-error in RastrilloAppleSnapshots.swift:25-32), and Sheets and the other apps picture the same view. Open a kit discussion with this evidence. If those screens flake the same way, the fix belongs in the kit (the view or the renderer), and this wrapper can then go.
  • One thing to check there: 24 against 30 looks like two different control-size metrics for a large field rather than a layout rounding, so it is worth confirming which height the shipping Mac app actually shows. If it is 30, the baselines are the odd ones out. I have not checked this.

2. Is the wrapper safe? Yes, with one overstated claim.

  • No state mutation in init or body. built flips once, from .task, after a yield. The .task sits outside .id(built), so it does not restart on the remount; the guard is belt and braces.
  • It terminates. One flip and no loop, so it cannot keep the screen unsettled.
  • "Draws only that second build" is not enforced. Nothing holds the screen unsettled until the remount. It relies on the task running before the kit's second capture at about 100 ms. I think that ordering holds, because the task is queued on the main actor at first appearance, ahead of the settle loop's next wake-up, and the runs back it. If the remount ever came late, the gate would draw the first build, which is exactly what it did before, so the failure mode is the old flake and never a wrong baseline. Suggest softening the comment, or once #161 lands, reusing its OpeningCounter to hold the screen unsettled until built is true.
  • Nit: content() now runs twice per variant, so Fixtures.connection() makes two connections and two throwaway defaults suites. Harmless. The wrapper also applies on iPhone, where it is not needed; also harmless, and iPhone compared green.

3. Fix the library flake now? No, do it as a follow-up after #161.

  • It only fails at 40 busy processes on 10 cores, and it fails loudly as a changed picture.
  • The right fix is the editor's pattern from #161 (a counter that changes every frame until ready). DocsWorkspace owns its model, so the fixture needs a way to see that the list has loaded. That is a small design choice better made once OpeningCounter is on main and can be shared, or as a readiness hook in the kit's SnapshotScreen.
  • One caution until then: do not record baselines on a heavily loaded machine. A record run there could save the library before its list arrives.

Landed on main (squash) after Fable's APPROVE. Library flake tracked as a task; possible kit issue opened on rastrillo/native.