diff --git a/.changeset/37659-screen-input-fields-wording.md b/.changeset/37659-screen-input-fields-wording.md new file mode 100644 index 00000000000..af24f82c7d7 --- /dev/null +++ b/.changeset/37659-screen-input-fields-wording.md @@ -0,0 +1,10 @@ +--- +'@objectstack/spec': patch +--- + +docs(spec): the screen-input refusal's `fields` carries one entry per finding, not one per field + +Clause-②: no +Metadata-protocol: none + +The `AutomationResult.fields` contract comment, the `TriggerFlowResponseSchema` `data.fields` description and the flows guide said a `400 INVALID_SCREEN_INPUT` refusal carries one `error.details.fields` entry per violated field. It carries one entry per finding, so one field can carry more than one entry: a value above a field's `max` but below its larger `min`, for instance, breaks both bounds. For `unknown_field`, `field` is the key the caller sent, not a declared screen field name. A runner that sizes its error display by one row per field groups the entries by `field`. The `ScreenInputIssue.code` comment now points at `error.details.fields`, where these codes travel. Text only: the response is unchanged. diff --git a/content/docs/automation/flows.mdx b/content/docs/automation/flows.mdx index 0d287366b09..a745d16ea27 100644 --- a/content/docs/automation/flows.mdx +++ b/content/docs/automation/flows.mdx @@ -1522,10 +1522,14 @@ is consumed: nothing is applied, the run stays parked, and the corrected submission still lands. The refusal also names each finding on its own, in `error.details.fields`: one -`{ field, code, message }` entry per violated field, with the field's `name` +`{ field, code, message }` entry per finding, with the field's `name` and an ADR-0114 field code (`required`, `invalid_type`, `invalid_value`, `min_value`, `max_value`, `unknown_field`), the same entries a -`VALIDATION_FAILED` carries. A client places the refusal at its fields from +`VALIDATION_FAILED` carries. One field can carry more than one entry: a value +above a field's `max` but below its larger `min`, for instance, breaks both +bounds. +For `unknown_field`, `field` is the key the caller sent, not a declared +screen field name. A client places the refusal at its fields from those, in its own language; `error.message` keeps the whole sentence, with the declared field names, for logs and API callers. The Console's flow runner marks each field it names, by the label it shows, and its banner reads a sentence of diff --git a/packages/services/service-automation/src/engine.ts b/packages/services/service-automation/src/engine.ts index a178e793a41..c3531eed817 100644 --- a/packages/services/service-automation/src/engine.ts +++ b/packages/services/service-automation/src/engine.ts @@ -9760,7 +9760,7 @@ export class AutomationEngine implements IAutomationService { error: `Invalid screen input: ${summary} — declared fields: ` + `${declared.map((n) => `'${n}'`).join(', ') || '(none)'}`, - // [#37526] The same findings, one per field, so a runner can place + // [#37526] The same findings, one entry per finding, so a runner can place // each at its field in its own language rather than show `error`, // which names the screen's declared fields for logs and API callers. fields: issues.map(({ field, code, message }) => ({ field, code, message })), diff --git a/packages/services/service-automation/src/screen-input-contract.ts b/packages/services/service-automation/src/screen-input-contract.ts index c0e8962f9cd..9255b6a0315 100644 --- a/packages/services/service-automation/src/screen-input-contract.ts +++ b/packages/services/service-automation/src/screen-input-contract.ts @@ -42,8 +42,9 @@ export interface ScreenInputIssue { * #17306 added three conditions to this surface and no code to that catalog. * * NOT an `error.code` (ADR-0112 D1). These are FIELD-ADDRESSED validator - * codes that ride inside the refusal's message; the refusal's own machine - * code is the SCREAMING `INVALID_SCREEN_INPUT` the engine returns. + * codes that ride on the refusal's `error.details.fields`, one entry per + * issue; the refusal's own machine code is the SCREAMING + * `INVALID_SCREEN_INPUT` the engine returns. */ code: FieldErrorCode; message: string; diff --git a/packages/spec/docs/references/api/automation-api.md b/packages/spec/docs/references/api/automation-api.md index d72b729096c..143fe482586 100644 --- a/packages/spec/docs/references/api/automation-api.md +++ b/packages/spec/docs/references/api/automation-api.md @@ -1223,7 +1223,7 @@ const result = AutomationApiErrorCode.parse(data); | **error** | `string` | optional | Error message if execution failed | | **durationMs** | `number` | optional | Execution duration in milliseconds | | **code** | `Enum<'PERMISSION_DENIED' \| 'INVALID_SIGNAL' \| 'RUN_NOT_FOUND' \| 'STORE_UNAVAILABLE' \| …>` | optional | Machine-readable failure classification, set alongside `error` when the caller must distinguish WHY it failed. A closed union - the members and their transport mappings are documented on the contract (`AutomationResult.code`, contracts/automation-service.ts). | -| **fields** | `{ field: string; code: Enum<'required' \| 'invalid_type' \| 'invalid_shape' \| 'unknown_field' \| …>; message: string; label?: string; … }[]` | optional | The field-addressed findings behind an `INVALID_SCREEN_INPUT` refusal, one per violated screen field: its `name`, the field-level code it broke and the engine's English line. Set with that code only. A transport serves it as `error.details.fields` | +| **fields** | `{ field: string; code: Enum<'required' \| 'invalid_type' \| 'invalid_shape' \| 'unknown_field' \| …>; message: string; label?: string; … }[]` | optional | The field-addressed findings behind an `INVALID_SCREEN_INPUT` refusal, one entry per finding: the screen field's `name`, the field-level code it broke and the engine's English line. One field can carry more than one entry (for instance, a value above a field's `max` but below its larger `min` breaks both bounds). For `unknown_field`, `field` is the key the caller sent, not a declared screen field name. Set with that code only. A transport serves it as `error.details.fields` | | **status** | `Enum<'completed' \| 'paused' \| 'failed' \| 'stranded' \| 'refused'>` | optional | Lifecycle status. `paused` means the run suspended at a node and can be continued with the resume route. Absent or `completed`/`failed`/`stranded`/`refused` means the run reached a terminal state. `refused` is a first-class refusal: the flow reached an `end` node declaring `outcome: 'refused'` — a successful evaluation that said no, so `success` is true, `successMessage` is absent and the per-record reason is on `refusalMessage`; a runner shows it with Close only. `stranded` is the terminally-failed-but-repairable run: a resume consumed the suspension and a downstream node threw, so the run is recorded as failed and can be re-armed only by an explicit operator verb - never by the resume route, which answers RUN_NOT_FOUND for it. | | **runId** | `string` | optional | Run id - set when `status` is `paused`, so callers can resume it | | **screen** | `{ nodeId: string; title?: string; description?: string; fields: object[]; … }` | optional | The screen to render - set when the run paused at a `screen` node awaiting user input. The client collects values for `screen.fields` and resumes the run with them. | diff --git a/packages/spec/src/api/automation-api.zod.ts b/packages/spec/src/api/automation-api.zod.ts index 21a599f341a..6b2bee309eb 100644 --- a/packages/spec/src/api/automation-api.zod.ts +++ b/packages/spec/src/api/automation-api.zod.ts @@ -433,8 +433,11 @@ export const TriggerFlowResponseSchema = lazySchema(() => BaseResponseSchema.ext // #37526 — mirrors `AutomationResult.fields`; the element IS the error // envelope's `FieldErrorSchema`, the entries `VALIDATION_FAILED` serves. fields: z.array(FieldErrorSchema).optional().describe( - 'The field-addressed findings behind an `INVALID_SCREEN_INPUT` refusal, one per violated ' - + 'screen field: its `name`, the field-level code it broke and the engine\'s English line. ' + 'The field-addressed findings behind an `INVALID_SCREEN_INPUT` refusal, one entry per ' + + 'finding: the screen field\'s `name`, the field-level code it broke and the engine\'s ' + + 'English line. One field can carry more than one entry (for instance, a value above a ' + + 'field\'s `max` but below its larger `min` breaks both bounds). For `unknown_field`, ' + + '`field` is the key the caller sent, not a declared screen field name. ' + 'Set with that code only. A transport serves it as `error.details.fields`', ), // `stranded` is the contract half of the #13937 shape-4 ruling (#14384); diff --git a/packages/spec/src/contracts/automation-service.ts b/packages/spec/src/contracts/automation-service.ts index da0290acf87..efcb8e29f89 100644 --- a/packages/spec/src/contracts/automation-service.ts +++ b/packages/spec/src/contracts/automation-service.ts @@ -695,10 +695,14 @@ export interface AutomationResult { code?: 'PERMISSION_DENIED' | 'INVALID_SIGNAL' | 'RUN_NOT_FOUND' | 'STORE_UNAVAILABLE' | 'RESUME_IN_PROGRESS' | 'RESUME_CHILD_PENDING' | 'INVALID_SCREEN_INPUT' | 'FLOW_DISABLED' | 'FLOW_NO_START_NODE' | 'FLOW_INPUT_SCHEMA_INVALID'; /** * [#37526] The field-addressed findings behind an `'INVALID_SCREEN_INPUT'` - * refusal, one entry per violated field: the screen field's `name`, the + * refusal, one entry per finding: the screen field's `name`, the * `FieldErrorCode` it broke (ADR-0114 D2: `required`, `invalid_type`, * `invalid_value`, `min_value`, `max_value`, `unknown_field`) and the * engine's English line for it. Set with that code only; absent otherwise. + * One field can carry more than one entry — a value above a field's `max` + * but below its larger `min` breaks both bounds, for instance — so a runner + * groups by `field` rather than counting one entry per field. For `unknown_field`, + * `field` is the key the caller sent, not a declared screen field name. * * It is what lets a runner place the refusal AT the field, in its own * language, by the label it shows, instead of reading `error`: `error`