acpmux: the write fence for a hosted agent (#23322 a3 fence, part 2 of 5)
What (#23322 a3 fence, part 2 of 5: the fence for a hosted agent)
It builds on the decision on #23322, quoted word for word:
"#23322 (sessions.allowFullAccess under MDM), decided: an MDM-managed value is an upper bound the user can't override. If MDM sets allowFullAccess=false, Full access is unavailable and the mode menu says "Managed by your organization". If MDM is unset, nothing changes. This only narrows access."
#25538 (#23322 a3) landed as 3e72956265, and part 1 (#25804) as 9cd4a013e3. Review 40 on it found that its family gate was released before the write (3) and that a blocked transport could stall an MDM off push forever (4). This stack of five PRs closes both. Each one lands on its own, in order:
- the fence for a direct agent;
- the fence for a hosted agent;
- host protocol 2 receipts;
- family messages;
- ancestor answers.
This PR lets a fenced line go to an agent that runs under an agent host (agent_host/link.rs).
- The daemon holds each fenced line, keyed by host incarnation, until it settles. That map is shared by every connection the daemon makes, so a reattach keeps it (review 82).
- No answer settles it: an error may be this side's own "agent process closed" or made up by a translator once its harness's output ended, and a translator answers prompts it gave up on too (review 87). Until part 3's receipts, a hosted line settles only when its host ends, or when a cut ends its host.
- A host's end is watched from its first fence, through its live lock in the pool, hosts or socket directory (
live_lock_dirs). This works whatever logs its entries or holds its connection.- A move from the pool to the hosts directory is not taken for death.
- A lock it can't judge fails closed and leaves the line unsettled (review 87).
- A harness's
Exitsettles nothing. The host may still be writing to a descendant that kept the harness's stdin; only the host's own end proves the line can't arrive (review 87). - A hosted cut ends the host by its start nonce (
terminate_unadoptable), proven by its live lock. It runs one bounded try at a time, and a try that outlived its bound is awaited again rather than started twice (review 87).
With MDM unset, nothing changes. No caller fences yet.
Risk:
- The daemon keeps one map entry per fenced hosted line until it settles, and one watch task per host incarnation that has fenced lines.
- A host that gives no receipt (protocol 1; a mixed-build host after part 3) never proves a fenced line written. So an MDM off push that finds a family line in flight to it waits 5 s, then ends that host. This fails closed, as the decision asks ("This only narrows access").
Tests
tests/agent_host.rs:
a_fenced_request_cut_off_by_a_new_controller_settles_only_with_its_host, which stays unsettled 7 s while its host lives. Red: run 40466670878 (review 87);a_fenced_answer_settles_once_its_host_is_killed, with a log that refuses every entry (review 85, 87);a_cut_of_an_unproven_line_to_a_protocol_1_host_ends_that_host(review 85);a_harness_exit_does_not_settle_a_line_its_host_still_writes: a setsid descendant keeps stdin, and Exit is never acknowledged. Red: run 40486944658 (review 87);an_answer_does_not_settle_a_request_its_host_still_writes, with a made-up error and a made-upcancelledresult. Red: run 40494474046 (review 87).
Green at d9f670f17a (run 40494474042), the same patch as this head before part 1 landed:
- fmt and clippy clean;
- agent_host 16/16 four times;
- lib 1387/1388, durable_agents 61/61 and hub_integration 508/508; the other suites pass.
The only failures are base reds: lib own_servers_run_under_the_daemon_prefix and session_pool pooled_sessions_end_with_the_daemon_and_after_a_crash.
Rerun at this head (b766a1dd18), run 40499167807: fmt and clippy clean; lib 1414/1415 and session_pool 25/26 (only the base reds above); agent_host 16/16 twice; durable_agents 61/61; hub_integration 510/510.
Review
An independent Codex reviewer (gpt-6-astra, xhigh) gave SHIP at d9f670f17a (review 87, round 6). This head is that patch rebased onto part 1 with no change. Rounds 1 to 5 blocked; each finding was fixed red-first:
- a request settled by this side's own "closed";
- a host's end observed only through its connection;
- a harness's Exit taken as proof;
- answers taken as proof of a write.
No capture: no UI changes.
Agent session: agent session
š¤ Generated with Claude Code