Skip to content

Commit 2482e24

Browse files
committed
fix(alerts): scope alert captures to the warm helper and split the unconfirmed press
The executed Android smoke failure at 5b1e1c1: the session's alert probes ran without the app-backed helper session scope, so each probe cold-started the snapshot helper inside the window that bounds it — the request log shows the post-press confirm capture aborted at 2.3s ("operation was aborted due to timeout") while the canary proves the dialog was in fact dismissed. Alert reads now carry the same helperSessionScope as every other app-backed read. The failure also proved the wording lied: with no confirm capture ever answering, "did not dismiss the visible alert"/"dialog is still visible" accused a dialog that was already gone. Only a re-read naming the same alert earns the still-visible failure; an unconfirmed press now says exactly that, on both the cut-off and the spent-budget exits, with a hint to run alert get before retrying. The same-alert stuck-alert failure keeps its message. Pinned: interactor scoping regression (fail-before against 5b1e1c1) and the three Limrun confirm-phase tests moved to the truthful split; the Android still-visible pin keeps its message via the same-alert path.
1 parent 5b1e1c1 commit 2482e24

5 files changed

Lines changed: 84 additions & 28 deletions

File tree

‎packages/platform-android/src/alert.ts‎

Lines changed: 45 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -493,10 +493,21 @@ async function confirmTreeAlertDismissed<
493493
action: 'accept' | 'dismiss',
494494
signal?: AbortSignal,
495495
): Promise<void> {
496+
// Only an observation that named this same alert on screen proves the "still visible" claim.
497+
// Captures that were cut off or stayed unresolvable prove nothing, and the failure wording
498+
// must not accuse a dialog that may already be gone of still standing.
499+
let sameAlertObserved = false;
500+
const probe: TreeAlertObserver<TCandidate> = async () => {
501+
const observation = await observe();
502+
if (observation.kind === 'alert' && sameTreeAlert(observation.candidate.alert, dismissed)) {
503+
sameAlertObserved = true;
504+
}
505+
return observation;
506+
};
496507
let settled: boolean;
497508
try {
498509
({ settled } = await pollUntilSettled({
499-
probe: observe,
510+
probe,
500511
settled: (observation) =>
501512
observation.kind === 'none' ||
502513
(observation.kind === 'alert' && !sameTreeAlert(observation.candidate.alert, dismissed)),
@@ -505,23 +516,44 @@ async function confirmTreeAlertDismissed<
505516
signal,
506517
}));
507518
} catch (error) {
508-
// A confirmation capture this phase cuts off says the same thing a budget spent without
509-
// confirmation says — and it says it after a press landed, so the stuck-alert phrasing is
510-
// the honest one here; the typed reason keeps the two causes distinguishable.
519+
// A confirmation capture this phase cuts off says what the press cannot say alone: whether
520+
// the dialog is still there, or whether the check itself never answered. Only the first is
521+
// the stuck-alert failure; the second must not claim a visible dialog it never observed.
511522
if (isAlertWindowExpired(error)) {
512-
throw new AppError('COMMAND_FAILED', `alert ${action} did not dismiss the visible alert`, {
513-
alert: dismissed,
514-
reason: ALERT_WINDOW_EXPIRED_REASON,
515-
hint: 'The alert button was pressed but the dialog is still visible. Inspect alert get --json, then press the visible button by label/ref or retry.',
516-
});
523+
if (sameAlertObserved) {
524+
throw new AppError('COMMAND_FAILED', `alert ${action} did not dismiss the visible alert`, {
525+
alert: dismissed,
526+
reason: ALERT_WINDOW_EXPIRED_REASON,
527+
hint: 'The alert button was pressed but the dialog is still visible. Inspect alert get --json, then press the visible button by label/ref or retry.',
528+
});
529+
}
530+
throw new AppError(
531+
'COMMAND_FAILED',
532+
`alert ${action} pressed the button but the dismissal could not be confirmed`,
533+
{
534+
alert: dismissed,
535+
reason: ALERT_WINDOW_EXPIRED_REASON,
536+
hint: 'The alert button was pressed; the post-press read never answered within the budget, so the dialog may already be gone. Run alert get --json before retrying.',
537+
},
538+
);
517539
}
518540
throw error;
519541
}
520542
if (settled) return;
521-
throw new AppError('COMMAND_FAILED', `alert ${action} did not dismiss the visible alert`, {
522-
alert: dismissed,
523-
hint: 'The alert button was pressed but the dialog is still visible. Inspect alert get --json, then press the visible button by label/ref or retry.',
524-
});
543+
if (sameAlertObserved) {
544+
throw new AppError('COMMAND_FAILED', `alert ${action} did not dismiss the visible alert`, {
545+
alert: dismissed,
546+
hint: 'The alert button was pressed but the dialog is still visible. Inspect alert get --json, then press the visible button by label/ref or retry.',
547+
});
548+
}
549+
throw new AppError(
550+
'COMMAND_FAILED',
551+
`alert ${action} pressed the button but the dismissal could not be confirmed`,
552+
{
553+
alert: dismissed,
554+
hint: 'The alert button was pressed; no post-press read resolved to an answer within the budget, so the dialog may already be gone. Run alert get --json before retrying.',
555+
},
556+
);
525557
}
526558

527559
/** Alert identity across a dismissal re-check: the same title and the same button row, in order. */

‎packages/provider-limrun/src/alert.test.ts‎

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -137,11 +137,11 @@ describe('wait budget', () => {
137137
await expect(handleLimrunIosAlert(client, 'wait')).rejects.toThrow('websocket closed');
138138
});
139139

140-
it('refuses a confirm capture that outruns its window and reports the stuck alert', async () => {
140+
it('refuses a confirm capture that outruns its window without claiming a visible dialog', async () => {
141141
// The Limrun WebSocket client cannot abort an in-flight `elementTree`, so a stalled capture
142-
// can outlive the confirm budget. The driver must not consume that late answer: the press
143-
// already landed, the capture proves nothing, and the honest terminal answer is the
144-
// stuck-alert failure on the typed window reason.
142+
// can outlive the confirm budget. The driver must not consume that late answer — and because
143+
// no post-press capture ever answered, the failure may not accuse the dialog of still being
144+
// visible; it reports the press as unconfirmed.
145145
const client = {
146146
elementTree: vi
147147
.fn()
@@ -164,7 +164,9 @@ describe('wait budget', () => {
164164
expect(client.tap).toHaveBeenCalledTimes(1);
165165
expect(thrown).toBeInstanceOf(AppError);
166166
const failure = thrown as AppError;
167-
expect(failure.message).toBe('alert accept did not dismiss the visible alert');
167+
expect(failure.message).toBe(
168+
'alert accept pressed the button but the dismissal could not be confirmed',
169+
);
168170
expect(failure.details?.reason).toBe('alert-window-expired');
169171
});
170172
});
@@ -209,28 +211,30 @@ describe('acting budgets', () => {
209211
expect(client.tap).not.toHaveBeenCalled();
210212
});
211213

212-
it('reports a stuck alert when the post-tap capture stays unresolvable to the end', async () => {
213-
// The first probe resolves the single alert; every post-tap probe carries two disagreeing
214+
it('reports an unconfirmed dismissal when the post-tap capture stays unresolvable to the end', async () => {
215+
// The first probe resolves the single alert; every post-press probe carries two disagreeing
214216
// alert-shaped sheets. An unresolvable capture proves absence for nothing, so the confirm
215-
// loop keeps its budget and fails rather than reporting the alert handled.
217+
// loop keeps its budget and fails — and, having never named this alert on screen again, it
218+
// reports the press as unconfirmed rather than claiming a dialog it never re-observed.
216219
const client = clientWithTrees([
217220
limrunAttAlertTree(),
218221
[limrunAttAlertTree(), limrunAttAlertTree()],
219222
]);
220223

221224
await expect(underFakeTimers(() => handleLimrunIosAlert(client, 'dismiss'))).rejects.toThrow(
222-
'alert dismiss did not dismiss the visible alert',
225+
'alert dismiss pressed the button but the dismissal could not be confirmed',
223226
);
224227
});
225228

226-
it('reports a stuck alert when the same root survives the tap with degraded buttons', async () => {
227-
// The tap was ignored: the post-tap capture is the same alert root with its choices dropped
228-
// to disabled, explicitly unhittable, and frameless. Degraded-but-present is not absence;
229-
// the leg must fail, not report handled.
229+
it('reports an unconfirmed dismissal when the same root survives with degraded buttons', async () => {
230+
// The tap was ignored: the post-press capture is the same alert root with its choices dropped
231+
// to disabled, explicitly unhittable, and frameless — an unresolvable shape, not a re-named
232+
// alert. Degraded-but-present is not absence; the leg must fail, not report handled, and it
233+
// may not claim "still visible" beyond what the undecided capture proved.
230234
const client = clientWithTrees([limrunAttAlertTree(), limrunAlertTreeWithUnpressableButtons()]);
231235

232236
await expect(underFakeTimers(() => handleLimrunIosAlert(client, 'accept'))).rejects.toThrow(
233-
'alert accept did not dismiss the visible alert',
237+
'alert accept pressed the button but the dismissal could not be confirmed',
234238
);
235239
expect(client.tap).toHaveBeenCalledTimes(1);
236240
});

‎src/core/interactors/android.test.ts‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,22 @@ test('a device-only session releases the helper after fill and scroll', async ()
9898
});
9999
});
100100

101+
test('alert reads ride the session-scope helper, not a per-probe cold start', async () => {
102+
// The executed Android smoke failure: an alert probe without the session scope cold-started
103+
// the snapshot helper inside the window that bounds the probe, so the post-press confirm read
104+
// was aborted before the device answered. Alert captures scope like every other read.
105+
snapshotAndroidMock.mockResolvedValue(makeAndroidSnapshotCapture([]));
106+
const interactor = createAndroidInteractor(device, undefined, {
107+
appBundleId: 'com.example.app',
108+
});
109+
110+
if (!interactor.readAlert) throw new Error('Android interactor must expose readAlert');
111+
await interactor.readAlert();
112+
113+
const options = snapshotAndroidMock.mock.lastCall?.[1];
114+
expect(options?.helperSessionScope).toBe('daemon-session');
115+
});
116+
101117
test('a transient snapshot reaches the Android capture with its settle deadline', async () => {
102118
snapshotAndroidMock.mockResolvedValue(makeAndroidSnapshotCapture([]));
103119

‎src/core/interactors/android.ts‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,10 @@ export function createAndroidInteractor(
6060
const capture = await snapshotAndroid(device, {
6161
includeHiddenContentHints: false,
6262
signal: seam.signal,
63+
// Alert probes must share the session's warm helper like every other app-backed read:
64+
// a command-scope alert probe cold-starts the helper past the window that bounds it,
65+
// so every re-poll and the post-press confirm would abort before the device answers.
66+
helperSessionScope,
6367
});
6468
return buildSnapshotState(androidSnapshotPublicationInput(capture), undefined).nodes;
6569
},

‎website/docs/docs/commands.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -386,7 +386,7 @@ agent-device alert dismiss
386386
- Polling wait timeouts, and a replayed wait refused with `wait_landmark_identity_mismatch`, also carry `captures`, `readableCaptures`, and `polls` so you can see where the budget went. Each poll has `startedMs`, `durationMs`, and an `outcome`: `readable`, `unreadable`, `retriable`, `deadline`, `runner-restart`, or `readiness`. Long waits keep the first 5 and last 25 polls. A wait that never saw a readable capture reports the error its polls hit, with that error's code and retry details, instead of a generic timeout; `wait stable` and a never-readable strict absence keep their own diagnostics. `logPath` links the full request log.
387387
- `alert` (same as `alert get`) inspects or handles system alerts on iOS simulator, macOS desktop, and Android permission dialogs. On iOS it also covers app-owned modal popups with native blocking markers. `alert wait <ms>` takes a budget up to 2147483647 ms (~24.8 days); larger is refused as `INVALID_ARGS` before anything runs.
388388
- On the snapshot-derived backends (Android, Limrun iOS) `alert get --json` answers with a typed `status`: `visible`, `none`, or `undecided` (an alert-shaped capture that resolves to no single alert). Branch on `status`, not on the message.
389-
- On those backends, when `alert accept`/`dismiss` fails, `error.details.reason` names why. Before any press, `dispatched: no` and the reason is `alert-not-found` (the action budget passed with no alert seen), `alert-window-expired` (the budget closed before a capture or the press could resolve), `alert_capture_undecided`, or `alert_button_undecided` (the sheet is too ambiguous to act on). After a press, `alert-window-expired` with "did not dismiss" wording means the tap went out and the disappearance could not be confirmed; `dispatched: unknown` means the press itself was cut off and may have landed. Run `alert get` before acting again.
389+
- On those backends, when `alert accept`/`dismiss` fails, `error.details.reason` names why. Before any press, `dispatched: no` and the reason is `alert-not-found` (the action budget passed with no alert seen), `alert-window-expired` (the budget closed before a capture or the press could resolve), `alert_capture_undecided`, or `alert_button_undecided` (the sheet is too ambiguous to act on). After a press, “did not dismiss the visible alert” means a re-read named the same dialog again; “could not be confirmed” means the press went out but no post-press read resolved in time, so the dialog may already be gone; `dispatched: unknown` means the press itself was cut off and may have landed. Run `alert get` before acting again.
390390
- On Android, an alert capture that outlives its budget is stopped in flight. On Limrun the transport cannot cancel a request: the command refuses a late answer and presses nothing, but a hung capture can keep running after the command has already failed. If Limrun alert commands stall, restart the instance session.
391391
- Use `alert get` for a quick check, and `alert wait <short-ms>` only when a prompt may appear after async work. Don't use `settings permission` to answer a dialog already on screen; it is for setup before a flow.
392392
- `accept` and `dismiss` are sent once on every platform and never replayed, even if the response is lost. On iOS the runner activates the button once, then only observes until the alert disappears, changes, or the deadline expires. A changed alert does not prove a permission was granted; verify the app outcome.

0 commit comments

Comments
 (0)