Skip to main content

Module approvals

Module approvals 

Source
Expand description

Durable approvals: the pending tool calls of a run, and the answer when it arrives.

The approval gate is normally a question asked of whoever is driving the loop, and its answer exists only in that process. That is fine until the process is not there — a CLI run in a script, a dashboard tab that was closed, a shell that lost its terminal — and then a call the model made is neither approved nor denied: it is simply unrecorded, and the transcript repairs it on the next run as “interrupted”. The intent is lost.

This module is the small amount of state that fixes it, and deliberately nothing more: one row per call the model made and the gate has not answered, keyed by the message that carried it (seq, ord), with the answer written into the same row when it arrives. There is no second state machine, no run registry and no job queue — a run is still just a transcript, and the rows are only the answers that were not in it yet.

Three answers, not two:

  • Decision::Allow runs the call;
  • Decision::Deny answers it as declined, with the reason the model reads;
  • Decision::Defer means nobody has answered and the loop must not guess. The call is recorded and the turn stops. Fail-closed: an unanswered gate is never an approval, and it is no longer a silent denial either.

Defer is what makes the state durable without a daemon: the process that asked can exit, and any later process can look at the same rows and answer them.

Structs§

Pending
One call the model made, as the gate sees it: enough to ask, enough to re-run it later.
PendingCall
One stored row: a call, and the answer if one arrived.
Recorded
The store’s answers, asked of the gate that replays a paused turn.
Ruling
One line of the append-only log: a call, its answer, and who gave it (#340).
Waiting
What a run left behind when it stopped on the gate.

Enums§

Decision
The gate’s answer to one call.

Constants§

DECIDED_BY_JUDGE
The aux route in smart mode (#340).
DECIDED_BY_USER
Who answered a waiting call, for the by column (#340).

Functions§

answer
Answer one waiting call by position, counting from 1 in the order waiting prints them.
answer_all
Answer every waiting call.
decision_for
The decision recorded for one call, if any. Used by the resumed run, which must run exactly what was approved and nothing else.
record
Record the calls of one assistant message as pending. An existing row is left alone: the same call re-recorded has the same answer or none, and overwriting it would lose a decision that arrived while the run was stopping.
record_at
Record calls as pending, starting at ord — the position calls[0] holds in the assistant message that carried it.
waiting
The calls waiting for an answer, oldest first.