50. Pipes and redirection: one sink protocol, and | turns out to be an endpoint
Closed 2026-08-14 by the integrator on the overnight verification lane's
evidence: every residual the paragraph below listed as open had closed on 2026-08-03 and the record
had not caught up. Buffering was measured and the verdict is build nothing (commit 8c27953;
notes/pipes.md carries the numbers and the honest caveats). The terminal sink adapter is
terminal_sink_caretaker, built, wired as the fifth boot component, name ratified (061066e). And
2> was decided by Chris and built as the declared second stream
(design/decisions/0067-second-stream.md).
(The Gate paragraph that stood here described the three residuals; all three closed 2026-08-03, and a BUILT milestone gates nothing, so it is gone rather than stale.)
The protocol lane built 2026-07-31 (crates/sink_proto, fixtures/src/sink.rs, the std PAL's
sys/stdio, and abi::Error::Gone; concept note: notes/sink-protocol.md). One framing for "write
these bytes there", proven on both ISAs by running one std_exerciser ELF against two destinations that
share nothing but sixteen bytes of message and comparing the bytes.
Three things came out of it that were not in the plan below.
- The kernel could not express the thing the plan required. "Gone" and "never had one" both
arrived as
NoSuchSlot, so no amount of userspace protocol design could have recovered the distinction; the ABI grew a variant. That is the finding, and it is why doing this before|existed was right. SIGPIPEneeded no new mechanism above the ABI, because std already splits fatal from swallowed print failures throughis_ebadf, and the old PAL was defeating it by answeringtrueunconditionally.- A sink capability must not double as a terminal-service capability, which is what stops
line_editorfrom simply serving the contract on the endpoint it already has. That endpoint also carriesOP_READLINE, so handing it to a child as its output slot would grant the child the terminal's input. The terminal's sink is therefore a separate endpoint served by an adapter, which is the shapefixtures/src/sink.rs's file role proves against a real backend. Convertingline_editorand the console server is left with the shell work, because their clients are the shell andsystem_initializer.
The operators lane built 2026-07-31 (crates/grant_plan/src/line.rs, components/src/wc.rs, the shell,
system_initializer, and two bits on grant_plan::spawnproto; concept note: notes/pipes.md). date | wc runs at a
real prompt on both ISAs, with the shell minting the endpoint out of its own budget and init putting
it in the child's output slot. The kernel did not change.
Four things came out of it that were not in the plan below.
- The input slot's shape had to be decided and the smallest answer was the right one: a source
is the sink contract received rather than sent. No new protocol, and
<and the right end of a|become one convention, exactly as>and the left end already were. - The manifest had to learn that not every program's slot 0 carries bytes.
workeranswers with au64in a register and the interrupt demonstrators hold no output capability at all, soworker 9 > out.txtwould have written an unreadable word into a file with no error anywhere.OutputSpecmakes it a refusal at the prompt. This is a wart the sink protocol inherited rather than created: the register fastpath is older than the contract. InputSpecproduces a refusal Unix cannot.wcwith nothing feeding it blocks on a receive forever, and on Unix that is a shell that appears to hang, because fd 0 always exists there. Here the manifest knows, so the prompt knows.- A pipe needs its own untyped region, not just an endpoint. Deleting every capability naming an
endpoint does not destroy it (the object lives in a page of a region), so a producer blocked in a
SENDafter its reader finished would stay blocked forever. The shell splits a region per pipeline andDESTROYs it, and that is what turns a dead reader intoGone.
Append is line::Mode and swish's open_sink, gated by cargo xtask swish-check. >> is the
cheapest of the four operators and that is DECISIONS §55 (the file behind a > is the shell itself)
paying out. The shell already backs the file, so append is one bit about how it opens one.
grant_plan asserts that date > f and date >> f plan to endowments equal in every other field.
The gate notes/pipes.md named as the milestone's most valuable test is script/swish-check: it
boots --features shell on both ISAs and types at the prompt, the only thing in the tree that runs
the real system_initializer.
Where the design below differs from notes/pipes.md and notes/sink-protocol.md, the notes are what is built.
In brief. The shell has no |, >, or <, and a shell without them is not a shell. The
surprise on investigating is that the mechanism is already built and the missing piece is
somewhere else entirely: the work is unifying the four byte-sink protocols we already have, after
which the pipeline operators are parser changes and wiring.
Why it matters. Pipelines are Unix's composition primitive and the reason the shell is worth having. They are also the place where the capability model gets to show a result that is better rather than merely equivalent, which is what a demonstrator exists to produce.
The finding: stdout is already a capability in a slot
patches/std-nife/.../pal/nife/rt.rs fixes STDOUT_SLOT = 1, and sys/stdio/nife.rs
implements println! as a SEND on that slot. So a program's output destination is a capability the
spawner chose, and redirection is putting a different capability in that slot. No kernel change, no
new object, no dup2. The existing doc comment even anticipates the case: a failed SEND is swallowed
so "a program without a console still runs, it just prints into the void".
The same is true at the other end of the design. line_editor::proto::OP_BYTES already documents
the rendezvous is the flow control, which is exactly a pipe's back-pressure story.
A pipe is an endpoint, not an object
For a | b, the shell creates an endpoint, grants SEND to a as its output slot and RECV to b as
its input slot, and spawns both. Nothing is added to the kernel. Unix needs a pipe object with a
64 KB buffer because fds are anonymous and the kernel has to decouple two parties who cannot name
each other; here the shell names both, so the rendezvous is the pipe.
The cost is honest and should be measured rather than argued: this is full lockstep, where Unix's
buffer lets a producer run ahead. The reply is that IPC speed is the thing this project has spent
itself on, so measure a | b throughput and only then decide. If buffering earns its place it
arrives as a component that speaks the sink protocol on both sides and is inserted into the
chain, not as a redesign. An optimization that is a process is the shape a microkernel wants.
SIGPIPE becomes a return code, the same way SIGTTIN disappeared in 48
yes | head: head exits, its endpoint dies, and the producer's next SEND fails. Unix needs a
signal because there is no other way to tell a writer that an anonymous fd is gone; §16 (object
revocation) already destroys the capability and the failure arrives as an error return. A third
signal disappears, as the sink protocol note says.
This forces one concrete change. Today's swallow ("print into the void") is right for a program with
no console and wrong for a pipeline, where a dead reader must end the writer. So the sink protocol
needs a distinguishable "gone" versus "never had one", and std's Stdout::write must stop discarding
the result.
The actual work: four sink protocols, one needed
| Sink | Protocol today |
|---|---|
std println! |
SEND, register-only, 16 bytes/msg, w0 = len, w1|w2 = bytes |
line_editor (crate and component) |
CALL, shared page, OP_WRITE, r0 = bytes consumed |
fs_proto |
CALL, handle + offset + shared page, WRITE |
| console server | shared page, SEND length, ACK on a separate reply endpoint |
Four shapes for "write these bytes there". A child cannot be indifferent to what is in its output
slot until they are one, and that unification is the milestone. The precedent is
fs_file_caretaker, which is a caretaker precisely because it "serves the same fs_proto protocol
its own client speaks": narrowing preserves the protocol, so a pipe, a file, and a terminal become
substitutable.
The result that is better than Unix, and worth stating plainly
> and file:PATH must stay different mechanisms, and the difference is the payoff. file:report.txt
grants the program a file its manifest declared it wanted (milestone 31, a capability shell; the
filesystem contract it grants against is §27). > report.txt substitutes the
stream the shell owns, and the program never holds a file capability at all: it cannot seek, cannot
truncate, cannot re-read, cannot stat. It can append bytes to a sink. Unix hands the same program fd
1 with full file semantics, so our redirection grants strictly less than Unix's while doing the same
job.
Keeping them distinct is also what keeps the manifest meaningful: run worker 5 > out.txt must not
become a way to route around FileSpec::Forbidden, and it does not, because the sink is not a file
grant.
The demo that shows it: caps can print where your output goes ("output: terminal" versus
"output: file report.txt, append-only"), because the destination is a capability rather than an
integer with a convention attached.
What is genuinely missing
- stdin.
sys/stdio/nife.rsreturns honest EOF because "nothing grants a std program input yet". Both< fileand a pipe's read end need an input-slot convention that does not exist. >>. Append is expressible withFSTAT/SIZEthen write-at-offset, but that is racy if the file is shared. Decide whether append is a mode on open or a sink property; do not over-solve it.- Multi-stage pipelines.
a | b | cis two endpoints, not one, and the shell's spawn path builds one child at a time today.
Sequencing. The protocol unification is independent of 47 and 48 and could start now; the parser
work wants 47's tokenizer changes, and the "who holds the terminal" story is shared with 48. So the
natural order is unify the protocol, then > and <, then |, then revisit 48's fg with pipelines
in hand. Effort: 3 lanes estimated (protocol, redirection, pipelines), noting estimates for
unbuilt work are guesses on a history-calibrated scale, and that the unification is the one most
likely to surprise.
Follow-on
- Refused. A buffering stage. The block said measure before deciding, it was measured on
2026-08-03, and the verdict is build nothing: the lockstep is not the bottleneck, the sixteen-byte
register-only sink message is, and a buffer costs roughly double for decoupling rather than
bandwidth.
notes/pipes.mdcarries the numbers and the honest caveat that the benchmark did not measure the case a buffer is actually for. This refusal is milestone 482 (design/roadmap/0482-a-buffering-stage-between-pipe-ends.md), which carries it with the condition that would change it. - Refused. Converting the console server to the sink protocol.
line_editoris its only client and now speaks for two writers, so once the terminal adapter existed the page-plus-ack channel looked like the right answer rather than a gap. A second client of the console would hit the same one-page wall one layer down with nothing gained.notes/sink-protocol.mdhas the reasoning. This refusal is milestone 483 (design/roadmap/0483-the-console-server-on-the-sink-protocol.md), which carries it with the condition that would change it. - Decision.
design/decisions/0067-second-stream.mdsettles2>, which this block named as a design fork rather than a task. calef chose the manifest declaration: a program that has diagnostics declares a second output, the shell plans an endpoint only for a declarer, and2>aimed at a non-declarer is a refusal at the prompt. - Milestone 48. Revisiting
fgwith pipelines in hand, which this block's sequencing paragraph put after the operators. Job control is still NOT-STARTED and carries it. - Recorded.
notes/pipes.mdnames the slot problem beside the wiring a reader meets. Slot 0 and slot 1 each mean several things depending on what the line granted, so the ordered convention is owed a numbered one. The register fastpath wartOutputSpecrefuses rather than fixes is recorded with it.
Index row
the sink contract is built (crates/sink_proto, notes/sink-protocol.md) and a program is
proven indifferent to what its output slot holds; all four operators run at a real prompt on both
ISAs. Buffering was measured and the verdict is build nothing, the terminal's own sink
adapter is terminal_sink_caretaker, and 2> was built as the declared second stream (§67)