Skip to content

fix(android): let press reach a foreign ANR dialog's own buttons - #5115

Open
kdy1 wants to merge 29 commits into
callstack:mainfrom
kdy1:fix/android-anr-dialog-buttons
Open

kdy1 wants to merge 29 commits into
callstack:mainfrom
kdy1:fix/android-anr-dialog-buttons

Conversation

@kdy1

@kdy1 kdy1 commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

Summary

While another package's Android "isn't responding" dialog has focus, the blocking-dialog guard refuses every input, including the dialog's own Close app and Wait, so an agent cannot dismiss it. #592 recovers only app-owned ANRs.

Now one plain press or click (count 1, no double tap, hold, or jitter) passes when it aims at the dialog's android:id/aerr_close or android:id/aerr_wait in a fresh capture: a ref's node in the tree the runtime taps from, or a raw point inside either button. Focus is then confirmed again. Selectors and other inputs refuse with dispatched: no.

App-owned recovery now finds Close app by the same id, in any device language.

Before / after

System UI frozen with SIGSTOP until its ANR dialog has focus, API 36 emulator:

Call Base 24f8181c3 Head 0f047ad15
press @e2 (Close app) Android system dialog is blocking press Tapped @e2, Settings gets focus
press 540 1600 (outside) refused Not dispatched, hint names Close app or Wait

Validation

Emulator run at 0f047ad15, android-helper backend 0.21.44-dev:

# agent-device 0f047ad15, e2e_api36_anr
 (API 36), System UI stopped with SIGSTOP
$ adb shell dumpsys window | grep mCurrentFocus
mCurrentFocus=Window{d56e672 u0 Application Not Responding: com.android.systemui}
$ agent-device snapshot -i
@e1 [text] "System UI isn't responding"
@e2 [button] "Close app"
@e3 [button] "Wait"
$ agent-device press 540 1600
Error (COMMAND_FAILED): Android system dialog is blocking press: Application Not Responding: com.android.systemui (package com.android.systemui). Not dispatched. Next: Take a new snapshot -i, then press the ref of one of the dialog's buttons (Close app or Wait). Every other input is refused while the dialog has focus.
$ agent-device press 'id="android:id/aerr_close"'
Error (COMMAND_FAILED): Android system dialog is blocking press: Application Not Responding: com.android.systemui (package com.android.systemui). Not dispatched. Next: Take a new snapshot -i, then press the ref of one of the dialog's buttons (Close app or Wait). Every other input is refused while the dialog has focus.
$ agent-device fill 540 900 hello
Error (COMMAND_FAILED): Android system dialog is blocking fill: Application Not Responding: com.android.systemui (package com.android.systemui). Not dispatched. Next: Wait for Android to recover, close the dialog, restart the app, or reboot the emulator, then retry.
$ agent-device snapshot -i
@e1 [text] "System UI isn't responding"
@e2 [button] "Close app"
@e3 [button] "Wait"
$ agent-device press @e2
Tapped @e2 (540, 1273)
$ adb shell dumpsys window | grep mCurrentFocus
mCurrentFocus=Window{521a11c u0 com.android.settings/com.android.settings.Settings}
$ agent-device press 'label="Network & internet"'
Tapped label="Network & internet" (540, 739)

pnpm check:affected --run --head 0f047ad15, exactCommit: true:

[passed] format; exit=0
[passed] lint; exit=0
[passed] typecheck; exit=0
[passed] layering; exit=0
[passed] fallow; exit=0
[passed] build; exit=0
[passed] vitest-related; exit=0
[passed] unit; exit=0
[passed] command-docs; exit=0
[passed] docs-links; exit=0
[passed] docs-prose; exit=0
  • Unit tests cover stale refs, moved buttons, focus changes, edges, hold, jitter, and selectors.
  • Risk: when a swipe into frozen System UI caused the ANR, Android can reject the first tap as an inconsistent event; the press reports it may have reached the device, and a second press closes the dialog.
  • Not run: Android below 7.0, whose dialogs have no aerr_ ids; the guard still refuses there.

🤖 Generated with Claude Code

kdy1 and others added 19 commits November 26, 2026 10:16
When another package (for example System UI) shows "isn't responding",
the blocking-dialog guard refused every command, including a press on the
dialog's Close app or Wait button, so the dialog could not be dismissed.

A single press or click is now admitted when its final tap point lies
inside one of the framework app-error dialog buttons (android:id/aerr_*)
that are visible and not covered. Every other input is still refused with
dispatched: no. After the admitted tap, the guard waits for the dialog
focus to clear before its after-command check.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…on tap

The dialog-button exception read the button rectangles at the readiness
check, before target resolution. If the dialog closed in between, a tap
at a stored button point reached whatever the dialog uncovered and was
reported as a success.

The gate now reads the focus again immediately before the send. When the
dialog no longer has focus, the tap is refused with dispatched: no.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…utton tap

Android removes the app-error dialog window asynchronously, so the first
focus reads after the tap can still show it. No test held the wait that
covers this: the press fixture cleared the focus at the tap.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The dialog-button exception still required the English "isn't responding"
title in the snapshot. On a device in another language, the guard
detected the ANR window from its fixed window title, but found no
buttons, so a press on the dialog's own Close app button stayed refused.

The focus read already identifies the ANR window, so the buttons are now
found by their framework resource id alone.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ts hit area

The dialog-button exception used the shared inclusive containsPoint, so a
raw-coordinate press on the pixel just past a button's right or bottom
edge was admitted. Android's view hit test excludes those edges, so the
tap reached the dialog around the button and closed nothing.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ommand

ADR 0039 requires dispatched: no for a refusal before any send. The
blocking-dialog guard's before-command refusal for a foreign dialog left
the field unset, so the request disclosure layer reported dispatched:
unknown for a mutating command, while the dialog-button gate's own
refusal of the same press already reported no.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…older tree

The dialog-button exception checked only the tap point. An app @ref from
a snapshot taken before the ANR dialog appeared resolves on that older
tree. When its point fell on Close app or Wait, the gate admitted it, the
tap closed the dialog, and the response reported a press of the app's
own control.

The gate now also requires the point to be a dialog button in the tree
the target was resolved on. A raw coordinate has no such tree and keeps
the point-only check.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…og-button tap

The focus read just before a dialog-button tap reported a probe that
answered nothing as "lost focus", although the dialog may still be up.
A read that threw (for example, the device went offline) reached the
request disclosure layer as dispatched: unknown, although nothing was
sent.

An unanswered read now says that focus could not be read, and a thrown
read is disclosed as dispatched: no. Tests also cover a different dialog
taking the focus before the send.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The alert handler recognizes the app-error dialog by its English labels
only, so on a device in another language `alert dismiss` finds no alert.
A press on one of the dialog's buttons works in every language, so the
hint names only that.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
When the snapshot read for the dialog's buttons failed, the tap was
refused like a dialog without buttons, and the read error was dropped.
The refusal stays, and the read failure is now recorded as a diagnostic.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…its or refuses

Only a repeated press was tested. A double tap and a multi-ref plan are
refused for the same reason, and click is admitted like press; a change
that dropped any of these checks passed every test.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… trees

The check against the tree a target was resolved on accepted any
app-error dialog button at the point. When the dialog's buttons moved
after the snapshot, for example after a rotation, a Wait ref whose old
point now lies on Close app was admitted, and the tap killed the app
that the agent meant to wait for.

Each admitted button now keeps its framework resource id, and the button
at the point must have the same id in both trees.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ssed

Every foreign-dialog refusal told the agent to press Close app or Wait.
When the guard found no button to admit, every such press is refused
the same way: before Android 7.0 the dialog's buttons carry no aerr_ ids
(the snapshot helper supports API 23), and a failed snapshot read admits
no button. The agent then looped on the same refusal.

These two refusals now keep the earlier recovery hint: wait, close the
dialog, restart the app, or reboot the emulator.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…al time

The test for the wait after a dialog-button tap slept through two real
500 ms focus polls. The repository keeps unit tests off real time, so the
file now mocks the poll's sleep, as the replay-divergence tests do.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A single click or press can now close another app's "isn't responding"
dialog, while every other input stays refused. Neither the press and
click help nor the command reference said so.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The conditional spread that handed admitTap to the interaction runtime
raised dispatchRuntimeInteraction's cognitive complexity to 16, over the
fallow limit of 15. The runtime already treats an undefined admitTap as
absent, so pass the optional value directly.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The press note added for a foreign ANR dialog raised the always-loaded
MCP tools to 23,180 bytes, over the 23,040-byte budget, and repeated a
search keyword. Shorten it to one clause without words from the search
hints. The refusal hint still tells the agent which buttons it may press.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A press the foreign-dialog guard refused, such as a stale Wait ref after
a rotation or an app ref from before the dialog appeared, got the hint
"Press one of the dialog's buttons", which the agent believes it just
did. Start the hint with a new snapshot so the next press uses a current
ref.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The paragraph said every command refuses while the dialog has focus,
but snapshot, screenshot, open, and close still run, and the same
paragraph tells the reader to take a snapshot. Name the input commands
instead.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All reported issues were addressed across 10 files

Reply with feedback, questions, or to request a fix.

View guided diff | Re-trigger cubic

@thymikee

Copy link
Copy Markdown
Member

Thanks for the fix. At db76959, an open high-priority thread still needs a change: dialog button allowlist.

The answers to these questions decide whether the change fits the project:

  • Which real use case hit a foreign ANR dialog, other than a SIGSTOP reproduction? Can you link a report?
  • fix: recover Android app-owned ANRs #592 kept foreign ANRs fail-fast to avoid closing other processes. Why should a caller close System UI instead of waiting or restarting the emulator?
  • Cloud provider sessions skip this guard. Which non-provider setup needs this exception?
  • Would admitting only aerr_close/aerr_wait, checked on the resolved node, cover your case with less code?

Could the check run once, before dispatch, on the resolved node, while keeping readAndroidBlockingSystemDialogReadiness? For a single plain press or click (count 1, no doubleTap, holdMs or jitterPx, one ref), it would admit only a target whose identifier is android:id/aerr_close or android:id/aerr_wait, then run confirmFocus right before send. For raw coordinates, it would check that the matching button rect in the fresh capture contains the point. Could this drop the dual-tree point comparison, the generic admitTap seam on InteractionRuntimeInput and the tap counter, since the shape check guarantees one tap? It would also narrow the pattern to the two buttons the issue names. Could the app-owned recovery reuse the same id reader, so ANDROID_CLOSE_APP_PATTERN can be deleted?

These other high-priority threads also still apply: refusal test assertions, post-tap app check, refusal hint wording, and hold and jitter. This wording thread does not apply and can be resolved, because "tap" accurately describes the single press that is admitted.

The required evidence is in place. The live emulator run and check:affected results are author-reported, with no output attached, and the run induced the ANR by sending SIGSTOP to System UI.

Not verified here: device behavior (this was a read-only review); whether Android captures during a foreign ANR return nodes from the underlying app window, which affects whether the first thread's case is reachable in production; and which aerr_* buttons a real image shows in the ANR dialog.

The only non-passing CI jobs are two cancelled Body rules runs. This is likely unrelated to the code, since that check reads the PR description and such runs are typically replaced after description edits. Their logs were not available, so a fresh Body rules run at this head would confirm it.

Before merge, the dialog button allowlist thread must be resolved.

@kdy1

kdy1 commented Nov 26, 2026

Copy link
Copy Markdown
Contributor Author

Note

This text was drafted with AI and posted after human approval.

  • Harnesses: T3 Code, Claude Code
  • AI agent: Claude Opus 5.5 (claude-opus-5-5)

Thanks for the review. Answers to your questions:

  1. Real case. A user report from e2e 0.17.0, which drives agent-device through MCP on a local Android emulator. System UI showed "isn't responding", and every press failed with Android system dialog is blocking press, including the agent's press on Close app. Restarting adb, rebooting, and cold-booting the emulator did not clear it. The report is in a private channel, so I can't link it. The SIGSTOP run is only how I reproduced the dialog locally.
  2. Why close System UI. In that report, waiting and the restart/reboot steps in the hint did not help, so the agent had no way forward. Close app on a System UI ANR kills System UI, and Android restarts it at once; in my run, Settings got focus again. This is the same action a person takes on the device, and Wait stays available. agent-device still never closes a foreign process by itself: the caller must press the button, and fix: recover Android app-owned ANRs #592's automatic recovery stays limited to the session app.
  3. Setup. A local emulator or device driven through the local daemon, which is where the report came from. Cloud provider sessions are not affected.
  4. Only aerr_close/aerr_wait. Yes, that covers the case. During the ANR on the API 36 image, the capture held one window and three nodes (alertTitle, aerr_close, aerr_wait), with no nodes from the app underneath.

I'll rework it the way you describe:

  • One check before dispatch on the resolved node, for a single plain press or click: count 1, no doubleTap, holdMs, or jitterPx, and one ref.
  • Only aerr_close and aerr_wait are admitted. For raw coordinates, the point must be inside one of those button rects in the fresh capture.
  • confirmFocus runs right before send, and readAndroidBlockingSystemDialogReadiness stays.
  • This drops the dual-tree comparison, the admitTap seam, and the tap counter.
  • The app-owned recovery will use the same id reader, so ANDROID_CLOSE_APP_PATTERN can go.

The same push addresses the other threads, and I'll attach the emulator and check:affected output to the PR body.

@thymikee

Copy link
Copy Markdown
Member

Thanks, this answers the fit questions. A System UI ANR on a local emulator that blocks every press, including the press on its own Close app button, with no way out through restart or cold boot, is a real dead end, and keeping the caller in control of that press preserves the #592 rule that agent-device never closes a foreign process by itself.

The smaller shape described above covers it: one check before dispatch on the resolved node, only aerr_close and aerr_wait, single plain press or click, confirmFocus right before send, and the shared id reader replacing ANDROID_CLOSE_APP_PATTERN. The next push will be reviewed against that shape and the open threads, together with the emulator evidence.

kdy1 and others added 7 commits November 26, 2026 13:00
…atch

The dialog-button exception checked the tap point inside the backend,
through an admitTap seam on InteractionRuntimeInput, compared the point
in two trees, and counted taps. Review asked for a smaller shape.

The check now runs once in readiness, before dispatch. It admits only
the ANR dialog's Close app and Wait buttons (android:id/aerr_close and
android:id/aerr_wait) in a fresh capture. A ref must name one of them,
and the button with the same id must contain the ref node's center, so a
ref read before the dialog appeared, or a Wait ref whose stored position
now shows Close app, is refused. A raw point must be inside either
button, and a selector is refused. The focus is then confirmed once more
before the command runs. The admitTap seam, the dual-tree comparison,
and the tap counter are gone: the press shape check already guarantees
one tap.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The dialog-button exception admitted a press with --hold-ms or
--jitter-px. A hold is not the single tap the exception allows, and
jitter can move the contact off the checked button. Admit only a press
with neither.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A press admitted on a foreign ANR dialog skipped the check that the
session app is still in front. Closing the dialog can reveal the
launcher or another app, and that check is what reports it. Run the
check after a dialog-button press too.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…efusal

The refusal's default hint said to press a dialog button ref. Only a
press or click can reach the buttons, so a swipe, fill, or generic
command got advice it cannot follow. Keep the recovery steps as the
default and pass the dialog-button hint only from the press path.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The refusal cases checked only dispatched: no and that no tap was sent,
so an unrelated refusal could make them pass. Assert the focused
package and window as well.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The press exception now admits only Close app and Wait, by ref or by
coordinates, and refuses a hold, jitter, and a selector. Say so.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The foreign ANR dialog check looked the ref up in session.snapshot, but
the runtime taps the ref's node in the authorized ref frame (ADR 0014),
and a find match taps its own node. A read after the dialog appeared,
such as a screenshot, replaces session.snapshot without a new frame. A
ref issued on the app screen could then pass the check as Close app and
tap the app's button, which nothing checked. Read the node the runtime
will tap.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
kdy1 and others added 3 commits November 26, 2026 13:09
The comment said the focus is read again just before the tap is sent.
It is read as the last step of readiness, before ref resolution and the
send.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The ANR dialog (AppNotRespondingDialog) names its Close app and Wait
buttons android:id/aerr_close and android:id/aerr_wait, not
android:id/button1..3. The helper's content classifier and alert
detection knew only button1..3, so a capture that held only the ANR
dialog was classified as system windows only. Recognize both ids, and
model the provider fixture's ANR dialog with them.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
App-owned ANR recovery matched the English "Close app" label, so it
could not recover on a device in another language. Read the button by
android:id/aerr_close through the same reader as the press exception,
and delete ANDROID_CLOSE_APP_PATTERN. The unit fixtures now carry the id
the real dialog has.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@kdy1

kdy1 commented Nov 26, 2026

Copy link
Copy Markdown
Contributor Author

Note

This text was drafted with AI and posted after human approval.

  • Harnesses: T3 Code, Claude Code
  • AI agent: Claude Opus 5.5 (claude-opus-5-5)

Pushed the rework at 0f047ad, in the shape you described. Each commit maps to one item:

  • 45b7fa1: one check before dispatch on the resolved node, only aerr_close/aerr_wait, raw points checked against the fresh rects, and selectors refused. The admitTap seam, the dual-tree comparison, and the tap counter are gone.
  • 575cfca: from a self-review. The check reads the ref's node from the authorized ref frame, the tree the runtime taps from, not from session.snapshot. Otherwise a screenshot taken after the dialog appeared could make an app ref pass as Close app.
  • 3d44215 and 0f047ad: app-owned recovery now uses the same id reader, and ANDROID_CLOSE_APP_PATTERN is gone. This needed the helper's content classifier and alert detection to recognize aerr_close/aerr_wait, which they did not: they knew only android:id/button1..3. A capture holding only the ANR dialog was classified as system windows only. The provider fixture now models the dialog with the real ids.
  • 47385f2, 93bbc98, 7ac2567, 75e0e34: the open threads, with replies in each.

The PR body has the emulator run and the check:affected output at 0f047ad.

@thymikee

Copy link
Copy Markdown
Member

Thanks for the follow-up. The points from the earlier review are resolved at 0f047ad, and no further code changes are needed.

These open threads no longer apply and can be resolved: the allowlist now holds only aerr_close and aerr_wait, matching the help text; refusal tests now assert typed details; the early return is gone, so the stayed-in-app check runs and a test covers the launcher-under-dialog case; the default hint is the recovery hint again, with the dialog hint passed only from the press/click tap path; hold and jitter presses are now excluded; and the tap wording is accurate because the admitted action is a single tap.

The emulator behavior and check:affected results rest on the transcripts in the PR. Not verified here: those runs were not repeated; it was not confirmed on a device that readAppState right after the tap resolves the underlying activity instead of the ANR window (the parser requires a package/activity component, which the ANR window title lacks); and alert accept or alert dismiss on a foreign ANR dialog was not traced end to end, although the alert detection pattern now classifies the aerr buttons.

The Body rules check was cancelled and the other 15 checks pass. The cancellation is likely unrelated to the code, since that job only reads the PR description; its log was not available.

Before merge, Body rules needs a fresh green run on this commit.

@thymikee thymikee added the ready-for-human Valid work that needs human implementation, judgment, or maintainer merge label Nov 26, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ready-for-human Valid work that needs human implementation, judgment, or maintainer merge

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants