acpmux: under MDM's forced off, what already runs in full access ends (#23322 b1)
What (part b1 of #23322, split out of #25539)
#25539 grew past 2000 lines over its review rounds, so it is split into PRs that each land on their own. This is the first: under MDM's forced off, what already runs in full access ends. The decision on #23322, word for word:
"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, so it needs no call from Leo."
"Full access is unavailable" covers agents already running in it. Under MDM's off, end_if_runs_full_access ends an agent wherever a1's one predicate (runs_full_access) turns true for it, always under the session's spawn lock: the live child and any host a restart left. It runs at:
- every off push (
full_access_turned_off, every session; a turn in progress ends with it). Pushes take turns through their teardown (Hub::full_access_pushes), so an unset push never lands while an off push still ends what runs (review 36); - a mode or option write, the harness's own included:
write_mode_statewakes the hub's background task (idle.rs); - a mode switch that raced the push (a1's post-write check now ends the agent);
- daemon start:
adopt_agent_hostsends a host left in full access instead of adopting it, an unadoptable one too (its nonce proves it); - the next start (
reach_or_start);child_fornever hands such an agent out.
A host whose end by nonce fails, or whose host records cannot be read, may still run: it stays counted as full access (FloorState::full_access_end_pending), every start of its chat is refused with full_access_off, and the next check tries again (reviews 51 and 66). The argv each start runs is saved before the agent starts (SessionMeta::spawn_argv), so a respawn a config reload pinned to --yolo is judged by that argv, also after a crash (reviews 36 and 44). MDM's off is read once per operation where it begins and passed down (the rest of that rule, and the one blank-id rule, are #25985).
With MDM unset nothing changes: every new path is behind full_access_managed_off.
Tests (red at c8b34b2d53, run 40469342716: all fail on base):
durable_agents:a_retained_full_access_host_ends_once_mdm_turns_full_access_off,an_unadoptable_full_access_host_ends_once_mdm_turns_full_access_off,a_host_a_daemon_left_while_it_started_ends_under_mdm_off_by_the_argv_it_ran,a_full_access_host_whose_end_failed_is_never_reached_under_mdm_off(debug seamACPMUX_TEST_HOST_END_FAILS),an_end_that_could_not_read_the_host_records_is_tried_again(debug seamACPMUX_TEST_HOST_RECORDS_FAIL_FILE).full_access_managedRUNNING: an agent running in full access takes no more work; a harness that reports an undeclared full-access mode, a full-accessmodeoption, or another full-access option ends; a respawn a reload pinned ends at the push; an off push ends every full-access agent though an unset push follows.
Review 1 (Codex, at cccc76ee41) blocked on two things, both fixed:
- The sweep waited on a session's spawn lock without a deadline; a cold start's cleanup can hold it. Now the wait is bounded (
SHUTDOWN_GRACEtwice): past it the session is markedfull_access_end_pending(every start refused, counted as full access) and the hub's background task tries again, and the sweep goes on to the next session. - A forced end left a ready chat to the exit handler, which marked it
Disconnected. Now the chat is set idle before its agent is ended, and again once it has.
Red for those at 0166ee8027, run 40480568650: lib an_off_push_does_not_wait_on_a_held_spawn_lock and durable_agents a_chat_whose_agent_mdm_ended_is_idle fail (the second reads disconnected).
Review 2 (Codex, at eee6d3a03d) blocked on three things, all fixed:
- The end still waited without a deadline on the agent slot, which a stop holds while its agent ends. Now that wait is bounded too; past it the end stays pending and is tried again.
child_for's fast path handed out an agent whose end was pending once its reports no longer said full access. Now a pending end counts there too (managed_off_runs_full_access), so the start ends it first.- A turn in progress when the off ended its agent could still end later as a cut turn: continue by itself, and mark the chat disconnected. Now the end stops it as a stop does (no continuation, pending questions cancelled), and that turn's end leaves the chat idle (
FloorState::ended_turn).
Red for those at a66c5d4949, run 40490540547: lib an_end_does_not_wait_on_a_held_agent_slot and an_agent_whose_end_is_pending_is_not_handed_out fail.
Review 3 (Codex, at c93ccbee8d) blocked on two things, both fixed:
- The cut turn's prompt failed as "agent process closed", and a chat with a fallback profile then ran it again there. Now an agent the off ends is marked on the agent (
ChildAgent::end_on_purpose), and no failover runs for its turn. - A turn whose end was already under way (its turn taken) when the off ended the agent was not the running turn, so its end marked the chat disconnected. The mark is now on the agent, not the turn, set under the lock the turn's end reads it under, so such an end leaves the chat idle too.
Red for those at d3ccf48d27, run 40498032947: durable_agents a_turn_mdm_ended_is_not_failed_over and a_turn_ending_as_mdm_ends_its_agent_leaves_its_chat_idle (debug seam ACPMUX_TEST_FINISH_HOLD_MS holds a turn's end after its turn is taken) fail. The turn these tests cut now holds (hang); review 2's a_turn_mdm_ended_leaves_its_chat_idle sent a prompt this branch's fake agent does not hold on, so it had tested an ended turn.
Green at 9a839118ab, run 40498033090: fmt, clippy; lib 1352/1353 with only base's red agent_tools::tests::own_servers_run_under_the_daemon_prefix; durable_agents 70/70, full_access_managed 2/2, session_pool 26/26, web_mode_current 13/13, hub_integration 508/508. Earlier greens: c93ccbee8d (run 40490540605; full_access_managed 6 more runs, all green).
The full_access_managed case "an off push ends every full-access agent, also when an unset push follows" can fail about 1 run in 8: two settings pushes at once share chat-settings.json.tmp (base code), and one save fails with ENOENT. That fix is its own PR, #26156, merged.
The rest of the split, each its own PR, stacked in this order: #26035 and #26052 (review 69's findings 1 and 3, on this one); #26054 (b2, the left host's log read back); #26055 (review 69's finding 2, on b2); #26057 (b3, a left host's replay judged before its agent is handed out); #26058 (b4, options a bare set_config_option answer took); #26059 (b5, agents whose host link stopped). #25539 closes when the last lands.
Risk: medium. It ends running agents, only under MDM's forced off. Size: about 930 changed lines, 590 of them tests (over the usual 800 by the review fixes).
No capture: no UI changes.
Review: reviews 1 to 3 (Codex gpt-6-astra xhigh) blocked; every finding is fixed above. Review 4 (Codex gpt-6-astra xhigh) passed (SHIP) at 9a839118ab.
Agent session: agent session
š¤ Generated with Claude Code