An action judgement holds at propose and wait is no longer a dead end. The new approvals module owns the request: it binds to the decision and the action's digest, so an answer covers the action the person was shown and nothing else, and it settles once. The answer wakes the run, which judges the action again and runs it only as the approval allows: a refusal still refuses, an altered input runs nothing, and a judgement that came back worse runs nothing on that approval. The composer carries the request as a message with the request id and its deadline, and its answer is a message too, so the trail shows what was asked and what was answered. A request nobody answers inside its deadline is settled as expired and nothing runs. How long a request waits is an organisation setting, edited in the dashboard and stored in milliseconds, because a Postgres interval scans as text. A run pins the deadline it started with, like its model. An agent that proposes the same action twice is asked about it once, and the notification says when the investigation proposed nothing at all.
29 lines
1.0 KiB
SQL
29 lines
1.0 KiB
SQL
-- +goose Up
|
|
CREATE SCHEMA approvals;
|
|
|
|
-- A request is one judged action waiting for a person's answer. key is the run
|
|
-- wait an answer wakes, and the decision columns bind the answer to the action
|
|
-- that was judged, so it can't be replayed onto another one.
|
|
CREATE TABLE approvals.requests (
|
|
id uuid PRIMARY KEY,
|
|
org_id text NOT NULL,
|
|
run_id uuid NOT NULL,
|
|
key text NOT NULL,
|
|
decision_id uuid NOT NULL,
|
|
digest text NOT NULL,
|
|
level text NOT NULL CHECK (level IN ('act_quietly', 'act_and_tell', 'propose_and_wait', 'escalate', 'never')),
|
|
summary text NOT NULL,
|
|
state text NOT NULL CHECK (state IN ('pending', 'approved', 'denied', 'expired')),
|
|
deadline timestamptz NOT NULL,
|
|
created_at timestamptz NOT NULL DEFAULT now(),
|
|
answered_at timestamptz,
|
|
answered_by text,
|
|
answered_via text,
|
|
UNIQUE (org_id, run_id, key)
|
|
);
|
|
|
|
CREATE INDEX requests_by_state ON approvals.requests (org_id, state, created_at);
|
|
|
|
-- +goose Down
|
|
DROP SCHEMA approvals CASCADE;
|