midnight-saci

Run contracts

The types in crates/saci-core are the shared vocabulary of the CLI, the backend and the worker. They are serialized as JSON on the wire and in the database; schema_version (currently 1) marks the run specification and report formats.

Identities

Identity Form Notes
Run run-<32 hex> Generated by the backend on acceptance.
Unit key 1.1, or 1.1>common/setup.md#2 The authored ID; units reached through a procedure are prefixed with the invoking unit and the procedure path, so repeated invocations stay distinct.
Attempt 1, 2, … One-based, per unit. Every attempt is kept.
Evidence ev-<n> Run-unique, assigned by the worker in recording order.
Event seq 1, 2, … Contiguous per run. Receivers apply exactly the next seq.

Source locations are { "document": "<bundle path>", "line": <1-based> }.

Lifecycle and outcome

Lifecycle (accepted → starting → running → stopping → finished) and outcome are separate. Runs only move forward; any non-terminal state may go to stopping or straight to finished (for example on a launch failure), and finished is terminal.

Outcomes are passed, failed, blocked, inconclusive, error, skipped and cancelled. Units and runs use the same outcomes:

Outcome Meaning
passed Every expected criterion is supported by evidence.
failed Evidence contradicts at least one expected criterion.
blocked A prerequisite or required input prevents execution.
inconclusive Execution produced insufficient evidence to establish the expected result.
error The agent, worker, tool infrastructure, provider, or execution limit prevented reliable completion.
skipped A unit was not attempted, with its reason recorded.
cancelled A user or external controller explicitly stopped execution.

A command failure can be a passing negative test, and a command that exits 0 can be evidence of a failed test: the outcome follows the authored expectation, not the transport status. A run’s summary outcome is the highest of its unit outcomes in the order cancelled, error, failed, blocked, inconclusive, passed. A skipped unit counts as blocked for the summary, so a run with unattempted units cannot pass. When the run ends:

Assessments

The agent finishes each attempt by submitting an assessment through the step-assessment tool: an outcome, one result per expected criterion (criterion index from 0, status satisfied, contradicted or undetermined, basis mechanical or model_judgment, the evidence ids it relies on, and an explanation), and an overall explanation. saci_core::assessment::validate rejects a submission, telling the model every problem so it can resubmit, when:

So a pass needs evidence for every criterion: a printed PASS or a zero exit status is only evidence for the criteria it actually shows. A negative test passes when its evidence matches the authored expectation, for example a recorded HTTP 401 for “the request is rejected”. basis records whether a result rests on a direct check or on the model’s interpretation; Saci records that claim but does not prove it.

An attempt’s outcome is its assessment’s outcome, unless an execution error occurred, which makes it error. A unit’s outcome is its last attempt’s outcome; earlier attempts stay in the report.

Events

A worker reports progress as ordered RunEvents (run_started, attempt_started, observation, command_running, attempt_finished, unit_finished, unit_skipped, cancellation_requested, investigation_concluded, run_finished). The backend folds them into a RunReport with RunReport::apply, which rejects events for another run, events out of sequence (including retransmissions), events after run_finished, and unit events that do not match the unit’s state: an attempt outcome that does not follow its assessment, an assessment that fails the same checks the worker applies (assessment::validate: every authored criterion assessed once, outcome consistent with the criteria, evidence recorded in the run), a unit outcome other than its last attempt’s, or a skip of a unit that was attempted. Each unit’s identity carries its authored criteria for this. A rejected event leaves the report unchanged.

run_started also carries environment: the worker’s Saci build, operating system, kernel, architecture and tool versions (environment details). The report keeps it as worker_environment. Workers that do not send it leave the field absent.

attempt_finished also carries timing: model_requests (the model requests sent), model_ms (the time spent on model requests, retries included), tool_ms (the time spent in tool calls), and the token counts that the provider reported: input_tokens, cached_tokens (the part of the input read from the provider’s prompt cache, absent when the provider does not report it) and output_tokens. The report keeps it on the attempt. Use it to find where a run spends its time.

command_running reports a shell command that is still running, every 15 seconds while it runs (long commands). It carries the redacted command and elapsed_secs. It does not change the report: the observation that follows carries the result.

Examples of complete event streams live in crates/saci-core/tests/fixtures/runs/ (success, failure with stop, and a retried-then-cancelled run).

Work of a run

A run specification contains exactly one of these fields:

A test run has the same format as before investigations existed, so the backend reads stored runs without change. A worker rejects a specification with both fields or with neither. A worker that does not run investigations rejects an investigation. The backend creates investigations from stored runs (failure investigations).

Investigations

The design describes investigations. These types are in saci_core::investigation.

InvestigationReport::check applies the rules that do not need the clones:

An investigation run has one unit, investigation, with one attempt (see investigation mode). These rules apply to the investigation_concluded event, which carries the report:

The report keeps the result as its investigation field.

Secrets

Public types hold secret references only: { "env": "NAME" } for a backend environment variable or { "secret": "name", "key": "key" } for a Kubernetes Secret. No serializable type has a field for a secret value.

Next steps