fix(settle): arm the iOS broad-transition confirmation at any requested quiet window

Merged
TH
2mo ago
+365-117

Part of #3470. The narrowing — arming on which transitions, rather than at which window — is not in this PR: it is the draft that sits on top of this stack and is blocked by #3565. See "Not in this PR" at the bottom.

Stacks on #3482 (fix/3469-ios-keyboard-chrome-interactive) — it builds on the chrome-free comparison that PR adds. Retarget to main once #3482 lands.

What changed

The confirmation #1831 added for a broad screen replacement armed on two things, and only one of them describes the transition the rule exists for. The second was requestedQuietMs >= DEFAULT_STABLE_QUIET_MS, which made the guard a function of the window the caller asked for:

  • --settle-quiet 499 behaved differently from 500, with no rule that explains the boundary;
  • a caller passing settleQuietMs: 150 (tester-army/e2e) got no guard at all, on exactly the dismissal the guard exists for;
  • a shorter window silently meant "trust a coherent transitional tree sooner", which is not what --settle-quiet asks for. It asks for a tighter verdict, not for a different set of transitions to distrust.

Arming now reads the transition only, and a confirmed replacement is held for the caller's own window, floored at 1.5 s. The trigger itself is unchanged from main: a complete-viewport post-action projection or a tiny presented baseline, plus fewer than half the node identities carried over. No narrowing, no new heuristic — this PR only removes the window coupling, so it can land and be reasoned about on its own.

One consequence stated up front, because it is the point of the split: at the default window a tab switch or a push already pays the 1.5 s floor on main, and still does here. What this layer adds is that a caller asking for a shorter window now pays it too (measured below). That is the correct reading of --settle-quiet, and it is also what makes removing the cost in the right places urgent — which is the successor layer's job, not this one's.

Verification

#1831's six loop-level cases now run at both 500 ms and 150 ms, and a caller-route case pins the same floor on the observation a caller reads (settle-confirmation-floor.test.ts): the response reports the window the caller asked for, while the confirmed replacement sets the wait. Restoring the requestedQuietMs >= DEFAULT_STABLE_QUIET_MS bar fails exactly the short-window cases and nothing else, so the guard cannot silently switch itself off at a shorter window again.

Cadence follows the window in force (second commit). Without it the extended wait was sampled on the caller's tight grid: at --settle-quiet 25 that is 109 capture round trips to reach a verdict the default grid reaches in 10 — a confirmation costing 11x the reads it needs, on the tightest windows where settle is asked for at all. Mutation-checked: removing the recompute fails the new capture-count assertion (109 vs 10) and nothing else in the file.

Live A/B (iPhone 18 Pro simulator, BDA9B772, RN test app, purpose-specific session)

Sheet = Settings → Open automation lab → Open automation sheet (pageSheet). late is diff snapshot -i after settle returned; late=0 means settle answered on the tree the UI kept.

routebaseline it carrieswaitedMs @ --settle-quiet 150confirms?
press 'label="Close automation sheet"' --settleinteractive, 4 nodes1855 / 1890 / 1862yes, late=0
snapshot then press @ref --settlefull tree, 6 nodes1854 / 1991 / 1856yes, late=0
press <tab> --settle (control, no dismissal)full tree1987 / 1848 / 1951armed, as at the default window on main

The generic-route case (back --system --settle, whose baseline is the session's stored full tree) is the third dismissal route and the one the reviewer's table marks as losing coverage under the narrowing. It could not be exercised as a dismissal on this device — back --system does not dismiss this pageSheet on the iPhone 18 Pro, verified across three independent runs (the sheet is still up afterwards). It was exercised over a transition back can perform there, with a stored full-tree baseline and a genuinely broad arrival (the settle diff reports 24 additions / 25 removals / 3 unchanged): 1840 ms over 5 captures and 1879 ms over 5, i.e. armed, against 506–583 ms over 2 captures on the narrowing head for the same arrival. Those four numbers were taken on the stack's second-layer build, which carries this layer's arming rule verbatim.

And the control row is not free — it is the cost the successor layer removes, measured so the reviewer can see exactly what this layer costs a short-window caller on ordinary navigation.

The provider-backed scenario is itself a dialog dismissal, so it now holds the floor at its 25 ms window too: 1510 ms over 6 captures, against 1511 ms over 6 for the same scenario at the default window on the base — same verdict, same price, no longer window-dependent. Its capture-count budget becomes a floor plus an explicit waitedMs >= 1_500, and the test gains the parallel-scenario timeout its 1.5 s wait needs (that scenario already timed out at base under this machine's load, and the body it sits in reindents as a result — ~210 of this PR's lines are that formatter-forced reindent).

Gates

pnpm format, pnpm lint, tsc --noEmit clean. vitest --project unit-core: 13,373 passed / 1 skipped (a first full run tripped one deadline-sensitive snapshot-source/lifecycle.test.ts case under host load; it passes in isolation and on the clean re-run above, and this layer touches no capture-source code). interaction-contract (68) and provider-integration green; two interaction-contract failures seen mid-branch were confirmed present at the base commit and pass at this head. pnpm check:affected --run --base origin/fix/3469-ios-keyboard-chrome-interactive at bee9e1f34: all runnable checks passed (exit 0) — 506 related test files / 3,962 tests, Fallow clean on the 7 changed files — held under the machine-wide lock. Counts in the gate comment on this PR.

Not in this PR

The narrowing — arming on "the baseline shows a surface presented over app content" instead of on any broad screen replacement — is split out. Its node-count rule keys on how the baseline was captured (the same sheet projects 4 nodes interactively and 6 in a full tree), so it loses dismissal confirmation on 2 of 3 routes; that is measured in https://github.com/callstack/agent-device/pull/3512#issuecomment-6130035139 and the durable rule is a producer-stamped presentedSurface fact, which is #3565. The narrowing now sits on top of this stack as draft #3570, blocked by #3565, so this decoupling can land without waiting for it — and so no head of this branch ever ships a showsPresentedSurface arm.