acpmux: under MDM's off, an agent whose host this daemon no longer hears ends (#23322 b5)
What (part b5 of #23322, split out of #25539)
The decision on #23322: "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."
A host link that broke (an entry could not be logged), closed (the host died, or another owner took it over) or failed an acknowledgement stops its reader: what the host reports from then on is not heard until a reattach, so a full-access mode it moved to could go unseen. Under MDM's off:
- such an agent counts as full access (
host_unheard), so the off push ends it, and so does the next push when an end failed; - a link that stops under MDM's off ends its agent at once: the reader queues
Inbound::LinkBroken, which wakes the hub's background check; - a reader that stopped otherwise (
Hosted::stopped,ChildAgent::is_stopped; a reattach clears it) counts as unheard, andchild_fordoes not hand such an agent out;is_aliveis as before, so with MDM unset the chat goes as it did; - what waits on an agent whose link broke is answered at once (
ChildAgent::fail_pending): a start waiting on itsinitializewould otherwise hold the spawn lock the check takes; - what waited on the ended agent is answered (
ChildAgent::fail_pending, pending permissions cancelled), since a stopped reader reads no exit for it.
With MDM unset nothing changes: LinkBroken does nothing then, and host_unheard and is_stopped are read only under the off. A link that stops ends no agent by itself.
Base: feat-cmux-next, with #26057 (b3) and #26058 (b4) merged; this head sits on b4's reviewed head 57f893249d, so the squash carries only this piece's diff.
Since review 4: an off push waits on a held agent slot only up to the shutdown grace when it checks for an unheard host (host_unheard, and the fail_pending_if_unheard call before the spawn-lock wait); a base test, an_off_push_returns_in_time_while_a_cut_message_is_being_written, hung on the unbounded wait. Rebased under #26057, ChildAgent::reattach sets b3's replay_to under the same pending and link locks it swaps the link and clears the flags under.
Tests (durable_agents; red at 78d44398de, run 40472834141: 6 of 6 fail): a host whose link broke ends at the off push; a link that breaks under the off ends its agent at once; a failed end of an unheard agent is tried again by the next push (ACPMUX_TEST_STALL_HOST_TERMINATE, ACPMUX_TEST_HOST_END_FAILS=once); a prompt on an unheard agent settles when MDM ends it; a link lost to another owner under the off; an agent whose acknowledgement failed (debug seam ACPMUX_TEST_ACK_FAILS_ONCE).
Review 1 fixes (red at 5c83131025, run 40483847077: both fail): a_link_that_breaks_while_its_agent_starts_under_mdm_off_ends_it (the initialize answer is not logged; the start waited 90 s on it) and an_ack_failure_with_mdm_unset_leaves_its_chat_as_before (the chat was marked disconnected).
Review 2 fix (red at fce53b7e56, run 40489310577: fails): a_late_notice_of_a_reattached_link_leaves_its_requests_alone (debug seam ACPMUX_TEST_LINK_BROKEN_DELAY_MS holds the notice). A broken link's notice now fails requests only while that link is still broken or stopped, checked under the lock a reattach clears those under (fail_pending_if_unheard).
Review 3 fixes (red at 56daf86118, run 40496259140: both fail): an_off_pushed_after_a_link_broke_while_its_agent_started_ends_it (a link broken while MDM was unset left the start's initialize waiter for the off to find; the off now answers what waits on an unheard agent before it takes the spawn lock) and a_held_reader_of_a_lost_link_leaves_the_reattached_link_heard (debug seam ACPMUX_TEST_READER_STOP_HOLD_MS: a lost link's reader marked the link that replaced it stopped; a reader now marks its link broken or stopped only while it is still the agent's link, under the lock a reattach replaces it under).
Green at 6523c06cb5 (on #26058 at 57f893249d), run 40569379624: fmt, clippy clean, durable_agents 113/113, full_access_managed 2/2, session_pool 33/33, web_mode_current 13/13, hub_integration 510/510, lib only base's red agent_tools::tests::own_servers_run_under_the_daemon_prefix. Green at d04176b351, run 40496375626: fmt, clippy, durable_agents 99/99, full_access_managed 2/2, web_mode_current 13/13; lib, session_pool and hub_integration only base's reds and load flakes (agent_tools::tests::own_servers_run_under_the_daemon_prefix, pooled_sessions_end_with_the_daemon_and_after_a_crash, prompt_supersede::a_prompt_queued_before_a_restart_is_still_replaced). Earlier greens: 73ba3ea508 (run 40493060474), 9a675899 (run 40489310282), 0dea4ae8f3 (run 40483848065).
Review 1 (Codex, at 11fc3082bb) blocked on two findings, both fixed above: (1) a link that broke while its agent started left the start holding the spawn lock on an answer never read; (2) Hosted::stopped made is_alive false with MDM unset too.
Review 2 (Codex, at 1e7f21f045) blocked: a broken link's notice that arrived after a reattach failed the new link's requests. Fixed above. Its out-of-scope finding (hub/pool: a pooled host whose link stopped is not refused before it is claimed) is its own follow-up PR, after this lands.
Review 3 (Codex, at 73ba3ea508) blocked on two findings, both fixed above: (1) a link that broke while its agent started with MDM unset left an off waiting on the start's spawn lock; (2) a lost link's reader could mark the reattached link stopped.
The last piece of the split: #25539 closes when this lands.
Risk: medium. It ends agents whose host this daemon no longer hears, only under MDM's forced off. Size: about 480 changed lines, 320 of them tests.
No capture: no UI changes.
Review: review 4 (Codex gpt-6-astra xhigh) passed (SHIP) at d04176b351; the code changed since, and review 5 (full) passed (SHIP) at 6523c06cb5.
Agent session: agent session
š¤ Generated with Claude Code