midnight-saci

Report results with outcome actions

An outcome action is an MCP tool call the backend makes after a run finishes, for example to open a ticket when a nightly run fails. The run’s policy selects its actions, and each action names the run outcomes that trigger it. The tools available depend on the MCP server you connect: a ticketing server may offer issue creation or commenting. Saci has no built-in GitHub or Jira client.

Actions follow these rules:

Configuration

actions:
  servers:                      # MCP servers the backend calls
    tickets:
      url: http://tickets-mcp:9090/mcp
      headers:
        Authorization: Bearer ${TICKETS_TOKEN}
  secrets:                      # values for ${NAME} in servers, read by the backend
    TICKETS_TOKEN: { env: SACI_TICKETS_TOKEN }
  definitions:
    open-ticket:
      server: tickets
      tool: create_issue
      on: [failed, error]       # run outcomes that trigger it
      approval: none            # or required
      idempotency_key: request_id   # only if the tool deduplicates on it
      arguments:
        title: ": "
        body: |
          Run  in  ended  ().

          

          Evidence:
          

policies:
  nightly:
    on_failure: continue
    actions: [open-ticket]
Setting Meaning
actions.servers.<name> An MCP server, written like mcp_servers: command, args and env for stdio, or url and headers for Streamable HTTP.
actions.secrets.<NAME> { env: VAR }: a backend environment variable. ${NAME} in servers expands to it, and it is redacted from stored results and errors.
actions.definitions.<name>.server A server under actions.servers.
.tool The tool to call.
.on Run outcomes that trigger the action: passed, failed, blocked, inconclusive, error, cancelled. Required.
.approval none (default): dispatched once recorded. required: kept as pending_approval until approved.
.arguments The tool’s arguments. Strings may contain the variables below. Other values are sent as written.
.idempotency_key Optional. The tool argument that receives Saci’s key for this run and action, saci-<run-id>-<name>. Set it only when the tool deduplicates calls on that argument; see Retries and restarts.
policies.<name>.actions The actions considered when a run under this policy finishes.

The configuration is checked at startup: unknown servers, unknown variables, empty on lists and undefined policy actions are errors. A run keeps the action definitions of its policy as they were when it was accepted. Server connection settings are read when the action is dispatched.

Variables

| Variable | Value | | — | — | | | The run ID. | |, | The run's outcome and why it ended. | | | Unit counts, such as 1 failed, 2 skipped. | | , | RFC 3339 timestamps. | | , | The plan title and entry document. | | ,, | Names recorded in the report header. | | | One line per finished unit: outcome, ID, title and the assessment’s explanation. | | | The unsuccessful units, each with its criterion results. | | | Excerpts of the evidence cited by unsuccessful units: commands with exit codes and output, HTTP requests with status and body, MCP results. Each output is cut to 1000 bytes, and the whole to 16 KiB. |

Evidence is redacted with the run’s secrets before it is stored, so excerpts never contain secret values.

Where the server must be reachable

The dispatcher runs inside the backend process, not in a worker:

Delivery

State Meaning
pending_approval Recorded with approval: required. It is not dispatched until approved.
queued Waiting for the dispatcher: automatic, approved, replayed or redispatched.
rejected A person rejected it. It is never dispatched.
executing Claimed: the claim is stored before the call is made.
completed The tool returned a result, or a person reconciled it as completed.
error Delivery failed. error says why, and result holds the tool’s text when it answered.
unknown The call may have reached the server, but no answer was recorded. It waits for a person.

The dispatcher connects to the server, initializes it and lists its tools within limits.operation_timeout_secs. It then checks the recorded arguments against the tool’s input schema: required properties, property types, and additionalProperties: false. A mismatch is an error, and nothing is sent.

When the schema gives a maxLength for a string property and the value is longer, the dispatcher shortens the value before the call. It counts the limit in bytes, so the value also fits a server that counts characters. It cuts the value at a character boundary, at the last line break in the second half of the kept text when there is one, and adds a [truncated] line. The recorded arguments keep the full value. The action’s result ends with [shortened to the tool's maxLength: <names>].

The call itself must answer within limits.operation_timeout_secs. Whatever happens to an action, the run’s outcome stays as it was.

Retries and restarts

Saci never retries a call blindly, and promises no exactly-once delivery for arbitrary tools: only the server can tell whether it acted on a call. What Saci guarantees:

An unknown action needs a person who checks the remote system (for example, whether the ticket exists):

saci actions show <run-id> open-ticket          # error, attempts and history
saci actions reconcile <run-id> open-ticket --as completed --note "ticket 42 exists"
saci actions reconcile <run-id> open-ticket --as error --note "no ticket"
saci actions redispatch <run-id> open-ticket --note "no ticket; sending again"

History

Each action keeps its history in SQLite: when it was recorded, approved or rejected, claimed, answered, failed, found uncertain, replayed, redispatched or reconciled, with its state and attempt count afterwards and the error or note. saci actions show prints it, and GET /api/v1/runs/{run_id}/actions/{name} returns it.

Approvals

Approval is configured per action (approval: required) and applies after a run, never before it: runs start immediately as usual. An approval- required action is recorded as pending_approval with its arguments already rendered. A reviewer decides on exactly that payload:

saci actions list                                   # what waits for approval
saci actions show <run-id> escalate                 # arguments and digest
saci actions approve <run-id> escalate --digest <digest> --note "on-call agreed"
saci actions reject <run-id> escalate --note "known issue"

API: POST /api/v1/runs/{run_id}/actions/{name}/approval and .../rejection with {"digest": "...", "note": "..."}, and GET /api/v1/actions?state=pending_approval across runs (API).

Inspecting actions

saci report <run> lists the actions after the report:

Actions (delivery does not change the outcome):
  open-ticket: completed (tickets/create_issue): created issue 42

GET /api/v1/runs/{run_id}/actions returns them with the exact arguments and their SHA-256 digest (API).

Next steps