Repository navigation
feat: run Sobek scripts as the action executor (WI-2174) - #511
Conversation
Add an execute_script action node that runs an author-supplied JavaScript
function body in a fresh Sobek runtime bound to the effective action
executor. Scripts reach the canonical v2 REST API through a synchronous
windshift.api.request({ method, path, body }) helper backed by a
short-lived temporary bearer token minted for that executor and revoked
in node cleanup.
Security boundaries:
- Identity is always the effective executor (actor override, otherwise
the triggering user); scripts cannot choose or read an identity, and a
missing or inactive executor fails closed before any dispatch.
- The minted token carries a fixed, server-owned scope allowlist with no
delete, admin, action-authoring, asset, test, agent-run, or MCP scope.
- Only validated relative v2 paths on this instance are accepted; the
bridge rejects alternate hosts, redirects, path escapes, encoded
traversal, fragments, and unsupported methods before minting.
- An initial resource allowlist keeps token-minting, delegation, and
admin routes out of reach even when the executor could reach them.
- Requests run through the real mounted v2 handler, so bearer auth,
token scopes, rate limits, and handler authorization still apply.
Runtime and product:
- Compile the function body once and run it exactly once; no
retry-as-IIFE fallback that could repeat side effects.
- Detached JSON inputs and results, explicit output variable, bounded
console capture, safe errors, and strict limits on source, runtime,
API calls, response and result size/depth.
- Preserve action/execution/node/revision provenance, cascade depth, and
private-trigger protection across the in-process REST calls.
- Catalog registration with save-time syntax validation, a flow-editor
node plus config/reference panel, and localized palette labels.
- Document that in-process Sobek has no hard per-script heap limit and
that trusted authors are required unless process isolation is added.
Tests cover executor-scoped credentials, fail-closed identity, fatal
uncatchable policy violations, call budgets, timeouts, unsupported
results, path policy, response truncation, scope exclusions, catalog
validation, and an end-to-end create-comment/failed-probe workflow.
|
Size Change: 0 B 🆕 Total Size: 0 B |
Review: changes requestedReviewed commit 1. [P1] Returned getters execute after the watchdog and credential cleanup
return {
get value() {
windshift.api.request({ method: 'GET', path: '/items/1' });
return 1;
}
};I reproduced this against the PR executor: one token minted, one request dispatched, zero tokens revoked, because the getter makes the first API call after cleanup has already been skipped. A getter containing 2. [P1] Transition-screen comments bypass private-trigger and recursion protections
The transition event gets provenance, but the subsequent 3. [P1] Allowed bulk item writes reset the automation cascade
Allowlisting all 4. [P1] Failed durable executions replay already-committed script writes
The existing durable execution log is only skipped when its status is Validation
|
…2174) Address review findings on the execute_script node: - Convert the returned script value while the runtime watchdog is still armed, and revoke the executor credential in deferred cleanup. A returned getter is script code, so it can no longer mint a credential after cleanup or run outside the timeout budget. Conversion panics are classified as conversion errors or timeouts. - Forward the request context through transition-screen comments so script provenance (private-trigger protection and comment-trigger suppression) reaches the comment service. - Exclude the bulk item write routes from the initial bridge policy: they emit update events without an action context and would reset the automation cascade. - Mark an execution reconciliation_required when a script commits a mutating REST call and the flow later fails, and block durable replay of that execution so the committed write is not repeated.
|
Addressed all four findings in 1. Returned getters after cleanup
2. Transition-screen comment provenance
3. Bulk item writes
4. Durable replay of committed writesAn execution that commits a mutating script call and then fails is now persisted as Validation
|
Re-review: changes still requestedReviewed The deferred credential cleanup, normal returned-getter conversion, transition-comment context forwarding, and named bulk-route denials address their original cases. The ordinary “write, then throw” path now has a terminal reconciliation state. Three gaps remain: 1. [P1] Script-defined error formatting still executes after the watchdog stops
The deferred handler closes and joins the watchdog before formatting the recovered value. For Sobek exceptions, both throw { toString() { while (true) {} } };
// Also reachable from a getter on the returned object.This can still hang the action worker indefinitely despite 2. [P1] Reconciliation is not persisted before writes, so crash recovery still repeats them
The new state fixes normal recorded failures, but does not yet implement the crash/recovery contract from WI-2174 or the PR description. Persist a write-ahead/in-flight marker before a potentially mutating dispatch and treat uncertain recovery as reconciliation-required, or provide durable per-call idempotency. Cover a restart/redelivery with an existing 3. [P1] Other allowed item mutation routes still drop cascade provenance
Denying the three bulk paths fixes those routes, but the resource-wide Either narrow allowed mutation routes to the explicitly audited provenance-preserving paths, or carry provenance through this route's persisted facts and emitted events. Add route-level coverage at the cascade boundary; checking only the newly denied bulk paths does not establish this invariant. Validation
|
…s (WI-2174) Address the second review round on the execute_script node: - Convert Sobek runtime errors and recovered panics to bounded, inert Go text while the watchdog is still armed. Formatting an exception can invoke a script toString, which is script code; a custom toString can no longer run after the timeout or retain a script-backed value. - Persist a write-ahead reconciliation marker on the execution log before dispatching a mutating script call. A worker that dies after the commit but before the terminal log update leaves the log reconciliation_required, so durable recovery blocks replay instead of repeating the write. - Restrict script mutations to the explicitly audited, provenance-preserving routes (item create/update/transition/comment and bulk transition). Other item mutations such as change-type and link creation emit user-origin events without an action context and would reset the cascade.
|
Addressed the three remaining findings in 1. Script-defined error formatting after the watchdog
2. Reconciliation not persisted before writesAdded a write-ahead marker: before dispatching a mutating request the executor calls 3. Unaudited item mutationsReplaced the resource-wide mutation surface with a strict, audited mutation allowlist: Validation
|
Third review: two replay-safety gaps remainReviewed The custom-error formatting fix and strict mutation allowlist address the preceding review's timeout and provenance findings. The write-ahead marker closes the first-attempt crash window, but two cases still undermine its recovery guarantee: 1. [P1] Failed executions dispatch retry writes without persisting the marker
The marker only updates rows whose stored status is I reproduced the executor/repository interaction with a real production-schema execution log in Persist the retry's running state before executing it, or implement an atomic marker transition that handles eligible retry states. In either case, verify the marker exists before permitting dispatch; a no-op update must not authorize a write. Add recovery coverage for a failed attempt followed by a retry that commits and crashes, not only an initially running row. 2. [P1] Uncertain write responses erase the persisted reconciliation marker
The executor persists the marker before dispatch, but only sets the in-memory A non-2xx response does not prove no write committed: the allowed item-create and item-patch paths perform their mutation before response enrichment/rendering ( I reproduced the status transition through the real durable consumer with a dispatcher returning 500 and a script throwing on Keep the execution non-replayable once a mutating dispatch may have run, unless there is positive evidence that no side effect occurred. Preserve this across transport errors, non-2xx responses, and later flow failures; do not infer rollback from the HTTP status. Add post-commit-error/redelivery coverage. Validation
|
Address the third review round on the execute_script node: - Mark the execution non-replayable before a mutating dispatch, not only after a 2xx response. A non-2xx response or transport error does not prove no side effect committed, so the persisted reconciliation marker must survive an uncertain outcome. - Promote a failed execution log to reconciliation_required when a retry persists its write-ahead marker, and treat a no-op marker update as an error so a write is never dispatched without a persisted marker. This closes the window where a retry of a failed log reused its row without re-marking it.
|
Addressed both findings in 1. Failed executions retried without persisting the marker
2. Uncertain write responses erased the markerThe executor now sets the in-memory
Validation
|
Fourth review: one regression remainsReviewed [P1] The second mutating script node in an execution now fails
The first mutating script node promotes the shared execution log to This breaks ordinary flows containing two mutating script nodes, and repeated executions of a mutating script node inside a related-items iterator. Multiple requests within one node still work, which is why the current two-request test does not catch it. I reproduced this with a real production-schema execution log and the production executor/marker: the first node dispatched successfully, then the second failed with: Share the successfully persisted marker state across the live execution's nodes/iterations, or otherwise make repeated marking safe for that same active execution. Keep the missing-row/invalid-state denial and recovery replay protections. Add a regression with separate node executions sharing one log, plus iterator coverage if the implementation handles iterations differently. Validation
|
Address the fourth review round on the execute_script node: The write-ahead marker promoted the shared execution log to reconciliation_required, but each script node built a fresh per-run marker flag. The second mutating script node in a flow (or a later iterator pass) then tried to re-mark the same log, which the repository correctly rejects as an invalid state, failing the node before dispatch. Track the persisted marker on the shared ExecutionContext so every script node and iterator pass in one execution reuses the first persisted marker. The repository still rejects a no-op marker update, so a write is never dispatched without a persisted marker and recovery replay protections are unchanged.
|
Fixed the multi-node regression in The second mutating script node failedThe persisted marker state now lives on the shared Coverage
Validation
|
Fifth review: no new actionable findingsReviewed The multi-node regression is resolved: Verified
Commands and limits
No further code changes requested from this review pass; the full-package validation limitation above remains. |
What this adds
An
execute_scriptaction node (WI-2174) that runs an author-supplied JavaScript function body in a fresh Sobek runtime bound to the effective action executor — the configured actor override, otherwise the triggering user. Scripts reach the canonical v2 REST API synchronously through:Go mints a short-lived temporary bearer token for that executor, dispatches the request through the real mounted
/rest/api/v2handler, and revokes the token in node cleanup. The raw credential never reaches JavaScript, logs, results, or persisted definitions.Security contract
ctx.EffectiveActorID. Scripts cannot choose, read, or override an actor, and there is no creator/admin/system fallback. Missing or inactive executors fail closed before any dispatch.ActionScriptScopes) with no delete, admin, action-authoring, asset, test, agent-run, or MCP scope. Scopes constrain the token; they never grant permissions the executor lacks.comment_createdtrigger.Runtime
windshift.api.request,console.log/info/warn/error/debug, a read-onlycontextview, and the reserved id variables. No Go services, pointers, or shared maps are exposed.output_variable, strict rejection of promises/functions/unsupported values, depth and size caps.try/catchcannot turn a denial into a successful step.Product integration
data-testidhooks for browser tests), and palette labels in all 12 locales.Documented limitations
Evidence
go build ./internal/...,go vet ./internal/...scripts/run-golangci-lint.sh run --timeout=5m ./internal/services/... ./internal/services/actioncatalog/... ./internal/models/... ./internal/restapi/v2/... ./internal/server/...— 0 issuesoverlay.shfocused./internal/services/,./internal/services/actioncatalog/,./internal/restapi/v2/, and./tests/for the new execute_script tests — pass./internal/services/package pass (with pre-existing stale timer/action test files set aside; see the companion core-tests PR)bun run check,svelte-check --threshold error,check-i18n— passCompanion tests: Windshiftapp/core-tests-internal#.