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/streams-sockets-and-ownership.md

View on GitHub
# Streams, Sockets, And Ownership

## Adapter Choice

| Source Or Sink | Use |
| --- | --- |
| Existing `Stream` input | `PipeReader.Create(stream, options)` |
| Existing `Stream` output | `PipeWriter.Create(stream, options)` |
| In-memory producer/consumer pair | `new Pipe(options)` |
| Socket receive loop | `PipeWriter.GetMemory`, receive into it, `Advance`, then `FlushAsync` |
| Socket send loop | `PipeReader.ReadAsync`, send sequence bytes, then `AdvanceTo` |

Pipe adapters centralize buffer management. Use `StreamPipeReaderOptions` or `StreamPipeWriterOptions` to define buffer sizes and whether completing the pipe leaves the underlying stream open.

## Ownership Rules

- Decide which component owns the stream/socket and which owns each pipe end before passing it across an API boundary.
- A method that owns the entire read/write loop also owns `CompleteAsync`. A helper that reads one frame must not complete a reader it did not create.
- Complete the pipe end before disposing its underlying transport, unless the transport lifetime contract requires an abort.
- Propagate a terminal transport exception through the corresponding `CompleteAsync(exception)` so the peer observes the cause.
- Do not use concurrent reads, concurrent flushes, or multiple owners on one pipe end.

## Protocol Framing

- Pipes carry arbitrary byte chunks, not messages. A transport read can split one frame or combine many frames.
- Parse fixed-size, delimiter, or length-prefixed frames incrementally. Validate headers and declared lengths before allocating/copying payloads.
- Process all available complete frames per read when possible; preserve the incomplete suffix through `AdvanceTo`.

## Sources

- [System.IO.Pipelines: streams](https://learn.microsoft.com/dotnet/standard/io/pipelines#streams)
- [PipeReader.Create](https://learn.microsoft.com/dotnet/api/system.io.pipelines.pipereader.create)
- [PipeWriter.Create](https://learn.microsoft.com/dotnet/api/system.io.pipelines.pipewriter.create)
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