perf(ios-runner): don't restart the settle window when re-binding an already-foreground target

Merged
TH
1mo ago
+246-44

Summary

After open --relaunch, the first tap waited an extra 250 ms. The daemon's targetReset starts the post-activation settle window, then the tap re-binds the target through activateTarget(reason: bundle_changed), which restarted the window even when activation was skipped (ACTIVATE_SKIPPED reason=already_foreground).

The runner now records where the window came from instead of inferring it:

  • FirstInteractionWindow { readyUptime, origin }, with origin .activation or .announcedRelaunch(bundleId:).
  • targetReset stamps .announcedRelaunch with the binding it dropped (nil if none, which matches any bundle; the wire carries no bundle). Every other stamp is .activation.
  • activateTarget keeps the existing window only when no activation ran and the origin is an announced relaunch of this bundle; otherwise it stamps a fresh window.
  • Removed: reacquiresBoundTarget, the window-mode enum, and the nil writes in invalidateCachedTarget and ensureRunnerHostAppActive. A stale .activation window is harmless because it restamps.

The invariant stays "at least 250 ms between activating a target and its first interaction" (#2395).

Validation

  • Tested commit 3aabddd92c.

  • 15 LifecycleCache runner unit tests: Executed 15, 0 failures. Mutations caught: keep the window regardless of origin (3 failures); ignore whether an activation ran (2 failures).

  • pnpm check:affected --run, pnpm lint, and check:xctest-selection pass.

  • Live runner.log (see PR comment): ACTIVATE_SKIPPED is followed by the text-input probe with no 250 ms gap.

  • A/B measured at fb1e51accd; the redesign keeps the same relaunch-to-skipped-activation behavior. 5 paired rounds on one iPhone 17 Pro / iOS 26.2 sim, open com.apple.Preferences --relaunch then click 'label="General"':

    metric (median Δ vs main)agent-pacedback-to-back
    runner accept→dispatch−224 ms−219 ms
    click−256 ms−195 ms

    Every paired round improved (−156 to −252 ms).