Skip to content

Add selectable channels for orchestration coroutines - #191

Open
andystaples wants to merge 3 commits into
mainfrom
andystaples-selectable-orchestration-channels
Open

andystaples wants to merge 3 commits into
mainfrom
andystaples-selectable-orchestration-channels

Conversation

@andystaples

Copy link
Copy Markdown
Contributor

Summary

Adds typed, orchestration-local channels for coordinating existing ctx.Go branches:

  • task.NewChannel[T](ctx, capacity) supports unbuffered rendezvous and bounded FIFO buffering.
  • Send/Receive and cancellation-aware SendErr/ReceiveErr yield through the durable scheduler.
  • OnSend/OnReceive participate in ctx.Select alongside 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.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot AI balanced review requested due to automatic review settings November 20, 2026 18:51

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 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

Comment thread task/channel.go Resolved
Comment thread task/channel.go Resolved

@berndverst Bernd Verst (berndverst) left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread task/select.go Resolved
Comment thread task/select.go Resolved
Comment thread task/channel.go Resolved
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot AI balanced review requested due to automatic review settings November 23, 2026 19:28

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

No active review issues remain for the typed orchestration-local channel changes.

No open issues 🎉

2 resolved since last review

Review effort: Balanced

@berndverst Bernd Verst (berndverst) left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread task/select.go Resolved
Comment thread task/channel.go Resolved
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot AI balanced review requested due to automatic review settings November 23, 2026 23:58

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

No active review issues were identified for the orchestration-local channel changes.

No open issues 🎉

Review effort: Balanced

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.

Support selectable channels for orchestration coroutine coordination

3 participants