Repository navigation
Add selectable channels for orchestration coroutines - #191
andystaples wants to merge 3 commits into
Conversation
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
🟡 Changes recommended
Channel handling has unresolved quadratic performance issues: unnecessary wakeups repeatedly resume blocked waiters, and buffered receives shift all remaining values on every drain.
2 open issues
What changed in this PR
Adds typed, orchestration-local channels to coordinate existing ctx.Go branches, addressing #179 without exposing scheduler internals.
Changes:
- Adds buffered and unbuffered channels with cancellation-aware operations and durable selection.
- Integrates channel waits with replay, deadlock detection, and scope cancellation inspection.
- Adds tests, documentation, and a channel-based coroutine sample.
| File | Description |
|---|---|
| tests/durabletaskscheduler/dts_coroutine_review_test.go | Tests channel coordination and deadlock failure against DTS. |
| task/select.go | Adds selection registration, cleanup, and atomic commitment. |
| task/orchestrator.go | Fails executions on detected channel deadlocks. |
| task/eventchannel.go | Adapts event cases to selection commitment. |
| task/coroutine.go | Tracks each coroutine’s active selection. |
| task/channel.go | Implements typed channels and deadlock detection. |
| task/channel_test.go | Tests ordering, cancellation, replay, and selection behavior. |
| task/cancel.go | Exposes applied scope cancellation through IsCanceled. |
| samples/coroutines/README.md | Explains channel coordination and replay behavior. |
| samples/coroutines/coroutines.go | Collects branch results through selectable channels. |
| README.md | Documents channel APIs, semantics, and usage. |
| cmd/orchestratorvet/README.md | Documents SDK channels as safe orchestration primitives. |
| CHANGELOG.md | Records the channel and cancellation-inspection additions. |
Review effort: Balanced
Bernd Verst (berndverst)
left a comment
There was a problem hiding this comment.
Orchestration-local channels fill a real gap, and the two-party commit keeps losing cases from sending or consuming values. Before merging, I would preserve behavior for reused task and event cases, keep ready selections on their fast path, and avoid building a cross-product of pending unbuffered cases on replay. That last item is separate from the existing buffer and wakeup threads.
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Bernd Verst (berndverst)
left a comment
There was a problem hiding this comment.
This revision fixes the duplicate-case behavior, restores the allocation-free ready path, and eliminates the pairwise match allocations. One compatibility regression remains in the new ready path: an existing SDK case embedded in an application type now panics. Separately, mixed send/receive selections still have a quadratic scan on replay.
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

Summary
Adds typed, orchestration-local channels for coordinating existing
ctx.Gobranches:task.NewChannel[T](ctx, capacity)supports unbuffered rendezvous and bounded FIFO buffering.Send/Receiveand cancellation-awareSendErr/ReceiveErryield through the durable scheduler.OnSend/OnReceiveparticipate inctx.Selectalongside task completions and external events. Unbuffered exchanges commit both selections before callbacks run; losing cases perform no send or receive.ctx.IsCanceled()reports applied durable scope cancellation.Channel state and branch execution are reconstructed on replay; no goroutine stays resident waiting for activity work between turns. The coroutine sample now receives branch results through a channel while selecting over approval and a durable timer.
Deadlock and cancellation behavior
Channel waits allow other branches to run and pending durable actions to be dispatched. When no coroutine is runnable and channel operations have no pending durable work or external event receiver that could wake the orchestration, execution fails explicitly with
task.ErrOrchestrationDeadlock. Detection is conservative: it does not diagnose application dependency cycles while durable work remains pending, or arbitrary code that never yields.Cancellation withdraws pending channel operations without closing the shared channel. Already-committed exchanges are not undone by later cancellation. Callbacks run in their respective selecting coroutines, and callers must join children when cleanup must finish before the root returns.
Scope
Channels are local to one orchestration and pass values by assignment, not serialization. There is no close operation or ordered-selection variant. Task/event selection retains history ordering; channel readiness uses deterministic scheduler ordering.
Closes #179.