checkpoint
checkpoint
¶
Checkpoint and state management models.
Defines the state that gets persisted between runs for resumable orchestration.
Attributes¶
TERMINAL_JOB_STATUSES
module-attribute
¶
The job-level terminal set — the single definition (GH #225).
TERMINAL_SHEET_STATUSES
module-attribute
¶
Public alias for the sheet-level terminal set.
Classes¶
ValidationDetailDict
¶
Bases: TypedDict
Schema for individual validation result entries in SheetState.validation_details.
Most keys are optional (total=False) to support partial dicts from
legacy data and simplified test fixtures. passed is required
because a validation result without a pass/fail status is meaningless.
PromptMetricsDict
¶
Bases: TypedDict
Schema for prompt analysis metrics in SheetState.prompt_metrics.
All keys are optional (total=False) to support partial metrics from legacy data or simplified test fixtures.
ProgressSnapshotDict
¶
Bases: TypedDict
Schema for execution progress snapshots in SheetState.progress_snapshots.
All keys are optional (total=False) because snapshots may contain varying subsets depending on when they were captured.
ErrorContextDict
¶
Bases: TypedDict
Schema for error context in CheckpointErrorRecord.context.
All keys optional since context varies by error type. Values may be None when the information is not available.
AppliedPatternDict
¶
Bases: TypedDict
Schema for a single applied pattern in SheetState.applied_patterns.
Replaces the parallel applied_pattern_ids / applied_pattern_descriptions
lists with a single structured list for safety and clarity.
OutcomeDataDict
¶
Bases: TypedDict
Schema for structured outcome data in SheetState.outcome_data.
All keys optional since this is extensible for learning/pattern recognition.
SynthesisResultDict
¶
Bases: TypedDict
Schema for synthesis result entries in CheckpointState.synthesis_results.
All keys are optional (total=False) to support partial data from legacy state files and test fixtures.
SheetStatus
¶
Bases: str, Enum
Status of a single sheet.
The baton tracks 11 scheduling states. Status display and persistence
use all 11. Consumers that only care about terminal/non-terminal can
check is_terminal.
OutcomeCategory
¶
Bases: str, Enum
Classification of sheet execution outcome (#7).
JobStatus
¶
Bases: str, Enum
Status of an entire job run.
CheckpointErrorRecord
¶
Bases: BaseModel
Record of a single error occurrence during sheet execution.
Stores structured error information for debugging and pattern analysis. Error history is trimmed to MAX_ERROR_HISTORY records per sheet to prevent unbounded state growth.
InstrumentIdentity
¶
Bases: BaseModel
The configured primary identity, including an explicit default model.
FlowAttemptRecord
¶
Bases: BaseModel
Bounded evidence retained when a flow transition reopens a sheet.
SheetState
¶
Bases: BaseModel
State for a single sheet.
Attributes¶
applied_pattern_ids
property
writable
¶
Backward-compatible accessor for pattern IDs.
applied_pattern_descriptions
property
writable
¶
Backward-compatible accessor for pattern descriptions.
has_fallback_available
property
¶
Whether there is another instrument in the fallback chain to try.
Methods:¶
record_attempt
¶
Record an attempt result and update tracking state.
Only non-successful, non-rate-limited attempts increment
normal_attempts. Successes and rate-limited attempts are
recorded in attempt_results for history but don't consume
retry budget.
Source code in src/marianne/core/checkpoint.py
935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 | |
advance_fallback
¶
Advance to the next instrument in the fallback chain.
Records the transition, switches instrument_name, resets retry budget, and increments current_instrument_index.
Returns the new instrument name, or None if the chain is exhausted.
Source code in src/marianne/core/checkpoint.py
reset_for_retry
¶
Reset this sheet to PENDING with a full, fresh retry budget.
Typed mirror of recover.py's _reset_sheet_data_for_retry (which
operates on the serialized dict). Used by the daemon resume path (#185)
so a recovered sheet starts over from the TOP of its instrument chain
with full budgets — not stuck on the fallback it died on (#187) with
exhausted budgets (which would immediately re-fail). Clears error
provenance so the status display doesn't show a phantom failure/fallback
tag (#190) after a clean restart.
Source code in src/marianne/core/checkpoint.py
remember_primary_identity
¶
Capture the configured primary before any fallback changes the live identity.
restore_primary_identity
¶
Return to the primary, retaining old-checkpoint identity when unknown.
Source code in src/marianne/core/checkpoint.py
reset_for_flow
¶
Reopen a sheet while preserving money, duration, and bounded history.
Source code in src/marianne/core/checkpoint.py
mark_dispatch_blocked
¶
Record that the ready sheet is waiting on dispatch capacity.
Returns True when persisted state changed. Repeated dispatch cycles with the same reason/details keep the original timestamp so the state backend is not rewritten every scheduler wake.
Source code in src/marianne/core/checkpoint.py
clear_dispatch_block
¶
Clear any previously recorded dispatch wait reason.
Source code in src/marianne/core/checkpoint.py
to_dict
¶
from_dict
classmethod
¶
Restore from dict. Compatibility with dataclass SheetExecutionState.
capture_output
¶
Capture tail of stdout/stderr for debugging.
Stores the last max_bytes of each output stream. Sets output_truncated
to True if either stream was larger than the limit. Both truncated and
untruncated tails are stored strictly UTF-8-encodable: every tail is
round-tripped through UTF-8 with errors="replace", so a lone surrogate
or other invalid byte from a mis-decoded subprocess stream never
survives into state or --json machine output (issue #495).
Credential scanning (F-003): Before storing, both streams are scanned for API key patterns (sk-ant-, AKIA, AIzaSy, Bearer tokens) and matches are replaced with [REDACTED_] placeholders. This prevents leaked credentials from propagating to learning store, dashboard, diagnostics, and MCP resources.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
stdout
|
str
|
Full stdout string from execution. |
required |
stderr
|
str
|
Full stderr string from execution. |
required |
max_bytes
|
int
|
Maximum bytes to capture per stream (default 50 KiB). |
MAX_OUTPUT_CAPTURE_BYTES
|
Source code in src/marianne/core/checkpoint.py
1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 | |
add_error_to_history
¶
Append an error record and enforce the history size limit.
All callers that add errors to error_history should use this
method instead of appending directly so that the list never exceeds
MAX_ERROR_HISTORY entries.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
error
|
CheckpointErrorRecord
|
The error record to add. |
required |
Source code in src/marianne/core/checkpoint.py
add_fallback_to_history
¶
Append a fallback record and enforce the history size limit.
All callers that add entries to instrument_fallback_history
should use this method instead of appending directly so the list
never exceeds MAX_INSTRUMENT_FALLBACK_HISTORY entries.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
record
|
dict[str, str]
|
Dict with keys from, to, reason, timestamp. |
required |
Source code in src/marianne/core/checkpoint.py
CheckpointState
¶
Bases: BaseModel
Complete checkpoint state for a job run.
This is the primary state object that gets persisted and restored for resumable job execution.
Zombie Detection
A job is considered a "zombie" when the state shows RUNNING status
but the associated process (tracked by pid) is no longer alive.
This can happen when:
- External timeout wrapper sends SIGKILL
- System crash or forced termination
- WSL shutdown while job running
Use is_zombie() to detect this state, and mark_zombie_detected()
to recover from it.
Worktree Isolation
When isolation is enabled, jobs execute in a separate git worktree. The worktree tracking fields record the worktree state for: - Resume operations (reuse existing worktree) - Cleanup on completion (remove or preserve based on outcome) - Debugging (know which worktree was used)
Methods:¶
record_hook_result
¶
Append a hook result to the checkpoint state.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
result
|
dict[str, Any]
|
Serialized HookResult dict from hook execution. |
required |
Source code in src/marianne/core/checkpoint.py
record_circuit_breaker_change
¶
Record a circuit breaker state transition.
Persists circuit breaker state changes so that mzt status
can display ground-truth CB state instead of inferring it from
failure patterns.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
state
|
str
|
Current CB state after transition ("closed", "open", "half_open"). |
required |
trigger
|
str
|
What caused the transition (e.g., "failure_recorded", "success_recorded"). |
required |
consecutive_failures
|
int
|
Number of consecutive failures at time of transition. |
required |
Source code in src/marianne/core/checkpoint.py
add_synthesis
¶
Add or update a synthesis result.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
batch_id
|
str
|
The batch identifier. |
required |
result
|
SynthesisResultDict
|
Synthesis result as dict (from SynthesisResult.to_dict()). |
required |
Source code in src/marianne/core/checkpoint.py
get_next_sheet
¶
Determine the next sheet to process.
Returns None if all sheets are complete.
Source code in src/marianne/core/checkpoint.py
mark_sheet_started
¶
Mark a sheet as started.
Source code in src/marianne/core/checkpoint.py
mark_sheet_completed
¶
mark_sheet_completed(sheet_num, validation_passed=True, validation_details=None, execution_duration_seconds=None)
Mark a sheet as completed.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sheet_num
|
int
|
Sheet number that completed. |
required |
validation_passed
|
bool
|
Whether validation checks passed. |
True
|
validation_details
|
list[ValidationDetailDict] | None
|
Detailed validation results. |
None
|
execution_duration_seconds
|
float | None
|
How long the sheet execution took. |
None
|
Source code in src/marianne/core/checkpoint.py
1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 | |
mark_sheet_failed
¶
mark_sheet_failed(sheet_num, error_message, error_category=None, exit_code=None, exit_signal=None, exit_reason=None, execution_duration_seconds=None, error_code=None)
Mark a sheet as failed.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sheet_num
|
int
|
Sheet number that failed. |
required |
error_message
|
str
|
Human-readable error description. |
required |
error_category
|
ErrorCategory | str | None
|
Error category from ErrorClassifier (e.g., "signal", "timeout"). |
None
|
exit_code
|
int | None
|
Process exit code (None if killed by signal). |
None
|
exit_signal
|
int | None
|
Signal number if killed by signal (e.g., 9=SIGKILL, 15=SIGTERM). |
None
|
exit_reason
|
ExitReason | None
|
Why execution ended ("completed", "timeout", "killed", "error"). |
None
|
execution_duration_seconds
|
float | None
|
How long the sheet execution took. |
None
|
error_code
|
str | None
|
Structured error code (e.g., "E001", "E006"). More specific than error_category — distinguishes stale (E006) from timeout (E001). |
None
|
Source code in src/marianne/core/checkpoint.py
1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 | |
mark_sheet_skipped
¶
Mark a sheet as skipped.
v21 Evolution: Proactive Checkpoint System - supports skipping sheets via checkpoint response.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sheet_num
|
int
|
Sheet number to skip. |
required |
reason
|
str | None
|
Optional reason for skipping (stored in error_message field). |
None
|
Source code in src/marianne/core/checkpoint.py
mark_job_failed
¶
Mark the entire job as failed.
Source code in src/marianne/core/checkpoint.py
mark_job_paused
¶
Mark the job as paused.
Source code in src/marianne/core/checkpoint.py
get_progress
¶
Get progress as (completed, total).
get_progress_percent
¶
is_zombie
¶
Check if this job is a zombie (RUNNING but process dead).
A zombie state occurs when: 1. Status is RUNNING 2. PID is set 3. Process with that PID is no longer alive
Note: This only checks if the PID is dead. It does NOT use time-based stale detection, as jobs can legitimately run for hours or days.
Returns:
| Type | Description |
|---|---|
bool
|
True if job appears to be a zombie, False otherwise. |
Source code in src/marianne/core/checkpoint.py
mark_zombie_detected
¶
Mark this job as recovered from zombie state.
Changes status from RUNNING to PAUSED, clears PID, and records the zombie recovery in the error message.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
reason
|
str | None
|
Optional additional context about why zombie was detected. |
None
|
Source code in src/marianne/core/checkpoint.py
set_running_pid
¶
Set the PID of the running orchestrator process.
Call this when starting job execution to enable zombie detection. If pid is None, uses the current process PID.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pid
|
int | None
|
Process ID to record. Defaults to current process. |
None
|
Source code in src/marianne/core/checkpoint.py
Functions:¶
execution_history_records
¶
Every sheet's attempt records, newest first, for mzt history (GH #488).
The checkpoint's per-sheet attempt_history is the conductor's one
persisted, redacted record of each attempt; history is a view over it.