Skip to content

Resume escalation tests through an actor so Thread Sanitizer sees the ordering - #107

Merged
dfed merged 1 commit into
mainfrom
claude/project-thread-lm3hgq
Nov 23, 2026
Merged

dfed merged 1 commit into
mainfrom
claude/project-thread-lm3hgq

Conversation

@dfed

@dfed dfed commented Nov 23, 2026

Copy link
Copy Markdown
Owner

Requested by Dan · project thread

Summary

The weekly scheduled CI run on main (run 45111712457) failed Thread Sanitizer on macOS. All 205 tests passed, but TSan reported a data race:

  • write in ManualTaskExecutor.runUntil(_:) on the test task's thread
  • previous read in UnsafeContinuation.resume() on the escalateWaitingTask dispatch thread, in cancelTasks_fifoQueue_whileTaskWaitingForItsTurnIsEscalated_escalatesTaskHoldingTurnWithoutWaitingForCancellationHandler

The test task can't reach runUntil(_:) until it has been resumed, so the code is correctly ordered. Most likely the dispatch thread resumed the continuation before the test task suspended on it. The task then keeps running without going through an executor, and that's where the runtime may not report the ordering to TSan. The race window is narrow, so this shows up only rarely.

This PR changes test code only. Both tests that used this pattern now wait on the test Semaphore actor:

  • the CancellableQueue test above
  • TurnsTests.begin_whenWaitingTaskIsEscalatedWhileTaskHoldingTurnRunsCancellationHandler_escalatesTaskHoldingTurnWithoutWaitingForHandler

The dispatch thread signals the semaphore from a new task after it escalates the waiting task. The semaphore resumes the test only after the test has suspended, and that resume goes through the runtime's annotated enqueue path. The order of the escalation and the cancellation is the same as before.

Testing

I couldn't build these changes in my container because it can't download a Swift toolchain, so this PR's CI is the first build and run. The race window was narrow and never reproduced on demand, so no test can show this fix failing 10 of 10 runs before it.


Generated by Claude Code

… ordering

Two tests resumed an unsafe continuation from a dispatch thread. When the
thread resumed it before the test suspended, Thread Sanitizer on macOS
missed that the thread's work happened before the test continued, and
reported a data race in ManualTaskExecutor.runUntil(_:) on the weekly CI
run. The tests now wait on the test Semaphore actor, which the dispatch
thread signals from a new task.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01HLuVQLVigABunsyxAFtbwu
@dfed dfed self-assigned this Nov 23, 2026
@codecov

codecov Bot commented Nov 23, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (c65d55b) to head (8276b3d).

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff            @@
##              main      #107   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           15        15           
  Lines         3714      3722    +8     
=========================================
+ Hits          3714      3722    +8     
Files with missing lines Coverage Δ
Tests/AsyncQueueTests/CancellableQueueTests.swift 100.00% <100.00%> (ø)
Tests/AsyncQueueTests/TurnsTests.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
dfed merged commit 928bec7 into main Nov 23, 2026
15 checks passed
@dfed
dfed deleted the claude/project-thread-lm3hgq branch November 23, 2026 18:13
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