decisions DECIDED

55. The file behind a > is the shell itself, because one page cannot serve two clients

Milestone 50, finished 2026-08-01. components/src/swish.rs, kernel::user::redirection_tests. See notes/pipes.md.

A redirected program's output goes to a file the shell writes, not to an adapter process holding that file. This was not the plan, and the reason it changed is a property of §27's contract rather than a preference.

What forced it

fs_proto shares one page between the FS server and its clients. A client stages bytes or a name into that page and then calls, so its use of the page straddles the call boundary. Two client processes doing that concurrently race, and nothing in the contract orders them: there is no lock, and a rendezvous on the FS endpoint cannot span a put-then-call pair.

The plan was for the shell to hold a filesystem and ask init to build a sink.rs file adapter per redirection, giving two FS clients. That survives date > out.txt, where the shell touches no file while the adapter writes. It does not survive ls > out.txt, which is exactly a line where the shell must read the filesystem while the redirection is being written.

There is no ordering fix, and that is the part worth stating precisely: there is no moment when both parties are done. fs_service::wait_for_caretaker already records the startup half of this hazard; this is the steady-state half, and startup ordering cannot solve it.

The answer

The shell already holds the directory capability, so it is the one process that can write the file without opening a second session.

Why this is the right shape and not a retreat

It costs the milestone nothing, which is the test.

What a redirected program holds is unchanged: one endpoint, WRITE, and no way to ask what is behind it. §51's indifference claim survives intact, because it was always a claim about what the writer holds and never about who implements the far end. And there is no change to grant_plan::spawnproto, to init, or to the kernel.

The honest smaller claim: > still grants strictly less than Unix's fd 1, but the sentence is now "the program holds an endpoint and the shell holds the file" rather than "an adapter holds the file". Sink::File and Source::File stay in the manifest, because the declaration check still needs them (worker 9 > out.txt is still refused as NotAByteStream); they simply need no capability at the prompt.

The adapter shape remains correct when the client is not the shell, which is what sink_tests measures against a real RedoxFS image. Nothing is deleted; one caller stopped needing it.

The demonstration, because it is better than a constant

$ ls
  globset/  motd  other/  redir/  rmtree/  scratch  sub/
$ ls > out.txt
$ wc < out.txt
  8 8 57

Seven entries listed, eight lines counted, because > truncates before the command runs, so ls sees the file it is writing into. riscv64 reports 10 on its own image. Two different numbers, each internally consistent, is stronger evidence than a pinned expectation could be.

BUGS