fix(snapshot): one-shot recovered warning for internally armed penalties
What
Follow-up hardening from the #1587 review — rebased onto main after #1587 merged..
The deferred-capture warning suppression assumes the capture that armed the XCTest-channel penalty already rendered the full "Detected an overly complex or slow accessibility tree…" warning. Internal captures — selector resolution, settle observation loops (updateSession: false), system-modal probes — can arm the penalty without any user-facing render, so the next public snapshot exposed only the structured verdict with no CLI warning line.
The runner cannot distinguish user-facing from internal captures, so the latch is daemon-side session state (SessionState.recoveredSnapshotWarningLatch), applied at the snapshot/diff response seam (dispatchSnapshotRuntimeCommand) — the only place quality warnings actually reach a client:
- a genuine
recoveredrender sets the latch silently (the same response already carries the full warning from the runtime); - the first public
deferredverdict without the latch re-renders the full warning once (prepended, so line order matches a genuine render) and sets the latch; - a
healthypublic verdict clears it — the penalty window is over, the next arming warns again; - an app switch supersedes it: the latch stores the
appBundleId, mirroring the runner's process-scoped penalty, so a latch held for app A never suppresses app B's first deferred verdict; sparse/verdict-less captures leave it untouched;- internal observation responses (
req.internal.observationOnly) neither consume nor clear it.
The daemon cannot observe penalty arming directly (a 120s TTL held runner-side), so the "penalty window" is approximated by public-capture verdicts: as long as no public capture reports healthy, an unbroken hostile stretch of the same app warns exactly once. The full warning line is extracted as recoveredSnapshotQualityWarning() so the runtime render and the daemon injection share one wording (pinned by a test).
No runner/Swift changes; the deferred wire contract is unchanged.
Tests
7 new tests in src/daemon/__tests__/snapshot-quality-latch.test.ts: pure transition coverage plus 3 integration tests through dispatchSnapshotViaRuntime (mocked dispatchCommand) covering the review's exact scenario — internal capture arms, first public deferred snapshot warns once, second stays quiet, healthy re-arms.
Red evidence (seam wiring reverted, latch module kept)
× an internally armed penalty warns once on the first public deferred snapshot
× a healthy public capture re-arms the one-shot warning
× a genuine recovered render keeps later deferred captures quiet without doubling
Typecheck, lint, and the neighboring suites (snapshot-quality, internal-observation, session-snapshot, response-views, settle) are green.