Deliver a leader's buffered output before Exited - #351
Merged
Merged
Conversation
The process protocol now orders Exited after every output byte buffered in a captured stream when the service reaps the leader, as a native parent sees all of its child's output once waitpid returns. Output written later by processes that still hold the stream can follow Exited. Exited never waits for an acknowledgement: when the replay limit stops reading, it follows the output read until then. With a PTY, output still in the kernel's asynchronous terminal queue at the reap can follow Exited. The Linux service records each open stream's mark at the reap, which is the offset it has delivered plus FIONREAD/TIOCINQ, and pushes Exited once every stream reaches its mark, closes or is abandoned, or once the retained output reaches the replay limit. Readers now read non-blocking and push under the operation lock, so no byte is uncounted between a read and its event. That also makes the replay budget exact and removes the per-stream reservations. An empty read lowers the mark, so a terminal flush cannot leave it unreachable. CloseOutput closes the file outside the lock because Close waits for a read in progress.
SaladDay
force-pushed
the
aos/exit-order
branch
from
October 1, 2026 02:28
a8ac2b5 to
c71f2a5
Compare
The launch now fails with EffectNone unless each output descriptor is non-blocking and watched by the runtime poller, so a read under op.mu never blocks. A read always has at least a page of room under the replay limit, so a packet-mode pipe never loses the rest of a packet; with less room the reader waits for acknowledgements and the exit gate treats it as the limit. The ordering rule now names its exceptions: an abandoned or lost stream, output held back by the replay limit, and the PTY residual. The ordering tests hold the readers through a test seam and use a FIFO handshake instead of scheduling and sleeps.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This change to the Process protocol comes from the #348 review. A client that mirrors a native child, such as the process broker, must see all of the leader's output before it sees
Exited, as a native parent does oncewaitpidreturns. Before this changeExitedcould overtake output still buffered in the service's pipe. A Harness that read a stdout file on exit then got truncated output.Protocol (
docs/process-protocol.md)Exitedfollows every output byte buffered in a captured stream when the service reaps the leader, and it never waits for an acknowledgement. The rule names its exceptions:CloseOutput, or lost to a read failure, delivers no more output;Exited;Exited, and a terminal flush discards output as it does natively.Exited, as it does natively.The protocol code (
internal/sandboxprocess) needs no type change.Linux service
TIOCINQ.Exitedis pushed once every stream has reached its mark, closed or been abandoned, or once less than a page of the replay limit remains.O_NONBLOCKand checked to be registered with the runtime poller. Otherwise the launch fails withIOandEffectNone. A read under the operation lock therefore never blocks, and the watermark is exact.O_DIRECTpipe never loses the rest of a packet.Runninguntil theExitedevent exists.Exited.Checks
TestOutputPrecedesExitedholds the readers through a test seam until the reap. It fails 5 of 5 runs with the watermark disabled.TestLaterOutputFollowsExiteduses a FIFO handshake.TestPacketsAtReplayLimitsends 20 × 4096-byteO_DIRECTpackets. It fails on the previous code, with a 1000-byte short read.-count=20on the new tests,go test ./apps/sandboxio/... ./internal/sandboxprocess, vet and gofmt.