Skip to content

feat: run Sobek scripts as the action executor (WI-2174) - #511

Merged
stefan-ernst merged 5 commits into
mainfrom
feat/wi-2174-sobek-script-execution
Nov 14, 2026
Merged

stefan-ernst merged 5 commits into
mainfrom
feat/wi-2174-sobek-script-execution

Conversation

@stefan-ernst

Copy link
Copy Markdown
Contributor

What this adds

An execute_script action 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:

windshift.api.request({ method, path, body })

Go mints a short-lived temporary bearer token for that executor, dispatches the request through the real mounted /rest/api/v2 handler, and revokes the token in node cleanup. The raw credential never reaches JavaScript, logs, results, or persisted definitions.

Security contract

  • Identity: always 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.
  • Scopes: the minted token carries a fixed, server-owned allowlist (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.
  • Paths: only validated relative v2 paths on this instance. The bridge rejects absolute URLs, protocol-relative paths, alternate hosts, path escapes, encoded traversal, fragments, backslashes, and unsupported methods. DELETE is denied independently.
  • Route policy: an initial resource allowlist keeps token-minting, delegation, and admin routes out of reach even when the executor could reach them.
  • Middleware preserved: requests run through the real mounted handler, so bearer auth, token scopes, rate limits, concurrency limits, DB budgets, and every handler-level authorization decision still apply. No direct handler calls.
  • Provenance: the in-process request carries trusted action/execution/node/revision attribution, cascade depth, chain ID, and the private-trigger flag. Item create/update/transition and comment creation consume it, so script side effects stay inside the cascade budget and a private trigger cannot publish a public comment. Script-driven comments do not re-enter the comment_created trigger.

Runtime

  • Function body compiled once and executed exactly once. The existing execute-then-retry-as-IIFE behavior is deliberately not used, since a retry after a runtime error could repeat host side effects.
  • Explicit closed binding set: windshift.api.request, console.log/info/warn/error/debug, a read-only context view, and the reserved id variables. No Go services, pointers, or shared maps are exposed.
  • Detached JSON inputs and results, explicit output_variable, strict rejection of promises/functions/unsupported values, depth and size caps.
  • Limits: 10 KB source, default 5s / max 30s runtime, 50 API calls, 256 KB response, 64 KB result, 20 levels deep, 16 KB console. Node config may narrow but never widen them.
  • Policy and budget violations are fatal: they interrupt the VM, so a try/catch cannot turn a denial into a successful step.

Product integration

  • Registered node type with a config schema and save-time syntax-only validation; saving never executes the script and never makes a live API call.
  • Flow-editor node, config/reference panel (data-testid hooks for browser tests), and palette labels in all 12 locales.

Documented limitations

  • In-process Sobek has no hard per-script heap limit; time and output budgets do not make hostile allocation safe. Trusted authors are required unless process isolation is added.
  • Script side effects are not transactional. A script that mutates and then fails has committed those writes, matching every other action node; durable replay reuses the first attempt's execution log, but a crash between a write and log completion is reconciliation-required rather than silently idempotent.
  • Asset-flow parity is out of scope, as agreed.

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 issues
  • overlay.sh focused ./internal/services/, ./internal/services/actioncatalog/, ./internal/restapi/v2/, and ./tests/ for the new execute_script tests — pass
  • Full ./internal/services/ package pass (with pre-existing stale timer/action test files set aside; see the companion core-tests PR)
  • Frontend bun run check, svelte-check --threshold error, check-i18n — pass
  • Pre-commit guards (SQL/audit literals, layering, handler DB access, deprecated v1, OpenAPI, frontend-v2 fields, inline styles) — pass

Companion tests: Windshiftapp/core-tests-internal#.

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.
@github-actions

Copy link
Copy Markdown

Size Change: 0 B 🆕

Total Size: 0 B

compressed-size-action

@stefan-ernst

Copy link
Copy Markdown
Contributor Author

Review: changes requested

Reviewed commit c28eae3a33199c3e8cdaa6f97692f9a2922384a6. Four correctness/security issues need addressing:

1. [P1] Returned getters execute after the watchdog and credential cleanup

internal/services/action_script_executor.go:183–216

runScriptProgram stops and joins its watchdog before strictScriptOutput calls result.Export(). Sobek export evaluates enumerable getters, so this is still executable script, not inert serialization. For example:

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 while (true) {} also runs outside the runtime watchdog. Keep result conversion inside the monitored execution/lifecycle, make revocation deferred, and reject or safely evaluate accessors under the same budget. Add regression coverage for returned getters, including exceptions and timeouts.

2. [P1] Transition-screen comments bypass private-trigger and recursion protections

internal/services/item_application_service.go:1198–1206

The transition event gets provenance, but the subsequent recordTransitionComment still calls s.comments.Create(...) without the request context and defaults IsPrivate to false. An allowed POST /items/{id}/transition with fields: { comment: '...' }, from an action triggered by a private comment, can therefore publish a public comment and emit a fresh comment_created trigger. The new protections in CommentService.create only run when CreateContext receives the stamped context. Propagate it through transition comments too, with regressions asserting private visibility and no comment-trigger re-entry.

3. [P1] Allowed bulk item writes reset the automation cascade

internal/services/action_script_bridge.go:57–60

Allowlisting all items routes also permits POST /items/bulk-update and /items/bulk-patch with the minted items:write scope. Those routes call BulkUpdate/BulkPatch, whose applyBulkEffects invokes EmitItemUpdated without an ActionContext. Thus script mutations on these routes lose the chain, cascade depth, and private-trigger flag, unlike the newly protected single-item patch. An item_updated action that bulk-updates an item can start a fresh chain repeatedly instead of reaching the cascade limit. Either exclude these routes initially or preserve provenance through their persistence/event paths; test the actual bulk routes at the cascade boundary.

4. [P1] Failed durable executions replay already-committed script writes

internal/services/action_script_executor.go:183–213

The existing durable execution log is only skipped when its status is completed (action_service.go:661–672); failed/running attempts rerun the entire flow. DurableActionConsumer returns execution errors for retry, and this executor has no persisted per-call idempotency or reconciliation gate. A script that successfully posts a comment and then throws will therefore post that comment again on delivery retry. This is not limited to a crash between a write and log completion: an ordinary recorded script failure is enough. Documentation saying reconciliation is required does not implement it. Before enabling writes, persist an explicit reconciliation-required state that blocks automatic replay, or implement durable idempotency for the side effects, as required by WI-2174.

Validation

  • go build ./internal/... — passed on the PR head.
  • Focused regression: core-tests/overlay.sh <PR-worktree> -- -tags=test -count=1 -run TestReviewReturnedGetterCredentialCleanup ./internal/services/ — blocked by existing timer-test compilation mismatches (StopResult.WorklogCreated, NewTimerService, StartTimer).
  • Isolated regression via core-tests/run-overlay-script.sh <PR-worktree> scripts/review-script-getter.sh, compiling production service files plus the temporary getter regression — failed as expected: credential leaked: minted=1 revoked=0. Temporary review-only test/runner removed afterward.
  • Full suites, PostgreSQL, frontend, and browser tests were not run. Findings 2–4 were traced through the production call paths, not exercised end-to-end.

…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.
@stefan-ernst

Copy link
Copy Markdown
Contributor Author

Addressed all four findings in 7d69d9fd (core-tests ffffe9e1).

1. Returned getters after cleanup

runScriptProgram now converts the return value before stopping the watchdog, and credential revocation moved to a deferred cleanup that always runs. A returned getter is therefore still inside the timeout budget and the credential window. Conversion panics are classified as conversion errors, and an interrupt during conversion still surfaces as the timeout. Regression tests cover a getter that calls the API (one mint, one revoke, one dispatch), a getter that throws, and a getter that loops (interrupted).

2. Transition-screen comment provenance

recordTransitionComment now takes the request context and calls CreateContext, so the private-trigger flag and comment-trigger suppression reach CommentService.create. Bulk transition already flows through the same per-item path. A black-box regression triggers an action from a private comment and asserts the script-driven transition comment is private.

3. Bulk item writes

/items/bulk-update, /items/bulk-patch, and /items/bulk-delete are now explicitly denied by the bridge policy, so those routes cannot reset the cascade. /items/bulk-transition stays allowed because it flows through the provenance-carrying per-item transition path. Path-policy tests assert the rejection.

4. Durable replay of committed writes

An execution that commits a mutating script call and then fails is now persisted as reconciliation_required. The durable Completed callback treats that state as terminal, and Execute reports the error as permanent, so the event is not redelivered. A white-box durable test posts through a script, fails the flow, asserts the log status, and proves a second delivery does not repeat the write or mint another credential.

Validation

  • go build ./internal/..., go vet ./internal/..., golangci-lint on touched packages — 0 issues
  • Focused overlay: ./internal/services/, ./internal/services/actioncatalog/, ./internal/restapi/v2/, and the new ./tests/ specs — pass
  • Frontend bun run check, svelte-check --threshold error, check-i18n — pass
  • Pre-commit guards (SQL/audit literals, layering, handler DB access, deprecated v1, inline styles) — pass

@stefan-ernst

Copy link
Copy Markdown
Contributor Author

Re-review: changes still requested

Reviewed 7d69d9fd8baef216b0047c270d0a98ec6d10b0af with companion tests at ffffe9e1.

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

internal/services/action_script_executor.go:461–479

The deferred handler closes and joins the watchdog before formatting the recovered value. For Sobek exceptions, both %w formatting and value.String() can invoke the thrown object's JavaScript toString. Normal runtime errors have the same issue: runScriptProgram returns a live exception and Execute formats it after the watchdog has exited.

throw { toString() { while (true) {} } };
// Also reachable from a getter on the returned object.

This can still hang the action worker indefinitely despite timeout_ms. I reproduced both paths without an unbounded loop: a custom toString called a dispatcher that waited for the script context deadline, then returned. Both executions reported the custom error instead of a timeout, proving error formatting ran with the watchdog disarmed. Convert exceptions to bounded, inert error text while the watchdog is active, and do not retain script-backed values that later formatting can evaluate. Add custom-toString regressions, not only new Error('boom').

2. [P1] Reconciliation is not persisted before writes, so crash recovery still repeats them

internal/services/action_script_executor.go:343–355

ReconciliationRequired is only an in-memory boolean set after a successful response. The terminal execution status is saved at flow completion. If the worker dies after a comment/item write commits but before that final log update, the durable log remains running; executeActionForEvent still reruns that status from the beginning (action_service.go:666–677). The committed writes are repeated, rather than surfaced as reconciliation-required. An execution-log persistence failure has the same replay window.

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 running execution that already committed a script write; the current regression only covers an orderly failure that successfully saves the terminal log.

3. [P1] Other allowed item mutation routes still drop cascade provenance

internal/services/action_script_bridge.go:92–101

Denying the three bulk paths fixes those routes, but the resource-wide items allowlist also permits POST /items/{id}/change-type with items:write. That route invokes ItemApplicationService.ChangeType, which calls ItemTypeChangeService.ApplyChange without provenance, records metadata as itemevents.User(userID, "application"), and calls EmitItemUpdated without an ActionContext (item_application_service.go:1653–1663). Script-driven type/status changes therefore still become fresh user-origin events, resetting the chain/depth and losing the private-trigger flag. For example, an item-updated flow alternating between two compatible item types can repeatedly start new chains instead of reaching the cascade limit.

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

  • go build ./internal/... — passed.
  • Companion executor, getter, path-policy, and dispatcher tests — passed in isolation, using run-overlay-script.sh <PR-worktree> scripts/review-script-errors.sh 'TestExecuteScriptExecutor_|TestValidateScriptAPIRequest|TestInProcessV2Dispatcher_' with production service files plus the companion executor test file.
  • Added temporary TestReviewScriptErrorFormattingRespectsDeadline coverage for ordinary thrown objects and returned-getter exceptions, run through the same overlay script — both cases failed, reporting custom error text after the context deadline instead of timing out.
  • Standard overlay.sh <PR-worktree> -- -tags=test -count=1 -run 'TestDurableScriptReplayBlockedAfterCommittedWrite|TestExecuteScriptExecutor_' ./internal/services/ — blocked by stale action-definition/template and timer-test compilation errors in the companion branch.
  • Full suites, PostgreSQL, frontend, and browser tests were not run. Findings 2–3 are based on production-path inspection, not end-to-end reproductions. Temporary review-only test/runner removed afterward.

…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.
@stefan-ernst

Copy link
Copy Markdown
Contributor Author

Addressed the three remaining findings in 406ceb59 (core-tests b4671dec).

1. Script-defined error formatting after the watchdog

runScriptProgram now converts runtime errors and recovered panics to bounded, inert Go text while the watchdog is still armed (inertScriptError / inertScriptPanic). Formatting a Sobek exception can invoke a script toString, so that formatting is itself treated as script execution and stays under the timeout; an interrupt during formatting is classified as the timeout. No script-backed value is retained past conversion. New regressions throw an object whose toString loops, and a returned getter whose exception toString loops — both now time out instead of hanging or reporting the custom error.

2. Reconciliation not persisted before writes

Added a write-ahead marker: before dispatching a mutating request the executor calls MarkScriptWritePending(executionLogID), which promotes the running execution log to reconciliation_required (never overwriting a terminal status). If the worker dies after the commit but before the terminal log update, recovery sees reconciliation_required and blocks replay. A marker persistence failure fails the node closed without dispatching. The durable regression now also covers an existing running log with the marker already persisted, proving recovery neither dispatches nor mints.

3. Unaudited item mutations

Replaced the resource-wide mutation surface with a strict, audited mutation allowlist: POST /items, PATCH /items/{id}, POST /items/{id}/transition, POST /items/{id}/comments, and POST /items/bulk-transition. Every other mutation is denied by the bridge policy, including change-type, merge, split, link creation, and any unlisted resource. Reads are unchanged. Path-policy tests now assert the denial for change-type, merge, /links, and unlisted resources alongside the allowed routes.

Validation

  • go build ./internal/..., go vet ./internal/..., golangci-lint on touched packages — 0 issues
  • Full overlay: ./internal/services/, ./internal/services/actioncatalog/, ./internal/restapi/v2/, ./internal/repository/ — pass
  • Black-box ./tests/ execute_script specs (comment, failed probe, private transition) — pass
  • Pre-commit guards (SQL/audit literals, layering, handler DB access, deprecated v1, schema pairing) — pass

@stefan-ernst

Copy link
Copy Markdown
Contributor Author

Third review: two replay-safety gaps remain

Reviewed 406ceb598a8bdc31980c00d545bd710fdd62da56 with companion tests at b4671dec.

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

internal/repository/action_repository.go:741–752

The marker only updates rows whose stored status is running, and treats zero affected rows as success. However, executeActionForEvent also retries existing failed logs: it reuses their ID without first persisting a transition back to running. A retry that reaches a mutating script call therefore gets a successful marker result without changing the database row, then dispatches the write. If that attempt crashes after the commit, the row is still failed and the next delivery repeats it.

I reproduced the executor/repository interaction with a real production-schema execution log in failed state: the dispatcher ran, and its read of the execution row still returned failed, not reconciliation_required.

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

internal/services/action_script_executor.go:376–388

The executor persists the marker before dispatch, but only sets the in-memory ReconciliationRequired flag for a 2xx response. A mutating dispatch returning 500 or an error leaves the flag false. When the script/flow fails, executeActionForEvent then saves failed, overwriting the persisted marker and enabling automatic replay.

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 (item_application_service.go:867–877, 890–900), which can subsequently fail. Thus a committed item creation followed by a response error can be repeated on retry despite the write-ahead marker.

I reproduced the status transition through the real durable consumer with a dispatcher returning 500 and a script throwing on !res.ok: the final execution row was failed, erasing the earlier marker. This regression simulates the uncertain response; it does not inject an actual post-commit HTTP-handler failure.

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

  • go build ./internal/... — passed.
  • Isolated companion executor/path/dispatcher/durable tests — passed using run-overlay-script.sh <core-worktree> scripts/review-script-marker.sh 'TestExecuteScript|TestValidateScriptAPIRequest|TestInProcessV2Dispatcher|TestDurableScript' (production service files plus the companion script/durable test files).
  • Temporary regressions via run-overlay-script.sh <core-worktree> scripts/review-script-marker.sh — both failed as expected: write dispatched without persisted marker on retry: status=failed and write-ahead marker erased after uncertain response: status=failed.
  • overlay.sh <core-worktree> -- -tags=test -count=1 -run 'TestExecuteScript|TestValidateExecuteScript' ./internal/services/actioncatalog/ — passed.
  • Standard service-package run, overlay.sh <core-worktree> -- -tags=test -count=1 -run 'TestExecuteScript|TestValidateScriptAPIRequest|TestInProcessV2Dispatcher|TestDurableScript' ./internal/services/, remains blocked by stale action-definition/template and timer-test compilation errors on the companion branch.
  • Full suites, PostgreSQL, frontend, and browser tests were not run. Temporary review-only regressions/runner removed afterward.

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.
@stefan-ernst

Copy link
Copy Markdown
Contributor Author

Addressed both findings in 683a8153 (core-tests dbb4157f).

1. Failed executions retried without persisting the marker

MarkExecutionReconciliationRequired now promotes both running and failed execution logs to reconciliation_required, and returns an error when zero rows are affected. The executor fails the node closed when the marker cannot be persisted, so a write is never dispatched without a persisted marker. A retry of a failed attempt therefore re-marks the row before dispatching; a crash after that commit leaves reconciliation_required and the next delivery is blocked.

  • New durable regression: an existing failed log is retried, the marker is promoted, the write dispatches once, the log ends reconciliation_required, and a second delivery does not re-dispatch.

2. Uncertain write responses erased the marker

The executor now sets the in-memory ReconciliationRequired flag 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 execution stays non-replayable across transport errors, non-2xx responses, and later flow failures. The persisted write-ahead marker is no longer overwritten with failed on an uncertain outcome.

  • New executor coverage: 500 response and transport error both keep ReconciliationRequired true with the marker persisted before dispatch.
  • New durable coverage: a mutating call returning 500 followed by a script throw ends reconciliation_required, and redelivery does not repeat the write.

Validation

  • go build ./internal/..., go vet ./internal/..., golangci-lint on touched packages — 0 issues
  • Full overlay: ./internal/services/, ./internal/services/actioncatalog/, ./internal/restapi/v2/, ./internal/repository/ — pass
  • Black-box ./tests/ execute_script specs — pass
  • Pre-commit guards (SQL/audit literals, layering, handler DB access, deprecated v1) — pass

@stefan-ernst

Copy link
Copy Markdown
Contributor Author

Fourth review: one regression remains

Reviewed 683a815326afeedbcb92074a2f3444589509ef2d with companion tests at dbb4157f. The previous failed-attempt and uncertain-response cases are addressed, and their focused companion tests pass.

[P1] The second mutating script node in an execution now fails

internal/repository/action_repository.go:741–759, together with internal/services/action_script_executor.go:412–422.

The first mutating script node promotes the shared execution log to reconciliation_required. The next script node creates a fresh scriptRun, so its per-run writeMarked flag is false and it tries to mark that same log again. The repository now rejects the existing reconciliation_required status as a zero-row update, causing the second node to fail before dispatch.

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:

script node 2 failed after 1 dispatched writes:
execute_script: persist write marker: execution log 1 is not in a markable state

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

  • go build ./internal/... — passed.
  • Isolated companion executor, path-policy, dispatcher, and durable tests — passed via run-overlay-script.sh <core-worktree> scripts/review-script-multinode.sh 'TestExecuteScript|TestValidateScriptAPIRequest|TestInProcessV2Dispatcher|TestDurableScript', compiling production services and the companion script/durable test files.
  • Temporary TestReviewMultipleScriptNodesCanMutateInOneExecution via run-overlay-script.sh <core-worktree> scripts/review-script-multinode.sh — failed with the second-node error above. Temporary test/runner removed afterward.
  • Standard overlay.sh <core-worktree> -- -tags=test -count=1 -run 'TestExecuteScript|TestValidateScriptAPIRequest|TestInProcessV2Dispatcher|TestDurableScript' ./internal/services/ — still blocked by stale action-definition/template and timer-test compilation errors in the companion branch.
  • Full suites, PostgreSQL, frontend, and browser tests were not run.

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.
@stefan-ernst

Copy link
Copy Markdown
Contributor Author

Fixed the multi-node regression in 06e81a0c (core-tests 112c2a9d).

The second mutating script node failed

The persisted marker state now lives on the shared ExecutionContext (ScriptWriteMarked) instead of a per-run flag. The first mutating node persists the marker; every later script node and iterator pass in the same execution reuses it and skips the repository update, so the already-promoted log is never re-marked. The repository still rejects a no-op marker update (missing/invalid state) and the recovery replay protections are unchanged: a write is only dispatched after the marker is confirmed persisted for that execution.

Coverage

  • White-box: two separate Execute calls sharing one execution log persist the marker exactly once and both dispatch. The fake marker rejects a duplicate marker for the same log (mirroring the repository denial), so this fails if the shared state regresses.
  • End-to-end durable: an action with two chained mutating script nodes dispatches both and records a completed execution rather than failing the second node.
  • The same shared state covers related-items iterator passes, since the iterator reuses one ExecutionContext.

Validation

  • go build ./internal/..., go vet ./internal/..., golangci-lint on touched packages — 0 issues
  • Full overlay: ./internal/services/, ./internal/services/actioncatalog/, ./internal/restapi/v2/, ./internal/repository/ — pass
  • Black-box ./tests/ execute_script specs — pass
  • Pre-commit guards (SQL/audit literals, layering, handler DB access, deprecated v1) — pass

@stefan-ernst

Copy link
Copy Markdown
Contributor Author

Fifth review: no new actionable findings

Reviewed 06e81a0ce0088b41ece25c06f32b14b673e88e04 with companion tests at 112c2a9d.

The multi-node regression is resolved: ScriptWriteMarked now belongs to the shared execution context, so later script nodes and iterator passes reuse the persisted marker. The repository's invalid-state denial and durable recovery guards remain intact.

Verified

  • Separate mutating node executions sharing one real production-schema execution log both dispatch successfully and retain the persisted reconciliation marker.
  • Repeated execution of the same node with the shared context also succeeds without losing the marker.
  • The companion two-node durable flow completes successfully.
  • Focused executor, URL/mutation policy, dispatcher, scopes/provenance, output, and durable-recovery regressions pass with -race, including the preceding review cases.

Commands and limits

  • go build ./internal/... — passed.
  • run-overlay-script.sh <core-worktree> scripts/review-script-shared-marker.sh — passed. The temporary runner compiled production service files plus the companion executor/durable tests and independent real-repository regressions, using:
    go test -race -tags=test -count=1 -run 'TestReviewSharedMarkerWithRealRepository|TestExecuteScript|TestValidateScriptAPIRequest|TestInProcessV2Dispatcher|TestDurableScript|TestDurableMultipleScript|TestActionScript|TestStrictScript' <selected files>
    
  • overlay.sh <core-worktree> -- -tags=test -count=1 -run 'TestExecuteScript|TestDurableScript|TestDurableMultipleScript' ./internal/services/ — still blocked by stale action-definition/template and timer-test compilation errors in the companion branch. This does not verify the claimed full-package pass.
  • Full suites, PostgreSQL, frontend, and browser tests were not run. Temporary review-only tests/runner removed afterward.

No further code changes requested from this review pass; the full-package validation limitation above remains.

@stefan-ernst stefan-ernst changed the title feat(actions): run Sobek scripts as the action executor (WI-2174) feat: run Sobek scripts as the action executor (WI-2174) Nov 14, 2026
@stefan-ernst
stefan-ernst merged commit db435be into main Nov 14, 2026
22 of 23 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant