Skip to content

aalmada/Stationary / .agents/skills/dotnet-pipelines

dotnet-pipelines

Verified

Design, implement, debug, test, and review high-throughput byte-stream processing with System.IO.Pipelines. USE FOR: Pipe, PipeReader, PipeWriter, ReadResult, FlushResult, ReadOnlySequence, SequenceReader, buffer lifecycle, AdvanceTo, GetMemory, Advance, FlushAsync, stream and socket adapters, framing protocols, incremental parsing, backpressure, cancellation, and Pipes-to-Channels handoff. DO NOT USE FOR: item-level producer-consumer queues, durable/distributed messaging, ordinary small file I/O with no measured bottleneck, generic Stream APIs with no buffer-management concern, or ASP.NET middleware pipelines unrelated to System.IO.Pipelines.

references/pipes-and-channels-boundary.md

View on GitHub
# Pipes And Channels Boundary

## Different Jobs

| Concern | Prefer |
| --- | --- |
| Buffered transport bytes, framing, partial messages | `System.IO.Pipelines` |
| Independently owned work items, bounded worker concurrency | `System.Threading.Channels` |
| Fan-out or durable/cross-process delivery | A dedicated messaging design or broker |

Parse on the pipe reader, create an independently owned message, and enqueue that message to a bounded channel. The channel consumers must never receive a `ReadOnlySequence<byte>` or a view over pipe-owned memory.

```csharp
while (TryReadFrame(ref buffer, out ReadOnlySequence<byte> frame))
{
    WorkItem item = DecodeOrCopy(frame);
    await workWriter.WriteAsync(item, cancellationToken);
}
```

Backpressure must be explicit at both stages:

- `PipeWriter.FlushAsync` limits retained transport bytes through pipe thresholds.
- A bounded channel limits parsed-but-unprocessed work items and applies the selected overload policy.
- Awaiting a bounded channel write inside the pipe reader retains its current buffer. Keep item ownership small, capacity bounded, and latency understood; alternatively decouple work admission at a deliberate ownership boundary.

## Avoid These Errors

- Do not fire-and-forget channel writes from the pipe reader; this loses failures and moves the queue into scheduled tasks.
- Do not dispatch pipe-backed payloads to background workers after `AdvanceTo`; copy/decode first.
- Do not use an unbounded channel to hide a downstream bottleneck. Choose a capacity and a documented full policy.
- Do not assume multiple channel consumers preserve global frame-processing order.

## Sources

- [System.IO.Pipelines](https://learn.microsoft.com/dotnet/standard/io/pipelines)
- [System.Threading.Channels](https://learn.microsoft.com/dotnet/core/extensions/channels)
- [Pipelines and Channels performance example](https://dev.to/joni2nja/use-system-io-pipelines-and-system-threading-channels-apis-to-boost-performance-2nj5)
finishing-a-development-branchobra/superpowersUse when implementation is complete, all tests pass, and you need to decide how to integrate the workStars: 322kUpdated Claude CodeCodexVerifiedInstall
systematic-debuggingobra/superpowersUse when encountering any bug, test failure, or unexpected behavior, before proposing fixesStars: 322kUpdated Claude CodeCodexVerifiedInstall
test-driven-developmentobra/superpowersUse when implementing any feature or bugfix, before writing implementation codeStars: 322kUpdated Claude CodeCodexVerifiedInstall
skill-creatoranthropics/skillsCreate new skills, modify and improve existing skills, and measure skill performance. Use when users want to create a skill from scratch, edit, or optimize an existing skill, run evals to test a skill, benchmark skill performance with variance analysis, or optimize a skill's description for better triggering accuracy.Stars: 198kUpdated Claude CodeCodexVerifiedInstall