From d26cf7de74e6bd36b2bd32aeeb71fdfefa0a6533 Mon Sep 17 00:00:00 2001
From: Stefan Ernst <24554551+stefan-ernst@users.noreply.github.com>
Date: Fri, 13 Nov 2026 15:33:43 +0100
Subject: [PATCH 1/2] feat(actions): persist transactional definition revisions
and bind executions (WI-2173)
Every successful workspace-action definition write now persists an
immutable, attributable revision and its durable audit rows in the same
transaction as the action row and graph. A revision or audit failure
rolls the mutation back, and the create/update/delete/template/import
paths all funnel through ActionDefinitionService so adapters cannot
double-write history.
- Add action_definition_revisions (retained after action deletion) plus
actions.current_revision_id and
action_execution_logs.definition_revision_id, with a migration that
backfills a clearly marked baseline for existing definitions without
inventing authorship.
- Bind each execution to the exact revision it runs by executing the
frozen snapshot and recording its id, reusing the first attempt's
revision on durable retries.
- Require global action.set_actor to change execution-affecting config on
an action with a configured actor; audit denied attempts with safe
metadata on the v2, v1, and AI-tool adapters.
- Expose authorized v2 revision list/detail endpoints and an action
history view in the editor.
---
api/openapi-v2.json | 509 ++++++++++++++++++
frontend/src/lib/api/actions.js | 7 +
.../lib/features/actions/ActionHistory.svelte | 307 +++++++++++
.../features/actions/ActionsManager.svelte | 16 +-
.../features/actions/ActionsSettings.svelte | 19 +
frontend/src/lib/locales/de/actions.js | 19 +
frontend/src/lib/locales/en/actions.js | 20 +
frontend/src/lib/locales/fa/actions.js | 18 +
frontend/src/lib/locales/fr/actions.js | 19 +
frontend/src/lib/locales/pl/actions.js | 19 +
frontend/src/lib/locales/ru/actions.js | 19 +
frontend/src/lib/locales/zh-CN/actions.js | 19 +
internal/aitools/actions.go | 105 ++--
internal/database/migrations.go | 260 +++++++++
internal/database/schema/actions.sql | 30 ++
internal/database/schema/actions_postgres.sql | 30 ++
internal/models/action_revision.go | 159 ++++++
internal/models/integration.go | 13 +-
internal/repository/action_repository.go | 83 ++-
.../repository/action_revision_repository.go | 250 +++++++++
.../action_revision_write_repository.go | 191 +++++++
internal/restapi/v1/handlers/actions.go | 45 +-
internal/restapi/v2/actions.go | 32 ++
internal/restapi/v2/contract-metadata.json | 109 ++++
internal/restapi/v2/router.go | 2 +
.../services/action_application_service.go | 168 ++++--
.../services/action_definition_service.go | 139 +++--
internal/services/action_revision_persist.go | 180 +++++++
internal/services/action_service.go | 54 ++
internal/services/action_template_service.go | 34 +-
30 files changed, 2690 insertions(+), 185 deletions(-)
create mode 100644 frontend/src/lib/features/actions/ActionHistory.svelte
create mode 100644 internal/models/action_revision.go
create mode 100644 internal/repository/action_revision_repository.go
create mode 100644 internal/repository/action_revision_write_repository.go
create mode 100644 internal/services/action_revision_persist.go
diff --git a/api/openapi-v2.json b/api/openapi-v2.json
index ebd964217..d628a26f6 100644
--- a/api/openapi-v2.json
+++ b/api/openapi-v2.json
@@ -18860,6 +18860,11 @@
"description": "The creator name value.",
"type": "string"
},
+ "current_revision_id": {
+ "description": "The current revision id value.",
+ "nullable": true,
+ "type": "integer"
+ },
"description": {
"description": "The description value.",
"type": "string"
@@ -33039,6 +33044,11 @@
"nullable": true,
"type": "string"
},
+ "definition_revision_id": {
+ "description": "The definition revision id value.",
+ "nullable": true,
+ "type": "integer"
+ },
"duration_ms": {
"description": "The duration ms value.",
"nullable": true,
@@ -33156,6 +33166,11 @@
"description": "The creator name value.",
"type": "string"
},
+ "current_revision_id": {
+ "description": "The current revision id value.",
+ "nullable": true,
+ "type": "integer"
+ },
"description": {
"description": "The description value.",
"type": "string"
@@ -33313,6 +33328,313 @@
],
"type": "object"
},
+ "GetWorkspacesWorkspaceIdActionsActionIdRevisionsResult": {
+ "additionalProperties": false,
+ "properties": {
+ "data": {
+ "items": {
+ "additionalProperties": false,
+ "properties": {
+ "action_id": {
+ "description": "The action id value.",
+ "type": "integer"
+ },
+ "change_summary": {
+ "description": "The change summary value.",
+ "type": "string"
+ },
+ "changed_fields": {
+ "description": "The changed fields value.",
+ "items": {
+ "type": "string"
+ },
+ "type": "array"
+ },
+ "created_at": {
+ "description": "The created at value.",
+ "format": "date-time",
+ "type": "string"
+ },
+ "editor_source": {
+ "description": "The editor source value.",
+ "type": "string"
+ },
+ "editor_user_id": {
+ "description": "The editor user id value.",
+ "nullable": true,
+ "type": "integer"
+ },
+ "editor_username": {
+ "description": "The editor username value.",
+ "type": "string"
+ },
+ "id": {
+ "description": "The id value.",
+ "type": "integer"
+ },
+ "revision_number": {
+ "description": "The revision number value.",
+ "type": "integer"
+ },
+ "source": {
+ "description": "The source value.",
+ "type": "string"
+ },
+ "workspace_id": {
+ "description": "The workspace id value.",
+ "type": "integer"
+ }
+ },
+ "required": [
+ "action_id",
+ "changed_fields",
+ "created_at",
+ "id",
+ "revision_number",
+ "source",
+ "workspace_id"
+ ],
+ "type": "object"
+ },
+ "type": "array"
+ },
+ "pagination": {
+ "$ref": "#/components/schemas/Pagination"
+ }
+ },
+ "required": [
+ "data",
+ "pagination"
+ ],
+ "type": "object"
+ },
+ "GetWorkspacesWorkspaceIdActionsActionIdRevisionsRevisionIdResult": {
+ "additionalProperties": false,
+ "properties": {
+ "data": {
+ "additionalProperties": false,
+ "nullable": true,
+ "properties": {
+ "action_id": {
+ "description": "The action id value.",
+ "type": "integer"
+ },
+ "change_summary": {
+ "description": "The change summary value.",
+ "type": "string"
+ },
+ "changed_fields": {
+ "description": "The changed fields value.",
+ "items": {
+ "type": "string"
+ },
+ "type": "array"
+ },
+ "created_at": {
+ "description": "The created at value.",
+ "format": "date-time",
+ "type": "string"
+ },
+ "editor_source": {
+ "description": "The editor source value.",
+ "type": "string"
+ },
+ "editor_user_id": {
+ "description": "The editor user id value.",
+ "nullable": true,
+ "type": "integer"
+ },
+ "editor_username": {
+ "description": "The editor username value.",
+ "type": "string"
+ },
+ "id": {
+ "description": "The id value.",
+ "type": "integer"
+ },
+ "revision_number": {
+ "description": "The revision number value.",
+ "type": "integer"
+ },
+ "snapshot": {
+ "additionalProperties": false,
+ "description": "The snapshot value.",
+ "properties": {
+ "actor_user_id": {
+ "description": "The actor user id value.",
+ "nullable": true,
+ "type": "integer"
+ },
+ "allowed_role_ids": {
+ "description": "The allowed role ids value.",
+ "items": {
+ "type": "integer"
+ },
+ "type": "array"
+ },
+ "description": {
+ "description": "The description value.",
+ "type": "string"
+ },
+ "edges": {
+ "description": "The edges value.",
+ "items": {
+ "additionalProperties": false,
+ "properties": {
+ "action_id": {
+ "description": "The action id value.",
+ "type": "integer"
+ },
+ "created_at": {
+ "description": "The created at value.",
+ "format": "date-time",
+ "type": "string"
+ },
+ "edge_type": {
+ "description": "The edge type value.",
+ "type": "string"
+ },
+ "id": {
+ "description": "The id value.",
+ "type": "integer"
+ },
+ "source_handle": {
+ "description": "The source handle value.",
+ "type": "string"
+ },
+ "source_node_id": {
+ "description": "The source node id value.",
+ "type": "integer"
+ },
+ "target_handle": {
+ "description": "The target handle value.",
+ "type": "string"
+ },
+ "target_node_id": {
+ "description": "The target node id value.",
+ "type": "integer"
+ }
+ },
+ "required": [
+ "action_id",
+ "created_at",
+ "edge_type",
+ "id",
+ "source_node_id",
+ "target_node_id"
+ ],
+ "type": "object"
+ },
+ "type": "array"
+ },
+ "is_enabled": {
+ "description": "The is enabled value.",
+ "type": "boolean"
+ },
+ "name": {
+ "description": "The name value.",
+ "type": "string"
+ },
+ "nodes": {
+ "description": "The nodes value.",
+ "items": {
+ "additionalProperties": false,
+ "properties": {
+ "action_id": {
+ "description": "The action id value.",
+ "type": "integer"
+ },
+ "created_at": {
+ "description": "The created at value.",
+ "format": "date-time",
+ "type": "string"
+ },
+ "id": {
+ "description": "The id value.",
+ "type": "integer"
+ },
+ "node_config": {
+ "description": "The node config value.",
+ "type": "string"
+ },
+ "node_type": {
+ "description": "The node type value.",
+ "type": "string"
+ },
+ "position_x": {
+ "description": "The position x value.",
+ "type": "number"
+ },
+ "position_y": {
+ "description": "The position y value.",
+ "type": "number"
+ },
+ "updated_at": {
+ "description": "The updated at value.",
+ "format": "date-time",
+ "type": "string"
+ }
+ },
+ "required": [
+ "action_id",
+ "created_at",
+ "id",
+ "node_config",
+ "node_type",
+ "position_x",
+ "position_y",
+ "updated_at"
+ ],
+ "type": "object"
+ },
+ "type": "array"
+ },
+ "trigger_config": {
+ "description": "The trigger config value.",
+ "type": "string"
+ },
+ "trigger_type": {
+ "description": "The trigger type value.",
+ "type": "string"
+ }
+ },
+ "required": [
+ "allowed_role_ids",
+ "edges",
+ "is_enabled",
+ "name",
+ "nodes",
+ "trigger_type"
+ ],
+ "type": "object"
+ },
+ "source": {
+ "description": "The source value.",
+ "type": "string"
+ },
+ "workspace_id": {
+ "description": "The workspace id value.",
+ "type": "integer"
+ }
+ },
+ "required": [
+ "action_id",
+ "changed_fields",
+ "created_at",
+ "id",
+ "revision_number",
+ "snapshot",
+ "source",
+ "workspace_id"
+ ],
+ "type": "object"
+ }
+ },
+ "required": [
+ "data"
+ ],
+ "type": "object"
+ },
"GetWorkspacesWorkspaceIdActionsResult": {
"additionalProperties": false,
"properties": {
@@ -33351,6 +33673,11 @@
"description": "The creator name value.",
"type": "string"
},
+ "current_revision_id": {
+ "description": "The current revision id value.",
+ "nullable": true,
+ "type": "integer"
+ },
"description": {
"description": "The description value.",
"type": "string"
@@ -49022,6 +49349,11 @@
"description": "The creator name value.",
"type": "string"
},
+ "current_revision_id": {
+ "description": "The current revision id value.",
+ "nullable": true,
+ "type": "integer"
+ },
"description": {
"description": "The description value.",
"type": "string"
@@ -60246,6 +60578,11 @@
"description": "The creator name value.",
"type": "string"
},
+ "current_revision_id": {
+ "description": "The current revision id value.",
+ "nullable": true,
+ "type": "integer"
+ },
"description": {
"description": "The description value.",
"type": "string"
@@ -90723,6 +91060,11 @@
"description": "The creator name value.",
"type": "string"
},
+ "current_revision_id": {
+ "description": "The current revision id value.",
+ "nullable": true,
+ "type": "integer"
+ },
"description": {
"description": "The description value.",
"type": "string"
@@ -123803,6 +124145,173 @@
]
}
},
+ "/workspaces/{workspace_id}/actions/{action_id}/revisions": {
+ "get": {
+ "description": "List action definition revisions. Results include only resources visible to the authenticated caller; collections use their documented stable order and bounds.",
+ "operationId": "getWorkspacesWorkspaceIdActionsActionIdRevisions",
+ "parameters": [
+ {
+ "description": "The workspace identifier.",
+ "in": "path",
+ "name": "workspace_id",
+ "required": true,
+ "schema": {
+ "minimum": 1,
+ "type": "integer"
+ }
+ },
+ {
+ "description": "The action identifier.",
+ "in": "path",
+ "name": "action_id",
+ "required": true,
+ "schema": {
+ "minimum": 1,
+ "type": "integer"
+ }
+ },
+ {
+ "description": "One-based page number.",
+ "in": "query",
+ "name": "page",
+ "required": false,
+ "schema": {
+ "default": 1,
+ "minimum": 1,
+ "type": "integer"
+ }
+ },
+ {
+ "description": "Maximum number of resources to return.",
+ "in": "query",
+ "name": "page_size",
+ "required": false,
+ "schema": {
+ "default": 50,
+ "maximum": 1000,
+ "minimum": 1,
+ "type": "integer"
+ }
+ }
+ ],
+ "responses": {
+ "200": {
+ "content": {
+ "application/json": {
+ "schema": {
+ "$ref": "#/components/schemas/GetWorkspacesWorkspaceIdActionsActionIdRevisionsResult"
+ }
+ }
+ },
+ "description": "List action definition revisions response."
+ },
+ "401": {
+ "$ref": "#/components/responses/AuthenticationError"
+ },
+ "403": {
+ "$ref": "#/components/responses/PermissionError"
+ },
+ "404": {
+ "$ref": "#/components/responses/NotFoundError"
+ },
+ "429": {
+ "$ref": "#/components/responses/RateLimitError"
+ },
+ "500": {
+ "$ref": "#/components/responses/InternalError"
+ }
+ },
+ "security": [
+ {
+ "BearerAuth": []
+ }
+ ],
+ "summary": "List action definition revisions",
+ "tags": [
+ "Automation"
+ ],
+ "x-required-scopes": [
+ "actions:read"
+ ]
+ }
+ },
+ "/workspaces/{workspace_id}/actions/{action_id}/revisions/{revision_id}": {
+ "get": {
+ "description": "Get an action definition revision. Results include only resources visible to the authenticated caller; collections use their documented stable order and bounds.",
+ "operationId": "getWorkspacesWorkspaceIdActionsActionIdRevisionsRevisionId",
+ "parameters": [
+ {
+ "description": "The workspace identifier.",
+ "in": "path",
+ "name": "workspace_id",
+ "required": true,
+ "schema": {
+ "minimum": 1,
+ "type": "integer"
+ }
+ },
+ {
+ "description": "The action identifier.",
+ "in": "path",
+ "name": "action_id",
+ "required": true,
+ "schema": {
+ "minimum": 1,
+ "type": "integer"
+ }
+ },
+ {
+ "description": "The definition revision identifier.",
+ "in": "path",
+ "name": "revision_id",
+ "required": true,
+ "schema": {
+ "minimum": 1,
+ "type": "integer"
+ }
+ }
+ ],
+ "responses": {
+ "200": {
+ "content": {
+ "application/json": {
+ "schema": {
+ "$ref": "#/components/schemas/GetWorkspacesWorkspaceIdActionsActionIdRevisionsRevisionIdResult"
+ }
+ }
+ },
+ "description": "Get an action definition revision response."
+ },
+ "401": {
+ "$ref": "#/components/responses/AuthenticationError"
+ },
+ "403": {
+ "$ref": "#/components/responses/PermissionError"
+ },
+ "404": {
+ "$ref": "#/components/responses/NotFoundError"
+ },
+ "429": {
+ "$ref": "#/components/responses/RateLimitError"
+ },
+ "500": {
+ "$ref": "#/components/responses/InternalError"
+ }
+ },
+ "security": [
+ {
+ "BearerAuth": []
+ }
+ ],
+ "summary": "Get an action definition revision",
+ "tags": [
+ "Automation"
+ ],
+ "x-required-scopes": [
+ "actions:read"
+ ]
+ }
+ },
"/workspaces/{workspace_id}/agent-runs": {
"get": {
"description": "Returns at most 200 visible agent runs in stable newest-first ID order. next_cursor resumes exclusively before the final returned run; private verification runs and unauthorized runs are omitted.",
diff --git a/frontend/src/lib/api/actions.js b/frontend/src/lib/api/actions.js
index 36b104a0d..57754ea9a 100644
--- a/frontend/src/lib/api/actions.js
+++ b/frontend/src/lib/api/actions.js
@@ -57,6 +57,13 @@ export const actions = {
}),
getLogs: (workspaceId, actionId) =>
fetchAllV2Pages(`/workspaces/${workspaceId}/actions/${actionId}/logs`),
+ // Definition history: immutable, attributable revisions of the executable
+ // configuration. Listing returns metadata; getRevision returns the full
+ // snapshot so an operator can reconstruct what actually ran.
+ getRevisions: (workspaceId, actionId) =>
+ fetchAllV2Pages(`/workspaces/${workspaceId}/actions/${actionId}/revisions`),
+ getRevision: (workspaceId, actionId, revisionId) =>
+ fetchV2Data(`/workspaces/${workspaceId}/actions/${actionId}/revisions/${revisionId}`),
};
// Action templates: read-only registry shipped with the binary, plus
diff --git a/frontend/src/lib/features/actions/ActionHistory.svelte b/frontend/src/lib/features/actions/ActionHistory.svelte
new file mode 100644
index 000000000..e9a1b7f7d
--- /dev/null
+++ b/frontend/src/lib/features/actions/ActionHistory.svelte
@@ -0,0 +1,307 @@
+
+
+
+
+
+
+ {#if loading}
+
+ {:else}
+ ({ 'data-testid': `action-history-row-${item.id}` })}
+ >
+ {#snippet source(item)}
+ {sourceLabel(item.source)}
+ {/snippet}
+
+ {#snippet editor(item)}
+ {#if item.editor_username}
+ {item.editor_username}
+ {:else}
+ {t('actions.history.system')}
+ {/if}
+ {/snippet}
+
+ {#snippet changed(item)}
+ {changedFields(item)}
+ {/snippet}
+
+ {#snippet date(item)}
+ {formatDate(item.created_at)}
+ {/snippet}
+
+ {#snippet details(item)}
+
+ {/snippet}
+
+ {/if}
+
+
+
+{#if selectedRevision}
+
+
+
+ {#if detailLoading}
+
+ {:else}
+
+ {sourceLabel(selectedRevision.source)}
+
+ {selectedRevision.editor_username || t('actions.history.system')}
+
+ {formatDate(selectedRevision.created_at)}
+
+
+
+
{t('actions.history.changedFields')}
+
+ {changedFields(selectedRevision)}
+
+
+
+
+
{t('actions.history.snapshot')}
+
+
+ {t('common.name')}
+
+ {selectedRevision.snapshot?.name}
+
+
+
+ {t('actions.history.triggerType', 'Trigger')}
+ {selectedRevision.snapshot?.trigger_type}
+
+
+ {t('actions.history.nodes')}
+
+ {selectedRevision.snapshot?.nodes?.length ?? 0}
+
+
+
+ {t('actions.history.edges')}
+
+ {selectedRevision.snapshot?.edges?.length ?? 0}
+
+
+
+
+
+
+
{t('actions.history.nodes')}
+
+ {#each selectedRevision.snapshot?.nodes ?? [] as node, index}
+ -
+ {node.node_type}
+
{node.node_config}
+
+ {/each}
+
+
+ {/if}
+
+
+{/if}
+
+
diff --git a/frontend/src/lib/features/actions/ActionsManager.svelte b/frontend/src/lib/features/actions/ActionsManager.svelte
index d2847bfc2..335c39b39 100644
--- a/frontend/src/lib/features/actions/ActionsManager.svelte
+++ b/frontend/src/lib/features/actions/ActionsManager.svelte
@@ -10,6 +10,7 @@
import Play from '@lucide/svelte/icons/play';
import Zap from '@lucide/svelte/icons/zap';
import MoreHorizontal from '@lucide/svelte/icons/more-horizontal';
+ import History from '@lucide/svelte/icons/history';
import Pencil from '@lucide/svelte/icons/pencil';
import Copy from '@lucide/svelte/icons/copy';
import Trash2 from '@lucide/svelte/icons/trash-2';
@@ -18,7 +19,7 @@
import PageHeader from '../../layout/PageHeader.svelte';
import Badge from '../../components/Badge.svelte';
- /** @type {{ workspaceId: any, actions?: any[], loading?: boolean, oncreate?: () => void, onfromtemplate?: () => void, onedit?: (action: any) => void, onrename?: (action: any) => void, onduplicate?: (action: any) => void, ontoggle?: (action: any) => void, ondelete?: (action: any) => void, onviewlogs?: (action: any) => void, ontestexecuted?: (action: any) => void }} */
+ /** @type {{ workspaceId: any, actions?: any[], loading?: boolean, oncreate?: () => void, onfromtemplate?: () => void, onedit?: (action: any) => void, onrename?: (action: any) => void, onduplicate?: (action: any) => void, ontoggle?: (action: any) => void, ondelete?: (action: any) => void, onviewlogs?: (action: any) => void, onviewhistory?: (action: any) => void, ontestexecuted?: (action: any) => void }} */
let {
workspaceId,
actions = [],
@@ -31,6 +32,7 @@
ontoggle,
ondelete,
onviewlogs,
+ onviewhistory,
ontestexecuted,
} = $props();
@@ -96,6 +98,10 @@
onviewlogs?.(action);
}
+ function handleViewHistory(action) {
+ onviewhistory?.(action);
+ }
+
function moreItems(action) {
return [
...(onrename ? [{ id: 'rename', title: t('actions.rename'), icon: Pencil, testid: `action-rename-${action.id}`, onClick: () => onrename(action) }] : []),
@@ -204,6 +210,14 @@
+