Skip to main content

TurnActivityTracker

Struct TurnActivityTracker 

Source
pub struct TurnActivityTracker {
    block_id: String,
    inner: Mutex<TurnActivityTrackerInner>,
    publisher: Mutex<Option<Arc<dyn Fn(&TurnLedger) + Send + Sync>>>,
    publish_order: Mutex<()>,
    clock: Box<dyn Fn() -> u64 + Send + Sync>,
}
Expand description

Per-block turn-activity tracker.

Fields§

§block_id: String§inner: Mutex<TurnActivityTrackerInner>§publisher: Mutex<Option<Arc<dyn Fn(&TurnLedger) + Send + Sync>>>§publish_order: Mutex<()>

Taken before inner is released and held through the publish, so ledgers go out in seq order. The broker keeps the last one for replay, so an older one published last would be what a new subscriber gets (#4492). Lock order: inner → publish_order.

§clock: Box<dyn Fn() -> u64 + Send + Sync>

Implementations§

Source§

impl TurnActivityTracker

Source

pub fn new(block_id: String) -> Self

Source

pub fn for_block(block_id: String, broker: Option<&Arc<Broker>>) -> Self

A tracker that publishes its turn ledger on broker, when there is one.

Source

fn with_clock( block_id: String, clock: Box<dyn Fn() -> u64 + Send + Sync>, ) -> Self

Source

pub fn set_ledger_publisher( &self, publisher: Arc<dyn Fn(&TurnLedger) + Send + Sync>, )

Where ledger changes go (the agentturn event). Set once by the controller that owns this tracker, when it has a broker.

Source

fn publish_in_order( &self, inner: MutexGuard<'_, TurnActivityTrackerInner>, before: Option<TurnLedger>, after: Option<TurnLedger>, )

Release inner and publish the ledger if it changed, in seq order, logging the change as a [turn] line (muxlog’s answer to “why did my timer reset”: turn-model spec §7).

Source

fn publish_if_changed( &self, before: Option<TurnLedger>, after: Option<TurnLedger>, )

Send the ledger to the publisher, if it changed. Called after the tracker’s lock is released.

Source

pub fn set_active_turn(&self, active: bool)

Called when a new turn starts (subprocess spawned).

Source

pub fn mark_turn_active_returning_was_active(&self) -> bool

Atomically marks a turn active and reports whether one was already in flight (the pre-call value) — a single lock acquisition, unlike calling is_active_turn() then set_active_turn(true) separately. That two-step form is a check-then-act race: send_message (user input) and send_user_message (muxbus delivery) can run concurrently on the same block, and both reading false before either writes true lets both decide to spawn a watchdog — the exact duplicate the “only re-arm when resuming from idle” logic exists to prevent.

Source

pub fn mark_turn_active_from(&self, input: Option<TurnInput>) -> bool

Self::mark_turn_active_returning_was_active, saying who delivered the input (turn provenance, SPEC_AGENT_SELF_QUIT §6.3):

  • starting a turn records input as what started it — or, unlabelled, whatever was queued for it (else unknown);
  • into a running turn, non-user input — or unlabelled input, which can’t be proven to be the user — taints it.
Source

pub fn note_cli_task_notification(&self, summary: Option<&str>)

The CLI reported a finished background task (system/task_notification). It tells the model in a pass it starts itself: at once if it is idle, straight after the running pass otherwise.

Source

pub fn mark_turn_active_from_cli(&self) -> bool

The CLI began a pass with no input from srv (system/init while idle). Marked active only when something explains it (a task notification, or input that reached it during the last pass), so a stray line can never leave the agent reported busy with nothing to end it. Returns whether the pass was marked (the caller then publishes status and re-arms the heartbeat).

Source

pub fn end_pass(&self, stats: Option<PassStats>)

The CLI’s result: the running pass is over. Its figures (when the frame carries them) go to the turn it belonged to in the same step as the idle flip, so input that arrives right after can’t take them.

Source

pub fn hint_join(&self, turn_id: u64)

A message the pane held while turn turn_id ran is about to be sent through a controller whose pass start carries no input (ACP, App Server, one-shot subprocess): the pass it starts joins that turn, as TurnInput::joins_turn does for the persistent controller (§4.3, J3).

Source

pub fn clear_join_hint(&self)

Drop a join hint whose dispatch failed: no pass will consume it, and a later message must not.

Source

pub fn set_exited(&self, exit_code: i32)

Called when the subprocess exits.

Source

pub fn is_active_turn(&self) -> bool

Whether there’s an active turn in progress.

Source

pub fn hint_next_turn(&self, input: TurnInput)

A message queued now will start a later turn (it waits for the process to spawn). Two queued before that turn starts: the second, if not the user’s, taints it.

Source

pub fn hint_next_turn_unlabelled(&self)

An unlabelled message queued for the next turn: it can’t be proven to be the user, so a turn already labelled by an earlier queued message is tainted. (Queued first, it leaves the turn unknown anyway.)

Source

pub fn mark_turn_active_for_queued(&self) -> bool

The turn is active because messages already accounted for are being delivered — the queue drained after a spawn, a retry flush. Not new input: an idle tracker starts the turn with whatever was queued for it, and a running turn is left as it is (ReAgent P1 on #3789 — the plain unlabelled mark tainted every freshly spawned user turn).

Source

pub fn provenance(&self) -> Option<TurnProvenance>

What started the turn in flight, if one is and it was reported.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<T> Downcast for T
where T: Any,

§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.
§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Convert Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
§

fn as_any(&self) -> &(dyn Any + 'static)

Convert &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
§

impl<T> DowncastSync for T
where T: Any + Send + Sync,

§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Send + Sync> ⓘ

Convert Arc<Trait> (where Trait: Downcast) to Arc<Any>. Arc<Any> can then be further downcast into Arc<ConcreteType> where ConcreteType implements Trait.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<A, B, T> HttpServerConnExec<A, B> for T
where B: Body,

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
§

impl<T> PolicyExt for T
where T: ?Sized,

§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] only if self and other return Action::Follow. Read more
§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more