Repository navigation
fix(apple): use typed screenshot timeouts and observed shutdown recovery - #4544
Conversation
…oot on observed state The screenshot retry, the runner fallback and the skipped-boot-check recovery each decided from the tool's prose. `screenshot.ts` matched "timeout waiting for screen surfaces", a POSIX-domain string pair, and six spellings of a shutdown state, so any CoreSimulator wording change could silently retire all three decisions at once. `tool-provider.ts` is the one adapter that runs `xcrun simctl` itself, so it is the one place allowed to read simctl's error protocol. It takes the top-level header's `domain= NSPOSIXErrorDomain, code=60` and stamps `details.reason`; a nested `Underlying error` line, another domain or code, stdout, and a caller-supplied command or simctl callback stay unattributed. The reason is stamped, never host-kit's `timeoutMs`, which is that layer's own evidence that it killed a child at its deadline. Recovery now asks the tool what state the simulator is in. `simulator.ts` owns the one boot-state read and takes the caller's ceiling, so the probe runs under a 5s screenshot-owned budget instead of the 60s inventory budget. Only the literal `Shutdown` authorizes a boot: `Booted`, `Booting`, `Creating` and `Shutting Down` describe a simulator that is already on its way, and a listing that failed, omits the simulator, or names no state proves nothing. A canceled request is terminal and never reaches the probe; a probe that is itself canceled travels on; every other probe failure answers `false` and leaves the capture's own error, details and hint, as the reported failure. The boot memo policy is unchanged, so a simulator turned off outside this process is still not seen until the memo expires. Refs #4442
Size Report
Startup median (7 runs, lower is better):
|
|
Coverage is base-blocked at 855aa4a, before coverage thresholds: The same test, location and assertion already fail in unchanged-main CI at d78be6c8, with the same Node 24.13 and coverage command. The source and test are byte-identical between that base and this head. This PR's failed job is retained as failed. The fixture mocks |
|
Pushed the fixture correction as 50034fe. All existing identity, zombie, command, ordering and call-count assertions remain; the dedicated Linux Regression proof in an isolated simulated Linux process/filesystem boundary, with the original assertions unchanged: corrected fixture 21 passed; removing only the seven-line isolation 1 failed / 20 passed, at the exact PID-202 start-time/zombie assertion from the failed Coverage jobs; restored fixture 21 passed. The harness was removed and source hashes restored. This models the boundary; it is not a Linux-host run. One pinned pnpm 11.17.0 exact affected gate passed at 5003: Real Linux CI is now running on the pushed fix. The original 855a Coverage job remains failed; this was a source correction, not a retry of unchanged CI. The PR stays draft: native Shutdown recovery and the real code-60 header remain unproven. |
|
Thanks for the typed timeout work. At 855aa4a I found one likely regression in the new retry rule, and the live evidence the PR body says is missing is still missing.
This change rewires native screenshot retry, runner fallback and skipped-boot recovery on the local simulator route, and every test feeds hand-written stderr. If the typed reason never fires on real hardware, the retries disappear and the tests still pass. Please run once on an owned simulator. First, capture with Not blocking, take or leave: The Coverage failure looks unrelated: the diff only touches This review covers 855aa4a. The newer head 50034fe only adds a host-kit liveness test fixture, which does not touch the findings above and may address the Coverage failure. |
|
I own #4544 and am addressing this review. The preamble finding is accepted. Local commit The native requests remain open. The earlier ordinary Settings screenshot did not prove recovery or a real timeout header. I am checking a deterministic supported T3-bound route before another owned-simulator attempt, including whether a running batch can retain the session across T3 shutdown without admission booting first. I will attach actual command/probe/capture evidence and raw adapter stderr if reachable, and will not substitute scripted stderr for it. The separate Linux process-fixture correction is already pushed at |
|
The source trace corrected my earlier explanation: an open-session screenshot does not run daemon device readiness, so admission is not what blocked the previous attempt. That attempt still provides no recovery proof—the returned CLI file was removed before the screenshot could be sent. A supported route is now planned: start one bound Successful recovery currently discards the first error and records no probe state. I recorded the bounded observation decision to preserve the observed state, original stderr and a separate typed failure reason in the existing redacted diagnostics, plus retry-reason telemetry. This changes evidence, not recovery policy. The patch is prepared but remains unapplied while the current CEC gate owns the frozen checkout. It will be tested and reviewed before the native run. A natural non-60 failure will remain unstamped; I will not present it as code-60 evidence or close that request without evidence or a waiver. |
|
Pushed review-round changes at b0cc374 include: the PNG-stderr-preamble correction plus diagnostics needed to observe recovery. The parser matches the first unindented protocol header anywhere on stderr; nested/indented/stdout-only and earlier-unrelated-header controls remain. Removing Exact local validation: one pinned pnpm 11.17.0 affected gate at b0cc passed, One owned native run, 2026-11-14, iPhone 17 Pro / iOS 27.0, candidate daemon The already-running bound batch waited 15 seconds, then took a screenshot. T3 shutdown returned during the wait and removed the CLI file, but the running client/session survived. Batch exited 0: 2/2 steps, 45,726 ms, screenshot step 30,718 ms, within the 60-second work budget. The memo had expired: the control completed >30 seconds before the failing capture. Screenshot request
Actual failure diagnostic excerpt (existing redaction, bounds and outer-whitespace normalization apply; not byte-exact stderr): The event has The requested Shutdown → observed probe → one boot recovery → one re-capture → PNG sequence is proven. The real simctl code-60/stamped-reason or actual attempt>1 item remains unobserved, not resolved by fixtures. Please keep that item open, or explicitly confirm whether this native host-timeout proof plus the adapter protocol regression tests satisfies the review requirement; I will not force a timeout or fabricate native output. Cleanup verified: session closed with shutdown; private daemon stopped gracefully, PID gone; config/token/state removed; token scan clean; assigned simulator stopped and T3 open list empty. Pre-dispatch authentication/quoting mistakes were excluded from the one recovery attempt. The checkout is clean; no merge. |
|
This PR is ready at b0cc374: I found nothing that must change in the code. CI is green, with 0 of 18 checks failing, and the earlier Coverage failure is fixed by the host-process-liveness test isolation in this diff. There are no conflicts. No real simctl code 60 failure was observed, so the header format rests on scripted stderr and simctl's known format. If a real stall prints 'Timeout waiting for screen surfaces' under another domain, or with no header, it now ends the run and skips the retry and runner fallback. #4442 asks for that, but we do not know how often it happens, so a maintainer should accept this explicitly. Before merge, please take the PR out of draft and have a maintainer accept that gap. Not blocking, and fine to take or leave: (1) the fallback check at https://github.com/callstack/agent-device/blob/b0cc374/packages/platform-apple/src/core/screenshot.ts#L213 now also runs on errors from normalizeDensity, so a timeout in the scale probe picks the runner re-capture; should it only apply to the capture step's error? (2) The fake-xcrun tests, such as screenshot-simulator-capture.test.ts line 100, return a pre-stamped AppError, so they no longer prove stderr leads to a retry; screenshot-simctl-retry.test.ts covers that path. (3) The long design comments in screenshot.ts, simulator.ts, config.ts and the test fixtures could shrink to one line each. (4) The new test files overlap, since the retry-policy negatives repeat the protocol negatives and the protocol positives overlap the simctl-retry positives; could they fold into one table? |
|
Marked ready for review at b0cc374 after the clean review above. The existing CI completed green, and there are no inline review threads. Marking the PR ready started fresh iOS/macOS smoke checks and automated reviews; the existing watch stays active until they settle. The owned Shutdown recovery sequence is proven. A real simctl code-60 header/stamped reason or actual retry above attempt 1 remains unobserved; that gap still needs explicit maintainer acceptance before merge. The PR description now names this as a maintainer decision rather than a draft blocker. The optional cleanup suggestions remain optional. No merge was performed. |
There was a problem hiding this comment.
All reported issues were addressed across 15 files
You’re at about 91% of the monthly reviewed-line limit. You may want to disable incremental reviews to conserve quota. Reviews will continue until that limit is exceeded. If you need help avoiding interruptions, please contact contact@cubic.dev.
Reply with feedback, questions, or to request a fix.
View guided diff | Turn on auto-fix | Re-trigger cubic
Apex Sentinel · ✅ ApproveSince the last review: 1 new · 0 still open · 0 no longer raised 1 finding(s): 1 minor. 🟡 Minor (1)
1 finding below 💬 Talking to SentinelIn a finding's thread, reply with:
On this conversation, comment Earlier reviewsReview of
|
There was a problem hiding this comment.
Apex Sentinel: 1 new finding on d4bc055. The verdict and the full list are in the summary comment.
|
I found no problems in d4bc055. The earlier review of b0cc374 found none either, and the changes since then only touch screenshot diagnostics and tests in platform-apple. All 20 checks pass, and there are no conflicts. I read the new diagnostic assertions but did not re-run the focused test file or your mutation. I also did not trace the diagnostic redaction into the shared emit path, and I relied on the PR body for the native recovery run on #4442. A real simctl code-60 header, or a retry above attempt 1, is still unobserved on a device, as the PR body says. The fixed items are the The boot-memo thread still stands (#4544 (comment)). A capture that fails within 5s of the memo being seeded is probed as Shutdown, so the boot is skipped and the retry repeats the failure. The typed-timeout route outlives that memo, so I don't see it as blocking this PR. Before merge, the maintainer decides whether to accept that disclosed gap and the unobserved code-60 header. |
Summary
Fixes #4442. Recognize the first unindented simctl error header after diagnostics and recover skipped boot checks only from a fresh
Shutdownobservation capped at 5 seconds. Preserve capture and probe-failure diagnostics with consistent device fields.Changes 15 files. Scope expansion: isolate process fixtures from live Linux
/proc; retain assertions. The feedback correction narrows the scripted state-read matcher and clarifies API docs. Boot memo, capture/boot signal and provider-callback limitations remain disclosed.Validation
Base
d78be6c88715ad80fc658497f23f91c86bf9489b; headd4bc0556139fa4078b4a79a28b81fdb493655dbb.exactCommit=true,checkoutChanged=false,failOpen=false. Eight checks passed; full unit 19,835 passed/10 skipped, related 377 passed. Provider integration deduplicated; coverage/replay checks skipped.