Repository navigation
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Size Report
Startup median (7 runs, lower is better):
|
There was a problem hiding this comment.
All reported issues were addressed across 27 files
Reply with feedback, questions, or to request a fix.
View guided diff | Turn on auto-fix | Re-trigger cubic
Apex SentinelVerdict: Since the last review: 5 new · 3 still open · 9 no longer raised 8 finding(s): 8 nit. Verdict: approve. reached max rounds (1). 🔵 Nit (8)
Reply under an inline comment with |
There was a problem hiding this comment.
Apex Sentinel: 10 new findings on 48e3052. The verdict and the full list are in the summary comment.
48e3052 to
2745707
Compare
There was a problem hiding this comment.
Apex Sentinel: 8 new findings on 2745707. The verdict and the full list are in the summary comment.
|
At 2745707, one defect in the near-miss check needs a fix before merge. CI is green (16 checks, none failing), and there are no conflicts.
Not blocking, and fine to take or leave: the help text in On the open threads: the cubic-dev-ai threads on the textCopy descent, help overclaim, docs overclaim and runner details still apply, as do the 4 lower-priority Cubic threads and 14 lower-priority apex-sentinel-staging threads. These do not apply and can be resolved: CommandExecution.swift:627 (no producer sends The live evidence in the PR body is prose only, with no command output or artifact, so I treated it as reported and did not reproduce it. I also did not run swift test, runner unit tests or pnpm checks. I checked the corpus and guard-test claims by reading the code and fixtures. Before merge, |
2745707 to
76d194a
Compare
|
Live command output, so the evidence is no longer prose only. iPhone Duo/27.0 ( Head $ agent-device alert get --json
{"success": true, "message": "Open this page in “Agent Device Tester”?", "buttons": ["Cancel", "Open"]}Head $ agent-device alert get --json
{"code": "COMMAND_FAILED", "hint": "Retry with --debug and inspect diagnostics log for details.", "nearMisses": "<absent>"}Head {"error": {"code": "COMMAND_FAILED", "message": "alert not found",
"hint": "No alert surface was recognised, but the screen shows a dialog-like surface. Run snapshot -i and press @ref by one of its button labels.",
"details": {"nearMisses": [{"identifier": "SFDialogView",
"label": "Open this page in “Agent Device Tester”?", "buttons": ["Cancel", "Open"], "type": "Other"}]}}}Also on that build, a prompt no rule knows is named as a true positive (Safari's "Include topics from other devices" sheet): |
|
Fixed on Blocking item. Taken: the docs and help now claim only "none recognised", listing the other empty cases (spent deadline, failed read, one or 5+ buttons, unlabelled buttons) and pointing at Also taken, unprompted: near misses are capped at four per refusal; Host suite is 32 tests green, corpus replays 6 fixtures, 4 runner unit tests pass on iPhone Duo/27.0, and |
There was a problem hiding this comment.
All reported issues were addressed across 15 files (changes from recent commits).
Reply with feedback, questions, or to request a fix.
View guided diff | Turn on auto-fix | Re-trigger cubic
fea511f to
7b89cba
Compare
|
I re-checked 76d194a against the earlier review (#4119 (comment)). The two-cells near-miss case is fixed: The PR has merge conflicts with main, so it needs a rebase before merge. I did not inspect the conflicting hunks. One open thread still applies: the alert deadline also bounds the main-thread block, but These threads do not apply and can be resolved: the scroll-bar one, because every scroll-bar node in the corpus is type Other and is already excluded from text copy (#4119 (comment)), and the help-wording one, because the placeholder rule lives at I did not run swift test, the runner unit tests or the pnpm checks. The live evidence is the PR body text, which I did not reproduce. The delta only narrows |
76d194a to
a2b59db
Compare
|
Rebased onto the force-pushed |
There was a problem hiding this comment.
Apex Sentinel: 10 new findings and 1 moved to a new line on a2b59db. The verdict and the full list are in the summary comment.
| func alertAbsence( | ||
| in ownerApp: XCUIApplication, | ||
| deadline: Date, | ||
| reading nearMissRead: () -> [RunnerAlertNearMiss] |
There was a problem hiding this comment.
🆕 🟡 Minor · An alert get refusal can now come back MAIN_THREAD_TIMEOUT instead of ALERT_NOT_FOUND on a screen whose snapshot is slower than the assumed 2.5 s
The whole main-thread block for an alert command runs under runMainThreadWork("command_execution", timeout: max(0.001, deadline.timeIntervalSinceNow)) (RunnerTests+CommandDispatch.swift:195-206), i.e. the same deadline the new guard reads. The guard at RunnerTests+AlertObservation.swift:19 only asks whether at least nearMissReadAllowance (2.5 s) remains at the moment the read starts, and the read itself — one ownerApp.snapshot() — cannot be cancelled. nearMissReadAllowance is a hand-picked estimate of "what one tree read costs at worst on a contended host", not a measured bound.
Suggested change
State what happens when the single snapshot exceeds nearMissReadAllowance (the answer becomes MAIN_THREAD_TIMEOUT and the main thread is marked busy for the commands behind it, per the runner's own comment) and either reserve the allowance from the block's own timeout so the read is always the part that is dropped, or gate the read on a cheaper signal than a wall-clock estimate of one uncancellable XCTest call.
Details
So on a screen where a full-tree snapshot genuinely costs more than the estimate — the heavy, loaded-page case this PR itself records as a new corpus fixture, iphone-duo-unfolded-safari-navigation-menu.json, whose tree has 457 nodes and a scroll bar reading "8 pages" — the sequence is: resolveAlert finds nothing with, say, 4 s left, the guard admits the read, snapshot() runs past deadline, the execution watchdog abandons the block, and the caller gets MAIN_THREAD_TIMEOUT (with the main thread then stamped busy so following commands are refused RUNNER_BUSY) where the same command previously answered ALERT_NOT_FOUND immediately. The comment at lines 24-30 acknowledges exactly this failure mode as the reason for the guard, but the guard reduces the odds rather than bounding the read: the block's timeout is never shortened to leave the allowance out of it, and nothing makes the read return when the deadline passes.
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.
| @@ -441,6 +458,7 @@ export function buildRunnerResponseError( | |||
| const classification = classifyRunnerReportedError(runnerErrorCode); | |||
| return new AppError(classification.code, errorMessage ?? 'Runner error', { | |||
There was a problem hiding this comment.
🆕 🔵 Nit · Runner-supplied error details are spread last over runner, so a runner can overwrite the payload echo
buildRunnerResponseError builds the AppError details as { runner: payload, ...readRunnerErrorDetails(payload.error?.details), ...classification.details, xcodebuild, hint, logPath }. The spread of the runner's own error.details object comes AFTER the runner: payload key, so a runner response that carries a details.runner key replaces the echoed payload the diagnostics and log readers rely on, with the runner's own object instead of the decoded envelope. RUNNER_CLASSIFICATION_DETAIL_KEYS blocks only dispatched, reason, retriable, runnerErrorCode; it does not block runner, xcodebuild, hint, logPath, diagnosticId or supportedOn — the last three are exactly the keys normalizeError lifts out of details as diagnostic metadata (see packages/kernel/src/errors-metadata.ts), so a runner that sends details: { hint: ..., logPath: ... } also stamps those. For hint/logPath the explicit trailing keys rescue it, but runner is set before the spread and has no such guard. Fix by spreading the diagnostics first, or by dropping every key the host owns alongside the classification keys.
| return new AppError(classification.code, errorMessage ?? 'Runner error', { | |
| const classification = classifyRunnerReportedError(runnerErrorCode); | |
| return new AppError(classification.code, errorMessage ?? 'Runner error', { | |
| ...readRunnerErrorDetails(payload.error?.details), | |
| runner: payload, | |
| ...classification.details, |
Details
Also raised here
Also raised at this location by maintainability: readRunnerErrorDetails passes every runner key except four into the caller's error details — The copy is a whole-payload spread: ...readRunnerErrorDetails(payload.error?.details) puts whatever object the runner put under error.details into AppError details, dropping only RUNNER_CLASSIFICATION_DETAIL_KEYS. The comment in ErrorDetailsPayload (RunnerTests+Models.swift) states this is intended — "a new field needs no host change to reach --json" — but the consequence is that a runner-side bug that writes e.g. hint, dispatchReason or a large blob into details reaches --json output and CI artifacts unvalidated and unbounded, and the host cannot tell a diagnostic it understands from junk. Since the host already models the one field it acts on (nearMisses), reading that named field (plus an explicit allowlist) would keep the pass-through contract for the fields the host has agreed to.
Also raised at this location by swift-ios: The host forwards the runner's whole details object, so the Swift payload type does not bound the wire shape — ErrorDetailsPayload declares only nearMisses, but readRunnerErrorDetails (runner-contract.ts:484) spreads every key of the runner's error.details object into the AppError details, minus four classification keys. So the wire shape the PR documents ("each entry carries type, identifier, the surface's own copy as label, and its buttons") is not a constraint on the host: a key the Swift payload adds later reaches the caller through the host untouched, and the only guard against a runner overwriting a host-owned detail is that hand-maintained four-entry denylist. A test that encoded an unknown key and asserted it either arrived or was refused would pin the contract from both sides; right now nothing distinguishes the intended pass-through of a new detail from a runner stamping a host field.
persona: senior-developer, maintainability, 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.
| (await runAppleRunnerCommand( | ||
| device, | ||
| { command: 'alert', action, appBundleId: options?.appBundleId, timeoutMs }, | ||
| { |
There was a problem hiding this comment.
🆕 🔵 Nit · "Only alert get pays for the read" is enforced only by the daemon handler; alert wait sends action get to the runner and forwards explainAbsence on every poll
The Swift rule claims the ownership of the restriction (RunnerTests+Models.swift: "get is the only alert action whose absence is an answer rather than a re-ask, so the rule lives here and an acting leg cannot buy the read by carrying the flag"), but the runner cannot tell alert get from alert wait: awaitAppleAlert polls with runAlert('get', budgetMs) (packages/platform-apple/src/alert.ts:~103), so the wait leg's wire request is {command:"alert", action:"get"} — identical to the read leg apart from the flag. alertInteractorOptions forwards explainAbsence for every leg (packages/contracts/src/alert-runtime.ts:112), including awaitAlert, and runAppleAlert attaches it to the request for every action. So the only thing keeping the wait leg from paying 2.5 s of extra snapshot reads on each poll inside its window is the action === 'get' ? { explainAbsence: true } : {} line in the daemon handler; any other caller of the contract (a future handler, an SDK caller building AlertRuntimeInput directly, or a test reusing the exported alertInteractorOptions) that sets the flag on the wait leg gets a near-miss read per poll, which is the cost this PR says settles nothing. The runner-side check is (action ?? "get") == "get" && explainAbsence == true, which is the flag plus an action the wait leg also uses — correct only because the current producer never sets it there.
Suggested change
Either state the flag's meaning in terms the runner can actually check (an explicit explainAbsence producer contract owned by the daemon handler, and drop the "the rule lives here" claim in the Swift comment), or have the wait leg's internal polls clear the flag (runAppleAlert(..., omitting explainAbsence for polled gets)) so the invariant is enforced where the comment says it is.
Details
Also raised here
Also raised at this location by javascript: awaitAppleAlert can now surface a near-miss hint ("Run snapshot -i...") on an alert wait timeout — explainAbsence: true is set by the daemon handler for action get (snapshot-alert.ts:161), and it rides into AlertInteractorOptions, which awaitAppleAlert consumes as options. awaitAppleAlert polls the runner with runAlert('get', budgetMs) (alert.ts:106) — the same native get action — so from the runner's point of view the final poll of a timed-out alert wait is an explaining get. When that last poll finds a dialog-like surface, the error it raises carries hint: AlertAbsence.nearMissHint and details.nearMisses. alert wait then throws AppError('COMMAND_FAILED', 'alert wait timed out', lastAbsence?.details) (alert.ts:116), and because buildRunnerResponseError sets hint inside details too, the AppError constructor's details.hint is not overwritten by the message — the CLI/MCP error output surfaces the hint. …
persona: senior-developer, javascript
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.
| return nearMisses.isEmpty ? .unexplained : .nearMisses(nearMisses) | ||
| } | ||
|
|
||
| /// What one tree read costs at worst on a contended host, the figure `alertActivationDeadline` |
There was a problem hiding this comment.
🆕 🔵 Nit · The near-miss read budget is justified by a constant that exists only in the test file
The new nearMissReadAllowance doc says it is "the figure alertActivationDeadline already budgets reads at" (RunnerTests+AlertObservation.swift:24-25). That constant does not exist in the runner target: the only declaration in the checkout is static let alertActivationDeadline: TimeInterval = 30 inside the unit-test block of UnitTests/RunnerTests+AlertObservationTests.swift:330, and it is a test fixture, not a read budget. The real production figures are defaultAlertCommandTimeout = 10 / alertCommandTimeout(timeoutMs:) and mainThreadExecutionTimeout.
Suggested change
Reference the production figure the allowance is derived from (the timeout alertCommandTimeout gives one read, or mainThreadExecutionTimeout), not the unit-test constant.
Details
The comment is the only justification given for the 2.5 s constant, and a maintainer tuning either budget has to follow it to a test helper whose value is 30 — so the invariant the guard encodes (one snapshot must fit the figure the command budget already assumes) is not stated in terms of anything in the target that enforces it.
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.
| /// Element types that name their own node when it has no label of its own. | ||
| static let textTypes: Set<String> = ["StaticText", "TextView", "Text"] | ||
|
|
||
| /// Part of the label XCTest gives a scroll indicator, "Vertical scroll bar, 8 pages", in every |
There was a problem hiding this comment.
🆕 🔵 Nit · Prompt-copy refusals match any text containing "scroll bar", not the indicator node
isPromptCopy rejects any label containing the substring "scroll bar" case-insensitively (AlertSurface.swift:243-246, scrollBarNoise = "scroll bar"). This is a substring filter on user-facing copy, not on a node type, so a real dialog whose text mentions a scroll bar — e.g. a help prompt "Scroll down using the scroll bar" or an accessibility settings dialog — is refused as a near miss even though the recorded trees identify scroll indicators structurally (an Other node, per the comment at line 82-83 and the new test's first case, scrolled("Other", ...)). The type-based check would cover the shape the trees actually show; the text filter only adds false refusals on real copy. The failure case: an alert-absence read on a screen whose dialog copy names a scroll bar reports nothing while a dialog is on screen — the exact symptom this PR sets out to fix.
Suggested change
Keep the scroll-indicator refusal structural (the node type / identifier the recorded trees show), or match the exact XCTest pattern ("^\s*(vertical|horizontal) scroll bar,\b") rather than any copy containing the phrase.
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.
| return root.children.flatMap { candidates(in: $0, source: source, viewport: childViewport) } | ||
| } | ||
|
|
||
| /// The dialog-like containers in `root` that no source answers: a compact placed container that |
There was a problem hiding this comment.
🆕 🔵 Nit · nearMisses(in:) renames viewport to hostWindow for the root call
AlertSurface.nearMisses(in:viewport:sources:) hands viewport straight to collectNearMisses as hostWindow, so the root node is measured against the viewport under the other name while collectNearMisses only switches to a real Window frame on the first Window child. Every other entry point in this file separates the two concepts by name; here one value carries two names in one call chain, which makes it unclear whether the root check is against the viewport or against a host window. Either name the parameter hostWindow or pass it explicitly as hostWindow: so the two roles are visible.
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.
| /// through an unnamed container. Reading only copy the buttons do not say, and none of it inside | ||
| /// an action, keeps out a web page's navigation cell, whose words are the link it wraps. The | ||
| /// caller has already refused the container to any source, so this checks the rest. | ||
| private static func nearMiss(in node: AlertSurfaceNode, hostWindow: CGRect) -> AlertSurfaceNearMiss? { |
There was a problem hiding this comment.
🆕 🔵 Nit · One near miss on a busy screen suppresses every later one and can spend the whole read on it
nearMiss(in:hostWindow:) (AlertSurface.swift:187) decides per node, and its subtreeTypes(of: node) check at line 194 is the only guard a node has against the subtree it carries: the node's own type, geometry and descendant count are all its own, never its subtree's. So a node of Other type that merely contains the keyboard fails the check and is dropped — and collectNearMisses (line 160) then descends into every one of its children with no further exclusion, because none of them is the keyboard itself and none inherits the ancestor's exclusion.
Suggested change
Stop descending when a node is refused for its subtree rather than for itself (or carry the excluded-subtree state down), so the keyboard/system-bar exclusion covers the region it was found on instead of only the first node that trips it, and skip the descendant walk for a node the subtree check has already refused.
Details
The exclusion is therefore applied once, at the first node that trips it, rather than to the region. For that one node it also pays the full cost the comment warns about — the whole subtree is walked twice (subtreeTypes at line 194 and actionableDescendants at line 195, each recursive over the same subtree) — on a node that is certain to be refused, before the cap at line 166 can help. That is the walk that runs inside the command's main-thread block, the block the 2.5 s nearMissReadAllowance exists to keep inside runMainThreadWork's watchdog (RunnerTests+CommandDispatch.swift:195-206): the allowance only gates starting the read and never bounds the scan that follows the snapshot.
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.
| /// through an unnamed container. Reading only copy the buttons do not say, and none of it inside | ||
| /// an action, keeps out a web page's navigation cell, whose words are the link it wraps. The | ||
| /// caller has already refused the container to any source, so this checks the rest. | ||
| private static func nearMiss(in node: AlertSurfaceNode, hostWindow: CGRect) -> AlertSurfaceNearMiss? { |
There was a problem hiding this comment.
🆕 🔵 Nit · Near-miss area ratio is measured only against Window ancestors, and its zero guard is dead
nearMiss refuses a container whose area exceeds 60% of hostWindow (AlertSurface.swift:190-193), and hostWindow switches to the node's own frame only for type == "Window". On a foldable, the recorded SpringBoard trees in this corpus show the hosting box is NOT always a Window: iphone-duo-folded-springboard-without-alert.json records an Application of 466x678 whose child Window measures 669x951 — larger than the app box — and iphone-duo-unfolded-springboard-open-in-app.json has the same inversion (Application 466x678, Window 951x669/669x951). Where a real prompt is presented by SpringBoard in a Window that covers only one panel but sits under an Other chain whose own box is the bigger window (the inverse of the case isPlaced's comment already anticipates), the ratio is computed against the wrong box and a genuine prompt exceeds 0.6 and is silently not named — exactly the case this feature exists for. The if hostWindow.width * hostWindow.height > 0 guard is additionally dead code: isPlaced(node.frame, in: hostWindow) on the line above already requires SnapshotGeometry.isPositiveFinite(hostWindow), which guarantees width > 0 and height > 0.
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.
| @@ -54,7 +54,13 @@ function runAppleAlert( | |||
| return async (action, timeoutMs) => | |||
There was a problem hiding this comment.
🆕 🔵 Nit · explainAbsence is accepted on the macOS alert leg and silently ignored
AlertInteractorOptions.explainAbsence is now part of the shared alert options, and the daemon sets it for every alert get regardless of platform (packages/daemon/src/execution/handlers/snapshot-alert.ts:161). On a macOS target, runAppleAlert returns the helper-backed closure that takes only {action} and drops the option (packages/platform-apple/src/alert.ts:48-52: return async (action) => runMacOsAlertAction(action, {...target, env})), so the flag is accepted and does nothing there — no refusal, no diagnostic. The docs added in this PR scope the behavior to "the Apple XCUITest runner", so the behavior itself is intended; what is missing is any statement on the option (packages/contracts/src/interactor-types.ts:547) that it is runner-only, so a macOS caller gets a no-op flag.
Suggested change
Note on AlertInteractorOptions.explainAbsence that only the XCUITest runner honours it and the macOS helper ignores it.
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.
An `alert` refusal said only "alert not found", so a caller could not tell a quiet screen from a prompt this release does not recognise. `alert get` now reads one more snapshot when its absence is the answer, and names the dialog-like containers none of the alert rules match. - `AlertSurface.nearMisses` decides it in the package the host already replays: a compact placed container with two to four actions and copy of its own, never chrome, never a surface a source answers. The corpus records what it reports, and what it reports when a source's rule is dropped, so a rule that stops matching is a named near miss rather than a silent loss. - The extra read belongs to `alert get` alone: the runner takes it only for a request marked `explainAbsence`, which the daemon sets on the leg whose absence is the caller's answer. `wait`, `accept` and `dismiss` re-ask an absence and answer plainly. - The names travel as runner error `details`, which the host passes through to the caller's `error.details.nearMisses`; the runner cannot stamp `dispatched`.
a2b59db to
f1c0ef9
Compare
There was a problem hiding this comment.
Apex Sentinel: 5 new findings and 3 moved to a new line on f1c0ef9. The verdict and the full list are in the summary comment.
| import AgentDeviceSnapshotPresentation | ||
|
|
||
| extension RunnerTests { | ||
| /// The answer to an `alert` request that resolved nothing. With a whole read's budget left before |
There was a problem hiding this comment.
🆕 🔵 Nit · Near-miss read is admitted with exactly its own worst-case cost left, so its stated worst case trips MAIN_THREAD_TIMEOUT — the outcome the guard exists to prevent
alertAbsence starts the uncancelable ownerApp.snapshot() whenever deadline.timeIntervalSinceNow >= Self.nearMissReadAllowance (RunnerTests+AlertObservation.swift:5-13, allowance = 2.5 at line 30). The comment states the allowance is "what one tree read costs at worst on a contended host" and that "starting a read that cannot finish inside it would leave the block to be abandoned by the execution watchdog, which turns a refusal the caller can act on into MAIN_THREAD_TIMEOUT and a busy main thread for the commands behind it". The comparison admits the boundary case: with exactly 2.5 s of deadline left, the read is started even though its declared worst-case cost equals the whole remainder and lands at (or a hair past) the deadline. It also uses the same 2.5 s constant as both "what the read costs" and "what must remain", with no margin for the AlertSurface.nearMisses traversal itself, the alertSurfaceNode conversion of every snapshot node into AlertSurfaceNode, or the JSON encoding of the response. On top of that, the enclosing main-thread slice was armed back in executeDispatched with timeout: max(0.001, deadline.timeIntervalSinceNow) measured before resolveAlert ran (RunnerTests+CommandDispatch.swift:195-206), so the read's slice is the remainder of that block's own timeout, and the very condition the guard checks is the condition under which that block is closest to expiring. What breaks: an alert get on a contended host whose deadline has roughly the allowance left answers MAIN_THREAD_TIMEOUT (dispatched: unknown) with a busy main thread for the following commands, instead of the actionable ALERT_NOT_FOUND the caller would otherwise get — i.e. the failure mode the doc-comment promises to avoid, reached by the normal path rather than an exotic one.
| /// The answer to an `alert` request that resolved nothing. With a whole read's budget left before | |
| func alertAbsence( | |
| in ownerApp: XCUIApplication, | |
| deadline: Date, | |
| reading nearMissRead: () -> [RunnerAlertNearMiss] | |
| ) -> AlertAbsence { | |
| // Strictly more than one read's worst case must remain: a read that lands exactly on the | |
| // deadline is abandoned by the execution watchdog, which is the outcome this guard exists to | |
| // avoid, and the tree-to-node conversion and response encoding cost time after the snapshot. | |
| guard deadline.timeIntervalSinceNow > Self.nearMissReadAllowance + Self.nearMissReadMargin else { | |
| return .unexplained | |
| } | |
| let nearMisses = nearMissRead() | |
| return nearMisses.isEmpty ? .unexplained : .nearMisses(nearMisses) | |
| } |
Suggested change
Give the read budget a margin over the allowance (a separate nearMissReadMargin, or compare > against allowance plus margin), and state in the comment whether the 2.5 s covers the alertSurfaceNode conversion and response encoding or only the snapshot() call. The existing guard test uses allowance / 2 for the refused case and .distantFuture for the accepted one, so it does not pin the boundary either way and will not notice the fix.
Details
Also raised here
Also raised at this location by javascript: The near-miss read is an uncancellable inline snapshot guarded only by a hard-coded, unsourced 2.5s budget — alertAbsence starts ownerApp.snapshot() from inside the command's own main-thread block (executeOnMainSafely → executeOnMain → the .alert case at RunnerTests+CommandExecution.swift:620-631), not through runMainThreadWork. That block was already enqueued with timeout: max(0.001, deadline.timeIntervalSinceNow) (RunnerTests+CommandDispatch.swift:195-206), so nothing bounds the read once it starts: if the snapshot outlives the remaining slice, the watchdog abandons the block, MAIN_THREAD_TIMEOUT replaces the ALERT_NOT_FOUND the caller can act on, and the abandoned work makes the runner answer RUNNER_BUSY to the commands behind it — exactly the outcome the doc comment says the guard prevents. The guard bounds only the start time (deadline.timeIntervalSinceNow >= nearMissReadAllowance), never the read's duration, and the 2.5s figure is presented as "the figure alertActivationDeadline already budgets reads at". …
…and 1 more (swift-ios), left out to fit the comment.
persona: senior-developer, javascript, 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.
| }>; | ||
| }>; | ||
|
|
||
| /** |
There was a problem hiding this comment.
🆕 🔵 Nit · RUNNER_CLASSIFICATION_DETAIL_KEYS duplicates the classification detail keys by hand, so the anti-spoofing guard silently rots
readRunnerErrorDetails withholds the keys that classify a failure by deleting every name in RUNNER_CLASSIFICATION_DETAIL_KEYS (runner-contract.ts:370-375). That list is a hand-maintained readonly string[] that must equal the key set of RunnerReportedErrorClass['details'] (runnerErrorCode, retriable, reason, dispatched, runner-contract.ts:356-364), which buildRunnerResponseError spreads over the runner's diagnostics at line 462. Nothing ties the two together: the guard holds only while the two lists happen to match. The first time someone adds a classification key to RunnerReportedErrorClass.details (a retryAfterMs, a second disclosure field), classifyRunnerReportedError will publish it, but a runner payload carrying that key will already have stamped it into the caller's details and the new key will bypass the guard — the exact hole the array exists to close, with no compile error and no failing test to say so. The list is also string[] rather than keyof, so a typo in either list is invisible. Typing the array as readonly (keyof RunnerReportedErrorClass['details'])[] makes the invariant a compile-time one and keeps the deletion loop identical.
| /** | |
| const RUNNER_CLASSIFICATION_DETAIL_KEYS: readonly (keyof RunnerReportedErrorClass['details'])[] = [ | |
| 'dispatched', | |
| 'reason', | |
| 'retriable', | |
| 'runnerErrorCode', | |
| ]; |
Details
Also raised here
Also raised at this location by swift-ios: RUNNER_CLASSIFICATION_DETAIL_KEYS duplicates the classification detail shape and must be kept in sync by hand — In packages/apple-runner/src/runner-contract.ts, readRunnerErrorDetails strips the keys listed in RUNNER_CLASSIFICATION_DETAIL_KEYS (dispatched, reason, retriable, runnerErrorCode) from a runner-supplied details object before ...classification.details is spread over it, so a runner cannot stamp how its own failure is classified. The block-list and the shape of RunnerReportedErrorClass.details (the object built in classifyRunnerReportedError: runnerErrorCode, retriable, reason, dispatched) are two independent definitions of the same set. Nothing links them: if a maintainer adds a fifth classification field to classifyRunnerReportedError/RunnerReportedErrorClass and forgets to add it to the const, a runner payload carrying that key would leak through and be spread before/after the classification (for a key the classification does NOT set for a given code, e.g. reason on a code that has no reason entry, the runner's value survives). …
persona: senior-developer, 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.
| @@ -441,6 +458,7 @@ export function buildRunnerResponseError( | |||
| const classification = classifyRunnerReportedError(runnerErrorCode); | |||
There was a problem hiding this comment.
🆕 🔵 Nit · readRunnerErrorDetails lets a runner overwrite runner (and a non-string code) in the caller's details
buildRunnerResponseError now spreads the runner's own error.details object into the AppError details (packages/apple-runner/src/runner-contract.ts:461) after runner: payload and before xcodebuild. The new RUNNER_CLASSIFICATION_DETAIL_KEYS (366-375) blocks the four classification keys, but not the other keys of that same object literal: a runner that sends error: { code: 'ALERT_NOT_FOUND', details: { runner: 'x' } } replaces the raw runner payload in the caller's details, which the runner field exists to carry for diagnostics. Separately, readRunnerErrorCode (450-456) writes String(runnerErrorCode) into runnerErrorCode for a non-string code, while the unchanged sibling readRunnerHint (443-447) drops a non-string hint — a runner sending code: 5 now yields runnerErrorCode: '5' instead of undefined.
Suggested change
Add 'runner' and 'xcodebuild' to the keys stripped in readRunnerErrorDetails (or spread the diagnostics before runner:), and keep the non-string code case aligned with readRunnerHint.
Details
Also raised here
Also raised at this location by swift-ios: Runner error details are passed through with only a four-key blocklist; dispatchedSteps is not blocked — That function copies every key of the runner-supplied object and deletes only the four names in RUNNER_CLASSIFICATION_DETAIL_KEYS (dispatched, reason, retriable, runnerErrorCode). Every other key the runner puts in its error details therefore lands at the top of the caller's error.details. The blocklist covers the keys classifyRunnerReportedError writes, but the dispatch-disclosure machinery consumes another runner-visible key that is not in it: dispatchedSteps. detailsAfterDispatchedSteps/addDispatchedSteps (packages/kernel/src/errors.ts:673-692) read details.dispatchedSteps, add their own count to it and publish it as the number of device-reaching steps that ran. A runner payload carrying dispatchedSteps (the Swift side encodes ErrorDetailsPayload as an open JSON object, so a future field or a mis-named one reaches the host verbatim) would be added to by the daemon and reported to the caller as a step count it never performed. …
persona: maintainability, 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.
| _ = RunnerObjCExceptionCatcher.catchException { | ||
| guard let snapshot = try? ownerApp.snapshot(), !snapshot.children.isEmpty, | ||
| !snapshot.frame.isNull, !snapshot.frame.isEmpty else { return } | ||
| found = AlertSurface.nearMisses(in: alertSurfaceNode(snapshot), viewport: snapshot.frame) |
There was a problem hiding this comment.
🔵 Nit · The near-miss fields are hand-copied across three shapes; a new AlertSurfaceNearMiss field never reaches the wire
AlertSurfaceNearMiss (snapshot-presentation), RunnerAlertNearMiss (RunnerTests+Models.swift:603-608) and the test's RecordedAlertSurface.NearMiss all declare the same four fields, and the runner maps them one by one in nearMisses(in:) (RunnerTests+AlertObservation.swift:39-49). Adding a fifth field to AlertSurfaceNearMiss compiles, keeps AlertSurface.nearMisses and the corpus replay green, and is silently absent from error.details.nearMisses — the Models test that checks the encoded keys only reflects RunnerAlertNearMiss, so nothing catches the drift. Have AlertSurfaceNearMiss conform to Codable and encode it directly instead of restating it.
Suggested change
Make AlertSurfaceNearMiss Codable and encode it on the wire rather than mirroring its fields in a runner-local struct.
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.
|
|
||
| /// Part of the label XCTest gives a scroll indicator, "Vertical scroll bar, 8 pages", in every | ||
| /// recorded tree. It names no question, so it never becomes a container's prompt copy. | ||
| static let scrollBarNoise = "scroll bar" |
There was a problem hiding this comment.
🔵 Nit · nearMissMaxAreaRatio is a CGFloat in an otherwise CoreGraphics-free part of AlertSurface
nearMissMaxAreaRatio (AlertSurface.swift, added with nearMissMinButtons, nearMissMaxButtons and nearMissMaxReports, all Int) is declared CGFloat only so it reads as a dimensionless share in the area division below it. The file already hand-writes CGFloat elsewhere, but the other four tunables in the same block are plain Int; declaring it Double (Swift divides CGFloat by Double without the cast the other usages would need) or naming it nearMissMaxAreaShare makes it read as a ratio rather than a measurement.
Suggested change
Rename to a name that says it is a share, or type it Double so it groups with the other Int tunables beside it.
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.
| /// through an unnamed container. Reading only copy the buttons do not say, and none of it inside | ||
| /// an action, keeps out a web page's navigation cell, whose words are the link it wraps. The | ||
| /// caller has already refused the container to any source, so this checks the rest. | ||
| private static func nearMiss(in node: AlertSurfaceNode, hostWindow: CGRect) -> AlertSurfaceNearMiss? { |
There was a problem hiding this comment.
🆕 🔵 Nit · Near-miss scan recomputes subtree sets per node, making the read quadratic in tree size on the main thread
In apple/snapshot-presentation/.../AlertSurface.swift, collectNearMisses calls nearMiss(in:) for every node it descends into, and nearMiss recomputes subtreeTypes(of: node) plus actionableDescendants(of: node) (and, on success, textCopy) over the whole subtree of that node. For a node at depth d whose subtree has n descendants, the walk visits the same descendants once per ancestor, so the whole-tree scan is O(n·depth) with a Set allocation per node — quadratic in the worst case. The new corpus fixture iphone-duo-unfolded-safari-navigation-menu.json is exactly the input shape that hits this: a loaded Safari page with ~450 nodes, several of them (indices 61, 136, 243) ancestors of hundreds of descendants with a positive area ratio check that passes the cheap guards only late in nearMiss. This read runs inside the one snapshot() the runner allows itself 2.5s for (RunnerTests+AlertObservation.swift nearMissReadAllowance), and the comment there states that exceeding that budget turns the answer into MAIN_THREAD_TIMEOUT and leaves the main thread busy for the commands behind it. Compute the subtree type set and actionable-descendant list once per node bottom-up (or abort subtreeTypes/actionableDescendants as soon as the button cap or an excluded type is hit) so the scan is linear.
Suggested change
Fold the per-node subtree scans into one bottom-up pass (or short-circuit subtreeTypes/actionableDescendants at the first excluded type / past nearMissMaxButtons) so the near-miss walk stays linear in the tree, keeping the read inside nearMissReadAllowance.
Details
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.
| /// caller has already refused the container to any source, so this checks the rest. | ||
| private static func nearMiss(in node: AlertSurfaceNode, hostWindow: CGRect) -> AlertSurfaceNearMiss? { | ||
| if chromeTypes.contains(node.type) || actionableTypes.contains(node.type) { return nil } | ||
| guard isPlaced(node.frame, in: hostWindow) else { return nil } |
There was a problem hiding this comment.
🆕 🔵 Nit · Redundant area-ratio guard: the host-window area check can never fail after isPlaced
In AlertSurface.swift nearMiss(in:), the area check is written as if hostWindow.width * hostWindow.height > 0, ratio > nearMissMaxAreaRatio { return nil }. The preceding line already required isPlaced(node.frame, in: hostWindow), which requires SnapshotGeometry.isPositiveFinite(hostWindow) — i.e. a positive, finite width and height — so the > 0 conjunct is always true and the ratio is always computed. As written the code reads as though a zero-area host could skip the size check, which is not a state this function can be in; the guard hides that the size rule is unconditional. Drop the conjunct (or move the area rule above isPlaced if a zero-size host is meant to be tolerated).
| guard isPlaced(node.frame, in: hostWindow) else { return nil } | |
| guard isPlaced(node.frame, in: hostWindow) else { return nil } | |
| if node.frame.width * node.frame.height / (hostWindow.width * hostWindow.height) > nearMissMaxAreaRatio { | |
| return nil | |
| } |
Details
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.
| @@ -128,6 +128,7 @@ Alerts: | |||
| If alert says no alert but a sheet is visibly on screen, treat it as app-owned UI: | |||
There was a problem hiding this comment.
🔵 Nit · New help line restates the snapshot -i + press advice already two lines above, as one very long line
The new help line repeats the instruction two lines above it: the existing entry already says "If alert says no alert but a sheet is visibly on screen, treat it as app-owned UI: agent-device snapshot -i / agent-device press 'label="Allow"'", and the added line ends with "When a dialog is visible, run snapshot -i and press the button ref that snapshot returns." It is also one ~460-character run-on line where every other entry in debuggingHelpTopics is a short lead-in plus an indented command list, so it is the one line agent-device help will wrap across several screen lines. Keep only the new fact (nearMisses names an unrecognised dialog-like surface, and an empty nearMisses proves nothing) and drop the trailing restatement.
Suggested change
Trim the added help sentence to the new fact and let the entry above keep the snapshot -i + press instruction; break the remainder into short sentences on separate lines.
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.
|
Thanks for the update. At f1c0ef9 the code looks good to me, and I have no new findings. The read-admission guard and the "scroll bar" copy check from my earlier review (#4119 (comment)) are now fixed. CI is green at this commit: all 21 checks pass. I did not run swift test, the runner unit tests, or the pnpm checks myself. Test claims come from reading the code and the PR body. I also did not re-run the live device evidence, which the PR body describes at the earlier head a2b59db. The delta only tightens the read guard and wording, so I do not ask for a new live run. Whether 2.5 s covers every slow host is an empirical question (the traced worst read is 1.7 s, #2708), and I did not verify it. Three earlier inline threads are fixed at this head and can be resolved: the read-admission margin (#4119 (comment)), the "scroll bar" rejection (#4119 (comment)), and the help wording (#4119 (comment)). Three more do not apply and can also be resolved: the alert wait leg never forwards explainAbsence because snapshot-alert.ts:161 sets it only for get (#4119 (comment)); the near-miss scan still visits siblings after a hit (#4119 (comment)); and AlertSurface already uses CGRect and CGPoint, so the ratio adds no new dependency (#4119 (comment)). The remaining 12 open threads are small nits or residual risks, and none blocks merge. Please answer or resolve the open nits when you can. |
|
Closing as superseded. Instead of guessing which containers look like dialogs, iOS's own accessibility modality now decides what a prompt is ( |
Summary
alert getansweredALERT_NOT_FOUNDwhile a visible dialog was on screen: no alert rule matched its tree. Safari renders its "Open this page in ...?" prompt asSFDialogView, whose placement and copy iOS 27 changed.When
alert getanswers its own absence, the runner reads the tree once and names any dialog-like container no rule answers, aserror.details.nearMisses(type,identifier,label,buttons), capped at four. The rule is conservative: placed in its host box, not chrome, not near host size, no keyboard or system bar below it, 2-4 actionable descendants that each name themselves, and copy no button of its already says, read only outside actionable subtrees and never a scroll-indicator label. The read starts only while the deadline still has a read's budget left, so a slow refusal staysALERT_NOT_FOUNDrather than a main-thread timeout. Onlyalert getpays for the read.Validation
pnpm check:affected --run --head a2b59dbac7passed. 33 host Swift tests pass, and each guard test fails when its rule is removed — two cells with subtitles give no near miss, and the scroll-indicator label is refused in every shape it arrives in. Corpus: 6 fixtures in the new one-node-per-line format, 0 near misses with rules on; dropping Safari's rule namesSFDialogViewalone. Runner unit tests pass on iPhone Duo/27.0, including the read-budget guard.Live: rules off,
alert getnamesSFDialogView; rules on, it answers the prompt. A promo sheet is named; a suggestions panel and a loaded page report nonearMisses.