acpmux: under MDM's off, a left host's replay is judged before its agent is reached (#23322 b3)

Merged
TE
25d ago
+604-13

What (part b3 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 a restart left keeps what its harness reported while no daemon was attached, and replays it to the next daemon on adoption; a host whose link broke replays what it kept on a reattach. Until now the agent could be handed out before that replay was judged. Under MDM's off:

  • adoption (adopt_one) waits for the replay (bounded, as before) and judges the session again from the log before the agent is handed out; a replay that did not complete may still hold a full-access report, so the host ends;
  • a reattach (readopt, judged_after_reattach) does the same. A host reattached while MDM is unset is handed out at once, and the next off judges its replay: the reattach drops any earlier log read (left_host_read), and until the replay is all in the log the agent counts as full access (ChildAgent::replay_pending, host_replaying);
  • how far the replay runs is learned, not taken from the host's hello: entries the host numbers after its hello and before it handles this daemon's Resume come in the same backlog. Link::replay_end_within asks the host a question after Resume; the host answers behind every entry it numbered before, so the highest entry seen by then is the replay's end (ChildAgent::learn_replay_end). Until it is learned, the replay counts as pending (mark_replay_unknown, reattach). Under MDM's off adoption and a reattach wait for that end before they judge; with MDM unset it is learned in the background (review 3);
  • child_for's fast path does not hand out an agent whose replay is pending under MDM's off; the start judges it first, as the off's teardown does (review 3);
  • an off pushed while adoption runs counts: adoption and re-adoption take one OffLatch (MDM's off with the count of offs) where they begin and pass it down, so a push that read the log before the replay reached it is not the last word.

With MDM unset nothing changes.

Tests (durable_agents; red at b59f6652a5, run 40472445556: 4 of 4 fail): a mode a left host replays is judged before a prompt reaches its agent (debug seam ACPMUX_TEST_UPDATE_DELAY_MS); a replay that did not complete ends the host (ACPMUX_TEST_REPLAY_INCOMPLETE); a mode a reattached host replays (ACPMUX_TEST_UNLOGGED_ONCE breaks the link); an off pushed while a left host is adopted (ACPMUX_TEST_ADOPT_HOLD_MS).

Review 1 fix: a_host_reattached_while_mdm_is_unset_is_judged_by_its_replay_at_the_next_off; red at e7e4137d66, run 40484533595: fails.

Review 3 fixes (red at 742a2dbdb2, the tests on the reviewed code, run 40554955919: both fail):

  • lib a_replaying_agent_is_not_handed_out_under_mdm_off: under MDM's off, child_for does not hand out an agent whose replay is pending.
  • durable_agents a_report_a_reattached_host_numbers_after_its_hello_is_judged_under_mdm_off: a link breaks (ACPMUX_TEST_UNLOGGED_ONCE); as the next request reattaches it, the harness moves into full access after the host's hello and before Resume, and that entry arrives late (debug seam ACPMUX_TEST_BEFORE_RESUME_FILE). The request never reaches that host.
  • durable_agents a_report_a_host_numbers_after_its_hello_is_judged_before_adoption_under_mdm_off: the same at a restart's adoption. A guard: it passes on the red commit too, since base's adoption asks the host a question after Resume (note_host_kind), whose answer comes behind that entry.
  • host_replaying waits on the agent slot only for SHUTDOWN_GRACE (the slot held means the agent counts as in full access): without that bound, base's an_off_push_returns_in_time_while_a_cut_message_is_being_written hung.

Green at f7e89ace27 (rebased onto feat-cmux-next 8520e78578, same patch as ded35e89f0), run 40560719936: durable_agents 99/99 with both new tests, the rest as below with only base reds. Green at ded35e89f0 (on feat-cmux-next with #26034, #26035, #26054, #26052, #26055, #25985), run 40554956476: fmt, clippy (only base's collapsible-if warnings in cli/codex_auth_broker.rs); lib 1527/1528 with only base's red agent_tools::tests::own_servers_run_under_the_daemon_prefix; the two lib tests above pass; durable_agents 92/92, full_access_managed 2/2, session_pool 32/33 with only base's flaky pooled_sessions_end_with_the_daemon_and_after_a_crash, web_mode_current 13/13, hub_integration 510/510. Earlier greens: 47ba2e160f (run 40541903998), 3b3314a67a (run 40493060697), 8511d07247 (run 40484533565), 905c66ae9f (run 40472445508).

Review 1 (Codex, at 905c66ae9f) blocked: a reattach with MDM unset kept an earlier log read, so a later off skipped the replayed full-access mode. Fixed as above. Its out-of-scope finding (hosts.rs: a host this build cannot speak to is left running, so a full-access mode only its replay holds is not judged) is tracked in #26337.

Review 2 (Codex, at 8511d07247) blocked on two findings. (1) adopt_one dropped an earlier log read only under MDM's off, so a host re-adopted while MDM was unset kept it: fixed, every adoption now drops it. (2) The replay is bounded by the host's last_h from its hello, and entries the host numbers after the hello arrive as live reports, not replay. That bound is base's (base's adoption already waits for last_h), and those later entries are live reports, which #26052 (in this PR's base) judges as they arrive.

Review 3 (Codex, at 47ba2e160f) blocked on two findings, both fixed above: (1) child_for's fast path ignored a pending replay; (2) the hello's last_h is not the replay's end.

Follow-ups, each its own PR: b4 (options a bare set_config_option answer took), b5 (agents whose host link stopped).

Risk: medium. Adoption and reattach, only under MDM's forced off. Size: about 620 changed lines, about 360 of them tests.

No capture: no UI changes.

Review: review 4 (Codex gpt-6-astra xhigh) passed (SHIP) at ded35e89f0; review 5 (rebase only) passed (SHIP) at f7e89ace27.

Agent session: agent session

šŸ¤– Generated with Claude Code