Skip to main content

agentmux_srv_core/backend/reactive/
turn_audit.rs

1// Copyright 2026, AgentMux Corp.
2// SPDX-License-Identifier: Apache-2.0
3
4//! What a message did to the agent's turns, for the audit (`SPEC_CHEAPER_FLEET_MESSAGING_2026_10_30.md` ยง7).
5
6use super::handler::{Handler, ReactiveHandler};
7
8/// Whether `block_id`'s agent has a turn in flight. Read just before a message is written, which flips the
9/// turn on: a message into a running turn costs no new context read, one to an idle agent starts a turn.
10pub(super) fn turn_in_flight(block_id: &str) -> bool {
11    crate::backend::blockcontroller::get_controller(block_id).and_then(|c| c.turn_tracker()).is_some_and(|t| t.is_active_turn())
12}
13
14impl Handler {
15    /// A reply that said nothing was refused before delivery (`backend::ack_policy`): an entry with outcome
16    /// `ack_refused`, so the Audit counts the turns it saved.
17    pub(super) fn log_ack_refused(&mut self, source_agent: &str, target_agent: &str, request_id: &str, why: &str) {
18        self.log_audit(Some(source_agent), target_agent, "", "", false, Some(why), request_id, Some("ack_refused"), None);
19    }
20}
21
22impl ReactiveHandler {
23    /// See [`Handler::log_ack_refused`].
24    pub fn log_ack_refused(&self, source_agent: &str, target_agent: &str, request_id: &str, why: &str) {
25        self.inner.lock().log_ack_refused(source_agent, target_agent, request_id, why);
26    }
27}