diff --git a/.changeset/36718-flow-teaching-accepted-shapes.md b/.changeset/36718-flow-teaching-accepted-shapes.md new file mode 100644 index 00000000000..babbf65c6fe --- /dev/null +++ b/.changeset/36718-flow-teaching-accepted-shapes.md @@ -0,0 +1,16 @@ +--- +'@objectstack/skills': patch +'@objectstack/spec': patch +'@objectstack/trigger-schedule': patch +--- + +docs(skills): the automation skill, the schedule trigger README and the start-node schedule refusals spell only flow shapes the publish checks accept + +Clause-②: no +Metadata-protocol: none + +Ten flow checks of `os validate` and publish (`flow-schedule-timezone-missing`, `flow-condition-option-label`, `flow-node-write-unknown-option`, `flow-subflow-unknown` and the rest) landed without the text that teaches flows. Three of them are warnings and refuse nothing: `flow-schedule-timezone-missing`, `flow-subflow-unknown` (run by the CLI only) and `flow-create-update-pair`. Wording only; no schema, rule or reader changes. + +- `@objectstack/spec`: the three refusals of a start node's `config.schedule` (an empty string, a typed schedule the published schema refuses, a value the readers read nothing from) now offer `{ type: 'cron', expression: '0 8 * * *', timezone: 'UTC' }` as the cron to write. They no longer offer a bare cron string or a cron object with no `timezone`, which `os validate` warns on. The typed-alias hint names `{ type: 'cron', expression: '…', timezone: 'UTC' }`. What is refused is unchanged. +- `objectstack-automation` skill: recipe 1's nightly cron states `timezone: 'UTC'`; the schedule example's comment says a cron with no `timezone` (a bare string) runs in UTC and warns, where it said a bare cron string also works; the `subflow` row says `os validate` warns `flow-subflow-unknown` on any name the stack does not hold, a correct call to another package's flow included, where it said `os validate` passes; the select-label rule says a start condition or a `fields` write that uses an option's label is refused at publish where the options are inline, where it said the flow stages clean, and says a label in a `filter` or an edge condition is never checked and silently matches nothing, where it said a `filter` fails the run. Eval 1's expected answer states the cron's `timezone`, and eval 20's states that warning. No skill file passes its token ceiling: `SKILL.md` gains one line, paid for by shorter wording and shorter table separator rows in the same file, and two node labels in recipe 1 are shortened to pay for the `timezone` key. +- `@objectstack/trigger-schedule` README: the time-relative example's cron states `timezone: 'UTC'`, and the schedule-shapes table is followed by the UTC reading and the warning. diff --git a/examples/app-showcase/src/automation/flows/index.ts b/examples/app-showcase/src/automation/flows/index.ts index a2407f05323..6218d66d8c5 100644 --- a/examples/app-showcase/src/automation/flows/index.ts +++ b/examples/app-showcase/src/automation/flows/index.ts @@ -442,8 +442,8 @@ export const ScheduledDigestFlow = defineFlow({ // this filled dev.db to 260MB+ over a multi-day `pnpm dev`. 60s keeps // the schedule trigger observable within a minute while cutting the // write rate 3x. Production digests use a cron expression instead, - // e.g. { type: 'cron', expression: '0 8 * * *' }. Real bounding comes - // from the lifecycle/retention work (ADR-0057), not this number. + // e.g. { type: 'cron', expression: '0 8 * * *', timezone: 'UTC' }. Real + // bounding comes from the lifecycle/retention work (ADR-0057), not this number. schedule: { type: 'interval', intervalMs: 60000 }, }, }, @@ -2044,7 +2044,7 @@ export const TaskDueReminderFlow = defineFlow({ filter: { status: { $ne: 'done' } }, // optional, ANDed with the date window }, // schedule defaults to daily 08:00 UTC; override with - // schedule: { type: 'cron', expression: '0 8 * * *' } + // schedule: { type: 'cron', expression: '0 8 * * *', timezone: 'UTC' } }, }, // "Your task is due" has nobody to address on a task with no assignee, so diff --git a/packages/spec/src/automation/flow-start-config-refusals.ts b/packages/spec/src/automation/flow-start-config-refusals.ts index 837ceab7107..0122dabb9e9 100644 --- a/packages/spec/src/automation/flow-start-config-refusals.ts +++ b/packages/spec/src/automation/flow-start-config-refusals.ts @@ -90,7 +90,7 @@ export function flowStartScheduleReadsNothing(raw: unknown): boolean { function typedAliasHint(raw: Record): string { const has = (k: string) => Object.prototype.hasOwnProperty.call(raw, k); if (raw.type === 'cron' && has('cron') && !has('expression')) { - return " A typed cron schedule names its cron in `expression`, not `cron`: write `{ type: 'cron', expression: '…' }`."; + return " A typed cron schedule names its cron in `expression`, not `cron`: write `{ type: 'cron', expression: '…', timezone: 'UTC' }`."; } if (raw.type === 'interval' && has('every') && !has('intervalMs')) { return " A typed interval schedule names its period in `intervalMs`, not `every`: write `{ type: 'interval', intervalMs: … }`."; @@ -102,8 +102,8 @@ function scheduleRefusal(raw: unknown): string | undefined { if (raw == null || typeof raw === 'string') { return typeof raw === 'string' && flowStartScheduleReadsNothing(raw) ? 'The start node\'s `config.schedule` is an empty string, so no schedule is read from it: a schedule ' + - 'flow stays unbound and a time-relative sweep falls back to daily 08:00 UTC. Write a cron expression ' + - "(e.g. '0 8 * * *') or remove the key." + 'flow stays unbound and a time-relative sweep falls back to daily 08:00 UTC. Write ' + + "`{ type: 'cron', expression: '0 8 * * *', timezone: 'UTC' }` or remove the key." : undefined; } if (isRecord(raw) && Object.prototype.hasOwnProperty.call(raw, 'type')) { @@ -117,7 +117,7 @@ function scheduleRefusal(raw: unknown): string | undefined { ' The schedule ' + 'readers cannot use it, so a schedule flow stays unbound and a time-relative sweep falls back to daily ' + "08:00 UTC. Write `{ type: 'cron', expression: '0 8 * * *', timezone: 'UTC' }`, " + - "`{ type: 'interval', intervalMs: 60000 }` or `{ type: 'once', at: '' }`, or a bare cron string." + "`{ type: 'interval', intervalMs: 60000 }` or `{ type: 'once', at: '' }`." ); } } @@ -125,8 +125,8 @@ function scheduleRefusal(raw: unknown): string | undefined { return ( 'The start node\'s `config.schedule` names no schedule the readers can use (a cron `expression` as a ' + 'string, a positive `intervalMs`, or an `at` datetime), so a schedule flow stays unbound and a ' + - 'time-relative sweep falls back to daily 08:00 UTC. Write a cron string such as \'0 8 * * *\', or ' + - "`{ type: 'cron', expression: '0 8 * * *' }`, `{ type: 'interval', intervalMs: 60000 }` or " + + 'time-relative sweep falls back to daily 08:00 UTC. Write ' + + "`{ type: 'cron', expression: '0 8 * * *', timezone: 'UTC' }`, `{ type: 'interval', intervalMs: 60000 }` or " + "`{ type: 'once', at: '' }`." ); } diff --git a/packages/triggers/trigger-schedule/README.md b/packages/triggers/trigger-schedule/README.md index 2f4fd8bdf3c..105a9ad854c 100644 --- a/packages/triggers/trigger-schedule/README.md +++ b/packages/triggers/trigger-schedule/README.md @@ -66,6 +66,10 @@ refusal names the spelling you wrote. | `{ type: 'interval', intervalMs }` / `{ every }` | interval | | `{ type: 'once', at }` / `{ at }` | once | +A cron with no `timezone` runs in UTC, and `os validate` warns on it +(`flow-schedule-timezone-missing`). Author the first row with its `timezone` +(`'UTC'` when UTC is meant); the bare string cannot carry one. + ## Usage ```ts @@ -127,7 +131,7 @@ schedule and launched **once per matching record**: maxRecords: 1000, // optional per-sweep cap (default 1000) }, organization: '', // REQUIRED — same refusal as above - schedule: { type: 'cron', expression: '0 8 * * *' }, // optional; defaults to daily 08:00 UTC + schedule: { type: 'cron', expression: '0 8 * * *', timezone: 'UTC' }, // optional; defaults to daily 08:00 UTC condition: '...', // optional per-record start-condition gate }, } diff --git a/skills/objectstack-automation/SKILL.md b/skills/objectstack-automation/SKILL.md index b6777d1790a..868820401cb 100644 --- a/skills/objectstack-automation/SKILL.md +++ b/skills/objectstack-automation/SKILL.md @@ -34,10 +34,10 @@ Also vendor-integration callbacks and **assignment rules**. ### Flow Types | Type | When to Use | -|:-----|:------------| -| `autolaunched` | Runs without user interaction — triggered by events, APIs, or other flows | -| `screen` | Presents UI screens | -| `schedule` | Runs on a cron/interval cadence declared on the **start node's `config.schedule`** — or a **per-record date sweep** via `config.timeRelative` | +|:--|:--| +| `autolaunched` | No user interaction: started by events, APIs or other flows | +| `screen` | Shows UI screens | +| `schedule` | Runs on a cron/interval cadence declared on the **start node's `config.schedule`**, or a **per-record date sweep** via `config.timeRelative` | | `record_change` | Fires on record create/update/delete. `autolaunched` + the same `record-*` binding behaves identically; `record_change` also opts into the trigger-readiness lint | | `api` | Inbound **webhook** (*Inbound webhook triggers*); a flow only ever started explicitly is `autolaunched` | @@ -69,33 +69,33 @@ Built-in (plugins register more; a `type` none runs is refused at a server's pub #### Control Flow | Node | Purpose | -|:-----|:--------| -| `start` | Entry point — every flow has exactly one | -| `end` | Exit point — can have multiple | -| `decision` | Conditional branching — routed by **edge `condition` predicates**, not node config | +|:--|:--| +| `start` | Entry point: exactly one per flow | +| `end` | Exit point: one or more | +| `decision` | Branch by **edge `condition` predicates**, not node config | | `loop` | Iterate a **nested `config.body` region** once per item of `config.collection` — a CEL value envelope or an inline list, never a string; `iteratorVariable` (default `item`) and optional `indexVariable` bind inside it, `maxIterations` caps it | | `parallel` | Fan out into `config.branches[]` (≥ 2 regions) run concurrently, **joined implicitly** at block end | | `try_catch` | Run `config.try`; on failure run `config.catch` with the error in `errorVariable` (default `$error`); `config.retry` re-runs `try` with backoff first; in a `record-after-*` flow it (or `errorHandling.strategy: 'retry'`) may not reach an inline `http` / `connector_action`: the save would wait out every attempt. Inside a `subflow` / `map` child, retried by either flow, that is **silent**: the flow saves but never arms (`GET /api/v1/automation/_status`: `bound: false`, `unboundCause: retried_callout_in_subflow`) until the child's `http` is `durable: true` or nothing retries the call. **No `finally`** — the container's ordinary out-edges are the continuation | | `map` | Sequential multi-instance — invoke the `config.flowName` flow (named as `subflow`'s) per item of `config.collection` (shaped as `loop`'s); each may pause (batch approvals); a refused name fails it at the first item | -| `wait` | Pause until a timer elapses or a named signal arrives | -| `subflow` | Invoke the flow bare `config.flowName` names: a package's flow gets its own, else the one holder in its `dependencies` closure plus `sys`; a package-less flow, the environment's, else the one package holder. Else `os validate` passes and the node fails at run time (`subflow 'X' failed: …` naming every candidate; no `code`): `outside-closure` — held only by an undeclared package (declare it) or the environment; `ambiguous-in-closure` / `ambiguous-in-environment` — two packages hold it (package / package-less caller) | +| `wait` | Pause for a timer or a named signal | +| `subflow` | Invoke the flow bare `config.flowName` names: a package's flow gets its own, else the one holder in its `dependencies` closure plus `sys`; a package-less flow, the environment's, else the one package holder. Else the node fails at run time (`subflow 'X' failed: …` naming every candidate; no `code`): `outside-closure` — held only by an undeclared package (declare it) or the environment; `ambiguous-in-closure` / `ambiguous-in-environment` — two packages hold it (package / package-less caller). `os validate` warns `flow-subflow-unknown` on any name this stack lacks, a correct cross-package call included | | `parallel_gateway` / `join_gateway` / `boundary_event` | BPMN-interop forms a `parallel` / `try_catch` container lowers into; author the container | #### Data Operations | Node | Purpose | -|:-----|:--------| +|:--|:--| | `assignment` | Set variable values | | `create_record` | Insert a record | | `update_record` | Modify records | | `delete_record` | Remove records | -| `get_record` | Fetch records with filters (**no `query_record`**) | +| `get_record` | Fetch records by filter (**no `query_record`**) | | `save_notice` | Tell the saver what this create/update started — record create/update trigger only, not after a pause: **objectstack-data** `rules/lifecycle.md` § Save Notice | #### External Integration | Node | Purpose | -|:-----|:--------| +|:--|:--| | `http` | Call an HTTP API — set `timeoutMs`, or it has no timeout and warns (`flow-http-timeout-missing`). `url` and `headers` are served as written with the definition to every member who can read flows — only `signingSecret` and a start node's `secret` are withheld — so never a credential there: use a declared connector via `connector_action`. Retried after a record change: `durable: true` (outbox-queued, else sent once in the background, unretried; no response) | | `notify` | Send a notification (below) | | `connector_action` | Dispatch an action of a declared connector (§ *Integrations are declared, not coded*) or a plugin's. `connectorConfig.input` is a value-slot map like `subflow` `input`. Evaluated, it is judged against the action's `inputSchema` (`required`, `type`, `items`, a key outside listed `properties`) before dispatch: a breach fails the step `VALIDATION_ERROR` (`fault`-routable); `os validate` does not judge that fit yet. Retried after a record change: drop the retry, or run the flow on demand / on a schedule | @@ -105,13 +105,13 @@ Built-in (plugins register more; a `type` none runs is refused at a server's pub #### Human Decision | Node | Purpose | -|:-----|:--------| +|:--|:--| | `approval` | Route a record for human sign-off | ### `notify` An undeclared key is a named parse error. **RAW** keys are read as written: -a `{token}` in one is refused. The node as JSON (TypeScript: the same +a `{token}` in one is refused. As JSON (TypeScript: the same literal, a `FlowNode`): ```json @@ -321,10 +321,11 @@ Most are caught by `objectstack build`: ``` 4. **A `select` is compared and written by its option `value`, never its label.** - The request speaks the label ("Lost"); the row stores the `value` (`lost`). - `condition: "record.status == 'Lost'"` parses, matches no row: the flow - stages clean and never fires; `fields: { status: 'Lost' }` / a `filter` - fails the run (`invalid_option`). Read the field's `options`. + The request says "Lost"; the row stores `lost`. + A start `condition: "record.status == 'Lost'"` or `fields: { status: 'Lost' }` + is refused at publish (inline options), else matches no row or fails the + run (`invalid_option`). A label in a `filter` or an edge `condition` is never + checked: it silently matches nothing. Read the field's `options`. --- @@ -417,7 +418,7 @@ token implies the other: ### Trigger Types (start-node `config.triggerType`) | `triggerType` | ObjectQL hook | -|:------|:------| +|:--|:--| | `record-before-create` (can modify/reject) | `beforeInsert` | | `record-after-create` | `afterInsert` | | `record-before-update` | `beforeUpdate` | diff --git a/skills/objectstack-automation/evals/flows-triggers-approvals.json b/skills/objectstack-automation/evals/flows-triggers-approvals.json index 5fee84afd1d..04e430fa2ca 100644 --- a/skills/objectstack-automation/evals/flows-triggers-approvals.json +++ b/skills/objectstack-automation/evals/flows-triggers-approvals.json @@ -4,7 +4,7 @@ { "id": 1, "prompt": "Every night at 02:00, mark `subscription` records whose `renewal_date` has passed as `lapsed`; `status` is a readonly field only automation may change.", - "expected_output": "A `defineFlow` with `type: 'schedule'`, the cadence on the START NODE's `config.schedule: { type: 'cron', expression: '0 2 * * *' }` (no top-level `schedule`), `runAs: 'system'` (a readonly field is stripped under `runAs: 'user'`); one `update_record` with a where-map `filter` (`renewal_date: { $lt: '{today}' }`) and `fields: { status: 'lapsed' }` (not `values`), `label` on every node, `edges` (never `next`), an `end` node.", + "expected_output": "A `defineFlow` with `type: 'schedule'`, the cadence on the START NODE's `config.schedule: { type: 'cron', expression: '0 2 * * *', timezone: 'UTC' }` (no top-level `schedule`; the request names no zone, and a cron with none warns `flow-schedule-timezone-missing`), `runAs: 'system'` (a readonly field is stripped under `runAs: 'user'`); one `update_record` with a where-map `filter` (`renewal_date: { $lt: '{today}' }`) and `fields: { status: 'lapsed' }` (not `values`), `label` on every node, `edges` (never `next`), an `end` node.", "files": [], "assertions": { "must_contain": [ @@ -354,7 +354,7 @@ { "id": 20, "prompt": "Our package `acme.billing` ships the flow `billing_invoice_paid`. When it runs it should call the `notify_owner` flow that the installed package `acme.crm` ships. Write the node and anything else the package needs.", - "expected_output": "A `type: 'subflow'` node with `config: { flowName: 'notify_owner' }` in `billing_invoice_paid`, plus `acme.billing`'s manifest declaring `dependencies: { 'acme.crm': '^1.0.0' }` (any range). A package flow's bare child name resolves to its own package's flow, else the one holder in its declared dependency closure plus `sys`; without the dependency the flow still passes `os validate`, and the node fails at run time (`outside-closure`, naming `acme.crm`). No copy of `notify_owner` into `acme.billing` or into the environment, and no package-qualified flow name.", + "expected_output": "A `type: 'subflow'` node with `config: { flowName: 'notify_owner' }` in `billing_invoice_paid`, plus `acme.billing`'s manifest declaring `dependencies: { 'acme.crm': '^1.0.0' }` (any range). A package flow's bare child name resolves to its own package's flow, else the one holder in its declared dependency closure plus `sys`; without the dependency the node fails at run time (`outside-closure`, naming `acme.crm`). `os validate` warns `flow-subflow-unknown` here with or without the dependency, because `acme.billing`'s own stack does not hold `notify_owner`: the warning is expected on this correct call and is not that failure. No copy of `notify_owner` into `acme.billing` or into the environment, and no package-qualified flow name.", "files": [], "assertions": { "must_contain": [ diff --git a/skills/objectstack-automation/references/examples-flows.md b/skills/objectstack-automation/references/examples-flows.md index c2a13bcafa4..335d57b4170 100644 --- a/skills/objectstack-automation/references/examples-flows.md +++ b/skills/objectstack-automation/references/examples-flows.md @@ -27,8 +27,8 @@ export const EscalateOverdueCasesFlow = defineFlow({ type: 'start', label: 'Daily at 09:00 Shanghai time', // The cadence lives HERE — FlowSchema has NO top-level `schedule` key (a - // named parse error). A bare cron string also works; a cron`…` tag does not. - // A bare expression runs in UTC. A wall-clock hour the request names is + // named parse error). A cron`…` tag fails. A cron with no `timezone` + // (a bare string) runs in UTC and warns. A wall-clock hour the request names is // written AS SAID with its IANA `timezone` — never converted to UTC by hand: // the arithmetic may be right, but nothing then records which zone was meant. config: { schedule: { type: 'cron', expression: '0 9 * * *', timezone: 'Asia/Shanghai' } }, diff --git a/skills/objectstack-automation/references/integration-recipes.md b/skills/objectstack-automation/references/integration-recipes.md index 4d30b8c4fb3..03afc0ed6a4 100644 --- a/skills/objectstack-automation/references/integration-recipes.md +++ b/skills/objectstack-automation/references/integration-recipes.md @@ -43,11 +43,11 @@ export const StripeBalanceSweep = defineFlow({ name: 'crm_stripe_balance_sweep', label: 'Stripe balance → house account', type: 'schedule', runAs: 'system', nodes: [ - { id: 'start', type: 'start', label: 'Nightly 03:00', - config: { schedule: { type: 'cron', expression: '0 3 * * *' } } }, + { id: 'start', type: 'start', label: 'Nightly', + config: { schedule: { type: 'cron', expression: '0 3 * * *', timezone: 'UTC' } } }, { id: 'bal', type: 'connector_action', label: 'GET /v1/balance', connectorConfig: { connectorId: 'stripe', actionId: 'GetBalance', input: {} } }, - { id: 'write', type: 'update_record', label: 'Write balance', config: { + { id: 'write', type: 'update_record', label: 'Write', config: { objectName: 'crm_account', filter: { is_house_account: true }, fields: { stripe_available: { dialect: 'cel', source: 'bal.body.available[0].amount / 100.0' }, stripe_synced_at: { dialect: 'cel', source: 'isoDatetime(now())' } } } },