Repository navigation
Run FIFOQueue operations in the task returned to the caller - #92
Merged
dfed merged 1 commit intoNov 17, 2026
Merged
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## claude/2.0-6-actor-queue-turns #92 +/- ##
=================================================================
Coverage 100.00% 100.00%
=================================================================
Files 14 12 -2
Lines 1739 1865 +126
=================================================================
+ Hits 1739 1865 +126
🚀 New features to boost your workflow:
|
dfed
commented
Nov 14, 2026
dfed
force-pushed
the
claude/2.0-7-fifo-queue-turns
branch
2 times, most recently
from
November 14, 2026 07:30
071e02d to
319308a
Compare
dfed
force-pushed
the
claude/2.0-7-fifo-queue-turns
branch
from
November 15, 2026 15:45
319308a to
1f23244
Compare
dfed
force-pushed
the
claude/2.0-7-fifo-queue-turns
branch
from
November 16, 2026 11:40
1f23244 to
601ea69
Compare
Owner
Author
|
Correction: I was wrong that this needed a decision. What happened, for the record. On
From that warning and GitHub's changelog for 2026-10-19, I concluded CodeQL couldn't analyze this package at all. That was wrong: the error came from SwiftPM's sandbox, and building without the sandbox avoids it. Generated by Claude Code |
Previously each operation ran in a task created by the queue's detached drain loop, and the returned task waited on a continuation for the result. As a result: - Operations never saw the caller's task-local values. - Operations ran at the drain loop's priority rather than the caller's, and three of the four `Task(on:)` initializers dropped `priority` from the returned task. - Awaiting the returned task did not escalate the operation. Now each `Task(on:)` runs its operation in the task it returns, so task-local values, priority, escalation, and cancellation behave as they do for `Task`. Tasks take turns in the order in which they are enqueued: each waits for its predecessor to finish, runs, and then lets its successor begin. A queue's priority is now a floor: a task enqueued with, or from a context with, a lower priority executes at the queue's priority. The comparison uses the priority `Task` would give the new task: the enqueuing task's base priority, ignoring escalation, or outside of a task the thread's priority, which defaults to `.medium`; an inherited user-interactive priority is lowered to user-initiated, and a priority with a raw value of zero counts as no priority. A queue without a priority no longer raises every task to the drain loop's priority. The queue's `name` named the drain task, which no longer exists, so `FIFOQueue(name:priority:)` is removed in favor of `FIFOQueue(priority:)`. Its doc comment is reworded to say plainly which priority each task runs at. `Delivery` is no longer used, so it and its tests are deleted. `Semaphore` is now used only by tests, so it moves to the test target. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01HLuVQLsTNvRnyh155N25UM
dfed
force-pushed
the
claude/2.0-7-fifo-queue-turns
branch
from
November 16, 2026 23:40
601ea69 to
a442493
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
FIFOQueuegets the same redesign asActorQueuein #91. Previously each operation ran in a task created by the queue's detached drain loop, so:Task(on:)initializers droppedpriorityfrom the returned task.Now the returned task waits its turn, runs the operation, and lets its successor begin. Tasks still begin and end in enqueue order.
A queue's priority is now a floor. A task enqueued with, or from a context with, a lower priority runs at the queue's priority. The comparison uses the priority
Taskitself would give the new task:.mediumif the thread has none.A queue without a priority no longer raises every task to
.medium.FIFOQueue(name:priority:)is removed in favor ofFIFOQueue(priority:): the name labeled the drain task, which no longer exists. TheFIFOQueue(priority:)doc comment is reworded to say plainly which priority each task runs at.Deliveryand its tests are deleted, andSemaphoremoves to the test target.This series' own
guardstatements are restored. The review round that removed early returns had rewritten them too, but as clarified since,guardis fine: only an early return from anifwithout anelseis avoided. Here that is theguardinpriorityOfNewTask(enqueuedWith:)for an inherited priority with a raw value of zero, which the previous revision had written as anif/else. Theifstatements inpriority(forTaskEnqueuedWith:)andpriorityOfNewTask(enqueuedWith:)keep theirelse. Behavior is unchanged.Tests
These fail on the parent and pass here:
task_,throwingTask_,taskIsolatedTo_andthrowingTaskIsolatedTo_holdsTurnUntilItsOperationReturnscheck through a probe turn that the next turn cannot begin while an operation is still running, andthrowingTask_andthrowingTaskIsolatedTo_whenOperationThrows_allowsNextTaskToBeginthat a throwing operation still ends its turn.FIFOQueueandCancellableQueueoverload.main's FIFO ordering loops (sendsEventsInOrder), the fourexecutesAsyncBlocksAtomicallytests andtask_/throwingTask_isNotReentrantstay: they are the only guard for aTask(on:)initializer that skipsawait turn.begin()and for a task enqueued from a task already running on the same queue.taskIsolatedTo_isNotReentrantandthrowingTaskIsolatedTo_isNotReentrantare deleted: tasks isolated to the same actor are serialized by that actor, so they could not observe a reentrant turn, and every bug they caught at any rate fails a remaining test 10 of 10 times.SemaphoreTestscover the test-onlySemaphore, which moves here. Five new tests run each waiter as a task on aManualTaskExecutor, so once a test has run the executor until it is idle, every waiter has either returned fromwait()or is suspended in it:signal_whenSignalCallsReachSuspendedWaitCalls_resumesEveryWaiterAtOnce(3 waiters) andsignal_whenSignalCallsReachAThousandSuspendedWaitCalls_resumesEveryWaiterAtOnce(1,000 waiters) check, after everysignal(), that no waiter resumes until the signals match the waits and that then every waiter resumes, and checkisWaitingalong the way;wait_whenPrecededByFewerSignalCalls_suspendsOnlyTheUnmatchedWaitchecks whatwait()returns when earlier signals match some of the waits;wait_afterEveryWaiterResumed_suspendsUntilSignaledAgainruns a second round of waiters;wait_whenSignalCallIsEnqueuedBehindIt_resumesenqueues a signal behind a waiter on the same executor, which catches a lost wakeup betweenwait()'s decrement and its storing its continuation.Against 30 mutants of
Semaphore, every mutant but one fails at least one new test 10 of 10 runs, 3 of them pinned to one CPU; one of those kills (a mutant that resumes continuations twice) is a crash. The survivor resumes waiters in reverse order. No test catches it, including the two older tests, andSemaphorepromises no order. The olderwait_suspendsUntilEqualNumberOfSignalCalls(1,000 waiters and a yield loop) andwait_doesNotSuspendIfSignalCalledFirstare therefore deleted, along with theSemaphoreextension and counter that only they used: they catch no mutant that the new tests miss. With them gone, no line ofSemaphoreorSemaphoreTestsreads zero in the Linux job's coverage steps.signal()'s doc comment now says that it resumes every waiting task once the count is zero or more, rather than "a waiting thread".Per-task cost is roughly 25 µs → 4 µs on Linux (noisy; release build).
Series
PR 8 of 10. It is stacked on #91.
Validation
Each commit in the series was validated on its own, on Linux with Swift 6.4.2, from a
git archivecopy:-warnings-as-errors, andswiftformat --lintis clean.ci.ymlunderbash -e, pass, including the atomic-counter check. No line inSourcesorTestsreads zero in the CI run.SemaphoreTeststest passes 10 of 10 runs (3 pinned to one CPU) on the real code and--repetitions 100 --repeat-until failunpinned and pinned; the mutant results are under Tests. The restoredguardinpriorityOfNewTask(enqueuedWith:)was rechecked: returning the raw-zero inherited priority instead of.mediumfailstask_onQueueWithPriority_enqueuedOutsideOfAnyTask_executesAtHigherOfNewTaskAndQueuePriority10 of 10 runs, as it did against theif/elseform. Earlier rounds checked the other tests against mutants the same way.Synchronization.Mutexeven in trivially correct code, so the TSan runs replaceMutexwith a pthread-based lock that TSan understands.Nothing was run on Apple platforms. CI is the first run there.
Review checklist
Left for code review because no test can force them:
Signal.waitmust checkisFiredand store its continuation in onewithLock,firemust setisFiredand take the waiter in one, andTurns.reservemust read and replace the last turn's signal in one. No test can force a thread switch inside one.FIFOQueueinitializer awaitsturn.begin(). A missingawait turn.begin()in one initializer fails only the probabilisticexecutesAsyncBlocksAtomicallyloop for that initializer (10 of 10 runs in our checks, including pinned to one CPU). Testing it deterministically would need a production change (shared functions, a begun-turn token or an executor seam), and each of those measured slower per task, so the code keeps the inlineawait turn.begin()and review covers this.SemaphoreTestsnow run their waiters on aManualTaskExecutorthroughTask(executorPreference:); nothing was built under Xcode. CI is the first run there.🤖 Generated with Claude Code
https://claude.ai/code/session_01HLuVQLsTNvRnyh155N25UM