Add a workflow cancellation + run-status example - #688
Conversation
There was a problem hiding this comment.
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 handlingcontext.Canceledas the expected termination. - Adds a small helper to render
inproc.RunStatusvalues in a user-friendly way. - Registers the new example in
cmd/verifyexampleswith stableMustContainassertions.
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 |
There was a problem hiding this comment.
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.
a928c00 to
ecc5d1a
Compare
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
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.
a38befb to
c2305e5
Compare
Parity Review — PR #688: Add workflow cancellation + run-status exampleScope: Exported API surface changed: None. The example uses existing public symbols ( Cross-repo parity:
Verdict: ✅ No parity issues. The PR adds a useful offline example that exercises already-public API without diverging from upstream semantics. The Warning Firewall blocked 1 domainThe following domain was blocked by the firewall during workflow execution:
network:
allowed:
- defaults
- "awmgmcpg"See Network Configuration for more information.
|
What
Adds
examples/03-workflows/cancellation, a runnable example that demonstrates cancelling a streaming workflow run and inspecting its status: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.RunStreaming, iteratesWatchStream, and after a few outputs callsrun.CancelRun().context.Canceledthat surfaces as the run tears down as the expected clean end of the stream.run.GetStatus(ctx)afterwards, illustratively. The status is read only for display: it is published from a deferredsetStatuson the unwinding goroutine and can still be settling, so the example does not branch on the value or assert a specificRunStatus.Also registers the example with
cmd/verifyexamplesso it is exercised by the example verifier (MustContainon stable output lines).Why
StreamingRun.CancelRun()(which delegates toRunHandle.Cancel()),GetStatus(), and theRunStatusalias/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/cancellationcompletes cleanly and deterministically (three outputs, cancellation, clean stream termination, final status line), with no self-loop or dead-end warnings.