Skip to content

Run a shell block until a cancellation token is cancelled - #51

Merged
Mpdreamz merged 2 commits into
mainfrom
shell-cancellation
Nov 12, 2026
Merged

Mpdreamz merged 2 commits into
mainfrom
shell-cancellation

Conversation

@Mpdreamz

Copy link
Copy Markdown
Contributor

ShellBuilder.Run(step, cancellationToken) runs a shell { } / steps { } block that its caller can stop. While the token can be cancelled, the block's commands print through Console.Out and Console.Error line by line.

Prompt summary: Nullean.Make.Fs runs targets side by side, and needs to stop a target's sh commands when another target fails, and to prefix each of their lines with the target's name. Proc.Fs keeps the token a block runs with internal, so a host has no way to do either.

Why

ShellContext.Token is internal, and ShellBuilder.Run(step) always runs with CancellationToken.None. A host that runs a block cannot cancel it, and with a token that cannot be cancelled Runner.run takes the Proc.Exec path, which writes to the shared console where a host that replaces Console.Out never sees the lines.

What

A Run overload that takes a token

ShellBuilder.Run(step, cancellationToken) creates the block's context with that token. Run(step) calls it with CancellationToken.None, so a shell { } block behaves as before. Cancelling stops the running command and throws OperationCanceledException; no command after it starts.

Output through Console.Out

This is what Runner.run already does for a token that can be cancelled; the README now says so, and that the output is then a pipe, so a tool that colours only for a terminal prints without colour.

Verify

dotnet test --project tests/Proc.Fs.Tests -c Release -f net11.0 --treenode-filter "/*/*/*CancellationTests*/*"
# cancelling the token stops the running command and the ones after it
# with a token that can be cancelled the output goes through Console.Out

🤖 Generated with Claude Code

`ShellBuilder.Run(step, cancellationToken)` lets a host stop a block: cancelling the token stops the running
command and starts no more. While the token can be cancelled, commands print through `Console.Out` and
`Console.Error`, so a host that replaces those writers sees every line.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Mpdreamz
Mpdreamz merged commit 517d8e8 into main Nov 12, 2026
8 checks passed
@Mpdreamz
Mpdreamz deleted the shell-cancellation branch November 12, 2026 10:55
Mpdreamz added a commit to nullean/argh that referenced this pull request Nov 12, 2026
…rappers (#137)

F# `sh` commands in a parallel stage now carry their target's name and
stop when another target fails, and the generated wrappers list the new
run switches.

**Prompt summary:** Close the gaps the earlier PRs left. Breaking the
wrapper output is fine.

## Why

Proc.Fs ran a `target { }` block with a token that could not be
cancelled, so its `sh` commands wrote to the shared console: no target
name on their lines, and a failing sibling did not stop them. The mise
include's `usage` spec did not list `--graph`, `-j`, `-k`, `--output` or
`--skip`, so mise did not complete them.

## What

#### F# `sh` in parallel stages
While targets run side by side, `target { }` runs its block with the
run's cancellation token through Proc.Fs's `ShellBuilder.Run(step,
cancellationToken)`. Its commands then print through `Console.Out`,
where each line gets the target's name, and cancelling stops the running
command. A run without a parallel stage passes no token, so commands
keep the console and its colours. Proc and Proc.Fs move to `0.22.0`.

#### Wrapper switches
The mise include lists the five switches. A build option with the same
short name keeps it, as on the command line.

**Breaking:** committed wrapper files change, so `__wrappers check`
fails until `__wrappers sync` runs once.

**Blocked:** this needs Proc and Proc.Fs `0.22.0`, which
nullean/proc#51 adds. Restore fails until that
is released.

## Verify

```bash
dotnet test --project tests/Nullean.Make.Fs.Tests -c Release --treenode-filter "/*/*/*ParallelShellTests*/*"
dotnet test --project tests/Nullean.Make.Tests -c Release --treenode-filter "/*/*/WrapperTests/*"
```

**Stack:** 6 of 6, on top of
[#136](#136)

🤖 Generated with [Claude Code](https://claude.com/claude-code)

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature A new capability (minor bump)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant