From 334d569405ab1c8724fbd687ec68e286078b9a62 Mon Sep 17 00:00:00 2001 From: Claude Date: Sat, 14 Nov 2026 16:40:44 +0000 Subject: [PATCH 1/2] feat(spec): declare warnings and droppedFields on ExecutionStepLogSchema The run-history routes serve each step the engine wrote, and the engine writes both members on a step that ran; the published step-log schema now names them (optional; strings, and the data engine's own drop event). The engine copies them onto the step only in that declared shape, so a host executor's malformed value is no longer persisted and served as-is. Claude-Session: https://claude.ai/code/session_01FEkQ5ps2JcdASVedaYorBN Co-Authored-By: Claude --- .../service-automation/src/dag-traversal.ts | 49 ++++++++-- .../src/run-dropped-fields.test.ts | 93 ++++++++++++++++++- .../spec/src/automation/execution.test.ts | 57 ++++++++++++ packages/spec/src/automation/execution.zod.ts | 12 +++ 4 files changed, 204 insertions(+), 7 deletions(-) diff --git a/packages/services/service-automation/src/dag-traversal.ts b/packages/services/service-automation/src/dag-traversal.ts index aca7bf1a896..93aab66eda9 100644 --- a/packages/services/service-automation/src/dag-traversal.ts +++ b/packages/services/service-automation/src/dag-traversal.ts @@ -41,6 +41,7 @@ import { type StepLogEntry, } from './engine.js'; import { createEvalUser, type EvalUserParsed } from '@objectstack/spec/identity'; +import { DroppedFieldsEventSchema, type DroppedFieldsEvent } from '@objectstack/spec/data'; import { structuralConditionRefusal } from '@objectstack/spec/automation'; // [#15137] The `value`-role half of the ledger. Both halves of "is this envelope // well-formed?" are IMPORTED, never re-spelled here: the shape rule is @@ -98,6 +99,41 @@ export function runUserOf(context: AutomationContext | undefined): EvalUserParse }); } +/** + * The step-log copy of an executor's advisory members, in exactly the shape + * `ExecutionStepLogSchema` declares for them. The step is persisted with the + * run and served verbatim by the run-history routes, so what reaches it is + * what a reader of the run is handed: a host-registered executor's malformed + * value must not be copied onto it as-is (a truthy `length` is not a list of + * drop events). + * + * `droppedFields` keeps each element that is a well-typed + * `DroppedFieldsEventSchema` event and skips the rest: the same per-element + * filter the run's terminal answer applies when it folds the step log + * (`foldDropEvents`), so the step and the answer can never disagree about + * which events were real. `warnings` keeps its string entries. A member with + * nothing well-typed left is omitted, never `[]`. Total, never throwing: it + * runs inside the step's `try`, where a throw would read as a node failure. + */ +function stepAdvisoriesOf(result: NodeExecutionResult): { warnings?: string[]; droppedFields?: DroppedFieldsEvent[] } { + const out: { warnings?: string[]; droppedFields?: DroppedFieldsEvent[] } = {}; + const rawWarnings: unknown = result.warnings; + if (Array.isArray(rawWarnings)) { + const warnings = rawWarnings.filter((w): w is string => typeof w === 'string'); + if (warnings.length > 0) out.warnings = warnings; + } + const rawDrops: unknown = result.droppedFields; + if (Array.isArray(rawDrops)) { + const droppedFields: DroppedFieldsEvent[] = []; + for (const raw of rawDrops) { + const parsed = DroppedFieldsEventSchema.safeParse(raw); + if (parsed.success) droppedFields.push(parsed.data); + } + if (droppedFields.length > 0) out.droppedFields = droppedFields; + } + return out; +} + /** * Does this `decision` take EVERY out-edge whose condition holds (#15429)? * Only an explicit `config.mode: 'inclusive'` says so; an omitted `mode` and @@ -414,8 +450,8 @@ export async function executeNode( completedAt: new Date().toISOString(), durationMs: Date.now() - stepStart, error: { code: 'NODE_FAILURE', message: errMsg }, - ...(result.warnings?.length ? { warnings: result.warnings } : {}), - ...(result.droppedFields?.length ? { droppedFields: result.droppedFields } : {}), + // In the declared step-log shape only (`stepAdvisoriesOf`). + ...stepAdvisoriesOf(result), // #4354 — a node that failed PART WAY may still have written // rows; dropping its counts would understate what the run did. ...(result.metrics ? { metrics: result.metrics } : {}), @@ -495,10 +531,11 @@ export async function executeNode( startedAt: stepStartedAt, completedAt: new Date().toISOString(), durationMs: Date.now() - stepStart, - ...(result.warnings?.length ? { warnings: result.warnings } : {}), - // #32861 — the structured events behind those warnings, folded - // onto the run's terminal answer (`dropEventsOf`). - ...(result.droppedFields?.length ? { droppedFields: result.droppedFields } : {}), + // #32861 — `droppedFields`, the structured events behind those + // warnings, is folded onto the run's terminal answer + // (`dropEventsOf`). Both members are copied in the declared + // step-log shape only (`stepAdvisoriesOf`). + ...stepAdvisoriesOf(result), ...(result.metrics ? { metrics: result.metrics } : {}), }); diff --git a/packages/services/service-automation/src/run-dropped-fields.test.ts b/packages/services/service-automation/src/run-dropped-fields.test.ts index b510f64e40f..bf15c3a1a68 100644 --- a/packages/services/service-automation/src/run-dropped-fields.test.ts +++ b/packages/services/service-automation/src/run-dropped-fields.test.ts @@ -15,7 +15,7 @@ */ import { describe, it, expect } from 'vitest'; import type { AutomationContext } from '@objectstack/spec/contracts'; -import { defineActionDescriptor } from '@objectstack/spec/automation'; +import { defineActionDescriptor, ExecutionStepLogSchema } from '@objectstack/spec/automation'; import { AutomationEngine } from './engine.js'; import type { NodeExecutor, StepLogEntry } from './engine.js'; import { InMemorySuspendedRunStore } from './suspended-run-store.js'; @@ -473,6 +473,97 @@ describe('delegated writes roll their drops up onto the parent\'s answer (#33019 }); }); +// The step itself is persisted with the run and served verbatim by the +// run-history routes, so it must carry `warnings` / `droppedFields` only in the +// shape `ExecutionStepLogSchema` declares — the same per-element filter the +// answer's fold applies, so step and answer agree about which events were real. +describe('the step log carries the advisory members only in the declared shape', () => { + const SLOPPY_DROPS = [ + null, + 'status', + { object: 'expense_report', fields: 'status', reason: 'readonly' }, + { object: 'expense_report', fields: ['status'], reason: 'no_such_reason' }, + { object: 'expense_line', fields: ['amount'], reason: 'readonly' }, + ]; + const stepOf = async (engine: AutomationEngine, flow: string, nodeId: string) => { + const [run] = await engine.listRuns(flow); + return run.steps.find((s) => s.nodeId === nodeId)!; + }; + + it('a host executor\'s malformed elements are not copied onto its success step; the well-typed ones are, and the step parses', async () => { + const engine = makeEngine(); + engine.registerNodeExecutor({ + type: 'sloppy_write', + async execute() { + return { success: true, warnings: ['amount was not written', 42, { text: 'x' }], droppedFields: SLOPPY_DROPS }; + }, + } as never); + engine.registerFlow('sloppy', chain('sloppy', [{ id: 'w', type: 'sloppy_write', label: 'W' }])); + + await engine.execute('sloppy', CALLER); + const step = await stepOf(engine, 'sloppy', 'w'); + + expect(step.droppedFields).toEqual([{ object: 'expense_line', fields: ['amount'], reason: 'readonly' }]); + expect(step.warnings).toEqual(['amount was not written']); + expect(ExecutionStepLogSchema.safeParse(step).success).toBe(true); + }); + + it('a failure step applies the same filter', async () => { + const engine = makeEngine(); + engine.registerNodeExecutor({ + type: 'sloppy_fail', + async execute() { + return { success: false, error: 'boom', warnings: [7], droppedFields: SLOPPY_DROPS }; + }, + } as never); + engine.registerFlow('sloppy_fail', chain('sloppy_fail', [{ id: 'f', type: 'sloppy_fail', label: 'F' }])); + + await engine.execute('sloppy_fail', CALLER); + const step = await stepOf(engine, 'sloppy_fail', 'f'); + + expect(step.status).toBe('failure'); + expect(step.droppedFields).toEqual([{ object: 'expense_line', fields: ['amount'], reason: 'readonly' }]); + expect('warnings' in step).toBe(false); + expect(ExecutionStepLogSchema.safeParse(step).success).toBe(true); + }); + + it('a value that is not a list at all (array-like, a truthy `length`) leaves neither member on the step', async () => { + const engine = makeEngine(); + engine.registerNodeExecutor({ + type: 'sloppy_write', + async execute() { + return { + success: true, + warnings: 'status was not written', + droppedFields: { length: 1, 0: { object: 'expense_report', fields: ['status'], reason: 'readonly' } }, + }; + }, + } as never); + engine.registerFlow('sloppy', chain('sloppy', [{ id: 'w', type: 'sloppy_write', label: 'W' }])); + + await engine.execute('sloppy', CALLER); + const step = await stepOf(engine, 'sloppy', 'w'); + + expect('droppedFields' in step).toBe(false); + expect('warnings' in step).toBe(false); + expect(ExecutionStepLogSchema.safeParse(step).success).toBe(true); + }); + + it('control: the in-tree write node\'s well-typed members reach its step unchanged', async () => { + const engine = makeEngine(); + engine.registerFlow('submit_for_approval', submitFlow('submit_for_approval', { status: 'submitted', note: 'please' })); + + await engine.execute('submit_for_approval', CALLER); + const [run] = await engine.listRuns('submit_for_approval'); + const step = run.steps.find((s) => s.nodeType === 'update_record')!; + + expect(step.droppedFields).toEqual([{ object: 'expense_report', fields: ['status'], reason: 'readonly' }]); + expect(step.warnings).toHaveLength(1); + expect(typeof step.warnings![0]).toBe('string'); + expect(ExecutionStepLogSchema.safeParse(step).success).toBe(true); + }); +}); + describe('dropEventsOf — the fold over the step log', () => { const AT = '2026-11-13T00:00:00.000Z'; const step = (nodeId: string, droppedFields?: Drop[]): StepLogEntry => ({ diff --git a/packages/spec/src/automation/execution.test.ts b/packages/spec/src/automation/execution.test.ts index 384b1f3897c..33e5959dad5 100644 --- a/packages/spec/src/automation/execution.test.ts +++ b/packages/spec/src/automation/execution.test.ts @@ -132,6 +132,63 @@ describe('ExecutionStepLogSchema', () => { expect(step.retryAttempt).toBe(2); }); + // The run-history routes serve the step log the engine wrote, and the + // engine writes both of these on a step that ran: the schema has to name + // them, or a reader parsing the run strips them away. + describe('warnings / droppedFields', () => { + const base = { + nodeId: 'mark_approved', + nodeType: 'update_record', + status: 'success' as const, + startedAt: '2026-02-01T10:00:00Z', + }; + const drop = { object: 'expense_report', fields: ['status'], reason: 'readonly' as const }; + + it('a step carrying both members parses and keeps them', () => { + const step = ExecutionStepLogSchema.parse({ + ...base, + warnings: ['update_record: field "status" on expense_report is readonly and was not written'], + droppedFields: [drop], + }); + expect(step.warnings).toEqual(['update_record: field "status" on expense_report is readonly and was not written']); + expect(step.droppedFields).toEqual([drop]); + }); + + it('a step without either member still parses, and neither is invented', () => { + const step = ExecutionStepLogSchema.parse(base); + expect('warnings' in step).toBe(false); + expect('droppedFields' in step).toBe(false); + }); + + it('the run log a run-history route serves keeps both members on its steps', () => { + const log = ExecutionLogSchema.parse({ + id: 'exec_drop', + flowName: 'approve_expense', + status: 'completed', + trigger: { type: 'manual' }, + steps: [{ ...base, warnings: ['w'], droppedFields: [drop] }], + startedAt: '2026-02-01T10:00:00Z', + }); + expect(log.steps[0].warnings).toEqual(['w']); + expect(log.steps[0].droppedFields).toEqual([drop]); + }); + + it('droppedFields is the data engine\'s own event: an element off that shape is refused at its path', () => { + const res = ExecutionStepLogSchema.safeParse({ + ...base, + droppedFields: [{ object: 'expense_report', fields: ['status'], reason: 'no_such_reason' }], + }); + expect(res.success).toBe(false); + expect(res.error?.issues[0].path).toEqual(['droppedFields', 0, 'reason']); + }); + + it('warnings are strings: a non-string entry is refused at its path', () => { + const res = ExecutionStepLogSchema.safeParse({ ...base, warnings: [{ message: 'w' }] }); + expect(res.success).toBe(false); + expect(res.error?.issues[0].path).toEqual(['warnings', 0]); + }); + }); + it('should accept a step log with input/output', () => { const step = ExecutionStepLogSchema.parse({ nodeId: 'transform', diff --git a/packages/spec/src/automation/execution.zod.ts b/packages/spec/src/automation/execution.zod.ts index 009ae7c25f5..eeb6fde232c 100644 --- a/packages/spec/src/automation/execution.zod.ts +++ b/packages/spec/src/automation/execution.zod.ts @@ -21,6 +21,7 @@ import { z } from 'zod'; * Tracks the lifecycle of a flow execution instance. */ import { lazySchema } from '../shared/lazy-schema'; +import { DroppedFieldsEventSchema } from '../data/data-engine.zod'; export const ExecutionStatus = z.enum([ 'pending', // Queued, not yet started 'running', // Currently executing @@ -204,6 +205,17 @@ export const ExecutionStepLogSchema = lazySchema(() => z.object({ .describe('Records this step selected / acted on — and, for a step that delegated to a child run (`subflow`, a `map` item), the failures that child contained — as reported by the node executor'), skippedBy: ExecutionStepSkipReasonSchema.optional() .describe('The gate that closed, when `status` is `skipped`'), + // What the node executor flagged about a step that still ran. Both members + // were written onto the step by the engine, persisted with the run and + // served verbatim by the run-history routes before this schema named them; + // declaring them makes the published step log say what the wire carries. + // `droppedFields` reuses the data engine's own strip event, so there is no + // second vocabulary, and it is the per-step source the run's terminal + // answer (`AutomationResult.droppedFields`) is folded from. + warnings: z.array(z.string()).optional() + .describe('Advisory warnings from the node executor. A `success` step may carry them — e.g. a write whose requested fields the data engine legally stripped — so a step that partially did not land never reads as a clean success. Absent when the executor raised none'), + droppedFields: z.array(DroppedFieldsEventSchema).optional() + .describe('The data engine\'s own drop events behind those warnings: which caller-supplied fields of which object the write did not store, and why. Absent when the step dropped nothing'), })); export type ExecutionStepLog = z.input; From e84915df95f561a7a9b57598ff75d4bd1a119d0c Mon Sep 17 00:00:00 2001 From: Claude Date: Sat, 14 Nov 2026 16:46:50 +0000 Subject: [PATCH 2/2] chore(spec): regenerate step-log references, hold the automation skill index, add changeset The new import edge from automation/execution.zod.ts to the data engine's event would have dragged five pointers into the objectstack-automation skill index; an allowlist row holds it at the pointers it already published. Claude-Session: https://claude.ai/code/session_01FEkQ5ps2JcdASVedaYorBN Co-Authored-By: Claude --- .changeset/33020-step-log-advisory-members.md | 13 ++++++++++ .../docs/references/automation/execution.mdx | 14 ++++++++++ .../spec/authorable-surface/automation.json | 2 ++ packages/spec/scripts/lib/skill-map-guards.ts | 26 +++++++++++++++++++ 4 files changed, 55 insertions(+) create mode 100644 .changeset/33020-step-log-advisory-members.md diff --git a/.changeset/33020-step-log-advisory-members.md b/.changeset/33020-step-log-advisory-members.md new file mode 100644 index 00000000000..f05fd9acb9d --- /dev/null +++ b/.changeset/33020-step-log-advisory-members.md @@ -0,0 +1,13 @@ +--- +'@objectstack/spec': minor +'@objectstack/service-automation': patch +--- + +feat(spec): a flow run's step log declares the `warnings` and `droppedFields` it already carried + +Clause-②: yes (widening) — `ExecutionStepLogSchema` (`@objectstack/spec/automation`) gains two optional members, `warnings` (strings) and `droppedFields` (an array of the data engine's own `DroppedFieldsEventSchema` event). Both reach every published schema that embeds a step log: `ExecutionLogSchema.steps`, and through it `GetRunResponseSchema` (`GET /api/v1/automation/:name/runs/:runId`) and `ListRunsResponseSchema` (the runs list). Nothing that parsed before is refused. +Metadata-protocol: added + +The engine has written both members onto a step that ran (`warnings` for a write whose requested fields the data engine legally stripped, `droppedFields` for the structured events behind those warnings), and the run-history routes serve the step as persisted. The published step-log schema named neither, so a reader that parsed a run through it stripped both and could not tell a step that partially did not land from a clean one. `droppedFields` reuses the data engine's event, so there is no second reason vocabulary. + +`@objectstack/service-automation`: the engine now copies the two members onto a step only in that declared shape. From a host-registered executor's result, a `droppedFields` element that is not a well-typed drop event is skipped (the same filter the run's terminal `droppedFields` answer already applied), and so is a warning that is not a string; a member with nothing well-typed left is omitted. Before, any value with a truthy `length` was persisted and served as it came. The in-tree write nodes produce well-typed values, so their steps are unchanged. diff --git a/content/docs/references/automation/execution.mdx b/content/docs/references/automation/execution.mdx index 03c4f370776..94adf5c74c8 100644 --- a/content/docs/references/automation/execution.mdx +++ b/content/docs/references/automation/execution.mdx @@ -147,6 +147,8 @@ const result = CheckpointSchema.parse(data); | **regionKind** | `string` | optional | Region kind the step ran in: loop-body \| parallel-branch \| try \| catch. Stays `try` / `catch` for a step inside a try/catch region nested in a loop body; the loop is reported through `iteration`. For `parallel-branch` the branch index is reported through `branch`, and the enclosing loop iteration — when the parallel node sits inside a loop body — through `iteration`. | | **metrics** | `{ selected?: integer; acted?: integer; unmeasuredEffect?: boolean; failures?: integer }` | optional | Records this step selected / acted on — and, for a step that delegated to a child run (`subflow`, a `map` item), the failures that child contained — as reported by the node executor | | **skippedBy** | `{ nodeId: string; edgeId?: string; label?: string }` | optional | The gate that closed, when `status` is `skipped` | +| **warnings** | `string[]` | optional | Advisory warnings from the node executor. A `success` step may carry them — e.g. a write whose requested fields the data engine legally stripped — so a step that partially did not land never reads as a clean success. Absent when the executor raised none | +| **droppedFields** | `{ object: string; fields: string[]; reason: Enum<'readonly' \| 'readonly_when' \| 'primary_key' \| 'computed' \| 'stored_expression'> }[]` | optional | The data engine's own drop events behind those warnings: which caller-supplied fields of which object the write did not store, and why. Absent when the step dropped nothing | ### Nested Shape: `ExecutionLog.summary` @@ -205,6 +207,8 @@ const result = CheckpointSchema.parse(data); | **regionKind** | `string` | optional | Region kind the step ran in: loop-body \| parallel-branch \| try \| catch. Stays `try` / `catch` for a step inside a try/catch region nested in a loop body; the loop is reported through `iteration`. For `parallel-branch` the branch index is reported through `branch`, and the enclosing loop iteration — when the parallel node sits inside a loop body — through `iteration`. | | **metrics** | `{ selected?: integer; acted?: integer; unmeasuredEffect?: boolean; failures?: integer }` | optional | Records this step selected / acted on — and, for a step that delegated to a child run (`subflow`, a `map` item), the failures that child contained — as reported by the node executor | | **skippedBy** | `{ nodeId: string; edgeId?: string; label?: string }` | optional | The gate that closed, when `status` is `skipped` | +| **warnings** | `string[]` | optional | Advisory warnings from the node executor. A `success` step may carry them — e.g. a write whose requested fields the data engine legally stripped — so a step that partially did not land never reads as a clean success. Absent when the executor raised none | +| **droppedFields** | `{ object: string; fields: string[]; reason: Enum<'readonly' \| 'readonly_when' \| 'primary_key' \| 'computed' \| 'stored_expression'> }[]` | optional | The data engine's own drop events behind those warnings: which caller-supplied fields of which object the write did not store, and why. Absent when the step dropped nothing | ### Nested Shape: `ExecutionStepLog.error` @@ -231,6 +235,16 @@ const result = CheckpointSchema.parse(data); | **edgeId** | `string` | optional | Edge whose condition evaluated false | | **label** | `string` | optional | Edge label, when the flow names its branches | +### Nested Shape: `ExecutionStepLog.droppedFields[number]` + +A write-path strip event: caller-supplied fields legally dropped from the payload, or written with the engine's computed value in place of the caller's + +| Property | Type | Required | Description | +| :--- | :--- | :--- | :--- | +| **object** | `string` | ✅ | Object the write targeted (resolved object name) | +| **fields** | `string[]` | ✅ | Caller-supplied field names whose value the engine did not store: removed from the write payload, or (`stored_expression`) written with the computed value in place of the caller's | +| **reason** | `Enum<'readonly' \| 'readonly_when' \| 'primary_key' \| 'computed' \| 'stored_expression'>` | ✅ | Why the fields were dropped: static readonly, a TRUE readonlyWhen predicate, the primary-key strip of a payload id the engine ruled is not an identifier, a computed (formula) field no driver has a column for, or a stored field whose declared expression the engine computes on every write, so the caller's different value was replaced by the computed one | + --- diff --git a/packages/spec/authorable-surface/automation.json b/packages/spec/authorable-surface/automation.json index c922c6f7998..4a3aac956b2 100644 --- a/packages/spec/authorable-surface/automation.json +++ b/packages/spec/authorable-surface/automation.json @@ -159,6 +159,7 @@ "automation/ExecutionLog:variables", "automation/ExecutionStepLog:branch", "automation/ExecutionStepLog:completedAt", + "automation/ExecutionStepLog:droppedFields", "automation/ExecutionStepLog:durationMs", "automation/ExecutionStepLog:error", "automation/ExecutionStepLog:input", @@ -174,6 +175,7 @@ "automation/ExecutionStepLog:skippedBy", "automation/ExecutionStepLog:startedAt", "automation/ExecutionStepLog:status", + "automation/ExecutionStepLog:warnings", "automation/ExecutionStepMetrics:acted", "automation/ExecutionStepMetrics:failures", "automation/ExecutionStepMetrics:selected", diff --git a/packages/spec/scripts/lib/skill-map-guards.ts b/packages/spec/scripts/lib/skill-map-guards.ts index 7d6188cfd43..eec53c8b7b3 100644 --- a/packages/spec/scripts/lib/skill-map-guards.ts +++ b/packages/spec/scripts/lib/skill-map-guards.ts @@ -302,6 +302,32 @@ export const TRANSITIVE_ALLOWLIST: Record = { 'shared/http.zod.ts', 'shared/suggestions.zod.ts', ], + // The closure as it stood when `automation/execution.zod.ts` (core) gained + // one import edge -- `data/data-engine.zod.ts`, for the drop events a flow + // step log carries -- that alone dragged five pointers into this index (the + // data engine, the Unified Query DSL's filter and query, the execution + // context, the access explanation) that the objectstack-automation SKILL.md + // does not teach. These are the transitive pointers the index already + // published; a new one joins by a row here, not by an import edge. + 'objectstack-automation': [ + 'automation/api-trigger-secret-ref.zod.ts', + 'automation/api-trigger-signature.zod.ts', + 'automation/control-flow.zod.ts', + 'automation/schedule-organization.zod.ts', + 'automation/schemaless-node-config.zod.ts', + 'data/context-tokens.zod.ts', + 'data/date-macros.zod.ts', + 'data/hook-body.zod.ts', + 'kernel/metadata-protection.zod.ts', + 'kernel/override-declaration.zod.ts', + 'shared/expression.zod.ts', + 'shared/identifiers.zod.ts', + 'shared/protection.zod.ts', + 'shared/retry-policy.zod.ts', + 'shared/suggestions.zod.ts', + 'shared/value-domain.zod.ts', + 'system/job.zod.ts', + ], }; /** Whether a `packages/spec/src`-relative path exists on disk; injected so the guard stays pure. */