base
base
¶
Abstract base for state backends.
Attributes¶
Classes¶
StateBackend
¶
Bases: ABC
Abstract base class for state storage backends.
Implementations handle persistence of job state for resumable execution.
Attributes¶
supports_execution_history
property
¶
Whether this backend persists execution history.
Backends that override record_execution should also override this
to return True. Callers can check this to avoid silent data loss
when a backend unexpectedly lacks execution recording.
Functions¶
load
abstractmethod
async
¶
Load state for a job.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
job_id
|
str
|
Unique job identifier |
required |
Returns:
| Type | Description |
|---|---|
CheckpointState | None
|
CheckpointState if found, None otherwise |
save
abstractmethod
async
¶
Save job state.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
state
|
CheckpointState
|
Checkpoint state to persist |
required |
delete
abstractmethod
async
¶
Delete state for a job.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
job_id
|
str
|
Unique job identifier |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if deleted, False if not found |
list_jobs
abstractmethod
async
¶
List all jobs with state.
Returns:
| Type | Description |
|---|---|
list[CheckpointState]
|
List of all checkpoint states |
get_next_sheet
abstractmethod
async
¶
Get the next sheet to process for a job.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
job_id
|
str
|
Unique job identifier |
required |
Returns:
| Type | Description |
|---|---|
int | None
|
Next sheet number, or None if complete |
mark_sheet_status
abstractmethod
async
¶
Update status of a specific sheet.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
job_id
|
str
|
Unique job identifier |
required |
sheet_num
|
int
|
Sheet number to update |
required |
status
|
SheetStatus
|
New status |
required |
error_message
|
str | None
|
Optional error message for failures |
None
|
Source code in src/marianne/state/base.py
close
async
¶
Release any resources held by the backend (Q018/#37).
Optional method — backends that hold persistent connections or file handles should override this. The default no-op is safe for backends that use per-operation connections (e.g. aiosqlite context managers).
Source code in src/marianne/state/base.py
record_execution
async
¶
record_execution(job_id, sheet_num, attempt_num, prompt=None, output=None, exit_code=None, duration_seconds=None)
Record an execution attempt in history.
Optional method -- backends that support execution recording (e.g. SQLite) override this. The default logs at WARNING level so silent data loss is traceable, then returns None.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
job_id
|
str
|
Job identifier. |
required |
sheet_num
|
int
|
Sheet number. |
required |
attempt_num
|
int
|
Attempt number within the sheet. |
required |
prompt
|
str | None
|
The prompt sent to the backend. |
None
|
output
|
str | None
|
The output received. |
None
|
exit_code
|
int | None
|
Exit code from the execution. |
None
|
duration_seconds
|
float | None
|
Execution duration. |
None
|
Returns:
| Type | Description |
|---|---|
int | None
|
The ID of the inserted record, or None if not supported. |
Source code in src/marianne/state/base.py
infer_state_from_artifacts
async
¶
Infer last completed sheet from artifact files.
Fallback when state file is missing - checks for output files. Based on the fallback logic in run-sheet-review.sh.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
job_id
|
str
|
Unique job identifier |
required |
workspace
|
str
|
Workspace directory path |
required |
artifact_pattern
|
str
|
Glob pattern for sheet artifacts (e.g., "sheet*-security-report.md") |
required |
Returns:
| Type | Description |
|---|---|
int | None
|
Inferred last completed sheet number, or None |