From d0e7e764496148e9081961575b491f99d9c2d474 Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 14 Sep 2026 04:23:50 +0000 Subject: [PATCH 1/6] wip(automation): require the wait/boundary config block at the contract MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Contract (packages/spec): - FlowNodeSchema refuses a `wait` node with no `waitEventConfig` and a `boundary_event` node with no `boundaryConfig`, with the key named and the remedy in the rejection. - `waitEventConfig.eventType: 'timer'` requires a non-blank `timerDuration`. - ScreenConfigSchema.mode declares `.default('create')` — the value the executor was measured to apply; HttpConfigSchema.method stays default-free because the executor applies GET inline and POST durable. Executor (service-automation): the `?? {}` block fallback and the `?? 'timer'` event-type fallback are retired; a node reaching execute without the block is a logged guard refusal instead of a silent `{ success: true, suspend: true }`. Claude-Session: https://claude.ai/code/session_014DBGjJFyndTj766aReCL2g Co-authored-by: Claude --- .../src/builtin/wait-node.ts | 67 ++++++- .../src/automation/builtin-node-config.zod.ts | 28 ++- packages/spec/src/automation/flow.test.ts | 166 +++++++++++++++++- packages/spec/src/automation/flow.zod.ts | 128 +++++++++++++- .../spec/src/automation/io-node-config.zod.ts | 18 +- 5 files changed, 390 insertions(+), 17 deletions(-) diff --git a/packages/services/service-automation/src/builtin/wait-node.ts b/packages/services/service-automation/src/builtin/wait-node.ts index 50191b7c36e..63e15c22580 100644 --- a/packages/services/service-automation/src/builtin/wait-node.ts +++ b/packages/services/service-automation/src/builtin/wait-node.ts @@ -4,6 +4,7 @@ import type { PluginContext } from '@objectstack/core'; import { defineActionDescriptor } from '@objectstack/spec/automation'; import type { IJobService, JobRunOutcome } from '@objectstack/spec/contracts'; import type { AutomationEngine, SuspendedRunStore } from '../engine.js'; +import { refuseNode } from '../guard-refusal.js'; import { describeThrownForLog, type ThrownCauseMeta } from '../thrown-cause-diagnostics.js'; /** @@ -230,10 +231,57 @@ export function registerWaitNode(engine: AutomationEngine, ctx: PluginContext): // including the `registerFlow` rehydration seam, so there is nothing left // to fall back to here (PD #12: no consumer-side fallbacks). // - // The `?? 'timer'` below is NOT such a fallback: `waitEventConfig` is - // itself optional, and a wait node without one is a valid timer wait. - const wec = (node.waitEventConfig ?? {}) as Record; - const eventType = String(wec.eventType ?? 'timer'); + // ── REVERSAL (#17928) ──────────────────────────────────────────────── + // Until this change the two lines below read `(node.waitEventConfig ?? {})` + // and `String(wec.eventType ?? 'timer')`, under a comment that declared + // the second one intentional: "`waitEventConfig` is itself optional, and + // a wait node without one is a VALID TIMER WAIT". It was not valid. A + // block-less node took that default into the timer branch, where the + // absent `timerDuration` computed no deadline — so no wake-up job was + // armed (measured with a job service ANSWERING), no `waitUntil` was + // persisted for a later boot's re-arm pass, not one log line was emitted + // at any level, and the node returned `{ success: true, suspend: true }`. + // A run parked forever, reporting success, from the state a freshly + // created node is in (PR #17937's `absent-config-node-characterization.test.ts` + // is that measurement; this file's own reversal is pinned there now). + // + // The contract now refuses the shape at parse (`FlowNodeSchema` requires + // the block on a `wait` node, and `timerDuration` under + // `eventType: 'timer'`), so this guard is the second door, for a document + // that reaches `execute` without passing the first: a stored + // pre-migration row rehydrated by a path that skipped the parse, or an + // executor invoked directly. Per the maintainer's ruling on defaults + // (decision batch #127 item 5) a required key has no "unset behaves as", + // so there is nothing left for this seam to assume — and PD #12 forbids + // re-inventing the tolerance in the consumer once the producer refuses + // it. Refuse LOUDLY instead: a `guard` failure, because the metadata is + // wrong and re-running changes nothing, so a `fault` edge must not be + // able to route this into a handler that reports success. + const wec = node.waitEventConfig as Record | undefined; + const declaredEventType = typeof wec?.eventType === 'string' ? wec.eventType.trim() : ''; + if (!wec || declaredEventType === '') { + // Logged as well as returned, because the defect this closes was + // SILENCE: the run's own `status=failed` summary line names no node and + // no cause, and the step log is not where an operator looks first. At + // `warn`, not `error`, by AGENTS.md's degradation rule — the failure is + // handed to the caller (the run fails and says so), so nothing looks + // normal from the outside and this is not a durability degradation. + ctx.logger.warn( + `[wait] node '${node.id}': no \`waitEventConfig\` block${wec ? ' `eventType`' : ''} — refusing to run. ` + + `A wait node must say what resumes it; this one would have parked the run forever while reporting ` + + `success, which is why the contract now refuses the shape at parse. This document predates that ` + + `refusal: edit the node to declare its resume condition (\`waitEventConfig: { eventType: 'timer', ` + + `timerDuration: 'PT1H' }\`, or an \`eventType\` of 'signal' / 'webhook' / 'manual' / 'condition' with ` + + `a \`signalName\`), then re-publish the flow. \`os migrate meta --from 17\` lists the nodes to edit.`, + ); + return refuseNode( + `wait '${node.id}': no waitEventConfig${wec ? '.eventType' : ''} — a wait node must declare what resumes it ` + + `(eventType: 'timer' with a timerDuration, or 'signal'/'webhook'/'manual'/'condition' with a signalName). ` + + `This is metadata, so re-running changes nothing: edit the node and re-publish the flow. A node in this ` + + `state used to suspend the run forever and report success.`, + ); + } + const eventType = declaredEventType; const runId = variables.get('$runId'); if (eventType === 'timer') { @@ -248,7 +296,12 @@ export function registerWaitNode(engine: AutomationEngine, ctx: PluginContext): // suspended run, so a cold-booted kernel can re-arm the timer from the // durable store ({@link rearmSuspendedWaitTimers}). const at = durationMs && durationMs > 0 ? new Date(Date.now() + durationMs).toISOString() : undefined; - const output = at ? { waitUntil: at } : undefined; + // Spread, never `output: undefined`. The two are the same value and + // different objects: `toStrictEqual` and `Object.keys` tell them apart, + // a JSON dump does not, and a present key holding `undefined` reads to + // the next author as "the node answered a deadline" when it computed + // none. Absent says the one true thing. + const output = at ? { output: { waitUntil: at } } : {}; const job = getJobService(); if (job && runId != null && at) { @@ -259,7 +312,7 @@ export function registerWaitNode(engine: AutomationEngine, ctx: PluginContext): { type: 'once', at }, makeWaitTimerJobHandler(engine, job, String(runId), jobName, ctx.logger), ); - return { success: true, suspend: true, correlation: jobName, output }; + return { success: true, suspend: true, correlation: jobName, ...output }; } catch (err) { // #5737 — `warn(message, meta?)`: the `Logger` contract has no // `Error` slot below `error`, so the job service's own failure goes @@ -281,7 +334,7 @@ export function registerWaitNode(engine: AutomationEngine, ctx: PluginContext): } // Degrade: still suspend; resumption comes from an external resume() // (or a later boot's re-arm pass, when the deadline was persisted). - return { success: true, suspend: true, correlation: `timer:${node.id}`, output }; + return { success: true, suspend: true, correlation: `timer:${node.id}`, ...output }; } // signal / webhook / manual / condition — suspend; an external producer diff --git a/packages/spec/src/automation/builtin-node-config.zod.ts b/packages/spec/src/automation/builtin-node-config.zod.ts index e6428c97214..ccfd5827055 100644 --- a/packages/spec/src/automation/builtin-node-config.zod.ts +++ b/packages/spec/src/automation/builtin-node-config.zod.ts @@ -570,8 +570,32 @@ export const ScreenConfigSchema = lazySchema(() => strictObject({ /** Object form only: variable bound to the saved record's id. */ idVariable: z.string().optional() .describe("Object form only: variable bound to the saved record's id"), - /** Object form only: create (default) or edit. Any value other than 'edit' behaves as create. */ - mode: z.enum(['create', 'edit']).optional().describe('Object form only: create or edit'), + /** + * Object form only: create or edit. + * + * `.default('create')` is DECLARED because the executor APPLIES it, measured + * rather than inferred: `screen-nodes.ts` builds the ScreenSpec with + * `mode: cfg.mode === 'edit' ? 'edit' : 'create'`, so an object-form screen + * with the key absent renders the create form — confirmed by running the + * executor with `config: { objectName }` and reading `result.screen.mode`, + * which answers `'create'`. Declaring it is the whole of the maintainer's + * ruling on defaults (decision batch #127 item 5): a default the protocol + * should have is declared BY THE PROTOCOL, so the authoring surface, the + * generated reference and the designer all read one answer instead of each + * inventing their own. + * + * ⚠️ Read only on the OBJECT-FORM branch. A flat `fields` screen never + * consults it — measured on the same run, the emitted ScreenSpec carries no + * `mode` key at all — so the materialised value is inert there rather than a + * second meaning. + * + * ⛔ Its sibling `http` key deliberately does NOT get this treatment: see + * `HttpConfigSchema.method` in `io-node-config.zod.ts`, where the executor + * applies two different values depending on `durable`, so there is no single + * default to declare and declaring one would change what a stored flow sends. + */ + mode: z.enum(['create', 'edit']).default('create') + .describe("Object form only: create (default) or edit; 'edit' needs a recordId to name its target"), /** Object form only: id of the record `mode: 'edit'` edits. Interpolates `{token}`. */ recordId: z.string().optional() .describe("Object form only: id of the record to edit (required for mode: 'edit' to be useful)"), diff --git a/packages/spec/src/automation/flow.test.ts b/packages/spec/src/automation/flow.test.ts index a1f5dc97bbf..e82da586a05 100644 --- a/packages/spec/src/automation/flow.test.ts +++ b/packages/spec/src/automation/flow.test.ts @@ -211,13 +211,24 @@ describe('FlowNodeSchema', () => { 'parallel_gateway', 'join_gateway', 'boundary_event', ] as const; + // The two type-scoped config blocks: a bare node of these types no longer + // parses, because the block is the whole of what the type declares (see + // `BPMN — Wait Event Configuration` below for the refusals themselves). + // Named here as DATA rather than skipped, so this list keeps covering every + // type in the seed set instead of quietly shrinking by two. + const REQUIRED_BLOCK: Record> = { + wait: { waitEventConfig: { eventType: 'timer', timerDuration: 'PT1H' } }, + boundary_event: { boundaryConfig: { attachedToNodeId: 'node_http', eventType: 'error' } }, + }; + types.forEach(type => { const node: FlowNode = { id: `node_${type}`, type, label: type, + ...REQUIRED_BLOCK[type], }; - expect(() => FlowNodeSchema.parse(node)).not.toThrow(); + expect(() => FlowNodeSchema.parse(node), type).not.toThrow(); }); }); @@ -1369,14 +1380,138 @@ describe('BPMN — Wait Event Configuration', () => { expect(result.success).toBe(true); }); - it('should accept wait node without waitEventConfig (backward compatible)', () => { + /** + * ⛔ REVERSED — this block used to read + * `it('should accept wait node without waitEventConfig (backward compatible)')` + * and asserted `success: true` with `waitEventConfig` undefined. That accept + * was the defect: measured end to end (PR #17937's + * `absent-config-node-characterization.test.ts`), the document it blessed ran + * to `{ success: true, suspend: true }` with no job armed though a job service + * was answering, no `waitUntil` persisted and not one log line at any level — + * a run parked forever, reporting success, from the state a freshly created + * node is in. "Backward compatible" named the compatibility and not its cost. + * + * The maintainer's ruling (decision batch #127 item 5) settles the direction: + * the protocol is the source of truth and a required key has no "unset + * behaves as", so the shape is refused at the contract rather than defaulted + * anywhere. Both directions are pinned — the refusal AND the shapes that must + * keep parsing, because a refusal that also swallowed legal documents would + * be the same class of defect pointing the other way. + */ + it('REFUSES a wait node with no `waitEventConfig` block at all, naming the key', () => { const result = FlowNodeSchema.safeParse({ id: 'wait_simple', type: 'wait', label: 'Simple Wait', }); - expect(result.success).toBe(true); - expect(result.data?.waitEventConfig).toBeUndefined(); + expect(result.success).toBe(false); + const issue = result.error!.issues.find(i => i.path.join('.') === 'waitEventConfig'); + expect(issue, 'the refusal is addressed at the block, not the node').toBeDefined(); + expect(issue!.message).toContain('`waitEventConfig`'); + // The remedy is in the rejection, not only in the docs: an author (or an + // agent) who reads only this string can fix the node from it. + expect(issue!.message).toContain("eventType: 'timer'"); + expect(issue!.message).toContain("'signal'"); + }); + + it('REFUSES a timer wait with no `timerDuration`, naming the key', () => { + const result = FlowNodeSchema.safeParse({ + id: 'wait_timer', + type: 'wait', + label: 'Wait', + waitEventConfig: { eventType: 'timer' }, + }); + expect(result.success).toBe(false); + const issue = result.error!.issues.find(i => i.path.join('.') === 'waitEventConfig.timerDuration'); + expect(issue).toBeDefined(); + expect(issue!.message).toContain('`timerDuration`'); + expect(issue!.message).toContain('PT1H'); + }); + + it('REFUSES a timer wait whose `timerDuration` is blank — the executor reads it as no duration', () => { + for (const timerDuration of ['', ' ']) { + const result = FlowNodeSchema.safeParse({ + id: 'wait_timer', type: 'wait', label: 'Wait', + waitEventConfig: { eventType: 'timer', timerDuration }, + }); + expect(result.success, `timerDuration: ${JSON.stringify(timerDuration)}`).toBe(false); + } + }); + + it('CONTROL — every shape that still parses: the refusals are scoped to what they name', () => { + // A declared timer wait: the one the showcase authors. + expect(FlowNodeSchema.safeParse({ + id: 'w', type: 'wait', label: 'Wait', + waitEventConfig: { eventType: 'timer', timerDuration: 'PT1H' }, + }).success).toBe(true); + // A numeric-string duration — quoted milliseconds, the spelling the + // `timeoutMs` tombstone prescribes. + expect(FlowNodeSchema.safeParse({ + id: 'w', type: 'wait', label: 'Wait', + waitEventConfig: { eventType: 'timer', timerDuration: '60000' }, + }).success).toBe(true); + // The four non-timer event types carry no duration and must not be asked + // for one: their resumer is named, not counted. + for (const eventType of ['signal', 'webhook', 'manual', 'condition']) { + expect(FlowNodeSchema.safeParse({ + id: 'w', type: 'wait', label: 'Wait', + waitEventConfig: { eventType, signalName: 'order_paid' }, + }).success, eventType).toBe(true); + } + // And the requirement is per NODE TYPE: nothing else acquired a block. + expect(FlowNodeSchema.safeParse({ id: 'n', type: 'script', label: 'S' }).success).toBe(true); + expect(FlowNodeSchema.safeParse({ id: 'n', type: 'screen', label: 'S' }).success).toBe(true); + }); + + /** + * Nested in an ADR-0031 region, the refusal is reached through the REGION + * CONTRACT, not through `FlowSchema` — measured here rather than assumed, + * because the two doors answer differently and only one of them is the door + * a run actually passes through. + * + * `parseFlowNodeRegions` parses each region slot with `safeParse` and, on a + * refusal, leaves the region RAW and continues (its own comment says so: a + * refused region is left for `validateControlFlow` to name). That policy + * predates this change and is not specific to `waitEventConfig` — it is why the + * flow-level parse below is GREEN with a block-less wait sitting in the loop + * body. The contract that refuses it is `LoopConfigSchema`, which is what + * `loop`'s executor parses its config through at execute time + * (`parseNodeConfig` → a guard refusal), so the nested shape still cannot + * run; it is refused one door later and by node id. + */ + it('nested in a region: the flow parse leaves it raw, and the REGION contract refuses it by path', () => { + const loopConfig = (bodyNode: Record) => ({ + collection: '{rows}', iteratorVariable: 'row', + body: { nodes: [bodyNode], edges: [] }, + }); + const bare = { id: 'pause', type: 'wait', label: 'Wait' }; + const declared = { + id: 'pause', type: 'wait', label: 'Wait', + waitEventConfig: { eventType: 'timer', timerDuration: 'PT1H' }, + }; + const flowWith = (bodyNode: Record) => ({ + name: 'nested', label: 'Nested', type: 'autolaunched', + nodes: [ + { id: 'start', type: 'start', label: 'Start' }, + { id: 'loop', type: 'loop', label: 'Loop', config: loopConfig(bodyNode) }, + ], + edges: [{ id: 'e1', source: 'start', target: 'loop' }], + }); + + // Door 1 — the flow parse: green, and the body node comes back UNPARSED. + const flowParse = FlowSchema.safeParse(flowWith(bare)); + expect(flowParse.success).toBe(true); + + // Door 2 — the region contract the `loop` executor parses through: refused, + // anchored on the block, at the node's own index inside the body. + const refused = LoopConfigSchema.safeParse(loopConfig(bare)); + expect(refused.success).toBe(false); + expect(refused.error!.issues.map(i => i.path.join('.'))).toContain('body.nodes.0.waitEventConfig'); + + // CONTROL — the declared body node passes both doors, so the refusal above + // is the missing block and not the region fixture. + expect(FlowSchema.safeParse(flowWith(declared)).success).toBe(true); + expect(LoopConfigSchema.safeParse(loopConfig(declared)).success).toBe(true); }); }); @@ -1492,6 +1627,29 @@ describe('BPMN — Boundary Event', () => { expect(faultEdge!.source).toBe('api_error_boundary'); } }); + + /** + * The contract half only. `boundary_event` has NO executor registered at all + * — measured in the same run that measured `wait`: the dispatch fails with + * `NO_EXECUTOR` before any config block is read, identically whether the + * block is absent or fully populated, and the seal warns about the type at + * boot. So unlike `wait` there is no silent executor branch behind this, and + * nothing in `service-automation` changes for it. What the refusal fixes is + * the authoring surface: a node that named neither its host activity nor its + * trigger used to parse clean. + */ + it('REFUSES a boundary_event node with no `boundaryConfig` block at all, naming the key', () => { + const result = FlowNodeSchema.safeParse({ + id: 'be_bare', + type: 'boundary_event', + label: 'Boundary', + }); + expect(result.success).toBe(false); + const issue = result.error!.issues.find(i => i.path.join('.') === 'boundaryConfig'); + expect(issue).toBeDefined(); + expect(issue!.message).toContain('`boundaryConfig`'); + expect(issue!.message).toContain('attachedToNodeId'); + }); }); describe('BPMN — Fault Edge Enhancement', () => { diff --git a/packages/spec/src/automation/flow.zod.ts b/packages/spec/src/automation/flow.zod.ts index 93f7c830641..1b6032a87dc 100644 --- a/packages/spec/src/automation/flow.zod.ts +++ b/packages/spec/src/automation/flow.zod.ts @@ -236,9 +236,99 @@ export const FlowVariableSchema = lazySchema(() => strictObject( * mode so that failure can never come back silently. */ export const FlowNodeSchema = lazySchema(() => flowNodeObject().transform( - (node, ctx) => parseEndNodeConfig(parseFlowNodeRegions(node), ctx), + (node, ctx) => parseEndNodeConfig(requireTypeScopedConfig(parseFlowNodeRegions(node), ctx), ctx), )); +/** + * Refuse a `wait` / `boundary_event` node that carries **no configuration block + * at all** — the third half of the node transform above. + * + * ## The document this closes + * + * `eventType` has always been REQUIRED *inside* each block, so + * `waitEventConfig: {}` was already a loud parse error. The BLOCK itself was + * optional, which made "omit the key" and "omit the block" two documents with + * two verdicts — and the accepted one was the silent one. That is the state a + * freshly created node is in, so it is a document an author could really save: + * measured end to end (PR #17937's `absent-config-node-characterization.test.ts`), + * `engine.execute()` on a block-less `wait` node answered + * `{ success: true, suspend: true }`, scheduled no job **though a job service was + * answering**, wrote no `waitUntil`, and emitted not one log line at any level. + * The run parked forever and reported success. The control — the same node with + * `{ eventType: 'timer', timerDuration: 'PT1H' }` — armed the job and persisted + * the deadline, so the zeros were a reading of this path and not of a dead + * harness. + * + * ## Why refusal, and why no default + * + * Maintainer ruling, decision batch #127 item 5, verbatim and untranslated: + * 「16678 具体解释,计划用哪个字段判断经理。其他同意」 — carrying option C′ as + * presented: the protocol is the source of truth; a designer never invents a + * default the protocol does not apply; a default the protocol *should* have is + * declared by the protocol; **a required key has no "unset behaves as"**. So + * `eventType` gets no `.default('timer')` here and none on the designer side + * (objectui#9354 deletes those declarations): a wait node says what it waits + * for, or it does not parse. A deliberate indefinite park, if one is ever + * wanted, is its own declared `eventType` — never the absence of configuration. + * + * The alternative considered and NOT taken (triage's reading on the closed + * duplicate #17939) was to warn and keep parsing. A warning on the authoring + * path an AI agent drives is read by nobody: the agent gets a success envelope + * and reports "done" over a flow that hangs. + * + * ## Where the refusal lands + * + * At the NODE level, so a `wait` nested in an ADR-0031 region is checked exactly + * like a top-level one, and next to {@link parseEndNodeConfig} because both + * answer the same question — "this node type owes a block the outer shape + * cannot demand". Issues are raised under the block's own key, so a flow-level + * parse reports them at `nodes[i].waitEventConfig`, the address `formatZodError` + * prints for any other node key. + * + * ⚠️ `boundary_event` gets the contract half ONLY: the platform registers no + * executor for that type at all (`NO_EXECUTOR` plus a startup `warn`, measured + * in the same characterization run), so unlike `wait` there is no silent + * executor branch to retire behind this. + */ +function requireTypeScopedConfig(node: T, ctx: z.RefinementCtx): T { + if (node.type === 'wait' && node.waitEventConfig === undefined) { + ctx.addIssue({ + code: 'custom', + path: ['waitEventConfig'], + message: + "a `wait` node requires a `waitEventConfig` block saying what resumes it — the block is what " + + 'the executor reads, and a node without one used to park the run forever while reporting ' + + 'success. Declare the resume condition, e.g. ' + + "`waitEventConfig: { eventType: 'timer', timerDuration: 'PT1H' }` for a delay (QUOTE the " + + "number: a bare numeric string is read as milliseconds, so '60000' is a 60s wait), or " + + "`waitEventConfig: { eventType: 'signal', signalName: 'order_paid' }` for an external " + + "producer to resume. `eventType` is one of 'timer' | 'signal' | 'webhook' | 'manual' | " + + "'condition' and has no default — an indefinite park is a declared `eventType`, never an " + + 'absent block.', + }); + } + if (node.type === 'boundary_event' && node.boundaryConfig === undefined) { + ctx.addIssue({ + code: 'custom', + path: ['boundaryConfig'], + message: + 'a `boundary_event` node requires a `boundaryConfig` block naming the host activity it ' + + 'watches and what fires it — without one the node declares nothing at all. Declare it, ' + + "e.g. `boundaryConfig: { attachedToNodeId: 'api_call', eventType: 'error', errorCode: " + + "'TIMEOUT' }`. `eventType` is one of 'error' | 'timer' | 'signal' | 'cancel' and has no " + + 'default. ⚠️ This node type is a BPMN interop representation: the runtime registers no ' + + 'executor for it, so a flow that reaches one at run time fails with NO_EXECUTOR — use a ' + + '`try_catch` region (ADR-0031) for native error handling.', + }); + } + return node; +} + /** * Parse a structural `end` node's `config` against {@link EndConfigSchema} * (#14945), the second half of the node transform above. @@ -493,7 +583,39 @@ function flowNodeObject() { return strictObject( + 'Run `os migrate meta --from 16` to list the mechanical edits for existing ' + 'sources; apply them by hand.', ), - }).optional().describe('Configuration for wait node event resumption').meta({ title: 'Wait Event' }), + }).superRefine((wec, ctx) => { + // A timer with nothing to count is the forever-hang in its second + // spelling. `parseIsoDuration` is the executor's only source for the wake + // deadline and it reads exactly this key: with no value it computes no + // deadline, so no one-shot job is scheduled, no `waitUntil` is persisted + // for a later boot's re-arm pass to find, and the node still answers + // `{ success: true, suspend: true }` — a run parked until something + // external calls `resume(runId)`, on a node whose author asked for a delay. + // Refused at authoring instead, with the key named, for the same reason + // `errorHandling.strategy: 'retry'` refuses `maxRetries: 0` above: a + // declared capability the runtime does not deliver (PD #10) is a defect at + // the contract, not a runtime degradation to log. + // + // Blank is absent. The value is a string and the executor's parse of `''` + // (or of any whitespace) yields no duration at all, so accepting it here + // would leave one byte of difference between the shape this refuses and a + // shape that hangs identically. + if (wec.eventType === 'timer' && (wec.timerDuration ?? '').trim() === '') { + ctx.addIssue({ + code: 'custom', + path: ['timerDuration'], + message: + "`waitEventConfig.eventType: 'timer'` requires a `timerDuration` — a timer wait with no " + + 'duration computes no deadline, schedules no wake-up job and parks the run forever while ' + + "reporting success. State the wait, e.g. `timerDuration: 'PT1H'` (ISO 8601), and QUOTE a " + + "bare number: the key is a string and a numeric string is read as milliseconds, so " + + "`timerDuration: '60000'` is the same 60s wait as `'PT1M'`. For a pause with no deadline " + + "use an `eventType` that names its resumer instead ('signal' / 'webhook' / 'manual' / " + + "'condition') — `wait` has no timeout, so nothing ever fails or resumes a wait on a " + + 'deadline it did not ask for.', + }); + } + }).optional().describe("Configuration for wait node event resumption. REQUIRED on a `type: 'wait'` node — the block is the whole contract, and a wait node without one parses into a run that parks forever reporting success. Under `eventType: 'timer'` a `timerDuration` is required too.").meta({ title: 'Wait Event' }), /** * Boundary Event Configuration (for 'boundary_event' nodes) @@ -536,7 +658,7 @@ function flowNodeObject() { return strictObject( timerDuration: z.string().optional().describe('ISO 8601 duration for timer boundary events'), /** Signal name — only for signal boundary events */ signalName: z.string().optional().describe('Named signal to catch'), - }).optional().describe('Configuration for boundary events attached to host nodes').meta({ title: 'Boundary Event' }), + }).optional().describe("Configuration for boundary events attached to host nodes. REQUIRED on a `type: 'boundary_event'` node — without it the node names neither the activity it watches nor what fires it.").meta({ title: 'Boundary Event' }), }); } /** diff --git a/packages/spec/src/automation/io-node-config.zod.ts b/packages/spec/src/automation/io-node-config.zod.ts index bec202af12b..1288f3f8e5c 100644 --- a/packages/spec/src/automation/io-node-config.zod.ts +++ b/packages/spec/src/automation/io-node-config.zod.ts @@ -335,7 +335,23 @@ export const HttpConfigSchema = lazySchema(() => strictObject({ }, { /** Target URL (execute-time required). */ url: z.string().describe('Target URL'), - /** HTTP method — default GET inline, POST when durable. */ + /** + * HTTP method — default GET inline, POST when durable. + * + * ⛔ **No `.default()`, and that is the measured answer, not an omission.** + * The executor applies TWO values for an absent key, decided by `durable`: + * run with `config: { url }` it calls `fetch` with `GET`; run with + * `config: { url, durable: true }` against a ready outbox it enqueues `POST` + * (`http-nodes.ts`: `method: cfg.method ?? 'POST'` on the durable arm, + * `const method = cfg.method ?? 'GET'` on the inline one). A static + * `.default('GET')` would materialise `GET` at parse time, the durable arm's + * `??` would never fire again, and every stored durable callout that omits + * the method would silently change from POST to GET — a protocol-declared + * default the runtime does not apply, which is precisely the defect the + * maintainer's ruling on defaults (decision batch #127 item 5) forbids. + * Contrast `ScreenConfigSchema.mode` in `builtin-node-config.zod.ts`, where + * one value IS applied and is therefore declared. + */ method: z.string().optional().describe('HTTP method (default GET; POST when durable)'), /** Request headers. */ headers: z.record(z.string(), z.string()).optional().describe('Request headers'), From 5a1e47ba5d02e78941d727eb6bfb3668f37f88ab Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 14 Sep 2026 04:32:07 +0000 Subject: [PATCH 2/6] wip(automation): declared default change, ADR-0087 semantic entry, changeset Claude-Session: https://claude.ai/code/session_014DBGjJFyndTj766aReCL2g Co-authored-by: Claude --- .changeset/17928-wait-node-config-required.md | 85 +++++++++++++++++++ .../docs/references/api/automation-api.mdx | 4 +- .../automation/builtin-node-config.mdx | 2 +- .../references/automation/control-flow.mdx | 8 +- content/docs/references/automation/flow.mdx | 8 +- .../spec/authorable-defaults/automation.json | 1 + packages/spec/scripts/lib/default-changes.ts | 26 ++++++ .../18.wait-node-event-config-required.ts | 65 ++++++++++++++ packages/spec/src/migrations/registry.ts | 61 +++++++++++++ 9 files changed, 249 insertions(+), 11 deletions(-) create mode 100644 .changeset/17928-wait-node-config-required.md create mode 100644 packages/spec/src/migrations/entries/semantic/18.wait-node-event-config-required.ts diff --git a/.changeset/17928-wait-node-config-required.md b/.changeset/17928-wait-node-config-required.md new file mode 100644 index 00000000000..de5398ca466 --- /dev/null +++ b/.changeset/17928-wait-node-config-required.md @@ -0,0 +1,85 @@ +--- +'@objectstack/spec': minor +'@objectstack/service-automation': minor +--- + +fix(automation): a `wait` node must say what resumes it — the config block is required at the contract, and the executor stops defaulting to a duration-less timer (#17928) + +**BREAKING** — a `type: 'wait'` flow node with no `waitEventConfig` block, and a +`type: 'boundary_event'` node with no `boundaryConfig` block, no longer parse. +Under `eventType: 'timer'`, `timerDuration` is now required and may not be blank. + +`eventType` has been required *inside* each block since protocol 17, so +`waitEventConfig: {}` was already a loud parse error. The block itself was +optional — so "omit the key" and "omit the block" were two documents with two +verdicts, and the accepted one was the silent one. It is also the state a +freshly created node is in, which is what made it reachable from a designer's +default screen rather than only by hand-authoring. + +What that document did, measured through a real `engine.execute()` run rather +than read off the source: + +``` +FROM { id: 'pause', type: 'wait', label: 'Wait' } // parses clean + -> { success: true, suspend: true } // run status: paused + scheduled jobs: [] <- with a job service ANSWERING + variables: no `pause.waitUntil` <- cold boot cannot re-arm + log lines: 0 at any level <- warn, error, info, debug + +TO FlowNodeSchema.safeParse(...) + -> { success: false, + issues: [{ code: 'custom', path: ['waitEventConfig'], + message: 'a `wait` node requires a `waitEventConfig` block saying + what resumes it … `waitEventConfig: { eventType: 'timer', + timerDuration: 'PT1H' }` … or `{ eventType: 'signal', + signalName: 'order_paid' }` …' }] } +``` + +The control — the same node with `{ eventType: 'timer', timerDuration: 'PT1H' }` +— armed the one-shot job and persisted the deadline, so the zeros above are a +reading of this path and not of a dead harness. + +**The executor follows the contract.** `wait-node.ts` carried +`(node.waitEventConfig ?? {})` and `String(wec.eventType ?? 'timer')` under a +comment declaring the second one deliberate — "a wait node without one is a +VALID TIMER WAIT". Both fallbacks are retired. A node that still reaches +`execute` without the block (a stored pre-migration document on a path that +skipped the parse) is now a **guard refusal** — `errorClass: 'guard'`, so a +`fault` edge cannot route a metadata defect into a handler that reports success +— and it **logs**, naming the node and the remedy, because the defect being +closed was silence. It never suspends with `success: true` again. Two smaller +corrections ride along in the same return: the timer branch stops answering +`output` as a present key holding `undefined` (it is absent when no deadline was +computed), and the reversed comment is deleted rather than left describing a +behaviour that is gone. + +**`screen.mode` now declares the default the executor applies; `http.method` +still declares none.** Both were read by running the executors with the key +absent, not by reading the Zod: + +| key | absent ⇒ the runtime applies | declared | +| --- | --- | --- | +| `ScreenConfig.mode` | `'create'` (object-form branch; the flat `fields` branch never reads it) | `.default('create')` | +| `HttpConfig.method` | `GET` inline, **`POST`** when `durable: true` | ⛔ none — two values, no single default | + +Declaring `.default('GET')` on `method` would materialise `GET` at parse time, +the durable arm's own `?? 'POST'` would never fire again, and every stored +durable callout that omits the method would silently change verb. That is the +defect this card exists to end, pointed the other way. + +**Migration.** A stored `wait` node with no block has no lossless conversion — +the missing value is an intent no artifact records, and the old runtime's pick +(`'timer'` with no duration) was not a wait at all — so this is an ADR-0087 D3 +semantic entry rather than a D2 conversion: `os migrate meta --from 17` names +each node to edit. Declare the resume condition and re-publish the flow. ⚠️ +Behaviour the fix deliberately changes: a run that used to park forever now +waits the duration you declare or the signal you name. + +**`boundary_event` gets the contract half only.** The runtime registers no +executor for that node type at all — a flow reaching one fails with +`NO_EXECUTOR` before any config is read, identically whether the block is +present or absent — so there is no silent executor branch behind it. The +refusal fixes the authoring surface; `try_catch` (ADR-0031) remains the native +construct for error handling. + + diff --git a/content/docs/references/api/automation-api.mdx b/content/docs/references/api/automation-api.mdx index 121cb25ff10..8cd367940bc 100644 --- a/content/docs/references/api/automation-api.mdx +++ b/content/docs/references/api/automation-api.mdx @@ -134,8 +134,8 @@ const result = AutomationApiErrorCode.parse(data); | **timeoutMs** | `integer` | optional | Maximum execution time for this node in milliseconds | | **inputSchema** | `Record; required?: boolean; description?: string }>` | optional | Input parameter schema for this node | | **outputSchema** | `never` | optional | [REMOVED] `flow.nodes[].outputSchema` was removed in @objectstack/spec 17.0.0 (audit close-out) — it was never validated: the engine does not check node outputs against it, so it documented a contract nothing enforced. Delete the key. Downstream nodes read prior outputs via expressions (`{{nodeId.field}}`) regardless of any declaration. Run `os migrate meta --from 16` to list the mechanical edits for existing sources; apply them by hand. | -| **waitEventConfig** | `{ eventType: Enum<'timer' \| 'signal' \| 'webhook' \| 'manual' \| 'condition'>; timerDuration?: string; signalName?: string }` | optional | Configuration for wait node event resumption | -| **boundaryConfig** | `{ attachedToNodeId: string; eventType: Enum<'error' \| 'timer' \| 'signal' \| 'cancel'>; interrupting?: boolean; errorCode?: string; … }` | optional | Configuration for boundary events attached to host nodes | +| **waitEventConfig** | `{ eventType: Enum<'timer' \| 'signal' \| 'webhook' \| 'manual' \| 'condition'>; timerDuration?: string; signalName?: string }` | optional | Configuration for wait node event resumption. REQUIRED on a `type: 'wait'` node — the block is the whole contract, and a wait node without one parses into a run that parks forever reporting success. Under `eventType: 'timer'` a `timerDuration` is required too. | +| **boundaryConfig** | `{ attachedToNodeId: string; eventType: Enum<'error' \| 'timer' \| 'signal' \| 'cancel'>; interrupting?: boolean; errorCode?: string; … }` | optional | Configuration for boundary events attached to host nodes. REQUIRED on a `type: 'boundary_event'` node — without it the node names neither the activity it watches nor what fires it. | ### Nested Shape: `CreateFlowRequest.edges[number]` diff --git a/content/docs/references/automation/builtin-node-config.mdx b/content/docs/references/automation/builtin-node-config.mdx index cb9348b103c..e531779ffe6 100644 --- a/content/docs/references/automation/builtin-node-config.mdx +++ b/content/docs/references/automation/builtin-node-config.mdx @@ -211,7 +211,7 @@ Value the variable takes: a string (`{token}` flow interpolation — a sole toke | **waitForInput** | `boolean` | optional | Pause to show the screen even with no fields; false forces a server pass-through | | **objectName** | `string` | optional | Render this object's full create/edit form instead of a flat field list | | **idVariable** | `string` | optional | Object form only: variable bound to the saved record's id | -| **mode** | `Enum<'create' \| 'edit'>` | optional | Object form only: create or edit | +| **mode** | `Enum<'create' \| 'edit'>` | optional (default: `"create"`) | Object form only: create (default) or edit; 'edit' needs a recordId to name its target | | **recordId** | `string` | optional | Object form only: id of the record to edit (required for mode: 'edit' to be useful) | | **defaults** | `Record` | optional | Object form only: prefilled values | diff --git a/content/docs/references/automation/control-flow.mdx b/content/docs/references/automation/control-flow.mdx index 32a319b7c26..43f36ab32c8 100644 --- a/content/docs/references/automation/control-flow.mdx +++ b/content/docs/references/automation/control-flow.mdx @@ -119,8 +119,8 @@ const result = FlowRegionSchema.parse(data); | **timeoutMs** | `integer` | optional | Maximum execution time for this node in milliseconds | | **inputSchema** | `Record; required?: boolean; description?: string }>` | optional | Input parameter schema for this node | | **outputSchema** | `never` | optional | [REMOVED] `flow.nodes[].outputSchema` was removed in @objectstack/spec 17.0.0 (audit close-out) — it was never validated: the engine does not check node outputs against it, so it documented a contract nothing enforced. Delete the key. Downstream nodes read prior outputs via expressions (`{{nodeId.field}}`) regardless of any declaration. Run `os migrate meta --from 16` to list the mechanical edits for existing sources; apply them by hand. | -| **waitEventConfig** | `{ eventType: Enum<'timer' \| 'signal' \| 'webhook' \| 'manual' \| 'condition'>; timerDuration?: string; signalName?: string }` | optional | Configuration for wait node event resumption | -| **boundaryConfig** | `{ attachedToNodeId: string; eventType: Enum<'error' \| 'timer' \| 'signal' \| 'cancel'>; interrupting?: boolean; errorCode?: string; … }` | optional | Configuration for boundary events attached to host nodes | +| **waitEventConfig** | `{ eventType: Enum<'timer' \| 'signal' \| 'webhook' \| 'manual' \| 'condition'>; timerDuration?: string; signalName?: string }` | optional | Configuration for wait node event resumption. REQUIRED on a `type: 'wait'` node — the block is the whole contract, and a wait node without one parses into a run that parks forever reporting success. Under `eventType: 'timer'` a `timerDuration` is required too. | +| **boundaryConfig** | `{ attachedToNodeId: string; eventType: Enum<'error' \| 'timer' \| 'signal' \| 'cancel'>; interrupting?: boolean; errorCode?: string; … }` | optional | Configuration for boundary events attached to host nodes. REQUIRED on a `type: 'boundary_event'` node — without it the node names neither the activity it watches nor what fires it. | ### Nested Shape: `FlowRegion.edges[number]` @@ -182,8 +182,8 @@ const result = FlowRegionSchema.parse(data); | **timeoutMs** | `integer` | optional | Maximum execution time for this node in milliseconds | | **inputSchema** | `Record; required?: boolean; description?: string }>` | optional | Input parameter schema for this node | | **outputSchema** | `never` | optional | [REMOVED] `flow.nodes[].outputSchema` was removed in @objectstack/spec 17.0.0 (audit close-out) — it was never validated: the engine does not check node outputs against it, so it documented a contract nothing enforced. Delete the key. Downstream nodes read prior outputs via expressions (`{{nodeId.field}}`) regardless of any declaration. Run `os migrate meta --from 16` to list the mechanical edits for existing sources; apply them by hand. | -| **waitEventConfig** | `{ eventType: Enum<'timer' \| 'signal' \| 'webhook' \| 'manual' \| 'condition'>; timerDuration?: string; signalName?: string }` | optional | Configuration for wait node event resumption | -| **boundaryConfig** | `{ attachedToNodeId: string; eventType: Enum<'error' \| 'timer' \| 'signal' \| 'cancel'>; interrupting?: boolean; errorCode?: string; … }` | optional | Configuration for boundary events attached to host nodes | +| **waitEventConfig** | `{ eventType: Enum<'timer' \| 'signal' \| 'webhook' \| 'manual' \| 'condition'>; timerDuration?: string; signalName?: string }` | optional | Configuration for wait node event resumption. REQUIRED on a `type: 'wait'` node — the block is the whole contract, and a wait node without one parses into a run that parks forever reporting success. Under `eventType: 'timer'` a `timerDuration` is required too. | +| **boundaryConfig** | `{ attachedToNodeId: string; eventType: Enum<'error' \| 'timer' \| 'signal' \| 'cancel'>; interrupting?: boolean; errorCode?: string; … }` | optional | Configuration for boundary events attached to host nodes. REQUIRED on a `type: 'boundary_event'` node — without it the node names neither the activity it watches nor what fires it. | ### Nested Shape: `ParallelBranch.edges[number]` diff --git a/content/docs/references/automation/flow.mdx b/content/docs/references/automation/flow.mdx index 6a2e562a235..202c5b47ca2 100644 --- a/content/docs/references/automation/flow.mdx +++ b/content/docs/references/automation/flow.mdx @@ -74,8 +74,8 @@ const result = FlowSchema.parse(data); | **timeoutMs** | `integer` | optional | Maximum execution time for this node in milliseconds | | **inputSchema** | `Record; required?: boolean; description?: string }>` | optional | Input parameter schema for this node | | **outputSchema** | `never` | optional | [REMOVED] `flow.nodes[].outputSchema` was removed in @objectstack/spec 17.0.0 (audit close-out) — it was never validated: the engine does not check node outputs against it, so it documented a contract nothing enforced. Delete the key. Downstream nodes read prior outputs via expressions (`{{nodeId.field}}`) regardless of any declaration. Run `os migrate meta --from 16` to list the mechanical edits for existing sources; apply them by hand. | -| **waitEventConfig** | `{ eventType: Enum<'timer' \| 'signal' \| 'webhook' \| 'manual' \| 'condition'>; timerDuration?: string; signalName?: string }` | optional | Configuration for wait node event resumption | -| **boundaryConfig** | `{ attachedToNodeId: string; eventType: Enum<'error' \| 'timer' \| 'signal' \| 'cancel'>; interrupting?: boolean; errorCode?: string; … }` | optional | Configuration for boundary events attached to host nodes | +| **waitEventConfig** | `{ eventType: Enum<'timer' \| 'signal' \| 'webhook' \| 'manual' \| 'condition'>; timerDuration?: string; signalName?: string }` | optional | Configuration for wait node event resumption. REQUIRED on a `type: 'wait'` node — the block is the whole contract, and a wait node without one parses into a run that parks forever reporting success. Under `eventType: 'timer'` a `timerDuration` is required too. | +| **boundaryConfig** | `{ attachedToNodeId: string; eventType: Enum<'error' \| 'timer' \| 'signal' \| 'cancel'>; interrupting?: boolean; errorCode?: string; … }` | optional | Configuration for boundary events attached to host nodes. REQUIRED on a `type: 'boundary_event'` node — without it the node names neither the activity it watches nor what fires it. | ### Nested Shape: `Flow.edges[number]` @@ -145,8 +145,8 @@ const result = FlowSchema.parse(data); | **timeoutMs** | `integer` | optional | Maximum execution time for this node in milliseconds | | **inputSchema** | `Record; required?: boolean; description?: string }>` | optional | Input parameter schema for this node | | **outputSchema** | `never` | optional | [REMOVED] `flow.nodes[].outputSchema` was removed in @objectstack/spec 17.0.0 (audit close-out) — it was never validated: the engine does not check node outputs against it, so it documented a contract nothing enforced. Delete the key. Downstream nodes read prior outputs via expressions (`{{nodeId.field}}`) regardless of any declaration. Run `os migrate meta --from 16` to list the mechanical edits for existing sources; apply them by hand. | -| **waitEventConfig** | `{ eventType: Enum<'timer' \| 'signal' \| 'webhook' \| 'manual' \| 'condition'>; timerDuration?: string; signalName?: string }` | optional | Configuration for wait node event resumption | -| **boundaryConfig** | `{ attachedToNodeId: string; eventType: Enum<'error' \| 'timer' \| 'signal' \| 'cancel'>; interrupting?: boolean; errorCode?: string; … }` | optional | Configuration for boundary events attached to host nodes | +| **waitEventConfig** | `{ eventType: Enum<'timer' \| 'signal' \| 'webhook' \| 'manual' \| 'condition'>; timerDuration?: string; signalName?: string }` | optional | Configuration for wait node event resumption. REQUIRED on a `type: 'wait'` node — the block is the whole contract, and a wait node without one parses into a run that parks forever reporting success. Under `eventType: 'timer'` a `timerDuration` is required too. | +| **boundaryConfig** | `{ attachedToNodeId: string; eventType: Enum<'error' \| 'timer' \| 'signal' \| 'cancel'>; interrupting?: boolean; errorCode?: string; … }` | optional | Configuration for boundary events attached to host nodes. REQUIRED on a `type: 'boundary_event'` node — without it the node names neither the activity it watches nor what fires it. | ### Nested Shape: `FlowNode.connectorConfig` diff --git a/packages/spec/authorable-defaults/automation.json b/packages/spec/authorable-defaults/automation.json index d0115dc9f34..21266b7d520 100644 --- a/packages/spec/authorable-defaults/automation.json +++ b/packages/spec/authorable-defaults/automation.json @@ -58,6 +58,7 @@ "automation/ScheduleState:status = \"active\"", "automation/ScheduleState:timezone = \"UTC\"", "automation/ScheduleState:totalRuns = 0", + "automation/ScreenConfig:mode = \"create\"", "automation/StateNode:type = \"atomic\"", "automation/TryCatchConfig:errorVariable = \"$error\"", "automation/WaitExecutorConfig:conditionMaxPolls = 0", diff --git a/packages/spec/scripts/lib/default-changes.ts b/packages/spec/scripts/lib/default-changes.ts index d82a423f57b..a1639c43e64 100644 --- a/packages/spec/scripts/lib/default-changes.ts +++ b/packages/spec/scripts/lib/default-changes.ts @@ -330,5 +330,31 @@ export const DEFAULT_CHANGES_BY_MAJOR: Readonly\' }` when an external producer resumes the run. For `boundary_event`, ' + + '`boundaryConfig: { attachedToNodeId: \'\', eventType: \'error\' | \'timer\' | ' + + '\'signal\' | \'cancel\' }`. ⛔ There is deliberately NO default for either `eventType`: a ' + + 'required key has no "unset behaves as", and an indefinite park — if one is ever wanted — ' + + 'is its own declared `eventType`, never the absence of configuration. ⚠️ `boundary_event` ' + + 'has no executor in the runtime at all (a flow reaching one fails with NO_EXECUTOR), so a ' + + 'stored boundary node is an authoring-surface repair: the native construct for error ' + + 'handling is a `try_catch` region (ADR-0031).', + reason: + 'Maintainer ruling, decision batch #127 item 5, verbatim and untranslated: ' + + '「16678 具体解释,计划用哪个字段判断经理。其他同意」 — carrying the presented option: the ' + + 'protocol is the source of truth; a designer never invents a default the protocol does ' + + 'not apply; a default the protocol should have is declared by the protocol; a required ' + + 'key has no "unset behaves as". ⛔ NOT losslessly convertible, and the reason is that the ' + + 'missing value is an INTENT no artifact records: a block-less wait node does not say ' + + 'whether its author meant a delay (and for how long) or a named signal (and which one), ' + + 'and a transform that picked one would be inventing the very default this ruling forbids. ' + + 'What the old runtime picked was \'timer\' with no duration, which is not a wait at all: ' + + 'measured through a real `engine.execute()` run, such a node answered `{ success: true, ' + + 'suspend: true }`, scheduled no wake-up job THOUGH A JOB SERVICE WAS ANSWERING, persisted ' + + 'no `waitUntil` for a later boot\'s re-arm pass, and emitted not one log line at any ' + + 'level — the run parked forever and reported success. So the conversion layer (D2) cannot ' + + 'hide this break and the tombstone channel cannot carry it either (nothing was renamed or ' + + 'retired; a key that was optional became required), which leaves D3: a structured TODO ' + + 'naming each node that must be edited. The alternative considered and NOT taken was to ' + + 'warn and keep parsing — a warning on the authoring path an AI agent drives is read by ' + + 'nobody, and the agent reports "done" over a flow that hangs.', + acceptanceCriteria: + 'Every `type: \'wait\'` node in the stack — at the top level AND inside every ADR-0031 ' + + 'region body — carries a `waitEventConfig` with an `eventType`, and every one whose ' + + '`eventType` is \'timer\' carries a non-blank `timerDuration`; every `type: ' + + '\'boundary_event\'` node carries a `boundaryConfig` with an `attachedToNodeId` and an ' + + '`eventType`. `FlowSchema.parse` (and therefore `registerFlow`, `os validate` and a ' + + 'Studio publish) accepts the stack: a node still missing its block is refused with the ' + + 'key named at `nodes[i].waitEventConfig` / `nodes[i].boundaryConfig` and the remedy in ' + + 'the message. ⚠️ A region body is checked through the REGION contract rather than the ' + + 'flow parse — `parseFlowNodeRegions` leaves a refused region raw — so a nested node is ' + + 'named by `LoopConfigSchema` / `ParallelConfigSchema` / `TryCatchConfigSchema` at ' + + '`body.nodes[i].waitEventConfig`, and at run time by the container node\'s own ' + + 'execute-time config parse; check the nested ones by parsing the container config, not ' + + 'only by parsing the flow. Behaviour to re-check after editing, because the fix CHANGES ' + + 'IT deliberately: a run that used to park forever on such a node now either waits the ' + + 'duration you declared or waits for the signal you named — anything that resumed those ' + + 'runs by hand (an operator calling `resume(runId)`, a nightly sweep) has less to do, and ' + + 'anything that COUNTED on the park is now on a timer.', +}; diff --git a/packages/spec/src/migrations/registry.ts b/packages/spec/src/migrations/registry.ts index 4d504ab5efd..614487c23c5 100644 --- a/packages/spec/src/migrations/registry.ts +++ b/packages/spec/src/migrations/registry.ts @@ -11522,6 +11522,67 @@ const step18: MigrationStep = { + 'reports no `component-props-unknown-key` / `component-props-invalid` finding for the ' + 'rail.', }, + { + id: 'wait-node-event-config-required', + surface: + 'The `waitEventConfig` block of every `type: \'wait\'` flow node, and the ' + + '`boundaryConfig` block of every `type: \'boundary_event\'` node — the BLOCK, not a key ' + + 'inside it. `eventType` has been required INSIDE each block since protocol 17, so the ' + + 'contract already refused `waitEventConfig: {}`; what it also accepted was the block ' + + 'missing entirely, which is the state a freshly created node is in. Two documents, two ' + + 'verdicts, and the accepted one was the silent one. Also narrowed one level down: under ' + + '`eventType: \'timer\'`, `timerDuration` is now required and may not be blank.', + replacement: + 'Declare what resumes the node, on the node: `waitEventConfig: { eventType: \'timer\', ' + + 'timerDuration: \'PT1H\' }` for a delay — QUOTE a bare number, the key is a string and a ' + + 'numeric string is read as milliseconds, so \'60000\' is the same 60s wait as \'PT1M\' — ' + + 'or `{ eventType: \'signal\' | \'webhook\' | \'manual\' | \'condition\', signalName: ' + + '\'\' }` when an external producer resumes the run. For `boundary_event`, ' + + '`boundaryConfig: { attachedToNodeId: \'\', eventType: \'error\' | \'timer\' | ' + + '\'signal\' | \'cancel\' }`. ⛔ There is deliberately NO default for either `eventType`: a ' + + 'required key has no "unset behaves as", and an indefinite park — if one is ever wanted — ' + + 'is its own declared `eventType`, never the absence of configuration. ⚠️ `boundary_event` ' + + 'has no executor in the runtime at all (a flow reaching one fails with NO_EXECUTOR), so a ' + + 'stored boundary node is an authoring-surface repair: the native construct for error ' + + 'handling is a `try_catch` region (ADR-0031).', + reason: + 'Maintainer ruling, decision batch #127 item 5, verbatim and untranslated: ' + + '「16678 具体解释,计划用哪个字段判断经理。其他同意」 — carrying the presented option: the ' + + 'protocol is the source of truth; a designer never invents a default the protocol does ' + + 'not apply; a default the protocol should have is declared by the protocol; a required ' + + 'key has no "unset behaves as". ⛔ NOT losslessly convertible, and the reason is that the ' + + 'missing value is an INTENT no artifact records: a block-less wait node does not say ' + + 'whether its author meant a delay (and for how long) or a named signal (and which one), ' + + 'and a transform that picked one would be inventing the very default this ruling forbids. ' + + 'What the old runtime picked was \'timer\' with no duration, which is not a wait at all: ' + + 'measured through a real `engine.execute()` run, such a node answered `{ success: true, ' + + 'suspend: true }`, scheduled no wake-up job THOUGH A JOB SERVICE WAS ANSWERING, persisted ' + + 'no `waitUntil` for a later boot\'s re-arm pass, and emitted not one log line at any ' + + 'level — the run parked forever and reported success. So the conversion layer (D2) cannot ' + + 'hide this break and the tombstone channel cannot carry it either (nothing was renamed or ' + + 'retired; a key that was optional became required), which leaves D3: a structured TODO ' + + 'naming each node that must be edited. The alternative considered and NOT taken was to ' + + 'warn and keep parsing — a warning on the authoring path an AI agent drives is read by ' + + 'nobody, and the agent reports "done" over a flow that hangs.', + acceptanceCriteria: + 'Every `type: \'wait\'` node in the stack — at the top level AND inside every ADR-0031 ' + + 'region body — carries a `waitEventConfig` with an `eventType`, and every one whose ' + + '`eventType` is \'timer\' carries a non-blank `timerDuration`; every `type: ' + + '\'boundary_event\'` node carries a `boundaryConfig` with an `attachedToNodeId` and an ' + + '`eventType`. `FlowSchema.parse` (and therefore `registerFlow`, `os validate` and a ' + + 'Studio publish) accepts the stack: a node still missing its block is refused with the ' + + 'key named at `nodes[i].waitEventConfig` / `nodes[i].boundaryConfig` and the remedy in ' + + 'the message. ⚠️ A region body is checked through the REGION contract rather than the ' + + 'flow parse — `parseFlowNodeRegions` leaves a refused region raw — so a nested node is ' + + 'named by `LoopConfigSchema` / `ParallelConfigSchema` / `TryCatchConfigSchema` at ' + + '`body.nodes[i].waitEventConfig`, and at run time by the container node\'s own ' + + 'execute-time config parse; check the nested ones by parsing the container config, not ' + + 'only by parsing the flow. Behaviour to re-check after editing, because the fix CHANGES ' + + 'IT deliberately: a run that used to park forever on such a node now either waits the ' + + 'duration you declared or waits for the signal you named — anything that resumed those ' + + 'runs by hand (an operator calling `resume(runId)`, a nightly sweep) has less to do, and ' + + 'anything that COUNTED on the park is now on a timer.', + }, { id: 'websocket-durations-unit-in-key', surface: 'the four WebSocket configuration durations whose name carried no unit: ' From 67dfff2f36c1968654c1fc6a7a260110cd70e7e3 Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 14 Sep 2026 04:45:43 +0000 Subject: [PATCH 3/6] test(automation): flip the absent-config characterization onto the reversal MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The photograph the card was filed from is now the pin of the opposite behaviour, channel by channel: the parse refuses, the run fails, nothing is parked, and the silence is replaced by a `warn` naming the node. Its `boundary_event` half is unchanged in substance — its fixtures gained the block the parse now requires, and the "a populated block fails identically" control is what proves that door moved nothing at execute time. `wait-node.test.ts`'s teardown case moves from an ABSENT `timerDuration` to an unparseable one — the shape that still reaches the no-deadline branch now that the contract requires the key. Claude-Session: https://claude.ai/code/session_014DBGjJFyndTj766aReCL2g Co-authored-by: Claude --- ...bsent-config-node-characterization.test.ts | 262 +++++++++++------- .../src/builtin/wait-node.test.ts | 12 +- 2 files changed, 167 insertions(+), 107 deletions(-) diff --git a/packages/services/service-automation/src/builtin/absent-config-node-characterization.test.ts b/packages/services/service-automation/src/builtin/absent-config-node-characterization.test.ts index df9e9d61e72..063be8b67d8 100644 --- a/packages/services/service-automation/src/builtin/absent-config-node-characterization.test.ts +++ b/packages/services/service-automation/src/builtin/absent-config-node-characterization.test.ts @@ -1,39 +1,53 @@ // Copyright (c) 2025 ObjectStack. Licensed under the Apache-2.0 license. /** - * ⚠️ CHARACTERIZATION — this file RECORDS what the executor does today with a - * node that carries **no config block at all**. It does **not** endorse it, and - * a green run here is **not** a statement that the behaviour is correct. + * ⚠️ WAS A CHARACTERIZATION — **flipped**, and the reversal is the point of the + * file now. * - * A later reader: every `expect` below is a photograph, not a contract. If the - * behaviour is deliberately changed, **update the photograph** — a red here is - * "the recorded behaviour moved", which may be exactly what a fix intends. The - * one thing it must never do is drift *unnoticed*. + * It was written to RECORD what the executor did with a node carrying **no + * config block at all**, explicitly not endorsing it: "every `expect` below is a + * photograph, not a contract. If the behaviour is deliberately changed, update + * the photograph — a red here is 'the recorded behaviour moved', which may be + * exactly what a fix intends." That is what happened. The photograph it took — + * a `wait` node with no `waitEventConfig` running to `{ success: true, suspend: + * true }`, with no job armed though a job service was ANSWERING, no `waitUntil` + * persisted, and **zero log lines at any level** — is the measurement that + * carried the defect card, and the behaviour has been deliberately reversed. * - * **Why the photograph was taken (#17843).** `@objectstack/spec` ACCEPTS a - * `wait` node whose `waitEventConfig` block is absent entirely — that is the - * state a freshly created node is in — while it REFUSES a node whose block is - * present with `eventType` omitted. So "block absent" is a document an author - * can really save, and what it then DOES at run time had never been observed: - * the question was answered from source, and this file is the observed run that - * closes that gap. It measures both halves the card asked for, because they are - * different execution branches and neither predicts the other: + * ## What moved, on each channel the old file measured * - * - **`wait`** — the executor defaults `eventType` to `'timer'` on purpose (the - * `?? 'timer'` in `wait-node.ts` carries a comment saying a wait node without - * a config block is a valid timer wait), and the timer branch with no - * `timerDuration` computes no deadline: no wake-up job, no `waitUntil`, not - * one log line, and `success: true, suspend: true`. The run parks there until - * something external calls `resume(runId)`. ⭐ Recorded, not blessed: - * whether a duration-less timer wait should warn or refuse is a product - * question that belongs to a successor card, not to this file. - * - **`boundary_event`** — ⭐ the opposite shape, and the reason extrapolating + * | channel | recorded before | pinned now | + * | ----------------------- | ------------------------------- | -------------------------------------------- | + * | the parse | block-less `wait` ACCEPTED | REFUSED, naming `waitEventConfig` | + * | `engine.execute()` | `{ success: true, suspend: true }` | run FAILS, node status `failure` | + * | suspended runs | one, parked forever | none — the run never suspends | + * | log lines during the run| **0 at any level** | a `warn` naming the node and the remedy | + * | `output` on the return | present key holding `undefined` | absent (the timer branch computes no deadline)| + * + * The ruling behind the direction (decision batch #127 item 5, maintainer, + * verbatim and untranslated): 「16678 具体解释,计划用哪个字段判断经理。其他同意」 + * — carrying the presented option: the protocol is the source of truth, a + * designer never invents a default the protocol does not apply, and **a required + * key has no "unset behaves as"**. Triage's alternative on the closed duplicate + * (warn and keep parsing) was considered and NOT taken. + * + * ## What did NOT move, and is still recorded here rather than re-derived + * + * - **`boundary_event`** — the opposite shape, and the reason extrapolating * from `wait` would have been wrong. No executor is registered for it at all * (`installBuiltinNodes` seeds twelve packs, none of them this one; the * README files it as BPMN *interop* representation rather than the native - * authoring model), so the run fails LOUDLY with `NO_EXECUTOR` before the - * config block is ever read — and it fails identically whether that block is - * absent or fully populated. + * authoring model), so a run fails LOUDLY with `NO_EXECUTOR` before any + * config block is read — and it fails identically whether that block is + * absent or fully populated. ⇒ the executor side had nothing to change for + * it; only the parse door moved, which is why its fixtures below now carry + * the block they are required to carry. + * - **a paused run still emits no run-level log line.** Paused is not + * terminal, so the #4354 run-summary line is not owed and is not printed. + * Left as it was — deliberately, and re-recorded here so the next reader does + * not fold it into the silence this card closed. The silence that MATTERED + * was a node that could never wake saying nothing; a legitimate pause that + * says nothing is a different question. */ import { describe, it, expect } from 'vitest'; @@ -117,8 +131,17 @@ const flowWith = (node: Record) => ({ * The executor's own return value is captured by wrapping the executor * `registerWaitNode` publishes — the value recorded is the one the ENGINE * received from a genuine run, never a second invocation staged by the test. + * + * `stripBlockAfterRegistration` is how a BLOCK-LESS node reaches `execute` now + * that the contract refuses it: `registerFlow` parses, so the only documents + * that can still arrive without the block are STORED ones that reached the + * executor by a path which did not re-parse them. Removing the block from the + * registered (already parsed) flow is that document, staged at the one seam + * where it is reproducible — and it keeps the ENGINE in the loop, so the run's + * status, its suspension ledger and its log stream are all still real readings + * rather than a direct call to `execute`. */ -async function runWaitNode(node: Record) { +async function runWaitNode(node: Record, stripBlockAfterRegistration = false) { const logs: LogLine[] = []; const ran: string[] = []; const engine = new AutomationEngine(recordingLogger(logs)); @@ -142,6 +165,13 @@ async function runWaitNode(node: Record) { delete (engine as unknown as Record).registerNodeExecutor; engine.registerFlow('f', flowWith(node)); + if (stripBlockAfterRegistration) { + const flows = (engine as unknown as { flows: Map> }> }).flows; + const stored = flows.get('f')!; + const target = stored.nodes.find((n) => n.id === node.id)!; + delete target.waitEventConfig; + expect(target.waitEventConfig, 'the staged document really has no block').toBeUndefined(); + } // Production seals the vocabulary at `kernel:bootstrapped` // (`AutomationServicePlugin`); sealing here keeps the engine's own // "never sealed" warning out of the window, so a log line seen during the run @@ -181,104 +211,128 @@ async function runUnexecutableNode(node: Record) { const nodeStatus = (result: AutomationResult, nodeId: string) => result.summary?.nodes?.find((n) => n.nodeId === nodeId)?.status; +/** The declared block a `wait` node must now carry to parse at all. */ +const TIMER_BLOCK = { eventType: 'timer', timerDuration: 'PT1H' } as const; + /** - * The premise, pinned: the documents measured below are ones an author can - * really save. Without this leg the readings are untethered — if the spec ever - * starts refusing a block-less node, this whole file characterizes a document - * that can no longer exist, and its reader must be told that rather than left - * reading run-time behaviour for an unreachable input. + * ⛔ REVERSED. This block used to assert that the parse contract ACCEPTS a node + * with no config block — it was the premise leg, there so a reader could tell + * "measured behaviour of a saveable document" from "measured behaviour of an + * unreachable input". The document is no longer saveable, and that IS the fix, + * so the leg now pins the refusal in the same position. */ -describe('premise (#17843) — the parse contract ACCEPTS a node with no config block', () => { +describe('premise — the parse contract REFUSES a node with no config block', () => { const parse = (node: Record) => FlowNodeSchema.safeParse(node); - it('accepts a `wait` node with no `waitEventConfig` at all, and refuses one whose block omits `eventType`', () => { - expect(parse({ id: 'pause', type: 'wait', label: 'Wait' }).success).toBe(true); - // The boundary the measurement turns on: "omitted key inside a present - // block" and "block absent" are different documents with different verdicts. + it('refuses a `wait` node with no `waitEventConfig` at all, as it already refused one whose block omits `eventType`', () => { + const bare = parse({ id: 'pause', type: 'wait', label: 'Wait' }); + expect(bare.success).toBe(false); + expect(bare.error!.issues.map((i) => i.path.join('.'))).toContain('waitEventConfig'); + // The boundary the OLD measurement turned on — "omitted key inside a present + // block" vs "block absent" — has closed: two documents, ONE verdict now. expect(parse({ id: 'pause', type: 'wait', label: 'Wait', waitEventConfig: {} }).success).toBe(false); + // CONTROL — the declared node still parses, so the refusals above are the + // missing contract and not a schema that stopped accepting `wait` at all. + expect(parse({ id: 'pause', type: 'wait', label: 'Wait', waitEventConfig: TIMER_BLOCK }).success).toBe(true); }); - it('accepts a `boundary_event` node with no `boundaryConfig` at all', () => { - expect(parse({ id: 'b', type: 'boundary_event', label: 'Boundary' }).success).toBe(true); + it('refuses a `boundary_event` node with no `boundaryConfig` at all', () => { + const bare = parse({ id: 'b', type: 'boundary_event', label: 'Boundary' }); + expect(bare.success).toBe(false); + expect(bare.error!.issues.map((i) => i.path.join('.'))).toContain('boundaryConfig'); }); }); -describe('characterization (#17843) — a `wait` node with NO config block at all · recorded, NOT endorsed', () => { - it('defaults to a timer, arms nothing, writes no deadline and says nothing — and the run parks there', async () => { - const m = await runWaitNode({ id: 'pause', type: 'wait', label: 'Wait' }); +describe('a STORED `wait` node that reaches execute with no config block · the reversal', () => { + it('fails the run with a named, LOGGED refusal — never a silent suspension reporting success', async () => { + const m = await runWaitNode({ id: 'pause', type: 'wait', label: 'Wait', waitEventConfig: TIMER_BLOCK }, true); // The run really reached the node and really stopped at it. expect(m.ran, 'the run must have reached the wait node').toEqual(['before']); - expect(m.result.status).toBe('paused'); - expect(m.result.success).toBe(true); - expect(m.suspended).toHaveLength(1); - - // ① The executor's return value, verbatim. ⚠️ `output` is a PRESENT key - // carrying `undefined` — not an absent one (`toStrictEqual`, because a - // plain `toEqual` cannot tell those two apart, and a JSON dump of this - // object drops the key entirely and reads as the second). - expect(m.returned).toStrictEqual({ - success: true, suspend: true, correlation: 'timer:pause', output: undefined, - }); - expect(m.returned?.output, 'nothing to write: no deadline was computed').toBeUndefined(); - // ② No wake-up job was scheduled, though a job service WAS available — - // which is what makes the silence below unconditional rather than a - // consequence of a job-less host. + // ① ⭐ The whole reversal, on the run's own verdict. + expect(m.result.success).toBe(false); + expect(m.result.status).toBe('failed'); + expect(nodeStatus(m.result, 'pause')).toBe('failure'); + expect(m.result.status).not.toBe('paused'); + + // ② The executor's return value: a guard refusal, so a `fault` edge cannot + // route a metadata defect into a handler that then reports success. + expect(m.returned?.success).toBe(false); + expect(m.returned?.errorClass).toBe('guard'); + expect(m.returned?.suspend).toBeUndefined(); + expect(m.returned?.error).toContain('waitEventConfig'); + expect(m.returned?.error).toContain('pause'); + + // ③ Nothing was parked: the suspension ledger and the durable store are both + // empty, where the old behaviour left one entry in each. + expect(m.suspended).toEqual([]); + expect(m.stored).toEqual([]); expect(m.scheduled).toEqual([]); - // ③ No `waitUntil` is written, so a later cold boot's re-arm pass - // (`rearmSuspendedWaitTimers`) skips this run as "not a timer wait". - const vars = (m.stored[0]?.variables ?? {}) as Record; - expect(Object.keys(vars).filter((k) => k.endsWith('.waitUntil'))).toEqual([]); - - // ④ ⭐ Not one log line — no `warn`, no `error`, nothing at any level. - expect(m.logsDuringRun, 'the node emits nothing an operator could see').toEqual([]); - - // ⇒ the correlation is a bare `timer:`, which arms nothing and which - // `onSuspensionReleased` deliberately does not treat as a job name. The - // only exit from this pause is an external `resume(runId)`. - expect(m.suspended[0]).toMatchObject({ nodeId: 'pause', correlation: 'timer:pause' }); + // ④ ⭐ The silence is gone. The old reading here was `[]` — not one line at + // any level — and it is what made the hang unobservable. + expect(m.logsDuringRun.length).toBeGreaterThan(0); + const named = m.logsDuringRun.find((l) => l.level === 'warn' && l.text.includes("node 'pause'")); + expect(named, 'the refusal names the node in the log, not only in the step record').toBeDefined(); + expect(named!.text).toContain('waitEventConfig'); + // The remedy travels with the complaint — an operator reading only this line + // can fix the flow from it. + expect(named!.text).toContain("eventType: 'timer'"); }); - it('CONTROL — the same node WITH `eventType: timer` + `timerDuration` behaves differently on every channel', async () => { - const control = await runWaitNode({ - id: 'pause', type: 'wait', label: 'Wait', - waitEventConfig: { eventType: 'timer', timerDuration: 'PT1H' }, - }); - const absent = await runWaitNode({ id: 'pause', type: 'wait', label: 'Wait' }); + it('CONTROL — the same flow, block INTACT, still suspends and arms its timer', async () => { + const control = await runWaitNode({ id: 'pause', type: 'wait', label: 'Wait', waitEventConfig: TIMER_BLOCK }); - // A wake-up job IS armed, one shot, ~1h out. + // A wake-up job IS armed, one shot, ~1h out… expect(control.scheduled).toHaveLength(1); expect(control.scheduled[0].schedule.type).toBe('once'); + // …the deadline IS persisted, under the key the re-arm pass reads… + const vars = (control.stored[0]?.variables ?? {}) as Record; + expect(typeof vars['pause.waitUntil']).toBe('string'); + expect(control.returned?.output).toEqual({ waitUntil: vars['pause.waitUntil'] }); + // …and the run parks, successfully, exactly as before this change. + expect(control.result.status).toBe('paused'); + expect(control.result.success).toBe(true); + expect(control.suspended).toHaveLength(1); + + // ⇒ the instrument discriminates: every channel that reads non-zero here + // reads the opposite above, so the failure above is the missing block and + // not a harness that fails everything. + }); - // …and the deadline IS persisted, under the key the re-arm pass reads. - const controlVars = (control.stored[0]?.variables ?? {}) as Record; - expect(typeof controlVars['pause.waitUntil']).toBe('string'); - expect(control.returned?.output).toEqual({ waitUntil: controlVars['pause.waitUntil'] }); - - // The correlation is the JOB's name here, the inert `timer:` there. - expect(control.returned?.correlation).toBe(control.scheduled[0].name); - expect(control.returned?.correlation).not.toBe(absent.returned?.correlation); - - // ⇒ the instrument discriminates: every channel that read zero above reads - // non-zero here, so the zeros are a reading of the absent-config path and - // not of a harness that measures nothing. - expect([absent.scheduled.length, control.scheduled.length]).toEqual([0, 1]); - expect([ - Object.keys((absent.stored[0]?.variables ?? {}) as Record).some((k) => k.endsWith('.waitUntil')), - Object.keys(controlVars).some((k) => k.endsWith('.waitUntil')), - ]).toEqual([false, true]); - - // Both halves park the run, so "paused" is the one thing that does NOT - // discriminate — recorded so a reader does not mistake it for a signal. - expect([absent.result.status, control.result.status]).toEqual(['paused', 'paused']); + it('a legitimate pause still emits no run-level summary line — deliberately unchanged', async () => { + const control = await runWaitNode({ id: 'pause', type: 'wait', label: 'Wait', waitEventConfig: TIMER_BLOCK }); + // `paused` is not terminal, so the #4354 summary is not owed. Recorded so a + // later reader does not mistake this silence for the one that was fixed: + // the defect was a node that could NEVER wake saying nothing. + expect(control.logsDuringRun.some((l) => l.text.includes('[automation] run'))).toBe(false); + }); + + it('the timer branch leaves `output` ABSENT when it computed no deadline', async () => { + // A signal wait never computes one — the narrowest node that still reaches + // a `return` with nothing to write. `toStrictEqual`, because a plain + // `toEqual` cannot tell an absent key from one holding `undefined`, and the + // old return carried the second (a JSON dump of it reads as the first, + // which is how it went unnoticed). + const m = await runWaitNode({ + id: 'pause', type: 'wait', label: 'Wait', + waitEventConfig: { eventType: 'signal', signalName: 'order_paid' }, + }); + expect(m.returned).toStrictEqual({ success: true, suspend: true, correlation: 'order_paid' }); + expect(Object.keys(m.returned!)).not.toContain('output'); }); }); -describe('characterization (#17843) — a `boundary_event` node · a DIFFERENT branch from `wait`, measured separately', () => { +describe('characterization — a `boundary_event` node · a DIFFERENT branch from `wait`, measured separately', () => { + // ⛔ The fixtures below gained their `boundaryConfig`: a bare boundary node no + // longer registers. What they measure is unchanged, and the second case is + // the proof — the block is never consulted, so requiring it at the parse + // door moved nothing at the execute door. + const BOUNDARY_BLOCK = { attachedToNodeId: 'before', eventType: 'error' } as const; + it('fails the run loudly with NO_EXECUTOR — nothing is registered for the type, silent suspension never enters it', async () => { - const m = await runUnexecutableNode({ id: 'b', type: 'boundary_event', label: 'Boundary' }); + const m = await runUnexecutableNode({ id: 'b', type: 'boundary_event', label: 'Boundary', boundaryConfig: BOUNDARY_BLOCK }); // The premise: the platform ships no `boundary_event` executor. expect(m.registeredTypes).not.toContain('boundary_event'); @@ -286,7 +340,7 @@ describe('characterization (#17843) — a `boundary_event` node · a DIFFERENT b // The run reached the node (`before` ran) and did NOT get past it. expect(m.ran).toEqual(['before']); - // ⭐ Loud, not silent — the opposite of the `wait` half above. + // ⭐ Loud, not silent — which is why this type needed no executor change. expect(m.result.success).toBe(false); expect(m.result.status).toBe('failed'); expect(m.result.error).toBe("No executor registered for node type 'boundary_event'"); @@ -309,9 +363,9 @@ describe('characterization (#17843) — a `boundary_event` node · a DIFFERENT b expect(populated.result.success).toBe(false); expect(populated.result.error).toBe("No executor registered for node type 'boundary_event'"); expect(populated.ran).toEqual(['before']); - // ⇒ presence or absence of the block changes NOTHING here: the dispatch - // fails before any executor could read it. Which is exactly why the - // `wait` reading could not have been extrapolated onto this type. + // ⇒ a minimal block and a full one fail identically: the dispatch fails + // before any executor could read either. Which is exactly why the `wait` + // reading could not have been extrapolated onto this type. }); it('CONTROL — the identical flow with a REGISTERED type in that slot runs to completion', async () => { diff --git a/packages/services/service-automation/src/builtin/wait-node.test.ts b/packages/services/service-automation/src/builtin/wait-node.test.ts index 63e51a7f6b2..f06c2923de0 100644 --- a/packages/services/service-automation/src/builtin/wait-node.test.ts +++ b/packages/services/service-automation/src/builtin/wait-node.test.ts @@ -332,9 +332,15 @@ describe('wait timer teardown when the pause ends another way (#5512)', () => { it('cancels nothing for a timer wait that armed no job (no parseable duration)', async () => { const { ctx, scheduled, cancelled } = fakeJobCtx(); registerWaitNode(engine, ctx); - // No `timerDuration` ⇒ no deadline ⇒ nothing scheduled; the pause carries - // the degraded `timer:` correlation instead of a job name. - engine.registerFlow('wait_flow', waitFlow({ eventType: 'timer' })); + // An UNPARSEABLE `timerDuration` ⇒ no deadline ⇒ nothing scheduled; the + // pause carries the degraded `timer:` correlation instead of a job + // name. This case used to be spelled `{ eventType: 'timer' }` with the key + // ABSENT, which the contract now refuses at parse — so the fixture moved to + // the shape that still reaches this branch. ⚠️ That it still reaches it is a + // residual: the contract can require the key but cannot evaluate the string, + // so a malformed duration reproduces the old silent park. Filed separately; + // what this test is about is the TEARDOWN, and that is unchanged. + engine.registerFlow('wait_flow', waitFlow({ eventType: 'timer', timerDuration: 'not-a-duration' })); const paused = await engine.execute('wait_flow'); expect(scheduled).toEqual([]); From f4825990e497e8913a5aab0c7339e12ab1acc533 Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 14 Sep 2026 05:10:01 +0000 Subject: [PATCH 4/6] test(approvals): the legacy revise-window fixture declares its wait contract MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit "Bare" in that case names the node TYPE — a plain `wait` where the revise window must be an `approval_revise` node. Without a `waitEventConfig` the flow no longer registers at all, so the send-back refusal it measures would have been measuring a flow that does not exist. Claude-Session: https://claude.ai/code/session_014DBGjJFyndTj766aReCL2g Co-authored-by: Claude --- .../plugin-approvals/src/approval-revise.test.ts | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/packages/plugins/plugin-approvals/src/approval-revise.test.ts b/packages/plugins/plugin-approvals/src/approval-revise.test.ts index 7f0cdf6518b..f93013dc690 100644 --- a/packages/plugins/plugin-approvals/src/approval-revise.test.ts +++ b/packages/plugins/plugin-approvals/src/approval-revise.test.ts @@ -702,8 +702,17 @@ describe('Send back for revision (ADR-0044)', () => { nodes: [ { id: 'start', type: 'start', label: 'Start' }, { id: 'review', type: 'approval', label: 'Review', config: { approvers: [{ type: 'user', value: 'u1' }] } }, - // The shape ADR-0044 D3 originally prescribed. - { id: 'wait_revision', type: 'wait', label: 'Awaiting Revision' }, + // The shape ADR-0044 D3 originally prescribed. "Bare" here means the + // node TYPE — a plain `wait` where the revise window must be an + // `approval_revise` node — and that is what this case is about. The + // `waitEventConfig` is not optional decoration: a `wait` node with no + // block stopped parsing when the contract began requiring it, so + // without this the flow never registers and the send-back refusal + // below would be measuring a flow that does not exist. + { + id: 'wait_revision', type: 'wait', label: 'Awaiting Revision', + waitEventConfig: { eventType: 'signal', signalName: 'revision_submitted' }, + }, { id: 'end', type: 'end', label: 'End' }, ], edges: [ From 14cb2a66b37baba0150e5784ab6376e553a6664d Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 14 Sep 2026 10:28:09 +0000 Subject: [PATCH 5/6] =?UTF-8?q?test(automation):=20the=20timerDuration=20r?= =?UTF-8?q?esidual=20is=20unfiled=20=E2=80=94=20say=20so=20in=20the=20fixt?= =?UTF-8?q?ure?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The teardown fixture's comment claimed the malformed-duration residual was "Filed separately". No card exists for it: the contract can require `timerDuration` but cannot evaluate the string, so `parseIsoDuration` returns `undefined` for a malformed or zero-valued one exactly as it did for the absent key, and the run parks forever reporting success. The fixture is its repro, and the PR's acceptance notes carry it for triage to file — a comment that asserts a filing nobody made is worse than no comment, because the next reader stops looking. Claude-Session: https://claude.ai/code/session_01KB5PFtxuy1x3dcR5gxudx6 Co-authored-by: Claude --- .../service-automation/src/builtin/wait-node.test.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/packages/services/service-automation/src/builtin/wait-node.test.ts b/packages/services/service-automation/src/builtin/wait-node.test.ts index f06c2923de0..2857b72bb42 100644 --- a/packages/services/service-automation/src/builtin/wait-node.test.ts +++ b/packages/services/service-automation/src/builtin/wait-node.test.ts @@ -338,8 +338,12 @@ describe('wait timer teardown when the pause ends another way (#5512)', () => { // ABSENT, which the contract now refuses at parse — so the fixture moved to // the shape that still reaches this branch. ⚠️ That it still reaches it is a // residual: the contract can require the key but cannot evaluate the string, - // so a malformed duration reproduces the old silent park. Filed separately; - // what this test is about is the TEARDOWN, and that is unchanged. + // so a malformed (or zero-valued) duration reproduces the old silent park — + // `parseIsoDuration` returns `undefined` for it exactly as it did for the + // absent key. ⚠️ NO card exists for that yet: it is reported in this PR's + // acceptance notes for triage to file, and THIS fixture is its repro. ⛔ Do + // not read the line above as a filing. What this test is about is the + // TEARDOWN, and that is unchanged. engine.registerFlow('wait_flow', waitFlow({ eventType: 'timer', timerDuration: 'not-a-duration' })); const paused = await engine.execute('wait_flow'); From 86247faf3598308ec3fc44585cb4d5a3d0172da0 Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 14 Sep 2026 11:15:18 +0000 Subject: [PATCH 6/6] =?UTF-8?q?docs(spec):=20say=20where=20the=20wait/boun?= =?UTF-8?q?dary=20refusal=20actually=20bites=20=E2=80=94=20prose=20only?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Review round on the draft PR caught a FALSE sentence this branch shipped on a published surface. `packages/spec` lists `src/**/*.zod.ts` in its `files[]`, so the docblock ships to npm verbatim. - `requireTypeScopedConfig` claimed the refusal ran "at the NODE level, so a `wait` nested in an ADR-0031 region is checked exactly like a top-level one". It does not. `parseFlowNodeRegions` leaves a refused region RAW, so `FlowSchema.safeParse` of a flow whose `loop` body holds a block-less `wait` answers `true`; the REGION contract refuses it at `body.nodes[i].waitEventConfig`. This branch's own test pinned that all along and the docblock contradicted it. Rewritten to say which door, and when. - The same false clause sat in `parseEndNodeConfig`'s docblock (predates this branch, same file, same sentence, same mechanism). Measured rather than assumed: a top-level `end` carrying `{ outcome: 'refused' }` and no `message` is refused by `FlowNodeSchema`, the identical node nested in a `loop` body passes `FlowSchema` and is refused only by `LoopConfigSchema` at `body.nodes.0.config.message`. Corrected in place and cross-referenced to the one explanation, so the two cannot drift. - The `timerDuration` refinement sits on the BLOCK and is not gated on `type: 'wait'` — measured: a `start` node spelled `waitEventConfig: { eventType: 'timer' }` is refused at head and parses on main, with both controls green. The changeset, the ADR-0087 entry and the refinement's own comment now say so instead of reading as wait-only. ⛔ No behaviour change: every changed line in the three `.ts` files is a comment or a prose string literal, and `registry.ts` is the regenerated mirror of the entry. The accept set is untouched. Claude-Session: https://claude.ai/code/session_01KB5PFtxuy1x3dcR5gxudx6 Co-authored-by: Claude --- .changeset/17928-wait-node-config-required.md | 8 ++- packages/spec/src/automation/flow.zod.ts | 61 +++++++++++++++---- .../18.wait-node-event-config-required.ts | 7 ++- packages/spec/src/migrations/registry.ts | 7 ++- 4 files changed, 67 insertions(+), 16 deletions(-) diff --git a/.changeset/17928-wait-node-config-required.md b/.changeset/17928-wait-node-config-required.md index de5398ca466..2875308afe1 100644 --- a/.changeset/17928-wait-node-config-required.md +++ b/.changeset/17928-wait-node-config-required.md @@ -7,7 +7,13 @@ fix(automation): a `wait` node must say what resumes it — the config block is **BREAKING** — a `type: 'wait'` flow node with no `waitEventConfig` block, and a `type: 'boundary_event'` node with no `boundaryConfig` block, no longer parse. -Under `eventType: 'timer'`, `timerDuration` is now required and may not be blank. +Under `eventType: 'timer'`, `timerDuration` is now required and may not be blank +— and that half sits on the `waitEventConfig` BLOCK, not on the node type, so it +bites on ANY node carrying the block: a `start` node spelled +`waitEventConfig: { eventType: 'timer' }` parsed before and is refused now. It is +still a narrowing in every direction (no shape starts parsing that did not), and +the block is inert on a node type no executor reads it from, so the practical +reach is `wait`. `eventType` has been required *inside* each block since protocol 17, so `waitEventConfig: {}` was already a loud parse error. The block itself was diff --git a/packages/spec/src/automation/flow.zod.ts b/packages/spec/src/automation/flow.zod.ts index 1b6032a87dc..553694a19a0 100644 --- a/packages/spec/src/automation/flow.zod.ts +++ b/packages/spec/src/automation/flow.zod.ts @@ -278,12 +278,28 @@ export const FlowNodeSchema = lazySchema(() => flowNodeObject().transform( * * ## Where the refusal lands * - * At the NODE level, so a `wait` nested in an ADR-0031 region is checked exactly - * like a top-level one, and next to {@link parseEndNodeConfig} because both - * answer the same question — "this node type owes a block the outer shape - * cannot demand". Issues are raised under the block's own key, so a flow-level - * parse reports them at `nodes[i].waitEventConfig`, the address `formatZodError` - * prints for any other node key. + * On the NODE contract, next to {@link parseEndNodeConfig} because both answer + * the same question — "this node type owes a block the outer shape cannot + * demand". Issues are raised under the block's own key, so a flow-level parse + * reports a TOP-LEVEL node at `nodes[i].waitEventConfig`, the address + * `formatZodError` prints for any other node key. + * + * ⚠️ A node nested in an ADR-0031 REGION BODY is refused at a different door, at + * a different time — ⛔ it is NOT "checked exactly like a top-level one", and + * saying so on a published surface would be false. {@link parseFlowNodeRegions} + * parses each region slot with `safeParse` and, on a refusal, leaves that region + * RAW and continues (its own comment says so: a refused region is left for + * `validateControlFlow` to name). That policy predates this change and is not + * specific to `waitEventConfig`, and the consequence is measurable: + * `FlowSchema.safeParse` of a flow whose `loop` body holds a block-less `wait` + * answers `success: true`. What refuses the nested node is the REGION contract — + * `LoopConfigSchema` / `ParallelConfigSchema` / `TryCatchConfigSchema` — at + * `body.nodes[i].waitEventConfig`, which is the same contract the container + * node's executor parses its config through at execute time, so the nested shape + * still cannot RUN; it is refused one door later and by node id. Both halves are + * pinned in `flow.test.ts` ("nested in a region: the flow parse leaves it raw, + * and the REGION contract refuses it by path"), and the ADR-0087 entry's + * `acceptanceCriteria` states the same thing for whoever migrates a stack. * * ⚠️ `boundary_event` gets the contract half ONLY: the platform registers no * executor for that type at all (`NO_EXECUTOR` plus a startup `warn`, measured @@ -339,17 +355,29 @@ function requireTypeScopedConfig(node: T, ctx: z.RefinementCtx): T { if (node.type !== 'end' || node.config === undefined) return node; @@ -600,6 +628,13 @@ function flowNodeObject() { return strictObject( // (or of any whitespace) yields no duration at all, so accepting it here // would leave one byte of difference between the shape this refuses and a // shape that hangs identically. + // + // ⚠️ SCOPE: this refinement lives on the BLOCK, so it is NOT gated on + // `type: 'wait'` — any node type carrying a `waitEventConfig` is held to it, + // and a `start` node spelled `waitEventConfig: { eventType: 'timer' }` + // parsed before this change and is refused after it. That is deliberate and + // it only ever narrows; ⛔ do not "fix" it by gating on the node type, which + // would re-admit the duration-less timer wherever the key is spelled. if (wec.eventType === 'timer' && (wec.timerDuration ?? '').trim() === '') { ctx.addIssue({ code: 'custom', diff --git a/packages/spec/src/migrations/entries/semantic/18.wait-node-event-config-required.ts b/packages/spec/src/migrations/entries/semantic/18.wait-node-event-config-required.ts index b118f93a6a3..bbb443e229f 100644 --- a/packages/spec/src/migrations/entries/semantic/18.wait-node-event-config-required.ts +++ b/packages/spec/src/migrations/entries/semantic/18.wait-node-event-config-required.ts @@ -11,7 +11,12 @@ export const entry: SemanticMigration = { + 'contract already refused `waitEventConfig: {}`; what it also accepted was the block ' + 'missing entirely, which is the state a freshly created node is in. Two documents, two ' + 'verdicts, and the accepted one was the silent one. Also narrowed one level down: under ' - + '`eventType: \'timer\'`, `timerDuration` is now required and may not be blank.', + + '`eventType: \'timer\'`, `timerDuration` is now required and may not be blank. ⚠️ That ' + + 'second narrowing sits on the BLOCK and is NOT gated on `type: \'wait\'`, so it reaches ' + + 'any node type that carries a `waitEventConfig` at all — a `start` node spelled ' + + '`waitEventConfig: { eventType: \'timer\' }` parsed before and is refused now. Inert in ' + + 'practice, because no executor but the wait one reads the block, but a stack that spells ' + + 'it elsewhere must be edited too, so scan for the KEY and not only for the node type.', replacement: 'Declare what resumes the node, on the node: `waitEventConfig: { eventType: \'timer\', ' + 'timerDuration: \'PT1H\' }` for a delay — QUOTE a bare number, the key is a string and a ' diff --git a/packages/spec/src/migrations/registry.ts b/packages/spec/src/migrations/registry.ts index 614487c23c5..7bae5089968 100644 --- a/packages/spec/src/migrations/registry.ts +++ b/packages/spec/src/migrations/registry.ts @@ -11531,7 +11531,12 @@ const step18: MigrationStep = { + 'contract already refused `waitEventConfig: {}`; what it also accepted was the block ' + 'missing entirely, which is the state a freshly created node is in. Two documents, two ' + 'verdicts, and the accepted one was the silent one. Also narrowed one level down: under ' - + '`eventType: \'timer\'`, `timerDuration` is now required and may not be blank.', + + '`eventType: \'timer\'`, `timerDuration` is now required and may not be blank. ⚠️ That ' + + 'second narrowing sits on the BLOCK and is NOT gated on `type: \'wait\'`, so it reaches ' + + 'any node type that carries a `waitEventConfig` at all — a `start` node spelled ' + + '`waitEventConfig: { eventType: \'timer\' }` parsed before and is refused now. Inert in ' + + 'practice, because no executor but the wait one reads the block, but a stack that spells ' + + 'it elsewhere must be edited too, so scan for the KEY and not only for the node type.', replacement: 'Declare what resumes the node, on the node: `waitEventConfig: { eventType: \'timer\', ' + 'timerDuration: \'PT1H\' }` for a delay — QUOTE a bare number, the key is a string and a '