Skip to content

Fix issues with runaway tasks and broken iterators - #338

Merged
Tyrrrz merged 25 commits into
primefrom
refactor
Jul 22, 2026
Merged

Fix issues with runaway tasks and broken iterators#338
Tyrrrz merged 25 commits into
primefrom
refactor

Conversation

@Tyrrrz

@Tyrrrz Tyrrrz commented Jul 22, 2026

Copy link
Copy Markdown
Owner

General description

This PR improves reliability around command cancellation and event streaming.

It ensures that commands behave predictably when event consumers stop listening, avoids unobserved background failures, makes pull- and push-based event streams more consistent, and clarifies the dummy text generator’s output semantics.

Behaviors that changed

Scenario Before After
A consumer stops a pull event stream early The command could block if it continued writing stdout or stderr. Event delivery stops, while the command continues and its output is drained.
A command fails after a pull stream is disposed Background failures could surface as unobserved task exceptions. Detached failures are observed internally.
A stdin source faults after command cancellation The late failure could become unobserved. The late failure is observed internally.
A push-stream command completes immediately Completion could be reported before the start event. The start event is always reported before completion or failure.

@Tyrrrz Tyrrrz added the bug label Jul 22, 2026
Copilot AI review requested due to automatic review settings July 22, 2026 14:02

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

This PR refactors internal async/event-stream plumbing and adds a small utility to prevent unobserved task exceptions from “detached” background work, particularly around event-stream cancellation scenarios.

Changes:

  • Added TaskExtensions.ObserveException() to explicitly observe faults from tasks that may be abandoned after cancellation.
  • Refactored pull/push event stream implementations to reduce detached-task/unobserved-exception risk and simplify flow.
  • Renamed Channel<T> members for clearer semantics and updated affected call sites; adjusted related docs/comments and added a non-parallel test collection for global-state observation.

Reviewed changes

Copilot reviewed 10 out of 10 changed files in this pull request and generated no comments.

Show a summary per file
File Description
Readme.md Minor punctuation tweak in documentation (i.e.,).
CliWrap/Utils/Extensions/TaskExtensions.cs New helper to observe task exceptions via a fault-only continuation.
CliWrap/Utils/Channel.cs Renames channel API/fields (PublishTransmit, ReportCompletionClose) for clearer intent.
CliWrap/EventStream/PushEventStreamCommandExtensions.cs Refactors push-based event stream completion/error signaling and observes detached faults.
CliWrap/EventStream/PullEventStreamCommandExtensions.cs Refactors pull-based event stream to close channel reliably and await command completion to avoid unobserved exceptions.
CliWrap/CommandResult.cs Minor punctuation tweak in XML docs (i.e.,).
CliWrap/Command.Execution.cs Improves stdin piping cancellation path to avoid unobserved exceptions after early cancellation.
CliWrap/Buffered/BufferedCommandExtensions.cs Small refactor/cleanup of buffered execution pipeline wiring.
CliWrap.Tests/TestCollections.cs Adds a non-parallel xUnit collection for tests observing global state.
CliWrap.Tests/CancellationSpecs.cs Updates the race-condition regression test for unobserved task exceptions and disables parallelism for the suite.

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

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

Copilot reviewed 9 out of 9 changed files in this pull request and generated 2 comments.

Comment thread CliWrap/EventStream/PullEventStreamCommandExtensions.cs Outdated
Comment thread CliWrap/EventStream/PushEventStreamCommandExtensions.cs

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

Copilot reviewed 9 out of 9 changed files in this pull request and generated no new comments.

@Tyrrrz Tyrrrz changed the title Improve handling of detached tasks and refactor Fix issues with runaway tasks and broken iterators Jul 22, 2026
@Tyrrrz
Tyrrrz requested a review from Copilot July 22, 2026 17:52
tom-wolfe pushed a commit to nschema-org/NSchema.Build that referenced this pull request Jul 30, 2026
Updated [CliWrap](https://github.com/Tyrrrz/CliWrap) from 3.10.2 to
3.10.3.

<details>
<summary>Release notes</summary>

_Sourced from [CliWrap's
releases](https://github.com/Tyrrrz/CliWrap/releases)._

## 3.10.3

<!-- Release notes generated using configuration in .github/release.yml
at 3.10.3 -->

## What's Changed
### Bugs
* Fix a race condition inside PullEventStream by @​kvpt in
Tyrrrz/CliWrap#337
* Fix issues with runaway tasks and broken iterators by @​Tyrrrz in
Tyrrrz/CliWrap#338

## New Contributors
* @​kvpt made their first contribution in
Tyrrrz/CliWrap#337

**Full Changelog**:
Tyrrrz/CliWrap@3.10.2...3.10.3

Commits viewable in [compare
view](Tyrrrz/CliWrap@3.10.2...3.10.3).
</details>

[![Dependabot compatibility
score](https://dependabot-badges.githubapp.com/badges/compatibility_score?dependency-name=CliWrap&package-manager=nuget&previous-version=3.10.2&new-version=3.10.3)](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores)

Dependabot will resolve any conflicts with this PR as long as you don't
alter it yourself. You can also trigger a rebase manually by commenting
`@dependabot rebase`.

[//]: # (dependabot-automerge-start)
[//]: # (dependabot-automerge-end)

---

<details>
<summary>Dependabot commands and options</summary>
<br />

You can trigger Dependabot actions by commenting on this PR:
- `@dependabot rebase` will rebase this PR
- `@dependabot recreate` will recreate this PR, overwriting any edits
that have been made to it
- `@dependabot show <dependency name> ignore conditions` will show all
of the ignore conditions of the specified dependency
- `@dependabot ignore <dependency name> major version` will close this
group update PR and stop Dependabot creating any more for the specific
dependency's major version (unless you unignore this specific
dependency's major version or upgrade to it yourself)
- `@dependabot ignore <dependency name> minor version` will close this
group update PR and stop Dependabot creating any more for the specific
dependency's minor version (unless you unignore this specific
dependency's minor version or upgrade to it yourself)
- `@dependabot ignore <dependency name>` will close this group update PR
and stop Dependabot creating any more for the specific dependency
(unless you unignore this specific dependency or upgrade to it yourself)
- `@dependabot unignore <dependency name>` will remove all of the ignore
conditions of the specified dependency
- `@dependabot unignore <dependency name> <ignore condition>` will
remove the ignore condition of the specified dependency and ignore
conditions


</details>

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants