Skip to content
Merged
39 changes: 39 additions & 0 deletions .changeset/19939-flow-callee-input-value-slots.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
---
'@objectstack/spec': major
'@objectstack/service-automation': major
---

The maps a flow node hands to a CALLEE are value slots now: a `subflow` node's `input`, a `map` node's `input` (evaluated once per item) and a `script` node's `inputs`. Each value is a CEL value envelope, `{ dialect: 'cel', source: '…' }`, evaluated in the calling flow's scope and handed over as the value it computes, or a literal written as it is. A `{…}` template token there is refused at `objectstack validate`, at `registerFlow` and by the executor, naming its CEL spelling, as in every other value slot.

Clause-②: no (narrowing)

<!-- adr-0087: not-required (already-registered flow-value-slot-template-dialect-refused) The value-slot retirement's step-18 D3 entry, registered on this line before this change, is amended in this diff: its surface widens to the three callee maps, and its replacement and reason gain what a guarded form's null does to a child flow's defaultValue. No new D3 entry and no D2 conversion: every whole-path spelling answers differently for an absent value. -->

**BREAKING**: an accept-set narrowing on a published authoring surface, shipped as `major` on the v18 line (`.changeset/pre.json` is open on `main` in `next` pre mode, so the release is `18.0.0-next.*`).

**Why.** ADR-0032 Decision 2 makes a computed value whole-field CEL, and Decision 3 deletes the single brace. These three maps are computed values: each one becomes the callee's input. Until now each executor handed its map to the single-brace interpolator, so a `{token}` resolved there, and a CEL envelope written there reached the callee as the object `{ dialect: 'cel', source: '…' }` it spells, with the run reporting success.

**What changes for a value that may be absent.** Where a whole token resolved to nothing, the template handed the callee nothing. A child flow then seeded its input variable from the variable's `defaultValue`. Under CEL an absent variable or key fails the run, and the guarded form `has(vars.x) ? vars.x : null` hands `null`. A `null` the caller supplies is a value: it wins over the child's `defaultValue`. To keep the default for an absent value, write it in the guard, `has(vars.x) ? vars.x : 'standard'`. Leave the key out where the value is never meant to be supplied. A `script` function is handed `null` where the template handed `undefined`. The refusal at those positions says this.

## FROM → TO

| you wrote | write instead | what changes |
|:--|:--|:--|
| `input: { ownerId: '{record.owner}' }` on a `subflow` | `input: { ownerId: { dialect: 'cel', source: 'record.owner' } }` | an absent `owner` fails the run; guarded, it hands `null`, which wins over the child's `defaultValue` |
| `input: { ownerId: '{x}' }` where the child's default should apply when `x` is absent | `input: { ownerId: { dialect: 'cel', source: "has(vars.x) ? vars.x : 'standard'" } }` | the default is written in the guard, because a supplied `null` is not absent |
| `input: { row: '{item}' }` on a `map` | `input: { row: { dialect: 'cel', source: 'item' } }` | evaluated once per item, with the item variable bound; a list or a record is handed over with its type |
| `inputs: { lines: '{lines}' }` on a `script` | `inputs: { lines: { dialect: 'cel', source: 'lines' } }` | the function receives the list; guarded, an absent value is `null` where it was `undefined` |
| `input: { message: 'Task "{record.title}" is done.' }` | `input: { message: { dialect: 'cel', source: "'Task \"' + record.title + '\" is done.'" } }` | one CEL concatenation; wrap a hole that may be null in `coalesce(…, '')` |

**The one-line fix: write each value of a `subflow` / `map` `input` and a `script`'s `inputs` as a CEL value envelope, and write a child's default into the guard where it should apply.**

**Who is affected, measured.** In this repository: 5 values in 3 nodes of the showcase example (`showcase_task_completed`'s `script`, and the `subflow` nodes of `showcase_task_done_notify_owner` and `showcase_project_closure`), 3 values in the todo example's `task_completion` `script`, 2 docs pages, the service-automation README, 2 dogfood fixtures and the test fixtures; all are migrated in this change. hotcrm's sites at these positions were not measured.

**Still accepted, unchanged.** A CEL value envelope and every literal. The single-brace dialect keeps resolving where it still lives: a `map` or `loop` `collection`, a `filter` value, a `notify` `recipients` entry, an `http` body, a screen's `defaults`. The value-slot retirement's earlier changesets on this line list `subflow.input` among those positions; this one supersedes that line.

### The kit

- **The contract.** `SubflowConfigSchema.input`, `ScriptConfigSchema.inputs` and `MapConfigSchema.input` take `FlowValueSlotSchema` per value (`@objectstack/spec/automation`), so the executor's contract parse refuses a token as a guard. Each published JSON Schema declares the dropped refinement (`dropped-refinements.baseline.json`).
- **The ledger.** `FLOW_NODE_EXPRESSION_PATHS` gains `subflow.input.*`, `map.input.*` and `script.inputs.*` (role `value`), and `LEDGER_DECLARED_NODE_CONFIG_SCHEMAS` carries `MapConfigSchema`. `registerFlow`, `objectstack validate` and `flow-bare-dollar-reference` / `flow-double-brace-interpolation`'s value-slot hints follow the ledger, so all of them cover the three maps.
- **The executor.** One per-key resolver, shared with the CRUD `fields` map, evaluates an envelope through `AutomationEngine.evaluateValueEnvelope` in the parent's scope and run context.
- **ADR-0087.** The step-18 D3 entry `flow-value-slot-template-dialect-refused` is amended. No key is removed, so there is no tombstone, and there is no D2 conversion.
33 changes: 24 additions & 9 deletions content/docs/automation/flows.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -226,10 +226,13 @@ node renders the variable as any other: `message: '{{ digest }}'`, and it render
the **evaluated** value.

The same rules hold for the field values of `create_record` / `update_record`
(below): the `assignments` map and the `fields` map are the flow's **value
slots**, and each takes a CEL value envelope or a literal. Only a slot's
top-level value is an expression — an object nested inside a JSON value or an
array is data, whatever keys it carries.
(below), and for the maps a node hands to a **callee**: a `subflow` node's and a
`map` node's `input` (the child flow's input variables — on a `map`, evaluated
once per item with the item variable bound) and a `script` node's `inputs` (the
registered function's `input`). Those maps — `assignments`, `fields`, `input`,
`inputs` — are the flow's **value slots**, and each value takes a CEL value
envelope or a literal. Only a slot's top-level value is an expression — an
object nested inside a JSON value or an array is data, whatever keys it carries.

<Callout type="info" title="Where a malformed envelope is refused">

Expand Down Expand Up @@ -282,9 +285,19 @@ for some input, so the rewrite is yours to judge.

No spelling is kept: a value slot reads no `{…}` token at all.

**A callee's input: the guarded form supplies `null`.** In a `subflow` or `map`
`input`, a whole token that resolved to nothing handed the child flow nothing,
and the child seeded its input variable from the variable's `defaultValue`. The
guarded form hands `null`, and a `null` the caller supplies is a value: it wins
over the default. So where the child's default should apply to an absent value,
write the default in the guard — `has(vars.x) ? vars.x : 'standard'` — or leave
the key out of `input` where the value is never meant to be supplied. A `script`
function is handed `null` there, where the template handed `undefined`. The
refusal at those positions says so.

**Where an envelope is data, the remedy names none there.** An envelope
evaluates only as the top-level value of the `fields` map or the `assignments`
map. Inside an object or list value, and in the two legacy `assignment` shapes
evaluates only as the top-level value of a value slot's map — `fields`,
`assignments`, or a callee's `input` / `inputs`. Inside an object or list value, and in the two legacy `assignment` shapes
(an `assignments: [{ variable, value }]` array, variables as the config's own
keys), it is stored as the object it spells — so the refusal there names what
does evaluate:
Expand Down Expand Up @@ -399,8 +412,9 @@ The built-in `script` executor never evaluates an arbitrary JavaScript string
it **calls a registered function**, and that is the whole of what it does.

**`config.function`** names a function registered through
`defineStack({ functions })`, and it is **required**. `config.inputs` is
`{var}`-interpolated and handed to it; `config.outputVariable` binds the
`defineStack({ functions })`, and it is **required**. `config.inputs` is a value
slot — each value a CEL value envelope evaluated against the flow's variables,
or a literal — handed to it as its `input`; `config.outputVariable` binds the
returned value as a flow variable, so a later declarative node persists it. A
node that names no function refuses before it runs; one naming a function
nothing registered fails the step loudly rather than passing silently.
Expand Down Expand Up @@ -439,7 +453,7 @@ compile error carrying the same prescription.
label: 'Score Lead',
config: {
function: 'scoreLead', // registered via defineStack({ functions })
inputs: { rating: '{record.rating}' }, // {var} templates resolve against flow variables
inputs: { rating: { dialect: 'cel', source: 'record.rating' } }, // CEL value envelope, type kept
outputVariable: 'leadScore', // later: fields: { score: { dialect: 'cel', source: 'leadScore' } }
},
}
Expand Down Expand Up @@ -1210,6 +1224,7 @@ the map waits for that item's decision, then moves to the next.
iteratorVariable: 'task',
flowName: 'one_task_signoff', // the per-item subflow (it may pause)
itemObject: 'showcase_task', // when an item is a record, it becomes the child's `$record`
input: { taskId: { dialect: 'cel', source: 'task.id' } }, // evaluated per item, `task` bound
outputVariable: 'signoffResults',// each item's subflow output, collected in order
},
}
Expand Down
2 changes: 1 addition & 1 deletion content/docs/kernel/runtime-services/examples.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ export const RollUpOrderTotals = defineFlow({
label: 'Sum the lines',
config: {
function: 'sales.orderTotals',
inputs: { lines: '{lines}' },
inputs: { lines: { dialect: 'cel', source: 'lines' } }, // the list itself, type kept
outputVariable: 'totals',
},
},
Expand Down
2 changes: 1 addition & 1 deletion content/docs/references/automation/builtin-node-config.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ A value: a CEL value envelope `{ dialect: 'cel', source }` evaluated by the expr
| **iteratorVariable** | `string` | optional (default: `"item"`) | Variable holding the current item |
| **indexVariable** | `string` | optional | Optional variable holding the current index |
| **itemObject** | `string` | optional | When items are records, the object they belong to (exposes each item as the child's record) |
| **input** | `Record<string, any>` | optional | Params passed to each item's subflow (interpolated per item) |
| **input** | `Record<string, any>` | optional | Params passed to each item's subflow, keyed by its input variables: each value a CEL value envelope `{ dialect: 'cel', source }` evaluated per item (the item variable is in scope), or a literal written as it is — a `{…}` template token is refused |
| **outputVariable** | `string` | optional | Each item's subflow output, collected in order — bound to a name without a leading `$` (the `$` names are the flow engine's own), read as `{{ name }}` |


Expand Down
4 changes: 2 additions & 2 deletions content/docs/references/automation/schemaless-node-config.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ const result = DecisionConditionSchema.parse(data);
| Property | Type | Required | Description |
| :--- | :--- | :--- | :--- |
| **function** | `string` | ✅ | Registered function to call (defineStack(`{ functions }`)). Contractually pure — it returns a value a later declarative node persists |
| **inputs** | `Record<string, any>` | optional | Inputs passed to the function (values interpolate `{token}` templates) |
| **inputs** | `Record<string, any>` | optional | Inputs passed to the function: each value a CEL value envelope `{ dialect: 'cel', source }` evaluated against the live flow variables, or a literal written as it is — a `{…}` template token is refused |
| **outputVariable** | `string` | optional | Flow variable the function's return value is bound to — a name without a leading `$` (the `$` names are the flow engine's own), read as `{{ name }}` |
| **actionType** | `never` | optional | [REMOVED] `script.config.actionType` was removed in @objectstack/spec 17 — none of its values did what it said. The two built-ins were logger-backed stubs that recorded the intent and delivered nothing under any configuration, and every other value was a second spelling of `config.function`. Replace it per branch: for `email` use a `notify` node (it delivers through the messaging service — the in-app inbox by default, real email once `@objectstack/plugin-email` is installed); for `slack` use a `connector_action` node with the Slack connector, or an `http` node posting to a webhook; for anything else, move the name into `config.function`. Run `os migrate meta --from 16` to list the mechanical edits for the shorthand case into `config.function`; `--write` applies the ones it can prove, and the stub and marker values are removed. |
| **template** | `never` | optional | [REMOVED] `script.config.template` was removed in @objectstack/spec 17 — it fed only the logger-backed `email`/`slack` stubs, which never rendered or sent a message, so no template id was ever resolved. Delete the key. A `notify` node carries its own `title`/`message`, and stored templates live in the messaging service (`sys_notification_template`), not on the node. Run `os migrate meta --from 16` to list the mechanical edits for existing sources; `--write` applies the ones it can prove, and you apply the rest by hand. |
Expand All @@ -181,7 +181,7 @@ const result = DecisionConditionSchema.parse(data);
| Property | Type | Required | Description |
| :--- | :--- | :--- | :--- |
| **flowName** | `string` | ✅ | Flow invoked as this step (it may pause — approval / screen / wait) |
| **input** | `Record<string, any>` | optional | Values passed to the subflow's input variables (interpolate `{token}` templates) |
| **input** | `Record<string, any>` | optional | Values passed to the subflow's input variables: each value a CEL value envelope `{ dialect: 'cel', source }` evaluated in the parent's scope, or a literal written as it is — a `{…}` template token is refused. A value handed over, null included, wins over the child variable's defaultValue |
| **outputVariable** | `string` | optional | Parent flow variable the subflow's output is bound to — a name without a leading `$` (the `$` names are the flow engine's own), read as `{{ name }}` |


Expand Down
22 changes: 17 additions & 5 deletions examples/app-showcase/src/automation/flows/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,14 @@ export const TaskCompletedFlow = defineFlow({
// A flow function is PURE: it takes `inputs`, RETURNS a value, and a
// later declarative node uses or persists it (#4396).
function: 'summarizeCompletedTask',
inputs: { title: '{record.title}', priority: '{record.priority}' },
// Each input is a CEL value envelope (the `{…}` template dialect is
// retired from value slots). `priority` is optional and a task that
// never set it has no such key, which CEL refuses, so it is guarded;
// the function reads the `null` as "normal".
inputs: {
title: { dialect: 'cel', source: 'record.title' },
priority: { dialect: 'cel', source: 'has(record.priority) ? record.priority : null' },
},
outputVariable: 'summary',
},
},
Expand Down Expand Up @@ -718,7 +725,7 @@ export const TaskDoneNotifyOwnerFlow = defineFlow({
triggerType: 'record-after-update',
condition: 'status == "done" && previous.status != "done"',
// The SAME resume-time trap this flow's sibling hit (#7381): the node
// below hops `{record.project.owner}`, and a flow record carries
// below hops `record.project.owner`, and a flow record carries
// `project` as a scalar FK. Un-hydrated it resolved to nothing, the
// subflow's `notify` refused for want of a recipient, and every
// completion of a task ran this flow to a failure. Unlike the invoice
Expand All @@ -733,9 +740,13 @@ export const TaskDoneNotifyOwnerFlow = defineFlow({
label: 'Notify Owner',
config: {
flowName: 'showcase_notify_owner',
// CEL value envelopes, evaluated in this flow's scope and handed to the
// subflow's input variables. A project with no owner hands `null`, as
// the template's empty value did, and the subflow's notify then has
// no recipient — guarded, because CEL refuses the absent key.
input: {
ownerId: '{record.project.owner}',
message: 'Task "{record.title}" is done.',
ownerId: { dialect: 'cel', source: 'has(record.project.owner) ? record.project.owner : null' },
message: { dialect: 'cel', source: `'Task "' + record.title + '" is done.'` },
},
outputVariable: 'notifyResult',
},
Expand Down Expand Up @@ -843,7 +854,8 @@ export const ProjectClosureFlow = defineFlow({
config: {
flowName: 'showcase_closure_signoff',
input: {
reason: 'Project "{record.name}" was marked completed — please sign off the closure.',
// A CEL concatenation — `name` is required on a project.
reason: { dialect: 'cel', source: `'Project "' + record.name + '" was marked completed — please sign off the closure.'` },
},
outputVariable: 'signoffResult',
},
Expand Down
18 changes: 15 additions & 3 deletions examples/app-todo/src/flows/task.flow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -366,10 +366,22 @@ export const TaskCompletionFlow: Flow = {
// Registered in `defineStack({ functions })` — see objectstack.config.ts
// and src/functions/task.functions.ts.
function: 'computeNextTaskDueDate',
// CEL value envelopes, evaluated against the flow's variables — the
// `{…}` template dialect is retired from the function's `inputs` too.
// Each field may be absent from the completed task's row, and CEL
// refuses an absent key where the template handed nothing, so each is
// guarded: the function reads `null` exactly as it read the empty
// value (no due date → `null`, no interval → the field's default 1).
inputs: {
dueDate: '{completedTask.due_date}',
recurrenceType: '{completedTask.recurrence_type}',
interval: '{completedTask.recurrence_interval}',
dueDate: { dialect: 'cel', source: 'has(completedTask.due_date) ? completedTask.due_date : null' },
recurrenceType: {
dialect: 'cel',
source: 'has(completedTask.recurrence_type) ? completedTask.recurrence_type : null',
},
interval: {
dialect: 'cel',
source: 'has(completedTask.recurrence_interval) ? completedTask.recurrence_interval : null',
},
},
outputVariable: 'nextDueDate',
},
Expand Down
Loading
Loading