Skip to content

fix(ios): place a matched alert window in the box it sits in - #4113

Merged
thymikee merged 2 commits into
mainfrom
fix/ios-alert-window-placement
Oct 31, 2026
Merged

thymikee merged 2 commits into
mainfrom
fix/ios-alert-window-placement

Conversation

@thymikee

@thymikee thymikee commented Oct 31, 2026 •

Copy link
Copy Markdown
Member

Summary

Follow-up to #4001. That PR merged one commit before this fix.

In #4001, alertSnapshots checked every window against its own frame. A dismiss-popup candidate is itself a window, so any marked window counted as on screen, even an off-screen one. The base code rejected those.

Now a window is checked against the box it sits in, and it is the box only for what it hosts. SpringBoard alerts still use the window that hosts them, so the foldable fix from #4001 is unchanged.

Also adds three tests:

Validation

  • pnpm check:affected --run --head f3b09b4748: passed.
  • On the iPhone 17 Pro sim, the alert/modal runner unit tests pass, including the two new tests.

🤖 Generated with Claude Code

View guided diff Turn on auto-fix

A dismiss-popup candidate is itself a window, so measuring it against its
own frame accepted any window, even one off screen. A window is now placed
in its parent's box and is the box only for what it hosts. Also pin the
refusal when the hosting window can no longer be read.

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

vercel Bot commented Oct 31, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
agent-device-website Ready Ready Preview Oct 31, 2026 11:08am UTC

Request Review

@github-actions

github-actions Bot commented Oct 31, 2026 •

Copy link
Copy Markdown
Contributor

Size Report

Metric Base Current Diff
Installed (including dependencies) 5.63 MB 5.63 MB +5 B
Package (unpacked) 5.63 MB 5.63 MB +5 B
Package (download) 1.71 MB 1.71 MB +8 B

Startup median (7 runs, lower is better):

Scenario Base Current Diff
CLI --version 39.7 ms 42.3 ms +2.6 ms
CLI --help 87.7 ms 91.7 ms +4.0 ms

@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 2 files

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

View guided diff | Turn on auto-fix | Re-trigger cubic

@thymikee

Copy link
Copy Markdown
Member Author

The code looks good at f3b09b4. Matched window alerts now use the base rule again, and non-window matches take the same path as the #4001 head, so the Duo inner-panel case is unchanged. Not blocking, and you can take or leave these: a fixture with a 466x678 root holding a 951x669 window holding an .alert at (341,250,270,170), asserting that alertSnapshots(in: root, source: .appAlert, viewport: root.frame) returns one alert, would pin the inner-panel rule, because the current alertSnapshots tests at lines 305-308 pass viewport: window.frame and would not catch a regression there; and testAlertActivationRefusesAnUnreadableHostWindowWithoutTapping covers activateAlertButton, which this PR does not touch, so the PR body could say it is #4001 coverage rather than part of the fix.

The 18 checks are green, with none failing; the native-fingerprint job is skipped. I read the main and head code but did not run the Swift unit tests, and I did not see a device run for dismiss-popup specifically. The pure-function test with the real alertSnapshots covers the changed window-match behaviour, so I do not think a new device run is needed. There are no conflicts.

The open inline thread on the unreadable window frame fallback (#4113 (comment)) does not apply, so you can resolve it. That fallback to the enclosing viewport is unchanged from #4001 and matches base. The matched node still needs a positive, finite frame, and the unreadable-window tap refusal is enforced on the activation path and covered by the new second test.

@thymikee thymikee added the ready-for-human Valid work that needs human implementation, judgment, or maintainer merge label Oct 31, 2026
@thymikee
thymikee added this pull request to stack #4116 October 31, 2026 09:18
…n frame

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

Copy link
Copy Markdown

Apex Sentinel

Verdict: approve

4 finding(s): 2 minor, 2 nit. Verdict: approve. reached max rounds (1).

🟡 Minor (2)

Where Finding
apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+AlertObservation.swift:68 Nested dismiss-popup window on a foldable's inner panel is now rejected as off screen
apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+AlertObservation.swift:68 Off-screen dismiss-popup windows are rejected only at the level the match happens; a marked window nested inside an off-screen window is still accepted
🔵 Nit (2)
Where Finding
apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/UnitTests/RunnerTests+AlertObservationTests.swift:117 New unreadable-host-window test relies on XCTExpectFailure absorbing a second, unrelated XCTest failure
apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+AlertObservation.swift:68 childViewport shadows the viewport parameter the line above already reads

Reply under an inline comment with @apex-sentinel-staging note ... or @apex-sentinel-staging pivot ... to re-check that finding.
Comment @apex-sentinel-staging review on this conversation to run a full review.

@apex-sentinel-staging apex-sentinel-staging Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Apex Sentinel: 4 new findings on 2624508. The verdict and the full list are in the summary comment.

}
if matches && Self.isPlaced(frame, in: hostWindow) { return [snapshot] }
return snapshot.children.flatMap { alertSnapshots(in: $0, source: source, viewport: hostWindow) }
if matches && Self.isPlaced(frame, in: viewport) { return [snapshot] }

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Minor · Nested dismiss-popup window on a foldable's inner panel is now rejected as off screen

The new placement check tests a window against the box it sits in, and at the observation root that box is the application frame: observeAlert calls alertSnapshots(in: snapshot, source: source, viewport: snapshot.frame) (RunnerTests+AlertObservation.swift:44), where snapshot is ownerApp.snapshot(), an .application node, so the children — the app's windows — are matched against the application frame.

Suggested change
if matches && Self.isPlaced(frame, in: viewport) { return [snapshot] }
if matches && Self.isPlaced(frame, in: viewport) { return [snapshot] }
// A window is placed in the box it sits in, and is itself the box of what it hosts.
// A foldable's inner-panel window extends past the application frame that names one panel,
// so a window that matches is also placed in the box it hosts (#4001).
let childViewport = snapshot.elementType == .window && SnapshotGeometry.isPositiveFinite(frame) ? frame : viewport
if matches, source == .dismissPopup, Self.isPlaced(frame, in: childViewport) { return [snapshot] }
return snapshot.children.flatMap { alertSnapshots(in: $0, source: source, viewport: childViewport) }

Suggested change

Decide whether a dismiss-popup window on a foldable's inner panel — a window whose center sits outside the 466-wide application frame, the geometry this PR adds a test for — must still be observed. If it must, place a window that matches (or any window) against the union of the box it sits in and the screen rather than against the box it sits in alone, and pin the answer with a dismissPopup case using the 951x669 inner-panel window and the 466x678 application frame.

Details

The PR's own second test records the foldable geometry: the inner-panel window is 951x669 inside a 466x678 application frame (testAnInnerPanelAlertIsPlacedInItsWindowNotTheApplicationFrame, lines 358-360). That window's center is (475.5, 334.5), and isPlaced compares exactly the center (hostWindow.contains(CGPoint(x: frame.midX, y: frame.midY)), RunnerTests+SystemModal.swift:167-170). With x = 475.5 > 466, isPlaced returns false for that window frame inside that application frame.

So for source == .dismissPopup — the only source that matches a window itself (line 66) — a popup window that lives in the inner-panel window of the shape this PR just documented is refused, and observeAlert reports .absent for a popup that is on screen. That is the same failure #​4001 fixed for SpringBoard alerts by comparing an alert against its hosting window instead of the application frame (the comment at RunnerTests+SystemModal.swift:165-166: "the application frame names only one of them"), now reintroduced one level up for the popup source.

The case is partly masked in handleAlert: an .absent verification is answered as ok (alertVerificationResponse maps .disappeared to ok), so the visible symptom is a confirmed answer that was never proved. The direct cost is the guard in observeAlert: if both an inner-panel popup window and another marked window are present, candidates.count <= 1 fails (line 45) and the observation stays unavailable, so a genuine dismissal is reported as ALERT_CONFIRMATION_UNAVAILABLE instead of a confirmed answer.

persona: swift-ios

Reply @apex-sentinel-staging note ... to add context, or @apex-sentinel-staging pivot ... if this is wrong — I will re-check the cited code.

Useful? Reply @apex-sentinel-staging like, or @apex-sentinel-staging dislike <why> if it is not.

}
if matches && Self.isPlaced(frame, in: hostWindow) { return [snapshot] }
return snapshot.children.flatMap { alertSnapshots(in: $0, source: source, viewport: hostWindow) }
if matches && Self.isPlaced(frame, in: viewport) { return [snapshot] }

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Minor · Off-screen dismiss-popup windows are rejected only at the level the match happens; a marked window nested inside an off-screen window is still accepted

alertSnapshots now checks a matching window against the viewport it was handed (line 68), which fixes a marked top-level window that sits off screen. The box it then hands to children (line 70) is the window's own frame unconditionally, without any check that this window is itself placed in viewport. That is required for the foldable case (the 951x669 inner-panel window is not placed in the 466x678 application frame, and the new testAnInnerPanelAlertIsPlacedInItsWindowNotTheApplicationFrame depends on it), but it means the new rejection is depth-sensitive: for source == .dismissPopup an off-screen window W1 (say x = 1000) that hosts another window W2 carrying the "dismiss popup" marker is accepted, because W2 is matched against W1's own frame and isPlaced compares only W2's centre with W1's frame, which trivially contains it. The runner then resolves an alert on a window that is off screen — the exact condition this PR set out to reject. The invariant the code now relies on is silently "a matching .window snapshot is always a direct child of the box it is measured against"; nothing in the type, the recursion or the tests enforces it, and the new fixture test only covers the one-level case (testDismissPopupWindowIsPlacedInTheBoxItSitsIn). Suggested action: either carry the placed-ness of each window ancestor down the recursion (e.g. keep an onScreenBox that a window may replace only while every enclosing box it sits in is placed), or add a fixture for a marked window nested inside an off-screen window so the accepted outcome is at least a deliberate, tested one.

Suggested change

Decide whether a marked window nested inside an off-screen window may be answered, and encode it: either gate a window's right to become the child box on it being placed in the box it sits in (without breaking the unplaced inner-panel foldable window) or add a fixture test for a marked window inside an off-screen window.

Details

persona: senior-developer

Reply @apex-sentinel-staging note ... to add context, or @apex-sentinel-staging pivot ... if this is wrong — I will re-check the cited code.

Useful? Reply @apex-sentinel-staging like, or @apex-sentinel-staging dislike <why> if it is not.

}
XCTAssertTrue(app.alerts.firstMatch.waitForFixtureExistence(timeout: appExistenceTimeout))
let resolved = try resolveAlertBeforeTheCommand()
let alert = RunnerAlert(

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🔵 Nit · New unreadable-host-window test relies on XCTExpectFailure absorbing a second, unrelated XCTest failure

testAlertActivationRefusesAnUnreadableHostWindowWithoutTapping points alert.window at app.windows.matching(identifier: "agent-device-missing-window").firstMatch, an element that does not exist in the fixture. activateAlertButton then reads window.frame (RunnerTests+Alert.swift:177) and button.frame reads and the coordinate-context read on a non-existent element raise XCTFailure issues (or, depending on the SDK, a caught XCUIElementQueryError), which is why the test needs XCTExpectFailure at all. Its issueMatcher keeps only issues whose compactDescription contains "agent-device-missing-window", so any additional issue raised along that path — a differently-worded frame-read failure on the same missing window, or one from the tap-synthesis path — fails the test on a runner whose diagnostics differ from the one this was validated on, while the assertion actually under test (outcome == .unsupported) is unaffected by the wording.

Suggested change
let alert = RunnerAlert(
let frame = button.frame
let options = XCTExpectedFailure.Options()
options.issueMatcher = { $0.compactDescription.contains("agent-device") }
options.isStrict = false
var outcome: RunnerInteractionOutcome?
XCTExpectFailure("The unreadable window is the condition under test", options: options) {
outcome = activateAlertButton(alert, button: button, action: "accept", frame: frame, deadline: .distantFuture)
}

Suggested change

Keep the refusal assertion, and make the unreadable window a value the test controls (for example a stub or override that returns CGRect.null for the window frame) so no XCTest issue has to be absorbed by XCTExpectFailure.

Details

The behavior the test pins (a refused tap when the host window cannot be read, so the tap is not routed through the owner app's first window on a foldable) is worth keeping; only the expected-failure matching is fragile.

Also raised here

Also raised at this location by senior-developer: New test matches an XCTest issue by error text rather than by a typed reason — options.issueMatcher = { $0.compactDescription.contains("agent-device-missing-window") } accepts the expected failure by substring of the rendered issue text. AGENTS.md says: "Use typed reasons and details for behavior. Do not match error text." Two consequences on this line: the test still passes if XCTest changes the wording of its no-match failure as long as the identifier stays in it, and any other issue that merely mentions that identifier (for example from a different read inside activateAlertButton) would satisfy the expectation, so a passing test would not prove the refusal came from the window read the test names. RunnerTests+TextInputProbeTests.testTextInputProbeContainmentExcludesRequiredReadsAndLaterIssues shows a stricter shape — matching issue.type and the full compactDescription, and counting how many issues were absorbed — which would say here that exactly one issue, of the expected type, was consumed.

persona: swift-ios, senior-developer

Reply @apex-sentinel-staging note ... to add context, or @apex-sentinel-staging pivot ... if this is wrong — I will re-check the cited code.

Useful? Reply @apex-sentinel-staging like, or @apex-sentinel-staging dislike <why> if it is not.

}
if matches && Self.isPlaced(frame, in: hostWindow) { return [snapshot] }
return snapshot.children.flatMap { alertSnapshots(in: $0, source: source, viewport: hostWindow) }
if matches && Self.isPlaced(frame, in: viewport) { return [snapshot] }

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🔵 Nit · childViewport shadows the viewport parameter the line above already reads

In alertSnapshots, the new childViewport local differs from the existing viewport parameter by one word and one branch, so a reader has to re-read both isPlaced(frame, in: viewport) and alertSnapshots(in: $0, source: source, viewport: childViewport) to tell which box each call uses. Naming it after the role it plays for the recursion (e.g. hostWindow, the name the predecessor used for this same expression, or boxForChildren) keeps the two boxes distinct at a glance. Behavior is correct either way; this is naming only.

Suggested change

Rename the new childViewport local to a name that says whose box it is (the window hosting the children), so it is not confused with the viewport parameter used one line earlier for the placement check.

Details

persona: maintainability

Reply @apex-sentinel-staging note ... to add context, or @apex-sentinel-staging pivot ... if this is wrong — I will re-check the cited code.

Useful? Reply @apex-sentinel-staging like, or @apex-sentinel-staging dislike <why> if it is not.

@thymikee

Copy link
Copy Markdown
Member Author

The new commit 2624508 only adds Swift unit tests, and the earlier review of f3b09b4 (#4113 (comment)) still holds: the alert placement fix looks correct and I found nothing to change. The two new tests and the placement route match the sources at this head, but I read them by hand and did not run the Swift runner tests; the inner-panel simulator run rests on your statement. All 19 checks pass, but the TS checks do not exercise the +57/-3 runner alert change, so they say little about it. No conflicts.

The Cubic thread on the unreadable window frame is answered by your reply and needs no code change, so you can resolve it: #4113 (comment). The four Apex threads do not apply and you can resolve them. The foldable popup case matches pre-#4001 behavior and is the scope of this PR (#4113 (comment)). The nested-window case is not shown in any tree, and gating on the parent would break the hosted-alert case (#4113 (comment)). The XCTExpectFailure matcher is the narrowest filter available (#4113 (comment)). The childViewport name matches its comment (#4113 (comment)). I did not check on a device whether XCUITest produces a window nested in a window, or a popup centered outside the application frame on a foldable.

@thymikee
thymikee merged commit ab0b9fc into main Oct 31, 2026
19 checks passed
@thymikee
thymikee deleted the fix/ios-alert-window-placement branch October 31, 2026 13:16
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.

1 participant