Skip to content

Commit 88fea6f

Browse files
committed
fix(settle): hold the dismissal floor once a capture proves the dismissal
The confirmation re-decided itself from every capture, so a capture that stopped qualifying handed the loop its short window back mid-confirmation. The comparison refuses a node-less side outright, which makes an empty mid-animation projection enough to drop the 1.5s floor: the loop then matched the NEXT empty read and settled 302ms after a dismissal that owed 1500ms (mutation-pinned). Whether the action dismissed a presented surface is a fact about the transition, so it is now latched once proved and never re-decided; the window still maxes against the current per-capture price so a mid-run fallback from the bridge to the runner can only widen the wait, never shorten it.
1 parent e1352ab commit 88fea6f

2 files changed

Lines changed: 54 additions & 9 deletions

File tree

‎src/commands/interaction/runtime/stable-capture.test.ts‎

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,33 @@ test('settle confirms the dismissal of a presented surface too large for the tin
208208
assert.ok(outcome.waitedMs >= 1_500, `settled prompt dismissal after ${outcome.waitedMs}ms`);
209209
});
210210

211+
test('a dismissal confirmation is not dropped by a later empty projection', async () => {
212+
// The confirmation is a fact about the transition, so it survives a capture that stops qualifying.
213+
// The comparison refuses a node-less side, so re-deciding it per capture hands the loop its 150ms
214+
// window again mid-confirmation — and the next empty read matches it, settling on two empty
215+
// projections 302ms after a dismissal that owed 1.5s (#3470).
216+
const { runtime } = transitionRuntime({
217+
settledAtMs: 0,
218+
emptyProjectionAtCaptures: [2, 3],
219+
});
220+
221+
const outcome = await runStableCaptureLoop(
222+
runtime,
223+
{ session: 'default' },
224+
{ quietMs: 150, timeoutMs: 5_000, transitionBaselineNodes: elementThreadsNoticeSnapshot.nodes },
225+
);
226+
227+
assert.equal(outcome.settled, true);
228+
assert.ok(
229+
outcome.waitedMs >= 1_500,
230+
`empty projection disarmed the confirmation: settled after ${outcome.waitedMs}ms`,
231+
);
232+
assert.ok(
233+
outcome.lastCapture!.snapshot.nodes.length > 0,
234+
'settled on an empty projection instead of the dismissed screen',
235+
);
236+
});
237+
211238
test('settle keeps the quiet window across a tab switch', async () => {
212239
// The live shape: both tabs project a complete viewport and share only the tab bar's buttons, so
213240
// fewer than half the node identities survive the switch. That is ordinary navigation, not the
@@ -378,6 +405,8 @@ function transitionRuntime(
378405
presented?: SnapshotState;
379406
/** What the screen under it looks like once the dismissal completes. */
380407
dismissesTo?: SnapshotState;
408+
/** 1-based capture indices that answer with an empty projection (mid-animation read). */
409+
emptyProjectionAtCaptures?: number[];
381410
} = {},
382411
) {
383412
const captureBackend = options.captureBackend ?? 'tree';
@@ -398,6 +427,11 @@ function transitionRuntime(
398427
captureSnapshot: async () => {
399428
const keepsBaseline = options.firstCaptureKeepsBaseline === true && captures === 0;
400429
captures += 1;
430+
if (options.emptyProjectionAtCaptures?.includes(captures)) {
431+
return {
432+
snapshot: withCaptureBackend({ ...dismissesTo, nodes: [] }, captureBackend),
433+
};
434+
}
401435
const snapshot = keepsBaseline
402436
? presented
403437
: withCaptureBackend(

‎src/commands/interaction/runtime/stable-capture.ts‎

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -343,8 +343,8 @@ function createStableCapturePacing(start: number) {
343343
/**
344344
* The presented-surface dismissal confirmation, as one decision the settle loop asks about each
345345
* capture. It answers two questions once for the run — could this action have dismissed a presented
346-
* surface, and how long does a confirmed dismissal hold the quiet window — and then compares each
347-
* capture against the pre-action surface.
346+
* surface, and how long does a confirmed dismissal hold the quiet window — compares each capture until
347+
* one proves the dismissal, and holds that window for the rest of the run.
348348
*
349349
* Arming never consults the requested quiet window: the old `requestedQuietMs <
350350
* DEFAULT_STABLE_QUIET_MS` bar is what made `--settle-quiet 499` behave differently from 500 and left
@@ -365,10 +365,14 @@ function presentedSurfaceConfirmation(params: {
365365
// undefined until the first capture answers it; null once the transition is ruled out, so a run
366366
// whose pre-action tree is an ordinary screen keeps its chrome-free comparison off the cadence.
367367
let dismissedSurface: StableCaptureSignal | null | undefined;
368+
// The comparison refuses a node-less side outright, so a mid-animation empty read must not be able
369+
// to cancel the floor: without the latch it hands the loop its 150ms window back, and the next empty
370+
// read matches it, settling 302ms after a dismissal that owed 1.5s.
371+
let confirmedDismissalQuietMs: number | undefined;
368372
return {
369-
// Do not memoize the verdict on `stableCaptureSignalsEqual`: signal identity omits `role`,
370-
// parent links, and >1px-free geometry, all of which the chrome classifier reads, and one pass
371-
// costs tens of microseconds against the 300 ms poll cadence.
373+
// While unconfirmed, do not memoize the verdict on `stableCaptureSignalsEqual`: signal identity
374+
// omits `role`, parent links, and >1px-free geometry, all of which the chrome classifier reads,
375+
// and one pass costs tens of microseconds against the 300 ms poll cadence.
372376
requiredQuietMs(snapshot, currentQuietMs) {
373377
// Not `??=`: that operator re-runs the right side whenever it resolves to `null`, which is
374378
// exactly the ruled-out answer a full-screen baseline gives, on every single poll.
@@ -381,10 +385,17 @@ function presentedSurfaceConfirmation(params: {
381385
});
382386
}
383387
if (dismissedSurface === null) return currentQuietMs;
384-
const candidate = stableCaptureSurfaceSignal(snapshot, snapshot.nodes, params.appBundleId);
385-
return stableCaptureSignalsHaveBroadReplacement(dismissedSurface, candidate)
386-
? Math.max(currentQuietMs, confirmationQuietMs)
387-
: currentQuietMs;
388+
if (confirmedDismissalQuietMs === undefined) {
389+
const candidate = stableCaptureSurfaceSignal(snapshot, snapshot.nodes, params.appBundleId);
390+
if (stableCaptureSignalsHaveBroadReplacement(dismissedSurface, candidate)) {
391+
confirmedDismissalQuietMs = confirmationQuietMs;
392+
}
393+
}
394+
// Still maxed against the current window: the loop can price a wider one after the latch, on a
395+
// mid-run fallback from the bridge to the runner.
396+
return confirmedDismissalQuietMs === undefined
397+
? currentQuietMs
398+
: Math.max(currentQuietMs, confirmedDismissalQuietMs);
388399
},
389400
};
390401
}

0 commit comments

Comments
 (0)