Skip to content

Run Thread Sanitizer on macOS, test on iOS 18, and run each test once - #99

Merged
dfed merged 5 commits into
claude/2.0-11-actor-queue-priorityfrom
claude/2.0-12-ci
Nov 17, 2026
Merged

dfed merged 5 commits into
claude/2.0-11-actor-queue-priorityfrom
claude/2.0-12-ci

Conversation

@dfed

@dfed dfed commented Nov 16, 2026 •

Copy link
Copy Markdown
Owner

Summary

This PR adds two kinds of CI coverage, changes how often the simulator jobs run the tests, and removes the last DispatchQueue used as a lock, in the tests' manual executors. It also keeps test results and crash reports when a test job fails.

Run Thread Sanitizer on macOS. No CI job ran Thread Sanitizer. On Linux it flags Synchronization.Mutex whenever two threads contend for it, because it can't see the lock's slow path in the prebuilt standard library, so a Linux job would fail on most runs: 8 of 9 trial runs reported races, all in code that Mutex guards. A new job, "Thread Sanitizer on macOS", builds the tests with --sanitize=thread on the xcode-27 runner with Xcode 27.2 and runs them. Thread Sanitizer makes the process exit with an error when it reports a data race, so a race fails the job. In three trial runs it took about 1.5 minutes and reported nothing. Like the other jobs that run tests outside a simulator, it stops after 15 minutes.

Test on the iOS 18 simulator. The package supports iOS 18, but CI tested only on iOS 27.2. Two new jobs test on iOS 18.5 with Xcode 27.2:

  • "Copy Minimum iOS Simulator" runs on macos-15, which has iOS 18.5 (build 22F77) installed as a disk image. Scripts/copy-ios-18-simulator.sh finds the image with xcrun simctl runtime list -j and copies it. The job uploads it as an artifact of about 9.1 GB, without compression and kept for one day.
  • "Build Xcode Minimum iOS" runs on xcode-27 once the first job is done. It downloads the image, and Scripts/install-ios-18-simulator.sh installs it and creates an iPad (10th generation) on iOS 18.5. A new iOS18 platform in Scripts/build.swift then runs the tests on that iPad, and the job uploads coverage like the other simulator jobs. Its derived data goes to .build/derivedData/iOS18, which Scripts/prepare-coverage-reports.sh picks up like any other platform's.

In trial runs, the copy took 28 s, the upload about 3 minutes, the download 2 to 9.5 minutes, and installing, building, and testing about 4 minutes. So the two jobs together take about 10 to 17 minutes, and they run alongside the other jobs. The test job has the 50-minute timeout of the other simulator jobs, and the copy job stops after 15 minutes.

Run each test once and require deterministic tests. The simulator jobs ran the suite up to 100 times and stopped at the first failure. Scripts/build.swift no longer passes -test-iterations 100 or -run-tests-until-failure, so they run it once. A new CLAUDE.md records the rule that replaces the repetition: every test must be deterministic, passing every run on correct code and failing every run, or hanging until the job's timeout, on the regression it guards. Tests force interleavings with semaphores, manual executors, and test hooks, never with sleeps, wall-clock timeouts, polling, or repetition. CLAUDE.md also records the package's other rules: 100% code coverage, which codecov.yml sets; never cancel, resume, or escalate a task while holding a lock, including the runtime's own lock on a task while it runs the task's handlers; prefer faster code over shorter code on the path that enqueues a task; guard is fine, but an early return from an if without an else is not; and documentation in the plain style of The Swift Programming Language's chapter on concurrency.

Run the manual executors' jobs without a dispatch queue. ManualTaskExecutor and ManualSerialExecutor in the tests wrapped runUntilIdle() in DispatchQueue.sync on a private serial queue, which used the queue as a lock. No test calls runUntilIdle() on one executor from two threads at once, or from a job that the executor runs, so neither a dispatch queue nor a Mutex is needed. The jobs still run synchronously on the calling thread, as DispatchQueue.sync ran them, and the doc comments now say to call runUntilIdle() from one task at a time and never from one of the executor's own jobs. Test-only; the suite's wall time is unchanged within noise.

Upload test results and crash reports when a test job fails. An iOS test process on #96 died without a message, and the job kept nothing that showed why. When a job fails, the two xcodebuild jobs now upload their result bundles (.build/derivedData/*/Logs/Test/*.xcresult) and the crash reports in ~/Library/Logs/DiagnosticReports/*.ips, and the "Swift Build Xcode" and Thread Sanitizer jobs upload the crash reports. Each upload is named after its job, is kept for 7 days, and uploads nothing when there are no files. A job that hits its time limit is cancelled rather than failed, so it uploads nothing, but a hang leaves no crash report anyway.

Why the iOS 18 jobs work this way

Each step works around something that failed in the trial runs:

  • The test job can't download iOS 18. On Xcode 27, xcodebuild -downloadPlatform iOS -buildVersion 22F77 fails with "iOS 22F77 is not available for download", and the xcode-27 runner has no older Xcode. So the image comes from the macos-15 runner.
  • Exporting the runtime on macos-15 fails at random. xcodebuild -downloadPlatform iOS -buildVersion 22F77 -exportPath with Xcode 26.1.1 wrote the disk image, then exited with code 70 after "Unable to connect to simulator." The copy job copies the disk image that is already on the runner instead.
  • The xcode-27 runner's disk is too full. The runner holds about 69 GB of simulator runtimes, and adding the image failed with "Cannot copy the image because the disk is almost full". The install script deletes every runtime except the 27.2 runtime of each platform, and also the iPhone-only iOS 27.2 runtime (build 24B91016s). It then waits until no runtime is still being deleted.
  • Adding the runtime. The script adds the image with sudo xcodebuild -importPlatform, and with sudo xcrun simctl runtime add if Xcode still lists no iOS 18 runtime afterward. It also builds the runtime's dyld shared cache before the simulator first boots.

What the iOS 18 job covers

In the trial run, the suite passed on iOS 18.5, and Swift Testing skipped the 29 tests that need iOS 26 with "Requires iOS 26". So the job runs every test that doesn't need iOS 26.

It is the first CI job that runs the queues on an OS without priority escalation. Before iOS 26, Turns takes its #available fallback path: a task waits for its turn without escalating the task ahead of it, and Turn.register(_:) registers nothing. Until now, tests reached that path only through Turns(escalatesPriority: false), and no queue's tests ran on it.

This PR adds no tvOS 18, watchOS 11, or visionOS 2 jobs. macos-15 has those runtimes installed too, so the same approach should work for each, but each would be another pair of jobs moving about 9 GB, and iOS matters most.

The remaining loop tests

A few older tests loop to make a bad interleaving more likely, because no deterministic test yet catches what they catch: the sendsEventsInOrder tests, the executesAsyncBlocksAtomically tests, and task_isNotReentrant and throwingTask_isNotReentrant. They stay as backstops. Each simulator job now runs them once instead of up to 100 times, so they are less likely to catch a rare bad interleaving on a simulator. CLAUDE.md says to delete such a test only once a deterministic test fails 10 of 10 runs for every bug it catches.

Validation

Locally, on Linux: ci.yml parses as YAML, actionlint 1.7.12 reports nothing beyond the custom xcode-27 runner label it doesn't know, the upload paths match what Scripts/build.swift writes and what @actions/glob matches, both scripts pass zsh -n, Scripts/build.swift type-checks with Swift 6.4.2, and swiftformat --lint is clean. Both scripts were also run against stand-ins for xcrun and sudo, to check which runtimes they delete, when they fall back to simctl runtime add, and that they fail when no image or runtime is found.

The jobs themselves were proven in the draft spike, #98, with these differences that CI will check for the first time:

  • The upload and download actions are actions/upload-artifact@v7 and actions/download-artifact@v8, their latest major versions. The spike used v4, which prints a Node 20 deprecation warning.
  • The copy job uses the runner's default Xcode to list the runtimes. The spike selected Xcode 26.1.1 for the export it no longer does.
  • The test job runs the tests through Scripts/build.swift with a destination of platform=iOS Simulator,OS=18.5,name=iPad (10th generation) and code coverage on. The spike passed the new device's ID straight to xcodebuild.

Series

This is stacked on #97, the top of the 2.0 series. The spike that measured these jobs was draft PR #98.

🤖 Generated with Claude Code

https://claude.ai/code/session_01HLuVQLsTNvRnyh155N25UM

@codecov

codecov Bot commented Nov 16, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (70d113b) to head (2bf44ae).

Additional details and impacted files

Impacted file tree graph

@@                         Coverage Diff                          @@
##           claude/2.0-11-actor-queue-priority       #99   +/-   ##
====================================================================
  Coverage                              100.00%   100.00%           
====================================================================
  Files                                      15        15           
  Lines                                    3294      3290    -4     
====================================================================
- Hits                                     3294      3290    -4     
Files with missing lines Coverage Δ
...ts/AsyncQueueTests/Utilities/ManualExecutors.swift 100.00% <100.00%> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

dfed commented Nov 16, 2026

Copy link
Copy Markdown
Owner Author

Build Xcode (visionOS) failed on 6bf50d5 before any test ran. The build succeeded, but the Apple Vision Pro simulator never finished booting:

xctest encountered an error (Failed to establish communication with the test runner. (Underlying Error: Timed out waiting 120 seconds for simulator to boot, current state is 1.))

State 1 is "Booting". The log has no test output, so this commit's code never ran on visionOS. Every other job on this commit has passed, including iOS/watchOS, macOS/tvOS and Thread Sanitizer on macOS; Build Xcode Minimum iOS is still queued. The new upload step worked: it saved xcode-test-results-visionOS with the result bundle. I'll re-run the visionOS job once when the run finishes.


Generated by Claude Code

@dfed
dfed added this pull request to stack #103 November 16, 2026 21:42

dfed commented Nov 16, 2026 •

Copy link
Copy Markdown
Owner Author

Correction: the CodeQL Swift failure I reported here is fixed by 9a40bac on #88, which builds without SwiftPM's sandbox under CodeQL, and this PR now sits on top of it. I was wrong that it needed a decision. See the corrected comment on #88.


Generated by Claude Code

No CI job ran Thread Sanitizer. On Linux it flags
`Synchronization.Mutex` even in correct code, so a Linux job would
fail on every run. A new job on the xcode-27 runner builds the tests
with Thread Sanitizer and runs them on macOS instead. When Thread
Sanitizer reports a data race, the test run exits with an error and
the job fails. In three trial runs on GitHub's runners the job took
about a minute and a half and reported nothing.

Like the other jobs that run the tests outside a simulator, it stops
after 15 minutes so that a deadlocked test can't hold the runner for
GitHub's six-hour default.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01HLuVQLsTNvRnyh155N25UM
The package supports iOS 18, but CI tested only on the iOS 27.2
simulator. Before iOS 26, a queue's tasks wait for their turns without
escalating priority. Tests reached that path in `Turns` only through
`Turns(escalatesPriority: false)`, and no queue's tests ran on it.

Xcode 27 can't download the iOS 18 simulator runtime:
`xcodebuild -downloadPlatform iOS -buildVersion 22F77` fails with
"iOS 22F77 is not available for download". The `macos-15` runner has
iOS 18.5 installed as a disk image, so a new job there copies the image
and uploads it as an artifact. Exporting the runtime with
`xcodebuild -downloadPlatform -exportPath` instead fails at random with
"Unable to connect to simulator."

A second job, on the `xcode-27` runner, downloads the image and
installs it. Adding the 9 GB image to the runner's simulator runtimes
fails with "Cannot copy the image because the disk is almost full", so
it first deletes every runtime but the 27.2 runtime of each platform.
It then creates an iPad (10th generation) on iOS 18.5, and runs and
uploads coverage for the tests there with Xcode 27.2, like the other
simulator jobs. Tests that need iOS 26 are skipped. The two scripts in
Scripts/ explain each step.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01HLuVQLsTNvRnyh155N25UM
The simulator jobs ran the suite up to 100 times and stopped at the
first failure, so that a test which fails only on some interleavings
had more chances to fail. Every test should instead give the same
result on every run: pass every run on correct code, and fail every
run, or hang until the job's timeout, on the regression it guards. The
simulator jobs now run the suite once, which also makes them shorter.

A new CLAUDE.md records that rule for people and agents working on the
package: force interleavings with semaphores, manual executors, and
test hooks, never with sleeps, wall-clock timeouts, polling, or
repetition. It names the few older loop tests that stay as backstops
until a deterministic test fails 10 of 10 runs for every bug each
catches. It also records the package's other rules: 100% code
coverage; never cancel, resume, or escalate a task while holding a
lock, including the runtime's own lock on a task while it runs the
task's handlers; faster code over shorter code on the path that
enqueues a task; `guard` but no early return from an `if` without an
`else`; and documentation in the plain style of The Swift Programming
Language.

Those loop tests now get one run per simulator job instead of up to
100, so they are less likely to catch a rare bad interleaving there.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01HLuVQLsTNvRnyh155N25UM
ManualTaskExecutor and ManualSerialExecutor ran their jobs inside
`DispatchQueue.sync` on a private serial queue, which only serialized
calls to `runUntilIdle()`. No test needs that. Each test makes its own
executors, and calls `runUntilIdle()` from its own task, one call after
another. No job calls `runUntilIdle()` on the executor that runs it.

So run the jobs directly on the calling thread, as `DispatchQueue.sync`
already did, and say in the documentation comments that a test calls
`runUntilIdle()` from one task at a time.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01HLuVQLsTNvRnyh155N25UM
A test process that crashes, such as one in a simulator, fails the job
without saying why in the log. When the Xcode jobs fail, upload the
result bundles that xcodebuild writes under .build/derivedData and the
crash reports in ~/Library/Logs/DiagnosticReports. When the macOS
swift test jobs fail, upload the crash reports. The artifacts expire
after 7 days.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01HLuVQLsTNvRnyh155N25UM
@dfed
dfed merged commit 5ff438e into main Nov 17, 2026
19 of 28 checks passed
@dfed
dfed deleted the claude/2.0-12-ci branch November 17, 2026 02:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants