Skip to content

Add a workflow cancellation + run-status example - #688

Open
PratikDhanave wants to merge 2 commits into
microsoft:mainfrom
PratikDhanaveFork:workflow-cancellation-example
Open

Add a workflow cancellation + run-status example#688
PratikDhanave wants to merge 2 commits into
microsoft:mainfrom
PratikDhanaveFork:workflow-cancellation-example

Conversation

@PratikDhanave

Copy link
Copy Markdown
Contributor

What

Adds examples/03-workflows/cancellation, a runnable example that demonstrates cancelling a streaming workflow run and inspecting its status:

  • Builds a bounded, fully offline two-executor loop (Counter -> Printer -> Counter) that would emit many outputs if left alone. A small per-step delay simulates long-running work so the cancellation lands while the run is still producing.
  • Starts the run with RunStreaming, iterates WatchStream, and after a few outputs calls run.CancelRun().
  • Treats the context.Canceled that surfaces as the run tears down as the expected clean end of the stream.
  • Prints run.GetStatus(ctx) afterwards, illustratively. The status is read only for display: it is published from a deferred setStatus on the unwinding goroutine and can still be settling, so the example does not branch on the value or assert a specific RunStatus.

Also registers the example with cmd/verifyexamples so it is exercised by the example verifier (MustContain on stable output lines).

Why

StreamingRun.CancelRun() (which delegates to RunHandle.Cancel()), GetStatus(), and the RunStatus alias/constants were only referenced from tests -- no example showed the cancellation + run-status flow. The .NET and Python Agent Framework SDKs both surface run cancellation and run-status inspection as first-class concepts in their workflow samples; this brings the Go examples to parity so users can see the same story.

Testing

  • go build ./...
  • go vet ./examples/... ./cmd/verifyexamples/...
  • go test ./cmd/verifyexamples/...
  • go run ./examples/03-workflows/cancellation completes cleanly and deterministically (three outputs, cancellation, clean stream termination, final status line), with no self-loop or dead-end warnings.

Copilot AI review requested due to automatic review settings July 24, 2026 01:34
@PratikDhanave
PratikDhanave requested a review from a team as a code owner July 24, 2026 01:34

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.

Pull request overview

Adds a new runnable Go example demonstrating how to cancel a streaming workflow run mid-flight and then query/display the run’s final status, and wires it into the example verifier so it’s exercised in CI-like checks.

Changes:

  • Introduces examples/03-workflows/cancellation, building a bounded Counter→Printer loop, streaming outputs, cancelling after a few outputs, and handling context.Canceled as the expected termination.
  • Adds a small helper to render inproc.RunStatus values in a user-friendly way.
  • Registers the new example in cmd/verifyexamples with stable MustContain assertions.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
examples/03-workflows/cancellation/main.go New example showing RunStreaming + WatchStream cancellation flow and post-run status inspection.
cmd/verifyexamples/examples.go Adds the new cancellation example to the verifier’s workflow examples list.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

if int(n) > bound {
return nil
}
time.Sleep(workDelay) // simulate a slow, long-running step

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Good catch — fixed in a38befb: the Counter executor now waits with a select on time.After(workDelay) vs ctx.Done(), returning ctx.Err() so a cancellation short-circuits the delay immediately instead of blocking the superstep until the sleep completes.

@PratikDhanave
PratikDhanave force-pushed the workflow-cancellation-example branch from a928c00 to ecc5d1a Compare July 24, 2026 01:40
@github-actions github-actions Bot added the parity-approved Go API consistency review found no parity issues label Jul 24, 2026
@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

Add examples/03-workflows/cancellation showing how to cancel a streaming
workflow run mid-flight and inspect its status. The sample runs a bounded,
fully offline two-executor loop via RunStreaming, iterates WatchStream,
calls run.CancelRun() after a few outputs, and prints run.GetStatus(ctx).

This exercises the StreamingRun.CancelRun / GetStatus / RunStatus surface,
which previously appeared only in tests, and mirrors the cancellation and
run-status story from the .NET and Python SDKs. Register the example with
cmd/verifyexamples so it is covered by the example verifier.
@PratikDhanave
PratikDhanave force-pushed the workflow-cancellation-example branch from a38befb to c2305e5 Compare July 24, 2026 09:34
@github-actions

Copy link
Copy Markdown
Contributor

Parity Review — PR #688: Add workflow cancellation + run-status example

Scope: examples/03-workflows/cancellation/main.go (new) and cmd/verifyexamples/examples.go (updated).

Exported API surface changed: None. The example uses existing public symbols (RunStreaming, WatchStream, CancelRun, GetStatus, RunStatus) without adding or modifying any exported identifiers. The public-api-change label is correctly absent.

Cross-repo parity:

  • Neither dotnet/samples/03-workflows nor python/samples/03-workflows has a dedicated cancellation sub-folder, so the Go example is slightly ahead in explicitness on this specific scenario.
  • The cancellation + run-status story is covered implicitly in upstream samples (e.g., HumanInTheLoop / control-flow) and in the respective SDK test suites. No conflicting semantics were found.
  • The Go example correctly treats context.Canceled as a clean terminal signal from a cancelled run, which matches how .NET CancellationToken and Python async task cancellation surface the same condition.

Verdict: ✅ No parity issues. The PR adds a useful offline example that exercises already-public API without diverging from upstream semantics. The parity-approved label remains valid.

Warning

Firewall blocked 1 domain

The following domain was blocked by the firewall during workflow execution:

  • awmgmcpg

To allow these domains, add them to the network.allowed list in your workflow frontmatter:

network:
  allowed:
    - defaults
    - "awmgmcpg"

See Network Configuration for more information.

Generated by Go API Consistency Review Agent · 32.9 AIC · ⌖ 5.59 AIC · ⊞ 5.9K ·

@gdams
gdams enabled auto-merge July 29, 2026 14:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

parity-approved Go API consistency review found no parity issues

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants