Skip to content

Commit 3cceede

Browse files
committed
docs(service-automation): state the held-record copy accurately for non-plain records
The comments above the record copy in resolveRunContext and seedRunVariables now say that copyHeldValue copies a plain record, that a record which is not a plain object is not copied (with no lookup graft it is itself the object the run binds as `record`), and that a self-containing record throws HeldValueCycleError. Drops the stale "taken before anything below writes onto it". Comment-only. Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017xRBcW9L8Noz9BxEwjwiov
1 parent 26d6b3a commit 3cceede

2 files changed

Lines changed: 14 additions & 9 deletions

File tree

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1292,9 +1292,12 @@ export function seedRunVariables(
12921292
): Map<string, unknown> {
12931293
const variables = this.seedDeclaredVariables(flow, context);
12941294
if (context?.record) {
1295-
// The run's own copy of the record it was handed (`copyHeldValue`):
1295+
// The run's own copy of a plain record it was handed (`copyHeldValue`):
12961296
// nothing the run does to `record` / `$record` — a node that changes
1297-
// it in place included — reaches the trigger's object.
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`.
12981301
const record = copyHeldValue(context.record) as Record<string, unknown>;
12991302
variables.set('$record', record);
13001303
variables.set('record', record);

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

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -139,13 +139,15 @@ export async function resolveRunContext(this: Pick<RunResumeHost, 'seedRunGrants
139139
flowName: flow.name,
140140
...(runId ? { flowRunId: runId } : {}),
141141
};
142-
// The run's own copy of the record it was handed (`copyHeldValue`), taken
143-
// before anything below writes onto it: the lookups the start node
144-
// declares (`expandDeclaredLookups`, at the end) are grafted into a new
145-
// top-level record that replaces it, and the run's variables are seeded
146-
// from that, so nothing the run does reaches the caller's object, a record
147-
// that is not a plain object included. A record that contains itself throws
148-
// `HeldValueCycleError` here, which `execute()` answers as a failed run.
142+
// The run's own copy of a plain record it was handed (`copyHeldValue`).
143+
// When the start node declares lookups (`expandDeclaredLookups`, at the
144+
// end), they are grafted into a new top-level record that replaces this
145+
// one, and the run's variables are seeded from that, so no engine write
146+
// reaches the caller's object, a record that is not a plain object
147+
// included. With no graft, a record that is not a plain object is not
148+
// copied: it is itself the object the run binds as `record`. A record that
149+
// contains itself throws `HeldValueCycleError` here, which `execute()`
150+
// answers as a failed run.
149151
if (context?.record) runContext.record = copyHeldValue(context.record) as Record<string, unknown>;
150152

151153
// #3356 (follow-up to #1888) — a `runAs:'user'` run must enforce its data

0 commit comments

Comments
 (0)