state
state
¶
Baton state model — the conductor's execution memory.
These are the data structures the baton uses to track what's happening during a performance: which sheets are in what state, which instruments are healthy, how many attempts have been made, what the cost budget looks like. This is the conductor's working memory — separate from the persistent CheckpointState, which is the sheet's record of outcomes.
The baton state persists to SQLite (in ~/.marianne/marianne-state.db)
for restart recovery. All models support to_dict()/from_dict()
serialization for this purpose.
Key types:
BatonSheetStatus— extended status enum (pending → ready → dispatched → running → completed/failed/skipped, plus waiting and fermata)SheetExecutionState— per-sheet tracking (attempts, costs, status)InstrumentState— per-instrument tracking (rate limits, circuit breaker)BatonJobState— per-job tracking (sheets, cost, pause state)AttemptContext— what the conductor tells the musician for each attemptCircuitBreakerState— three-state circuit breaker (closed/open/half-open)
See: docs/plans/2026-03-26-baton-design.md — Persistent State section
Classes¶
AttemptMode
¶
Bases: str, Enum
The mode a sheet attempt runs in.
NORMAL— standard execution (first try or retry)COMPLETION— partial validation passed, trying to completeHEALING— self-healing after retry exhaustion
CircuitBreakerState
¶
Bases: str, Enum
Three-state circuit breaker for per-instrument health tracking.
CLOSED— healthy, accepting requestsOPEN— unhealthy, rejecting requests, waiting for recovery timerHALF_OPEN— probing, allowing one request to test recovery
AttemptContext
dataclass
¶
AttemptContext(attempt_number, mode, completion_prompt_suffix=None, healing_context=None, previous_results=None, learned_patterns=None, total_sheets=1, total_movements=1, previous_outputs=dict(), previous_files=dict())
Context provided by the conductor to the musician for a single attempt.
Each dispatch carries this context so the musician knows: - Which attempt this is (1 = first try, 2+ = retry) - What mode to operate in (normal/completion/healing) - Any extra context for non-normal modes - Learned patterns from the learning store (instrument-scoped) - Previous attempt results (for failure history injection)
Attributes¶
attempt_number
instance-attribute
¶
1-based attempt number. First try = 1, first retry = 2, etc.
completion_prompt_suffix
class-attribute
instance-attribute
¶
For completion mode: appended to the prompt to fix partial failures.
healing_context
class-attribute
instance-attribute
¶
For healing mode: diagnostic context from self-healing analysis.
previous_results
class-attribute
instance-attribute
¶
Previous attempt results for failure history injection into prompts.
learned_patterns
class-attribute
instance-attribute
¶
Patterns from the learning store, scoped to this instrument.
total_sheets
class-attribute
instance-attribute
¶
Total concrete sheet count in the job (for preamble and template vars).
total_movements
class-attribute
instance-attribute
¶
Total movement count in the job (for template vars).
previous_outputs
class-attribute
instance-attribute
¶
Stdout outputs from completed sheets. Keys are sheet numbers (1-indexed). Populated by the adapter from completed sheet attempt results.
previous_files
class-attribute
instance-attribute
¶
File contents captured via capture_files patterns. Keys are file paths. Populated by the adapter from workspace files matching CrossSheetConfig patterns.
InstrumentState
dataclass
¶
InstrumentState(name, max_concurrent, running_count=0, rate_limited=False, rate_limit_expires_at=None, circuit_breaker=CLOSED, consecutive_failures=0, circuit_breaker_threshold=5, circuit_breaker_recovery_at=None)
Per-instrument state tracking for rate limits, circuit breakers, and concurrency.
The baton tracks each instrument's health independently. Rate limits on claude-code don't affect gemini-cli. Circuit breaker thresholds are per-instrument. Concurrency limits come from the InstrumentProfile.
Attributes¶
max_concurrent
instance-attribute
¶
Maximum concurrent sheets on this instrument (from InstrumentProfile).
running_count
class-attribute
instance-attribute
¶
Number of currently running sheets on this instrument.
rate_limited
class-attribute
instance-attribute
¶
Whether this instrument is currently rate-limited.
rate_limit_expires_at
class-attribute
instance-attribute
¶
Monotonic time when the rate limit is expected to clear.
circuit_breaker
class-attribute
instance-attribute
¶
Current circuit breaker state.
consecutive_failures
class-attribute
instance-attribute
¶
Consecutive failures across all jobs for this instrument.
circuit_breaker_threshold
class-attribute
instance-attribute
¶
Number of consecutive failures to trip the circuit breaker.
circuit_breaker_recovery_at
class-attribute
instance-attribute
¶
Monotonic time for circuit breaker recovery check.
is_available
property
¶
Whether this instrument can accept new sheets.
Available when not rate-limited and circuit breaker is not open. Half-open allows one probe request through.
Functions¶
record_success
¶
Record a successful execution on this instrument.
Resets consecutive failures. If circuit breaker is half-open, closes it (the probe succeeded).
Source code in src/marianne/daemon/baton/state.py
record_failure
¶
Record a failed execution on this instrument.
Increments consecutive failures. If threshold reached, opens the circuit breaker. If already half-open, reopens it.
Source code in src/marianne/daemon/baton/state.py
to_dict
¶
Serialize to a dict for SQLite persistence.
Source code in src/marianne/daemon/baton/state.py
from_dict
classmethod
¶
Restore from a serialized dict.
Source code in src/marianne/daemon/baton/state.py
BatonJobState
dataclass
¶
The baton's per-job tracking during a performance.
Contains all sheet states for a job, plus job-level flags (paused, pacing, cost tracking).
Attributes¶
paused
class-attribute
instance-attribute
¶
Whether dispatching is paused for this job.
pacing_active
class-attribute
instance-attribute
¶
Whether inter-sheet pacing delay is currently active.
sheets
class-attribute
instance-attribute
¶
Map of sheet_num → SheetExecutionState.
terminal_count
property
¶
Number of sheets in a terminal status (completed, failed, skipped).