roadmap BUILT

1108. socket_contract: what an outside maintainer would fix before it leaves

Raised by a read-only review of crates/socket_contract as a stranger to this tree would meet it, ahead of its move under step 2 of milestone 1017 (the contract crates leave in this order). It changes nothing; it lists what the next lanes change.

The review took its accepted baseline from the review package. It raises none of the decisions it puts to the architect. They are the identity values (INTERFACE_ID 19, VERSION 1, since ruled), where fixture, ephemeral and polled_wait live, the table of 55 proposed names (ratified 2026-11-20 UTC), and the clearance itself. Nothing here reopens them. Where this review reads a later rule differently from the package, it says so at the item. The bind-time version check belongs to milestone 1000 (message contracts carry bind-time version checks) and is not repeated here.

Reuse: the template partsfoundry/crate-workflows and its scaffold, Kani, cargo-mutants, the crate's own tests and falsification patches. No new tool, no new dependency.

Goal

A stranger who finds socket_contract can write a client, or a second network stack, from the crate's text alone and have it interoperate with the stack nife ships. Today the text and the wire disagree on where a send's length travels, which fails that goal before anyone discusses a name. After this block, every operation's documentation states its argument word, its reply words and what the frame carries in each direction. The repository's gates are green for the crate's own reasons. The proofs cover the one piece of logic the crate holds beyond the grants.

Finding status

Rules in force

What was checked, and how

The tools run, the sources read and what was not run are in the appendix.

Prior art

The comparison with nearby work is in the appendix.

The items

Effort: S is under half a day for a lane, M a day or two, L more. A door is one-way when somebody outside the repository acts on it after the release (a published name, a wire format, a layout, an identity, a dependency); everything else is two-way and the maintainer decides it. The crate has not released, so its names are two-way today and the package's naming table stands.

P0: blocks the move

  1. The contract's text and its wire disagree on where a send's length travels. DONE (every OPERATION_ states its argument and reply words; the OPERATION_SEND doc test sends with the length as the argument; LENGTH_OFFSET_BYTES says only RECEIVE writes it; D1 ruled 2026-11-11). Finding: the layout note at crates/socket_contract/src/lib.rs lines 454 to 459 says the len field at LENGTH_OFFSET_BYTES is "in for SEND*, out for RECEIVE". The documentation of OPERATION_SENDTO and OPERATION_SEND (lines 53 to 60) says "payload in the frame" and nothing about the argument word. The stack never reads LENGTH_OFFSET_BYTES: components/src/socket_server.rs lines 172 and 182 pass the CALL's argument as the length, and socket_operations.rs lines 45 and 328 bound that argument by DATA_MAXIMUM. The std platform layer and the test client both pass the length as the argument and never write LENGTH_OFFSET_BYTES (nife.rs lines 496 and 856, socket_test_client.rs line 406). A client written from the crate's text, which writes LENGTH_OFFSET_BYTES and passes 0, sends nothing and hears that it sent nothing. The only writer of LENGTH_OFFSET_BYTES is the stack's RECEIVE (socket_operations.rs line 116), and its only reader is components/src/socket_squatter.rs line 164, which polls it as a "data arrived" flag. Evidence: the lines above. Change: state the wire as both sides already speak it. Each OPERATION_ constant's documentation names its argument word. For SEND and SENDTO it is the payload length in bytes, at most DATA_MAXIMUM. For LISTEN and BIND_UDP it is the port. For RECEIVE, CONNECT, CLOSE and ACCEPT the stack ignores it, so pass 0. The documentation also names the reply. SEND replies the count of bytes the stack accepted, which may be short. SENDTO replies REP_OK. RECEIVE replies the count written to the frame. The layout note says RECEIVE writes len and nobody the contract requires reads it; a test asserts that LENGTH_OFFSET_BYTES's documentation and OPERATION_SEND's agree (a doc test that sends from a fake frame is enough). The README's "Replies" bullet changes with it. This is item D1 below, since the choice of which side carries the length is a wire-format door; the recommendation is to ratify the implementation. Door: the text is two-way; the wire choice it records is one-way. Effort: S.

  2. The manifest's publish comment points outside the repository. PARTIAL: the comment and repository are in place. LEFT: the caller's allow-unpublished, at the move. Finding: Cargo.toml line 11 reads publish = false # the default; the allowlist lint holds the exception (crates/publish-allowlist.txt). That file is nife's and will not be in the new repository; the crate is not on the allowlist today. The template's check / standalone expects either a publishable manifest or the caller's allow-unpublished input. Evidence: Cargo.toml line 11; crates/publish-allowlist.txt (no socket_contract row); the template README's description of check.yml. Change: at the move, replace the comment with one sentence a stranger can act on ("set to true only in the release that publishes") and pass allow-unpublished in the caller until then. Add repository = "https://github.com/nifeos/socket_contract" (the scaffold's badges assume it). Publishing itself stays held, as the package records. Door: two-way. Effort: S.

P1: before the first release

The P1 items are in the appendix.

P2: for later

The P2 items are in the appendix.

Decisions for the architect

Only one-way doors, all ruled. The package's decisions 2, 3 and 4 are two-way doors the maintainer rules provisionally. D1 and D2 are additions the package did not raise.

Background. A client fills the shared frame with a payload and asks the stack to send it. The stack must learn how many bytes to send. The frame has a len field at LENGTH_OFFSET_BYTES, and the CALL has an argument word. The crate's text says the field; the stack, the std platform layer and the test client all use the argument word, and nobody writes the field before a send. The two agree only by accident of one tree holding both sides. Once the crate leaves, a second implementation follows the text.

Recommendation: ratify the argument word as the carrier, and make LENGTH_OFFSET_BYTES an output of RECEIVE only. The argument arrives with the request atomically and the kernel's word bounds it, so the stack checks one value against DATA_MAXIMUM before it touches the frame. A length in the frame is a second copy of the same fact that a client could leave stale. The alternative, the field, would make every in-tree client change for no gain and keep two places where a length can live.

Prior art: send(2) and write(2) take the length as an argument and return the count accepted; smoltcp::socket::tcp::Socket::send_slice and embedded-nal's send take a slice and return the count; io_uring's submission entry carries its length beside the buffer address (unverified).

Example: a client writes b"nife-out!" at PAYLOAD_OFFSET_BYTES and issues CALL(connection, OPERATION_SEND, 9); the stack replies 9, or fewer if its buffer is short, and the client sends the rest. It never touches LENGTH_OFFSET_BYTES.

Background. A listener's ACCEPT replies with the new connection's capability and nothing else. The connection has no frame yet, so the peer's address has nowhere to ride, and std reports 0.0.0.0:0 as the peer of every accepted stream. A server that logs who connected, applies a per-peer limit, or speaks a protocol that embeds the peer address (FTP, SIP) cannot. The tree already holds this as a contract change.

Recommendation: carry the peer in the second reply word. Pack it as the IPv4 address big-endian in bits 16 to 47 and the port in bits 0 to 15 (peer_word, word_peer), with a harness proving the round trip for every address and port. The word is already on the wire and always 0; filling it changes no client that ignores it. The alternative, writing the peer into the connection's frame once attached, delays the fact until a second operation and ties it to a frame the client may not attach.

Prior art: accept(2) returns the peer's sockaddr with the new descriptor; embedded-nal's TcpFullStack::accept returns (socket, SocketAddr); Fuchsia's socket Accept returns the address (unverified).

Example: a client calls CALL(listener, OPERATION_ACCEPT, 0) and receives (REP_OK, 0x0a00_0202_c3f1): the peer is 10.0.2.2:50161, and word_peer says so.

Done when

The checks are in the appendix.

BUGS

Follow-on

Index row

An outside review of socket_contract before its move. The text says a send's length rides in the frame while every implementation passes it as the argument word, which blocks the move until ruled. A manifest comment points into nife. Nine more items follow: the peer address ACCEPT does not return, the reply words left unstated, the README against the scaffold, three equivalent mutants to exempt, a proof for the ephemeral cursor, and one type for offsets and lengths.