Skip to content

Commit 5d8d69d

Browse files
fix(service-automation)!: automation variable keys cannot use reserved object segments, and one run's writes never change a flow's defaults (#38001)
Clause-②: no (narrowing) Metadata-protocol: narrowed Skills-docs: none — no published skill teaches a flow variable name, assignment target, screen field name or resume-signal key rule (checked: `git grep` over `skills/**` for `__proto__`, `constructor`, `prototype`, and the automation skill's variable, `outputVariable`, assignment, screen-field and resume text; the only hits are `skills/objectui` expression-sandbox lists, unrelated) ## 维护者速读 - 用户能看到什么变化:流程作者把变量名(或名字里以点分隔的任一段)写成三个保留词之一时,注册和保存会被拒并指出每一处;恢复暂停中的流程时,提交的数据里带这类键会被拒,流程保持暂停;普通流程无感。 - 为什么做:自动化流程的变量命名与运行之间的隔离加固,安全席位按维护者授权接手的高危项。 - 出错会怎样:已有流程若恰好用了这些名字会注册失败,改名后重新保存即可;整个改动可以直接撤回。 - 要你做什么:审阅后由授权审批人批准,再由席位落地。 ## What changes Three rules, stated once each in the automation service: 1. **A flow variable key may not use `__proto__`, `constructor` or `prototype` as its name or as any dot-separated part of it — at registration.** Registration, and the stored pass that previews it, judges every key a flow names, in every graph it holds: each node's `id` (it heads every key the node's output is stored under), each declared variable's `name`, each `assignment` node's targets in every shape, each node's `outputVariable` / `iteratorVariable` / `indexVariable` / `errorVariable` / `idVariable`, and each `screen` field's `name`, each judged with surrounding whitespace trimmed. The judged positions are held equal to the spec's binding positions by a pin. The refusal names every such key and where it sits. A name that only contains one of the words (`constructor_name`) is unaffected. 2. **A caller's resume signal may not carry such a key.** Each key of `output` and of `inputs` is judged first, before anything reads the submitted values, a signal handed on to a paused subflow child included; the answer is `INVALID_SIGNAL` (400), nothing is applied, and the run stays paused for a valid submission. The engine's own continuations (a `map` item handing back, a subflow child finishing) are not judged, so a run paused before this release still completes. 3. **One run's writes never change a flow's defaults, another run's values, or the record the run was handed.** Each run binds its own copy of an object or list default and of the trigger record (`record` and `$record`), seeded once the run's context has resolved so the copy carries the lookups the start node declares. A dotted write whose head names a value the run holds is read back by the run's expressions (conditions and CEL values) and leaves the value as it was, so a text hole and `$record` read the value. With no durable store, a resumed run works on its own copy of its variables, as a stored run does. A run value that contains itself is refused by the copy by name; a paused run holding one still resumes. Commits: the door half (rules 1 and 2), then rule 3, then the docs page and changeset, then one more pin for the chokepoint, then a dogfood pin updated, then the published prose and the ledger entry, then the review round: node ids, `idVariable` and trimmed names at registration, the engine's own continuations exempt at resume, the run's own record copy (seeded after the context resolves), and the named refusal for a value that contains itself; then a patch round: the run's record copy taken as its context resolves, so declared lookups land on the copy; `previous` copied too; a value that contains itself answered as a failed run; the third changeset bullet trimmed to its readers; and a second ledger entry; then a should-fix round (26d6b3a): a declared lookup is grafted into a new top-level record, so the caller's record, a class instance included, is never written; new pins cover retry-attempt and dry-run seeding and a class-instance record. Bound, stated: with no graft, a record that is not a plain object is used as handed; the engine writes nothing into it, though a node's in-place change of `record` then reaches that object, and CEL cannot read a record that is not a plain object unless a graft landed (service-automation 299 files / 4436 tests, trigger-record-change 123). - **A pin in `packages/triggers/trigger-record-change/src/before-update-flow-payload-reach.test.ts` stated that a run's `record` variable is the record on its context; it now states the rule: the run's own copy.** - **Dogfood pin updated in this PR:** `packages/qa/dogfood/test/flow-condition-scope-keys.dogfood.test.ts` (a screen resume's `inputs` and `output` bags) stated the earlier accept set and goes red under this change; it now states the ruled one — refused with `INVALID_SIGNAL`, the run stays paused, and the valid submission then lands. - **Published prose brought in line with the rule (prose only, no schema shape change):** the assignment config's comments in `packages/spec/src/automation/builtin-node-config.zod.ts`, the `INVALID_SIGNAL` description in `packages/spec/src/contracts/automation-service.ts`, and the resume route's status note in `packages/runtime/src/domains/automation.ts`. - **ADR-0087 ledger:** two semantic entries, `flow-variable-key-reserved-segment-refused` and `flow-dotted-write-read-by-run-expressions-only` (`packages/spec/src/migrations/entries/semantic/`), so `os migrate meta` and the upgrade guide carry both rules; the changeset is marked `registered` with both. The changeset is `minor` on `@objectstack/service-automation` (the kind `narrowed`), `patch` on `@objectstack/spec` and `@objectstack/runtime`. ## Tests - `src/variable-key-reserved-segments.test.ts` — rules 1 and 2: each sample is refused at registration and listed by the stored pass; each resume sample is refused on a screen (the screen's conditions are never evaluated, the paused variables are byte-identical, and the valid submission then lands) and on a pause with no input contract; the chokepoint refuses them as a whole. Controls: ordinary dotted keys and names containing the words register, run and resume. - `src/run-values-isolation.test.ts` — rule 3: object and list defaults (dotted writes, list index and length, a node that changes the value in place), the trigger record against `$record`, and a paused run with and without a store. - Red before the fix: 38 failed / 5 passed (the controls) on the unfixed tree, every failure an assertion on the rule. - Review round: the same two files grow to 88 tests — one case per judged position, held equal to the spec's binding positions; every assignment shape (map, the legacy array's three name keys, the bare config); a key in a nested graph; trimmed names; a `map` node id; a signal delegated to a subflow child; engine-built signals and an engine-built continuation that completes; a node changing the trigger record in place before any pause; a value that contains itself. All 88 pass. - After: both files 50/50 (first round); the whole package suite 299 files / 4392 tests passed at `5cd060c9d6d` (existing flow suites with ordinary dotted keys unchanged). The commits after it change no service-automation source. <details><summary>Reverse verification — each new pin, one change reverted at a time (counts only)</summary> Each leg through `scripts/ablation-replace.mjs` (anchor x1 -> x0, restored to HEAD, `git diff HEAD` empty after every leg), on the two new files (50 tests): | Reverted | Red | Which pins | | :--- | :--- | :--- | | the registration check | 18 | every authoring case, registration and stored pass | | the resume door's first check | 6 | every screen case; the no-contract pause stays refused by the chokepoint | | the chokepoint's check | 6 | every chokepoint case; resume stays refused by the first check | | the scope's copy on descent | 1 | the record case | | the per-run copy of a default | 2 | the in-place cases | | both copies together | 7 | every default case and the record case | | the held run's copy | 1 | the paused run with no store | Review round, on the same two files (88 tests), at `2da449d7736`: | Reverted | Red | Which pins | | :--- | :--- | :--- | | judging node ids | 2 | the node-id position, the `map` node id | | judging `idVariable` | 4 | the `idVariable` position, the three trimmed-name cases | | trimming before judging | 5 | the three trimmed-name cases, the `outputVariable` and `idVariable` positions | | `nodeId` in the judged positions | 2 | the two enumeration pins | | the legacy-array branch | 3 | the three legacy-array cases | | the engine-built exemption | 7 | the six engine-built cases, the continuation that completes | | the resume door's first check | 9 | the six screen cases, the three delegated `inputs` cases | | the run's record copy | 1 | the record changed in place before any pause | | the cycle guard | 2 | the named refusal, the paused run holding such a value | The record copy taken before the context resolved reds 2 tests in the existing `record-lookup-expand.integration.test.ts` (declared lookups missing from the run's copy); seeding after the context resolves turns them green. </details> ## Acceptance notes - A flow whose text hole or `$record` read relied on reading a dotted write now reads the held value; the changeset gives the rewrite (assign the computed value to a variable of its own). - A security item is with the owner seat. ## Verification First read (by risk): 1. `packages/services/service-automation/src/run-resume.ts` — the resume-door block just before the screen contract. 2. `packages/services/service-automation/src/flow-registration-checks.ts` — `validateVariableKeySegments`. 3. `packages/services/service-automation/src/dag-traversal.ts` — the descent in `celScope`, the default and record seeding, and seeding after the context resolves. Two-minute check: `pnpm --filter @objectstack/service-automation exec vitest run src/variable-key-reserved-segments.test.ts src/run-values-isolation.test.ts` — expect `Tests 94 passed (94)` (at 26d6b3a). <details><summary>Local gates at b1d5a7f (later rounds: service-automation 299 files / 4436 tests and trigger-record-change 123 at 26d6b3a)</summary> - `@objectstack/service-automation` typecheck (tsc and the test-layer typecheck): exit 0; the whole package suite: 299 files / 4430 tests passed (at `82e81476d6c`; the later commits change no source of that package). `@objectstack/trigger-record-change` tests: 12 files / 123 tests passed. `@objectstack/spec` `check:generated` exit 0 and `src/migrations` 203/203; `@objectstack/runtime` typecheck exit 0. - The derivation at `b1d5a7f4597` is the same 142 families as at `469a6acd57c`; `check:nul-bytes`, `check:test-source-alias`, `check:tier-file-adoption` and `check:cross-package-test-inputs` re-run there: exit 0. - `check:adr-0087-registration`: exit 0, `registered flow-variable-key-reserved-segment-refused, flow-dotted-write-read-by-run-expressions-only` (at d2273ab). `check:cross-package-test-inputs`: exit 0, after declaring the spec module the enumeration pin reads (the package's declared globs and its turbo `test` inputs). - The derived gate list (`dispatch-gates --commands`, 142 families): 139 exit 0; 3 NOT MEASURED, prerequisite not met on this box (exit 3): `check:skill-examples` (no client SDK build), `check:dual-build-cjs-loads` (no full build), `check:type-check-debt` (no full build). CI runs all three. `--ran` reconciliation: 142 derived, 142 run, 0 unrun. </details> <details><summary>Dogfood battery at b1d5a7f (re-run at d2273ab: 490 files passed)</summary> - Closure built at that head, then `pnpm --filter @objectstack/dogfood test` under the verify lock, no shard: exit 0 · Test Files 490 passed / 3 skipped (493) · Tests 4144 passed / 68 skipped (4212). - An earlier run at `469a6acd57c` failed to load packages (`Cannot find package '@objectstack/platform-objects/…'`) because that package's built output was rewritten while the run was going; the re-run after rebuilding the closure was green at that head too. </details> --- _Generated by [Claude Code](https://claude.ai/code/session_01ASNY8XNef4ywkQio6S9ju4)_ <!-- signed: security#2 · sunhaolin · session_017xRBcW9L8Noz9BxEwjwiov --> --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent 3ad3b41 commit 5d8d69d

19 files changed

Lines changed: 1364 additions & 60 deletions
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
---
2+
'@objectstack/service-automation': minor
3+
'@objectstack/spec': patch
4+
'@objectstack/runtime': patch
5+
---
6+
7+
fix(service-automation)!: automation variable keys cannot use reserved object segments, and one run's writes never change a flow's defaults
8+
9+
Clause-②: no (narrowing)
10+
Metadata-protocol: narrowed
11+
12+
<!-- adr-0087: registered flow-variable-key-reserved-segment-refused, flow-dotted-write-read-by-run-expressions-only -->
13+
14+
- **BREAKING: a flow variable key may not use `__proto__`, `constructor` or `prototype` as its name or as any dot-separated part of it.** Registration (and `os migrate meta --stored`, which previews it) judges every key a flow names, in every graph it holds: each node's `id` (it heads every key the node's output is stored under), each declared variable's `name`, each `assignment` node's targets in every shape, each node's `outputVariable`, `iteratorVariable`, `indexVariable`, `errorVariable` and `idVariable`, and each `screen` field's `name`. A name is judged with surrounding whitespace trimmed.
15+
- FROM: a flow naming such a key registered.
16+
- TO: the flow is refused at registration, and the refusal names every such key and where it sits. A name that only contains one of the three words (`constructor_name`, `prototype_count`) is unaffected.
17+
- The fix: rename the key, for example `constructor` to `constructor_name`, and save the flow again.
18+
- **BREAKING: a resume signal may not carry such a key.** Each key of a caller's `output` and `inputs` is judged, a signal handed on to a paused subflow child included; the engine's own continuations (a `map` item handing back, a subflow child finishing) are not, so a run paused before this release still completes.
19+
- FROM: such a key in `output` was accepted; in `inputs` on a screen with declared fields it answered 400 under `INVALID_SCREEN_INPUT`.
20+
- TO: the resume answers `INVALID_SIGNAL` before anything reads the submitted values; nothing is applied, and the run stays paused for a valid submission.
21+
- The fix: send the screen's declared field names, and `output` keys without those segments.
22+
- **BREAKING: one run's writes never change a flow's defaults, another run's values, or the record the run was handed.** Each run binds its own copy of a declared variable's object or list default, and of the trigger record (`record` and `$record`). A dotted write whose head names a value the run holds (`cfg.mode` over a declared `cfg`, `record.x` over the trigger record) is read back by the run's expressions (conditions and CEL values); the value itself keeps what it was, and a text hole (`{{ cfg.mode }}`) and `$record` read the value. With no durable suspended-run store, a resumed run works on its own copy of its variables, as a stored run does.
23+
- FROM: a text hole and `$record` read a dotted write.
24+
- TO: only the run's expressions read the write; a text hole and `$record` read the value.
25+
- The fix: to show or keep a value a run computed, assign it to a variable of its own (`assignments: { mode_now: { dialect: 'cel', source: 'cfg.mode' } }`) and read that variable in the text hole or the later step.

‎content/docs/automation/flows.mdx‎

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1476,6 +1476,15 @@ key. A reserved name answers **400**, nothing is applied (not even legitimate
14761476
keys sent alongside it), and the run stays parked. Ordinary author variables are
14771477
unaffected, `$` mid-name (`price$`) included.
14781478

1479+
A third: **no signal key, nor any dot-separated part of one, may be `__proto__`,
1480+
`constructor` or `prototype`** — the rule a flow's own variable keys follow (see
1481+
[Variables](#variables)). It covers both signal fields of a caller's signal,
1482+
one handed on to a paused subflow child included, and is judged before anything
1483+
else reads the submitted values: such a key answers **400** `INVALID_SIGNAL`,
1484+
nothing is applied, and the run stays parked. The engine's own continuations (a
1485+
`map` item handing back, a subflow child finishing) are not judged, so a run
1486+
paused before this rule still completes.
1487+
14791488
### A `screen` resume is checked against the declared fields
14801489

14811490
A screen node's `config.fields` is a **contract**, not just a rendering hint:
@@ -2242,6 +2251,23 @@ variables: [
22422251
| `defaultValue` | `unknown` | Bound at run start when no parameter supplies one — this is what makes the declaration a guarantee. Optional |
22432252
| `objectName` | `string` | **Planned.** On an input only (refused at parse on any other variable): the input is the id of a record of this object. No start door reads it yet. See [a start input that is a record id](#a-start-input-that-is-a-record-id). Optional |
22442253

2254+
A variable key — a node's `id` (it heads every key the node's output is stored
2255+
under), a declared `name`, an `assignment` target, a node's `outputVariable` /
2256+
`iteratorVariable` / `indexVariable` / `errorVariable` / `idVariable`, a
2257+
`screen` field's `name` — may not be `__proto__`, `constructor` or `prototype`,
2258+
nor have one as any dot-separated part (`cfg.prototype`), judged with
2259+
surrounding whitespace trimmed. Registration refuses such a flow and names each
2260+
key; a name that only contains one of the words (`constructor_name`) is fine.
2261+
2262+
Each run starts from its own copy of a declared object or list `defaultValue`
2263+
and of the trigger record (`record` and `$record`). A dotted write under a value
2264+
the run holds (`cfg.mode`, `record.x`) is read back by the run's expressions —
2265+
conditions and CEL values — and leaves the value itself as it was, so a text
2266+
hole (`{{ cfg.mode }}`) and `$record` read the value, not the write. To show or
2267+
keep a computed value, assign it to a variable of its own and read that. One run
2268+
never changes the flow's default, the next run's values, or the object the
2269+
trigger handed over.
2270+
22452271
### `defaultValue` — declaring a variable is not the same as binding it
22462272

22472273
Without `defaultValue`, a declaration is documentation. The engine binds an

‎packages/qa/dogfood/test/flow-condition-scope-keys.dogfood.test.ts‎

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@
88
// The doors, each with its own probe name:
99
// • the record that starts a record-triggered flow (`POST` / `PATCH /data`);
1010
// • a flow trigger's `params` bag (`POST /automation/:name/trigger`);
11-
// • a screen resume's `inputs` and `output` (`POST …/runs/:runId/resume`).
11+
// • a screen resume's `inputs` and `output` (`POST …/runs/:runId/resume`),
12+
// where a key with a reserved segment is refused (`INVALID_SIGNAL`) and the
13+
// run stays paused for a valid submission.
1214
//
1315
// Control: an ordinary dotted key (`<node>.<key>`, a resumed screen's output)
1416
// still nests, and a condition after the screen still reads it.
@@ -214,16 +216,24 @@ describe('a flow condition scope: no variable key reaches a prototype', () => {
214216
const runId = await pause();
215217
const res = await resume(runId, { inputs: { note: 'fcsk-in', '__proto__.fcsk_resume_inputs': true } });
216218
expect(res.status, await res.clone().text()).toBe(400);
217-
expect(((await res.json()) as any).error?.code).toBe('INVALID_SCREEN_INPUT');
219+
expect(((await res.json()) as any).error?.code).toBe('INVALID_SIGNAL');
218220
expect(inherited('fcsk_resume_inputs')).toBeUndefined();
221+
// Nothing was applied: the pause is live, and the valid submission lands.
222+
const ok = await resume(runId, { inputs: { note: 'fcsk-in' }, output: { tag: 'go' } });
223+
expect(ok.status, await ok.clone().text()).toBeLessThan(300);
224+
expect(await marks('fcsk-in')).toBe(1);
219225
});
220226

221227
it('its output bag', async () => {
222228
const runId = await pause();
223229
const res = await resume(runId, { inputs: { note: 'fcsk-out' }, output: { tag: 'go', '__proto__.fcsk_resume_output': true } });
224230
expect(inherited('fcsk_resume_output')).toBeUndefined();
225-
// The rest of the bag still nests: the condition after the screen read `ask.tag`.
226-
expect(res.status, await res.clone().text()).toBeLessThan(300);
231+
expect(res.status, await res.clone().text()).toBe(400);
232+
expect(((await res.json()) as any).error?.code).toBe('INVALID_SIGNAL');
233+
expect(await marks('fcsk-out')).toBe(0);
234+
// Nothing was applied: the pause is live, and the valid submission lands.
235+
const ok = await resume(runId, { inputs: { note: 'fcsk-out' }, output: { tag: 'go' } });
236+
expect(ok.status, await ok.clone().text()).toBeLessThan(300);
227237
expect(await marks('fcsk-out')).toBe(1);
228238
});
229239

‎packages/runtime/src/domains/automation.ts‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4798,7 +4798,9 @@ export async function handleAutomationRequest(deps: DomainHandlerDeps, path: str
47984798
// resume ran and the flow failed"):
47994799
// PERMISSION_DENIED → 403, the suspension is service-owned (#3801)
48004800
// INVALID_SIGNAL → 400, the signal wrote the engine's `$` variable
4801-
// namespace (#3853 follow-up)
4801+
// namespace (#3853 follow-up), or named a key
4802+
// whose name or any dot-separated part of it is
4803+
// `__proto__`, `constructor` or `prototype`
48024804
// INVALID_SCREEN_INPUT → 400, the bag violates the suspended screen's
48034805
// declared field contract — a required field the
48044806
// caller was asked for is missing, or an

‎packages/services/service-automation/src/dag-traversal.ts‎

Lines changed: 36 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ import { readPartialSteps } from './partial-steps.js';
6868
import { isRegionSuspensionRefusal, refuseRegionSuspension } from './region-suspension-refusal.js';
6969
import { stampFlowRunSlot } from './flow-slots.js';
7070
import { stampRootRun } from './root-run.js';
71-
import { isSkippedScopeKey, scopeContainer } from './scope-key-segments.js';
71+
import { copyForScopeDescent, copyHeldValue, isSkippedScopeKey, scopeContainer } from './scope-key-segments.js';
7272

7373
/**
7474
* The value the flow CEL scope binds as `current_user` for a run (#19939 —
@@ -1052,17 +1052,28 @@ export function celScope(
10521052
): { extra: Record<string, unknown> } {
10531053
// No variable key reaches a prototype (`./scope-key-segments.ts`):
10541054
// prototype-free containers, and a key with a skipped segment binds
1055-
// nothing. A dotted tail whose head names a value the run holds is still
1056-
// written into that value.
1055+
// nothing. And no key writes into a value the run holds: a dotted tail
1056+
// whose head names one descends into a copy the scope owns
1057+
// (`copyForScopeDescent`), so the scope reads the write and the held
1058+
// value — a flow's default, the trigger's record, a value `$record`
1059+
// shares — keeps what it was.
10571060
const vars = scopeContainer();
1061+
const owned = new WeakSet<object>([vars]);
10581062
for (const [key, value] of variables) {
10591063
// Convert "step.result" keys into nested object paths.
10601064
const segs = key.split('.');
10611065
if (isSkippedScopeKey(segs)) continue;
10621066
let cursor = vars;
10631067
for (let i = 0; i < segs.length - 1; i++) {
1064-
if (typeof cursor[segs[i]] !== 'object' || cursor[segs[i]] === null) {
1065-
cursor[segs[i]] = scopeContainer();
1068+
const next = cursor[segs[i]];
1069+
if (typeof next !== 'object' || next === null) {
1070+
const container = scopeContainer();
1071+
owned.add(container);
1072+
cursor[segs[i]] = container;
1073+
} else if (!owned.has(next)) {
1074+
const copy = copyForScopeDescent(next);
1075+
owned.add(copy);
1076+
cursor[segs[i]] = copy;
10661077
}
10671078
cursor = cursor[segs[i]] as Record<string, unknown>;
10681079
}
@@ -1262,7 +1273,10 @@ export function seedDeclaredVariables(
12621273
if (supplied !== undefined) {
12631274
variables.set(v.name, supplied);
12641275
} else if (v.defaultValue !== undefined) {
1265-
variables.set(v.name, v.defaultValue);
1276+
// The default is the registered flow's; the run gets its own copy
1277+
// (`copyHeldValue`), so nothing one run does to it — a node that
1278+
// changes it in place included — reaches the flow or the next run.
1279+
variables.set(v.name, copyHeldValue(v.defaultValue));
12661280
}
12671281
}
12681282
return variables;
@@ -1278,13 +1292,21 @@ export function seedRunVariables(
12781292
): Map<string, unknown> {
12791293
const variables = this.seedDeclaredVariables(flow, context);
12801294
if (context?.record) {
1281-
variables.set('$record', context.record);
1282-
variables.set('record', context.record);
1283-
for (const [k, v] of Object.entries(context.record)) {
1295+
// The run's own copy of a plain record it was handed (`copyHeldValue`):
1296+
// nothing the run does to `record` / `$record` — a node that changes
1297+
// it in place included — reaches the trigger's object. A record that
1298+
// is not a plain object is not copied: it is itself the object bound
1299+
// as `record` / `$record`. A record that contains itself throws
1300+
// `HeldValueCycleError`.
1301+
const record = copyHeldValue(context.record) as Record<string, unknown>;
1302+
variables.set('$record', record);
1303+
variables.set('record', record);
1304+
for (const [k, v] of Object.entries(record)) {
12841305
if (!variables.has(k)) variables.set(k, v);
12851306
}
12861307
}
1287-
variables.set('previous', context?.previous ?? null);
1308+
// `previous` is the run's own copy too, by the same rule as the record.
1309+
variables.set('previous', copyHeldValue(context?.previous ?? null));
12881310
variables.set('$runId', runId);
12891311
variables.set('$flowName', flowName);
12901312
variables.set('$flowLabel', flow.label ?? flowName);
@@ -1378,7 +1400,6 @@ export async function executeWithoutRetry(
13781400
// to its author — and a pausing node on a retry attempt had no `$runId`
13791401
// to map its external state back to this run with (ADR-0019).
13801402
const runId = this.nextRunId();
1381-
const variables = this.seedRunVariables(flow, flowName, context, runId);
13821403
const startedAt = new Date().toISOString();
13831404
const steps: StepLogEntry[] = [];
13841405

@@ -1387,6 +1408,10 @@ export async function executeWithoutRetry(
13871408
// `flowRunId` is stamped here too (#3456). [#31696] And the slot, as
13881409
// `execute()` stamps it.
13891410
const runContext = await this.resolveRunContext(flow, context, runId);
1411+
// Seeded AFTER the context resolves, from the resolved context: its record
1412+
// is the run's own copy, carrying the lookups the start node declares
1413+
// (`expand`, grafted while the context resolves).
1414+
const variables = this.seedRunVariables(flow, flowName, runContext, runId);
13901415
stampFlowRunSlot(runContext, flowName, runPackage);
13911416
// [ADR-0162 item 7] Each attempt is a run of its own, and its own root
13921417
// when it has no parent, as `execute()` stamps it.

‎packages/services/service-automation/src/dry-run.ts‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -796,9 +796,12 @@ export async function dryRun(this: DryRunHost, definition: unknown, options: Flo
796796
...(options.params !== undefined ? { params: options.params } : {}),
797797
...(options.locale !== undefined ? { locale: options.locale } : {}),
798798
};
799-
const variables: Map<string, unknown> = this.seedRunVariables(flow, flow.name, start, '');
800-
variables.delete('$runId');
801799
const runContext = await this.resolveRunContext({ ...flow, runAs: 'user' }, start);
800+
// Seeded after the context resolves, from the resolved context, as a run
801+
// is: its record is the run's own copy, carrying the lookups its start
802+
// node declares.
803+
const variables: Map<string, unknown> = this.seedRunVariables(flow, flow.name, runContext, '');
804+
variables.delete('$runId');
802805

803806
const startNode = flow.nodes.find((n) => n.type === 'start')!;
804807
const condition = (startNode.config as { condition?: unknown } | undefined)?.condition;

0 commit comments

Comments
 (0)