mirror of
https://github.com/block/buzz.git
synced 2026-10-31 06:21:34 +00:00
feat(workflows): persist owner command state
Bind owner-signed lifecycle commands to the immutable managed-agent owner and exact workflow revision. Persist private ordered commands, terminal agent results, replay outcomes, and community deletion fencing without activating relay routing or execution. Co-authored-by: Carl <a28e67e1813c6f044108ee870f118aff86f233ec6b3f6e2098a711321e1e1fc8@buzz.block.builderlab.xyz> Signed-off-by: Logan Johnson <loganj@squareup.com>
This commit is contained in:
@@ -1723,6 +1723,42 @@ BEGIN
|
||||
END
|
||||
$$;
|
||||
|
||||
-- Durable, private state for owner-signed managed-workflow commands.
|
||||
CREATE TYPE workflow_owner_command_status AS ENUM ('pending', 'applied', 'rejected');
|
||||
|
||||
CREATE TABLE workflow_owner_commands (
|
||||
community_id UUID NOT NULL REFERENCES communities(id),
|
||||
command_id UUID NOT NULL,
|
||||
command_sequence BIGSERIAL NOT NULL,
|
||||
event_id BYTEA NOT NULL CHECK (length(event_id) = 32),
|
||||
owner_pubkey BYTEA NOT NULL CHECK (length(owner_pubkey) = 32),
|
||||
agent_pubkey BYTEA NOT NULL CHECK (length(agent_pubkey) = 32),
|
||||
workflow_id UUID NOT NULL,
|
||||
expected_revision BYTEA NOT NULL CHECK (length(expected_revision) = 32),
|
||||
operation TEXT NOT NULL CHECK (operation IN ('start', 'pause', 'resume', 'cancel', 'restore')),
|
||||
status workflow_owner_command_status NOT NULL DEFAULT 'pending',
|
||||
result_event_id BYTEA CHECK (result_event_id IS NULL OR length(result_event_id) = 32),
|
||||
result_reason TEXT,
|
||||
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
|
||||
completed_at TIMESTAMPTZ,
|
||||
PRIMARY KEY (community_id, command_id),
|
||||
UNIQUE (community_id, event_id),
|
||||
FOREIGN KEY (community_id, workflow_id) REFERENCES workflows (community_id, id) ON DELETE CASCADE,
|
||||
CHECK ((status = 'pending') = (result_event_id IS NULL)),
|
||||
CHECK ((status = 'pending') = (completed_at IS NULL))
|
||||
);
|
||||
|
||||
CREATE UNIQUE INDEX workflow_owner_commands_result_event_idx
|
||||
ON workflow_owner_commands (community_id, result_event_id)
|
||||
WHERE result_event_id IS NOT NULL;
|
||||
CREATE INDEX workflow_owner_commands_agent_pending_idx
|
||||
ON workflow_owner_commands (community_id, agent_pubkey, command_sequence)
|
||||
WHERE status = 'pending';
|
||||
CREATE UNIQUE INDEX workflow_owner_commands_workflow_pending_idx
|
||||
ON workflow_owner_commands (community_id, workflow_id)
|
||||
WHERE status = 'pending';
|
||||
|
||||
|
||||
-- Desired-state schema application does not replay migration history, so keep
|
||||
-- these explicit calls as first-class catalog declarations. They also make the
|
||||
-- fence contract visible to migration linting instead of hiding it only in the
|
||||
@@ -1752,6 +1788,7 @@ SELECT attach_community_write_fence('scheduled_workflow_fires');
|
||||
SELECT attach_community_write_fence('subscriptions');
|
||||
SELECT attach_community_write_fence('thread_metadata');
|
||||
SELECT attach_community_write_fence('users');
|
||||
SELECT attach_community_write_fence('workflow_owner_commands');
|
||||
SELECT attach_community_write_fence('workflow_approvals');
|
||||
SELECT attach_community_write_fence('workflow_runs');
|
||||
SELECT attach_community_write_fence('workflows');
|
||||
|
||||
Reference in New Issue
Block a user