pub struct RunState {
pub total_actions: usize,
pub turn_actions: usize,
pub run_has_actions: bool,
pub reasoning_only_strikes: usize,
pub empty_response_strikes: usize,
pub nudge_count: usize,
pub thinking_disabled_for_rest_of_run: bool,
pub original_thinking_enabled: bool,
pub truncation_strikes: usize,
pub awaiting_human: bool,
}Expand description
Run-level state tracking for the react loop.
Manages counters and flags that track the current run’s progress.
Most fields are reset at the start of each run (when a new user message
arrives); total_actions and
original_thinking_enabled are
session-lifetime and survive run boundaries.
§Backward compatibility
Before this struct existed, nudge_count and turn_tool_calls were flat
fields on AgentSession (and the session total lived in a top-level
total_tool_calls). The RawAgentSession deserialization shim migrates
them automatically; the field aliases below keep pre-T7 run_state wire
keys readable.
Fields§
§total_actions: usizeSession-lifetime count of actions executed (across all runs).
Not reset by reset_for_new_run — a session
that already acted stays “not first turn” across run boundaries.
Used by ToolEnforcementMiddleware for “first_turn_only” enforcement.
turn_actions: usizeNumber of actions already executed in the current turn.
Reset to 0 at the start of each turn (when a new user message arrives).
Used by TurnToolLimitMiddleware to enforce per-turn action limits.
run_has_actions: boolWhether any actions ran in the current run. Reset to false at the start of each run. Used by the completion judge to determine if actions were used before a text-only response.
reasoning_only_strikes: usizeNumber of consecutive LLM turns that produced only reasoning_content (no text, no tool call). Reset to 0 when a normal response or tool call is produced. Used by the react loop to fail instead of looping forever on a reasoning-model runaway.
empty_response_strikes: usizeNumber of consecutive LLM turns that produced a completely empty response (no text, no reasoning, no tool call). Reset to 0 when a normal response or tool call is produced. Used by the react loop to retry a bounded number of times, then fail instead of looping forever.
nudge_count: usizeNumber of tool-enforcement nudges issued in the current turn.
Reset to 0 at the start of each turn (when a new user message arrives).
Used by ToolEnforcementMiddleware to cap nudge attempts per turn.
thinking_disabled_for_rest_of_run: boolThinking is disabled for the rest of the current run. Set to true when reasoning_only_strikes reaches the maximum (3). Reset to false at the start of each new run (when a new user message arrives). This allows the model to continue without thinking after too many reasoning-only responses.
original_thinking_enabled: boolOriginal thinking configuration (for restoration)
Records whether thinking was originally enabled when the session started. Used to restore thinking to its original state after DisableThinking → RestoreThinking cycle.
truncation_strikes: usizeNumber of consecutive LLM turns where the truncation guard fired (all tool_calls had invalid/truncated arguments). Reset to 0 when at least one valid tool call executes successfully. Used to break the re-issue death spiral: after N consecutive truncations, stop retrying and fail with an actionable message.
awaiting_human: boolThe latest tool batch parked on a human step (a design-canvas screen
awaiting a pick) and no tool ran after it. Overwritten per batch by
handle_tool_calls. When true at the end of a run, the run is
waiting for the user — the guard must complete instead of nudging
“continue working” over their pending answer.
Implementations§
Source§impl RunState
impl RunState
Sourcepub fn reset_for_new_run(&mut self)
pub fn reset_for_new_run(&mut self)
Reset all run-level state for a new run (when a new user message arrives).
Session-lifetime state (total_actions, original_thinking_enabled)
is not reset.
Sourcepub fn record_actions(&mut self, n: usize)
pub fn record_actions(&mut self, n: usize)
Record executed actions (branch 3: actions ran). Counts them against both the turn and the session total (D5: one counting entry point, unit = actions) and resets reasoning_only_strikes, empty_response_strikes, and truncation_strikes.
Sourcepub fn record_reasoning_only(&mut self) -> usize
pub fn record_reasoning_only(&mut self) -> usize
Record reasoning-only response (branch 1). Resets empty_response_strikes. Returns the new strike count. If strikes reach 3, disables thinking for the rest of the run (the caller owns the observability for that flip — types stay I/O-free).
Sourcepub fn record_empty_response(&mut self) -> usize
pub fn record_empty_response(&mut self) -> usize
Record empty response (branch 2). Resets reasoning_only_strikes. Returns the new strike count.
Sourcepub fn record_truncation(&mut self) -> usize
pub fn record_truncation(&mut self) -> usize
Record a truncation guard firing (all tool_calls had invalid arguments). Returns the new strike count. Caller should check against threshold.