Files
floci/src/main/java
Alex Banna f558472a4d feat(stepfunctions): run executions under the execution's account (#1566)
* feat(stepfunctions): run executions under the execution's account

AslExecutor runs each execution on a worker-thread pool with no active CDI
request scope, so service integrations (Lambda, DynamoDB, SQS, …) and the
execution-store writes fell back to the configured default account. An
execution started under account B therefore had its integrations run
against account A's resources — e.g. a dynamodb:putItem targeting a table
that exists only in account B would fail with ResourceNotFound.

Wrap doExecute in a synthetic request scope whose account is the one
encoded in the state machine ARN (mirroring CurEmissionScheduler's
runUnderAccount), so integrations and store writes resolve to the
execution's own account. Falls back to running directly when Arc is not
running (plain unit tests that construct AslExecutor without a container).

Test: an execution started under a non-default account writes to a table
that exists only in that account; the execution succeeds, the item is
readable in that account, and a different account has no such table.

* fix(stepfunctions): restore previous account after runUnderExecutionAccount

Greptile review on #1566: when execution ran inside an already-active request
scope, runUnderExecutionAccount overwrote the account ID without restoring it.
Save and restore the previous account in finally so a reused thread isn't left
with the execution's account. (Executions run on background workers with no
active scope, so this hardens the already-active path.)

* fix(stepfunctions): run Parallel branches under the execution's account

executeParallelState submitted each branch to the executor pool without
re-establishing the execution's CDI request scope. RequestContext is
@RequestScoped (thread-bound), so a branch running on a worker thread had no
active scope: its Task integrations resolved via RegionResolver.getAccountId(),
which falls back to the default account on ContextNotActiveException. Branch
Task states therefore ran against the default account's resources instead of
the execution's.

Extract the scope-activation logic into a Callable-returning
callUnderExecutionAccount (runUnderExecutionAccount now delegates to it) and wrap
each branch submission with it, so every branch worker thread activates its own
request scope for the execution's account — mirroring how executeAsync/executeSync
wrap doExecute. Map states already run executeBranch synchronously on the parent
thread, so they were unaffected.

Adds a Parallel-branch case to StepFunctionsAccountContextIntegrationTest whose
branches dynamodb:putItem into a table that exists only in the execution's
account; it FAILs without per-branch propagation and SUCCEEDs with it.
2026-06-30 22:17:52 -05:00
..