acpmux: under MDM's off, a full-access report counts before it is applied (#23322, review 69)

Merged
TE
25d ago
+351-8

What (#23322, review 69 finding 3)

The coordinator's order, word for word: "child_for: make the mode change visible at once. Record the off in the session's in-memory state before the log write returns, so the fast path sees it. Do NOT gate prompts on a log read: the busy-session send must still be accepted in under 1 s (P0)."

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 harness's session/update is logged by the session tap before the inbound loop applies it (on_update). In that window a session whose harness just reported full access still looked like it asks, so under MDM's off child_for's fast path could hand the agent a prompt.

Now the tap counts a full-access mode or option report of the session's own harness (not a subagent's) as it logs it (FloorState::unapplied_full_access), and on_update takes the count back once it applied the report. FullAccessView::of_session reads the count as the reported form, so child_for, cap_full_access and #26034's end path see the report at once. The count resets when the agent ends or exits, or a new host starts. No log read is added on the prompt path: the check is one atomic load. With MDM unset nothing changes: every reader of the form is behind MDM's off.

Its base is feat-cmux-next, where #26034 (b1) has merged.

Test (durable_agents): a_full_access_report_counts_before_it_is_applied_under_mdm_off, with the debug seam ACPMUX_TEST_UPDATE_DELAY_MS (updates are held 1.5 s before they are applied): the harness reports full access outside any turn, and the next prompt is never written to that agent. Red at 14441ea3ed, run 40472936381: fails 3 of 3. Green at 3cc246fcf5, run 40472936421: the test 3 of 3, fmt, clippy -D warnings, durable_agents 67/67, full_access_managed 2/2, web_mode_current 13/13, hub_integration 508/508, lib and session_pool only base reds.

How a report is kept (after reviews 3 to 5): the tap counts a full-access report as it logs it, under the session's meta lock; write_mode_state publishes the mode or option the report sets and takes its count back under that same lock; and FullAccessView::of_session reads the mode, the options and the count in one snapshot under it. A view therefore sees a report counted, applied, or not yet come, never in between. An agent MDM's off ends moves FloorState::retired_through to its generation under its agent slot's lock (generations only grow), and the inbound loop applies a mode or option report only from a newer agent, checked and applied under that lock, so a report of an ended agent, however late, is dropped, not applied to the agent after it; nothing is kept per agent, so nothing expires (review 6); the end also moves the taps' epoch (report_epoch), so the ended agent counts no more reports. An agent's exit no longer drops the count (the next agent's report may be counted by then).

Tests for reviews 3 to 5 (red at e6a5fe8b59, run 40523445879): lib a_report_tapped_and_applied_while_the_view_is_read_is_seen (test seam BETWEEN_VIEW_READS holds the view's read while another thread taps, then applies, the report: the order review 5 found) and a_report_of_an_ended_agent_is_not_counted; durable_agents a_report_of_an_agent_mdm_ended_leaves_the_next_agent_alone (red at 5876193ae1, run 40512360310).

Review 6 test (red at 1939df677f, run 40527363503: fails): lib a_report_queued_across_nine_ends_is_not_the_next_agents (the first agent's report is queued, it and eight agents after it are ended, a ninth starts, the queue drains).

Green at 83a444b212 (rebased onto feat-cmux-next 938668b321), run 40531611126: fmt, clippy, durable_agents 83/83, full_access_managed 2/2, web_mode_current 13/13, hub_integration 510/510, lib and session_pool only base's reds. Earlier greens: 38e16b8711 (run 40527363129), f65ac80738 (run 40524372575), 1fbba72f88 (run 40503077273).

Reviews 3 to 6 (Codex, at 1fbba72f88, 9d2e4b3a8a, 3e362c2c2c and f65ac80738) blocked on the read order between the count and the mode, on an ended agent's late report, on an exit dropping the next agent's count, and on a capped list of ended agents forgetting one; the lock and the generation bound above answer them. Out of scope (its own PR): start_mode.rs cap ends of cold or pooled agents do not record the ended agent.

Part of the split of #25539; review 69's other two findings get their own PRs.

Risk: medium. The tap, the update path and the full-access view share the meta lock for a report; only under MDM's off does the count change what runs. Size: about 330 changed lines, about 190 of them tests.

No capture: no UI changes.

Review: review 1 passed (SHIP) at 3cc246fcf5; reviews 3 to 6 blocked (answered above); review 7 (Codex gpt-6-astra xhigh) passed (SHIP) at 38e16b8711; after the rebase, review 8 blocked on a test that no longer compiled against base's new Inbound fields (fixed), and review 9 (Codex gpt-6-astra xhigh) passed (SHIP) at 83a444b212.

Agent session: agent session

šŸ¤– Generated with Claude Code