ci: abort an app-host shard once its restart budget is spent
When the XCTest app host crashes, xcodebuild prints Restarting after unexpected exit, crash, or test timeout; summary will include totals from previous launches. and relaunches it, resuming the run. Nothing bounds that loop: a restarting host keeps producing output, so the 1200s idle timeout never fires, and the 1800s per-batch cap and the job's timeout-minutes: 75 are the only stops. A crash-looping shard therefore held one of roughly ten Blacksmith macOS concurrency slots for up to 75 minutes and still failed. In the 24h ending 2026-09-22T16:10Z, app-host unit tests spent 6,705 of 18,704 macOS runner minutes (35.8%) across 384 failing shard jobs and 2 successes, which is the direct cause of the 36-deep macOS queue (#13707).
That wall clock was already lost work. Any restart makes the run non-ratchetable in app_host_result_accounting.run_is_complete, the accounting added in #7471 because restarts lost the failure summary. Once the marker appears, resuming could not have produced a passing verdict.
Resulting behavior
scripts/ci/xcodebuild_noninteractive.py counts restart markers on the PTY output it already streams. Once the count exceeds CMUX_XCODEBUILD_NONINTERACTIVE_RESTART_BUDGET it terminates the xcodebuild process group and exits 123, after printing:
Aborted by the app-host restart budget: xcodebuild restarted the app host N times (budget M) after unexpected exits, crashes, or test timeouts. The shard was stopped here so a crash loop cannot hold a macOS runner to the job timeout; a restarted run is already non-ratchetable, so resuming it could not have produced a passing verdict. This abort is a CI capacity guard, not a test verdict: the failure to investigate is the app-host crash above it.
scripts/ci/run-app-host-xcodebuild.sh treats 123 as non-retryable, so the wrapper's 3-attempt backstop cannot replay the loop, and defaults the budget to 2 for every app-host invocation including the focused gates. ci-macos.yml sets it explicitly on app-host-unit-tests, next to the other timeout knobs, with the capacity rationale.
Nothing else changes: the batch still runs app_host_result_accounting.py check-run over the typed xcresults, the second logical batch still runs, no test is deleted or skipped, and timeout-minutes stays 75 as the backstop for non-crash hangs.
Why a restart budget and not a wall clock
The budget keys on crash evidence, not duration, so a slow-but-healthy shard cannot become flaky no matter how long it runs. The measured 7.55-minute median of the Run unit tests step across 60 failing shards and the observed 40-plus-minute crash-looping shards are not separable by a duration threshold at a safe margin, so lowering timeout-minutes or the step's wall-clock bound would buy capacity by killing slow-but-healthy shards. The margin here is in restarts instead: a healthy shard restarts zero times, the existing CMUX_UNIT_TEST_TIMEOUT_SECONDS comment budgets wall time for one, and the abort fires on the third. A shard must crash three times in one invocation to be stopped.
Validation
Two commits, so CI shows the guard catching the bug: 3d636a4 adds the failing test, ad610ae adds the fix.
Locally, with the fix reverted and the tests kept:
### tests/test_ci_xcodebuild_noninteractive_helper.py (no fix)
FAIL: the helper resumed a restarting app host instead of aborting it once the restart budget was spent
exit=1
### tests/test_ci_app_host_xcodebuild_retry.sh (no fix)
Idle timed out after 60s (no test progress; app-host log lines do not count): xcodebuild test ...
Preserving app-host failure from attempt 1; retry blocked after test execution evidence
FAIL: expected restart-budget abort status 123, got 124
exit=1
The second failure is the current production behavior in miniature: the crash loop is only stopped by the idle timeout, standing in for the 1200s one.
With the fix restored:
PASS: xcodebuild noninteractive helper dismisses crash prompts, heartbeats quiet children, idle-times out stuck children, and aborts an app-host crash loop once its restart budget is spent
PASS: app-host xcodebuild wrapper retries only before test execution, and aborts a crash loop without retrying
The new coverage also pins the two cases that must stay unaffected: a run that spends its restart headroom and finishes keeps exit 0, and a run that never restarts is never bounded by the budget. Marker counting is exercised across the helper's 4096-byte read boundary so a split marker is counted once.
I ran every guard-test invocation in ci-guards.yml (124 commands) against this branch: 119 pass. The 5 failures are test_check_ghostty_zig_workflows.py (no bashlex), test_dev_fleet_warm_slot.py (load-sensitive), test_ios_testflight_assignment_after_upload.py (file not in the tree), test_ci_nightly_prune_python_compat.sh (no python3.9), and test_ghostty_zig_version_sync.sh (no ghostty submodule). All five fail identically on pristine origin/main, so none are caused by this change. shellcheck -S warning is clean on both modified shell scripts and ci-macos.yml parses.
No guard test needed a workflow-string update: the added env: key is not pinned by test_ci_cmux_unit_test_shard.py (which matches CMUX_APP_HOST_* only), and no if: condition or step name changed, so test_ci_app_host_guard_structure.py and test_ci_self_hosted_guard.sh are untouched.
Remaining gap
The budget only bounds crash loops. A shard that hangs without restarting is still bounded by the 1200s idle timeout and the 75-minute job cap, and this change does nothing about why the app host crashes; the census in scripts/ci/app_host_failure_census.py remains the path to that. Unverified on real macOS hardware: the abort path is covered by the mocked wrapper guard, not by a live crash-looping shard.
๐ค Generated with Claude Code
Need help on this PR? Tag @codesmith-bot with what you need. Autofix is disabled.
Summary by cubic
When an XCTest app host crashes, xcodebuild relaunches it and resumes the run, with nothing bounding that loop โ a crash-looping shard held a macOS runner to the 75-minute job timeout and still failed, consuming 6,705 of 18,704 macOS runner minutes in one day (#13707). This bounds the loop by aborting the shard once its restart budget is spent.
xcodebuild_noninteractive.pycounts app-host restart markers on the output it already streams and exits 123 once the budget is spent;run-app-host-xcodebuild.shtreats 123 as non-retryable, so the wrapper's 3-attempt backstop can't replay a crash loop.- The budget defaults to 2 and keys on crash evidence, not wall clock, so a slow-but-healthy shard is never bounded โ a shard must crash three times in one invocation to be stopped.
- A restarted run is already non-ratchetable (#7471), so resuming can't produce a passing verdict; accounting is unchanged and no test is deleted or skipped.
- Coverage pins that a run spending its headroom and finishing keeps exit 0, and a never-restarting run is never bounded, including a marker split across the 4096-byte read boundary.