Repository navigation
Commit 1538596
fix(lint,service-automation)!: a flow value envelope is typed for the date-text verdicts, so timestamp() over a date field is refused at os validate and registerFlow (#34654)
<!-- claude-projects-attribution: {"github_login":"os-steve"} -->
_Requested by **Steve** · [project
thread](https://claude.ai/code/project/chan_01FdL1XeUyvVNxLreh3F4Qi9?thread=cmsg_01FdL1XeUyvVNxLreh3F4Qi9USTJYAvMcxS7CFGZygeZG6)_
Fixes #34451
Completes #34661 (not closed by this PR: the seat closes it after
merge).
Clause-②: yes (narrowing) — narrowed: a flow value envelope
(`assignment` values, `create_record` / `update_record` `fields.*`) that
registered and published now refuses at `os validate` and at
`registerFlow` when it hands `timestamp()` a date field (the date-text
verdict family). Widened: the published `ExprSchemaHint` type gains one
optional key, `flowValueEnvelope`.
Metadata-protocol: narrowed
Skills-docs: none — no published skill teaches a flow value envelope
over a date field; `skills/objectstack-formula/SKILL.md` already states
the `timestamp()` / `date-text-call` rule without naming a site, so it
now holds for value envelopes as written
## 维护者速读
- 改了什么:flow 的值信封(`update_record` / `create_record` 的
`fields.*`、`assignment` 的值)在记录触发或对被定型对象的 sweep、且 flow 不自己重绑
`record`/`previous`(previous 只算节点绑定,声明的会被运行时覆盖)时,按触发对象的字段类型校验,只放行
date-text 这一族判词;`isoDate(timestamp(record.DATE_FIELD) +
duration('168h'))` 这类写法在 `os validate` 和引擎 `registerFlow` 同时被拒,并提示改写为
`isoDate(addDays(record.DATE_FIELD, N))`;inbound
hook、schedule、无触发或被父流程调用的 flow 不判。spec 的三条 ADR-0087 条目 surface
同步点名这个新位置(#34661)。
- 为什么改:日期字段运行时是 `YYYY-MM-DD` 文本,`timestamp()`
只认完整时间戳,这种写法过去校验通过、发布成功、每次运行都失败(cloud#4717 的现场);#34447 的拒绝够不到值信封。
- 风险与回滚:收窄(BREAKING,按 minor 发布):已存的、值信封里带这种写法的 flow
在挂了对象解析器的引擎上会注册失败,直到改写;只判 `record.FIELD` / `previous.FIELD`
读,其它类型判词不进值信封,运行时求值路径不变。回滚即 revert 本 PR。
- 先看:`packages/formula/src/validate.ts`(`flowValueEnvelopeDateTextIssue`
与新 hint
键)、`packages/services/service-automation/src/flow-registration-checks.ts`(注册门传字段类型、存量预览也算)、`packages/lint/src/validate-expressions.ts`(`checkDeclaredValue`)。
- 两分钟验证:`pnpm --filter @objectstack/service-automation exec vitest run
--maxWorkers=2 src/builtin/assignment-value-envelope.test.ts -t
34451`,预期全部通过。
- 需要你做的:受管面未触及;本 PR 是收窄,落地前需一次契约复审记录,由席位路由。
## What changes
A flow value envelope was validated with no field types, by
`@objectstack/lint`'s `checkDeclaredValue` and by the engine's
`valueEnvelopeRefusals` alike, so the date-text verdicts (#28944,
#32595, #34447) never reached it. Measured on `origin/main` ffa6db1
before building: a record-triggered flow whose `update_record` writes
`due_date` from `isoDate(timestamp(record.borrow_date) +
duration('168h'))` got zero findings from `validateStackExpressions` and
registered clean, in `update_record`, `create_record` and `assignment`
alike.
Route A, as the seat named it: the date-text family only.
- `packages/formula/src/validate.ts`: `ExprSchemaHint` gains the
optional `flowValueEnvelope` key. With it (and `fieldTypes`), the
`value` role runs ONE schema-aware pass,
`flowValueEnvelopeDateTextIssue`: the date-text check typed at `record`
scope, so it judges `record.FIELD` / `previous.FIELD` reads only; the
Timestamp-typing mismatch is asked first and stands it down (so
`record.due_date + 1` and `record.title * 2` stay another family's and
say nothing here); the result is kept only when its code is
`date-text-call*` / `date-text-arithmetic*`, under the `run-may-fail`
arm. A bare name and a source that reads `input` take no verdict. Field
existence, the near-miss, the bare-reference refusal, `type-mismatch*`,
`date-arithmetic*`, `date-duration-value` and the traversal arm all
stand down. Without the key the call is unchanged.
- `packages/lint/src/validate-expressions.ts`: `checkDeclaredValue`
takes the field types of the object the flow's conditions are typed
against (start `objectName`, else a time-relative flow's swept object)
and passes the hint only where the run's `record` is that object's row:
the same `faultOutcomeOf` set a flow condition's proven outcome uses
(record-triggered, or a sweep of the typed object), and only while the
flow rebinds neither `record` (any row of `collectFlowVariableNames`)
nor `previous` (a node row only: the collector asked without
`flow.variables`, since `seedRunVariables` sets `previous` over a
declared variable). Every other flow's envelopes are judged untyped, as
before.
- `packages/services/service-automation`: `valueEnvelopeRefusals(value,
fieldTypes?)` passes the same hint when handed types.
`validateFlowExpressions` hands it the resolver's field types for the
bound object in BOTH modes, so `registerFlow` throws the refusal and the
stored pass (`canonicalizeStoredFlow`) lists it at the slot; the binding
is now derived in the stored mode too, so a time-relative flow is typed
with its swept object there as well. The run-time evaluator still calls
`valueEnvelopeRefusals(envelope)` untyped, unchanged. Three `engine.ts`
docblocks that said "a resolver can never break a flow that used to
register cleanly" now name this one exception. The typing is handed on
only where `deriveTriggerBinding` gives record_change (string
`triggerType`) or a time-relative sweep of the typed object, and
`flowRebindsRunRowRoots` finds neither `record` (declared variable, node
id, output / iterator / index / error variable, assignment target) nor
`previous` (the same rows less the declared variable) via
`flowNodeBoundNames`, so both doors judge one set. `plugin.ts`'s
resolver wiring comment and debug line now say the same (L2 N2).
- `.changeset/34451-flow-value-envelope-date-text.md`: `minor` for
`@objectstack/spec`, `@objectstack/formula`, `@objectstack/lint` and
`@objectstack/service-automation`, the declaration lines, **BREAKING**
banner, FROM to TO table, ADR-0087 disposition `already-registered`
naming the three semantic entries
(`formula-timestamp-date-only-refused`,
`formula-date-text-call-refused`, `formula-date-subtraction-refused`),
whose `surface` this PR rewrites to name the value-envelope site, its
scope (record-triggered or a sweep of the typed object, rebinding
neither `record` nor `previous`), its boot-registration consequence, and
an acceptance-criteria line telling an operator how to confirm a stored
flow is clear (no "failed to register flow" warning at boot; no
`registerFlow` TODO from `POST /api/v1/meta/_migrate-stored` on the
running server — the CLI's `os migrate meta --stored` boots automation
inert, `armRuntime: false`, with no object-schema resolver, so it types
no value envelope and cannot show this); it states #34661 is completed
by this PR.
-
`packages/spec/src/migrations/entries/semantic/18.formula-timestamp-date-only-refused.ts`,
`18.formula-date-text-call-refused.ts`,
`18.formula-date-subtraction-refused.ts`: `surface` text only (seat
ruling on L2 S1, option i). No generated file moves (`check:generated`
14/14 up to date).
## Tests
- `packages/formula/src/validate-date-text-arithmetic.test.ts`, new
top-level describe: the measured expression refused under
`date-text-call-run-may-fail` with its params (call, reference, rewrite,
shift); the bare call, a `previous.FIELD` read and `record.borrow_date -
duration('24h')`; CONTROL: a `datetime` field under `timestamp()` and
the taught `addDays` shift stay clean; CONTROL: `record.title * 2`,
`record.due_date + 1`, `today() - record.borrow_date` and an unknown
field say nothing in an envelope while a formula site still reports
`type-mismatch`; a bare name and an `input` read take no verdict; a
malformed envelope is still refused, and no hint means no change.
- `packages/lint/src/validate-expressions.test.ts`, new top-level
describe: `validateStackExpressions` refuses the measured expression and
the bare call in `update_record`, `create_record` and `assignment`, at
the slot's key path, naming the `addDays` shift; a time-relative flow is
typed with its swept object; CONTROL: a `datetime` field and the taught
shift are clean, and a text field in arithmetic stays silent in the
envelope. CONTROLs for the stand-down, each carrying
`timestamp(record.borrow_date)`: an inbound-hook (`api`) start, a start
with no trigger, a schedule, a child flow a parent starts through
`subflow`, a record-triggered flow declaring a `record` variable, and
one whose assignment assigns `record`. For the no-trigger and schedule
starts the lint CONTROL asserts the findings equal those of a bare
`record.borrow_date` read (the existing unbound-root refusal, #22565)
and carry no date-text verdict. Round 3: `record` bound through a
get_record outputVariable, a loop iterator / index variable, a try_catch
errorVariable, a node id, and assignment shapes 2 and 3, and a sweep
whose start names another object, each a CONTROL;
`timestamp(previous.borrow_date)` refused, and two `previous` CONTROLs
(get_record `outputVariable: 'previous'`, an assignment building it); a
declared `previous` still refused; field minus field refused.
-
`packages/services/service-automation/src/builtin/assignment-value-envelope.test.ts`,
new top-level describe: `registerFlow` throws for all three slots,
located and led by the published value-envelope sentence, naming the
shift; the stored pass lists exactly the slot `registerFlow` refuses; a
time-relative flow is typed with its swept object; CONTROL: `datetime`,
a text field in arithmetic and `record.due_date + 1` still register;
with no resolver nothing changes, and the evaluator's own call stays
untyped. CONTROLs for the stand-down, each carrying
`timestamp(record.borrow_date)`: an inbound-hook (`api`) start, a start
with no trigger, a schedule, a child flow a parent starts through
`subflow`, a record-triggered flow declaring a `record` variable, and
one whose assignment assigns `record`. Each registers, with no stored
todos. Round 3: `record` bound through a get_record outputVariable, a
loop iterator / index variable, a try_catch errorVariable, a node id,
and assignment shapes 2 and 3, and a sweep whose start names another
object, each a CONTROL; `timestamp(previous.borrow_date)` refused, and
two `previous` CONTROLs (get_record `outputVariable: 'previous'`, an
assignment building it); a declared `previous` still refused; field
minus field refused.
- No existing test changed: no test pinned the untyped value-envelope
behaviour this narrows.
## Acceptance notes
- **The outcome clause says "condition".** The verdict rides the
existing `-run-may-fail` codes, whose shared clause reads "when the
condition runs ... a flow condition that cannot be evaluated fails the
run". On a value envelope the run does fail at that node (the evaluator
throws), but the sentence names a condition. A value-worded arm would be
a new code in the refusal ledger, which this card does not decide; the
location and the leading value-envelope sentence name the slot. Reported
to the seat. Disposition: filed #34660.
- **Bare names stand down.** In a value envelope a bare name holds
whatever the run's variable map holds; `@objectstack/lint` knows a
flow's declared variables and open binders, the engine does not, and the
two doors must refuse one set. So only `record.FIELD` / `previous.FIELD`
reads are judged, at both doors.
- **`date-duration-value` stays out.** It is a date verdict outside the
date-text family the ruling names.
- **ADR-0087.** The three registered entries carry the same verdicts,
codes and rewrites; this PR rewrites their `surface` to name the flow
value envelope (assignment values, create_record / update_record
`fields.*`) within the stand-down scope (record-triggered flow or a
time-relative sweep of the typed object, rebinding neither `record` nor
`previous`), and the consequence: a stored flow carrying one fails to
register at boot on an engine with the object-schema resolver wired
until rewritten. For the subtraction entry only its first two shapes
reach the envelope. Completes #34661 (not closed by this PR: the seat
closes it after merge).
- **Found on the way (reported to the seat, not fixed here):** in a flow
CONDITION (flattened scope) a `record.FIELD` read is not typed by the
date-text check: a record-triggered start condition comparing
`timestamp(record.borrow_date)` with `now()` gets zero findings from
`validateStackExpressions`, while the same comparison over the bare
`timestamp(borrow_date)` is refused. Disposition: filed #34662.
- **Stand-down residues (seat ruling).** (1) A screen field named
`record` is not counted as the flow binding `record`, at either door, as
lint's `declaredVariables` does not count screen fields: kept. (3) An
open binder node (`script` and the like) could in principle rebind
`record`; it is not counted, as lint's existing reading of
`record.FIELD` in flow conditions keeps the row outcome (#30025): kept.
(2) A record-triggered flow that a parent also starts through `subflow`
/ `map` is judged as if `record` were its trigger row, while on that
entrance it is the parent's record. Disposition: filed #34694.
- **A declared `record` variable stands the envelope down.** Kept from
the S2 ruling: on a record-triggered or sweep entrance
`seedRunVariables` writes `record` over a declared variable, so counting
a declared `record` only refuses less, never wrongly. A conservative
under-refusal, accepted by the seat.
- **A `previous.F` read in a branch that never runs is refused too (L2
N8).** That is the scope of the published date-text rule itself, the
same as on flow conditions on `main`; follows the published rule's
scope, accepted by the seat, no card.
- Governed surfaces: none in the diff.
## Verification
Final head: `8598c1dcb77d7865c91fac5e967d1df84ed44d7d` (round 5, text
only: 2a1630d, then a merge of `origin/main`). Round 5: the three
entries' printed guidance no longer cites a tracker number (CI red at
f11fa42: `packages/cli/test/migrate-meta-engine-guidance.test.ts:420`);
`packages/cli/test/migrate-meta-engine-guidance.test.ts` 3/3, spec
`src/migrations` + upgrade-guide-surface-span 213/213, `check:generated`
up to date, the three changeset gates exit 0, `check:nul-bytes` exit 0.
Round 4 head `f11fa429a9928903a4c41f400f34eb5ccc70be0e` ( text only: L2
S4 and N7 in 50adcc3, then a merge of `origin/main`). Round 4 (text
only): spec build, `check:generated` (14 up to date), spec
`src/migrations` + upgrade-guide-surface-span +
build-migration-registry-entry 216/216, spec and formula typecheck, the
three changeset gates on the current body (exit 0), `check:nul-bytes`
exit 0; the derived-gate set, the lint / service-automation suites and
the dogfood battery were not re-run (last at 97856f7, readings below).
Round 3 head `97856f7327f7470fedfc65045b9a03eb4e4a6da8` ( L2 S3 / N5 /
N6 in b49e849, then a merge of `origin/main` a34eb07; round 2 was
9a6882b and 8401e76). At that head: `@objectstack/formula` 68
files / 1872 tests, `@objectstack/lint` 214 / 9132,
`@objectstack/service-automation` 287 / 4132, `@objectstack/spec` 848 /
27168 (1 todo), all passed, the four typechecks exit 0; spec
`check:generated` exit 0 (14/14 up to date); `dispatch-gates --commands`
98 families, all exit 0, `--ran` 98 run / 0 NOT-MEASURED
(`/mnt/project-files/objectstack-seat2/34451-gates-ran.txt`); dogfood
battery `VERDICT command-exit 0`, 478 files passed / 3 skipped, 4055
tests passed / 68 skipped; the three changeset gates exit 0
(`not-required (already-registered)`).
Stand-down ablations (`scripts/ablation-replace.mjs`, each restored,
`git diff HEAD` empty): lint, the `previous` stand-down removed → 2
failed / 23 passed (the two `previous` CONTROLs); engine, `||
nodeBound.has('previous')` removed → 2 failed / 74 passed; lint, the
trigger half removed → 5 failed (api, no trigger, schedule, subflow
child, mismatched sweep); lint, the `record` half removed → 9 failed
(declared `record`, the seven other binders, an assignment to `record`);
engine, the whole predicate replaced by `true` → 16 failed (every
CONTROL).
The details below are the first round's, at `81d78bb0f0` (merge of
`origin/main` 31096af into the branch).
<details><summary>Premise on origin/main ffa6db1</summary>
`validateStackExpressions` over a record-triggered flow, three slots,
the measured expression, the bare call, the `datetime` control and
`record.note * 2`: zero findings in all twelve. `registerFlow` with a
resolver wired: all six (three slots, measured and `datetime`)
registered, no warning logged.
</details>
<details><summary>Packages</summary>
- `pnpm --filter @objectstack/formula test`: `Test Files 68 passed
(68)`, `Tests 1872 passed (1872)`; `typecheck` exit 0 (at 17673d2;
formula is untouched by the later merge).
- `pnpm --filter @objectstack/lint test` at 81d78bb: `Test Files 214
passed (214)`, `Tests 9097 passed (9097)`; `typecheck` exit 0.
- `pnpm --filter @objectstack/service-automation test` at 81d78bb:
`Test Files 287 passed (287)`, `Tests 4113 passed (4113)`; `typecheck`
exit 0.
</details>
<details><summary>Ablation: the field types withheld at each
door</summary>
Through `scripts/ablation-replace.mjs` (both suites import the edited
file from source):
- lint: anchor `fieldTypes ? { fieldTypes, flowValueEnvelope: true } :
undefined,` x1 to x0, blob a47831c to 71212190e115: `Tests 4 failed
| 2 passed` (the three slot cases and the time-relative case red; the
two CONTROLs green). Restored: blob == HEAD a47831c, `git diff
HEAD` empty.
- service-automation: anchor `this.valueEnvelopeRefusals(found.value,
schemaHint?.fieldTypes)` x1 to x0, blob 104d6e1 to b7c46e5799bc:
`Tests 5 failed | 52 passed` (three slots, the stored pass,
time-relative). Restored: blob == HEAD 104d6e1, `git diff HEAD`
empty.
</details>
<details><summary>Gates and dogfood battery</summary>
- `node scripts/pm/dispatch-gates.mjs --commands` at 81d78bb: 74
families, each run with its exit captured before any pipe; `--ran`: `74
derived famil(ies) accounted for — 74 run, 0 NOT-MEASURED`.
`check:dual-build-cjs-loads` and `check:type-check-debt` first answered
exit 3 (unbuilt packages; the lock held by the battery) and were re-run
after building: exit 0 both.
- `check-adr-0087-registration`:
`[BREAKING+clause-②-narrowing+metadata-protocol-narrowed] not-required
(already-registered)`, exit 0.
- Dogfood battery at 81d78bb (closure `@objectstack/dogfood^...`
built, then `pnpm --filter @objectstack/dogfood test` under the verify
lock): `VERDICT command-exit 0`, `Test Files 478 passed | 3 skipped
(481)`, `Tests 4055 passed | 68 skipped (4123)`.
</details>
<details><summary>git merge-tree against the in-flight lint
PRs</summary>
`git merge-tree --write-tree --name-only` of 81d78bb with each head,
exit code and tree:
- #34600 head 2da6508: exit 0, tree c652042ab2e9, no conflicted path.
- #34513 head e5d2d0c (merged into main as b1efa37, and in this
branch through the merge): exit 0, tree 49596be, no conflicted
path.
</details>
---
_Generated by [Claude
Code](https://claude.ai/code/session_01ADHkmQAXHSQEgnYyx9tstb)_
<!-- signed: repo:objectstack#2 · os-steve ·
session_01ADHkmQAXHSQEgnYyx9tstb -->
---------
Co-authored-by: Claude <noreply@anthropic.com>1 parent dfbc316 commit 1538596
13 files changed
Lines changed: 871 additions & 33 deletions
File tree
- .changeset
- packages
- formula/src
- lint/src
- services/service-automation/src
- builtin
- spec/src/migrations/entries/semantic
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
432 | 432 | | |
433 | 433 | | |
434 | 434 | | |
| 435 | + | |
| 436 | + | |
| 437 | + | |
| 438 | + | |
| 439 | + | |
| 440 | + | |
| 441 | + | |
| 442 | + | |
| 443 | + | |
| 444 | + | |
| 445 | + | |
| 446 | + | |
| 447 | + | |
| 448 | + | |
| 449 | + | |
| 450 | + | |
| 451 | + | |
| 452 | + | |
| 453 | + | |
| 454 | + | |
| 455 | + | |
| 456 | + | |
| 457 | + | |
| 458 | + | |
| 459 | + | |
| 460 | + | |
| 461 | + | |
| 462 | + | |
| 463 | + | |
| 464 | + | |
| 465 | + | |
| 466 | + | |
| 467 | + | |
| 468 | + | |
| 469 | + | |
| 470 | + | |
| 471 | + | |
| 472 | + | |
| 473 | + | |
| 474 | + | |
| 475 | + | |
| 476 | + | |
| 477 | + | |
| 478 | + | |
| 479 | + | |
| 480 | + | |
| 481 | + | |
| 482 | + | |
| 483 | + | |
| 484 | + | |
| 485 | + | |
| 486 | + | |
| 487 | + | |
| 488 | + | |
| 489 | + | |
| 490 | + | |
| 491 | + | |
| 492 | + | |
| 493 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
297 | 297 | | |
298 | 298 | | |
299 | 299 | | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
300 | 344 | | |
301 | 345 | | |
302 | 346 | | |
| |||
778 | 822 | | |
779 | 823 | | |
780 | 824 | | |
| 825 | + | |
| 826 | + | |
| 827 | + | |
| 828 | + | |
| 829 | + | |
| 830 | + | |
| 831 | + | |
| 832 | + | |
| 833 | + | |
| 834 | + | |
| 835 | + | |
| 836 | + | |
| 837 | + | |
| 838 | + | |
| 839 | + | |
| 840 | + | |
| 841 | + | |
| 842 | + | |
| 843 | + | |
| 844 | + | |
| 845 | + | |
| 846 | + | |
| 847 | + | |
| 848 | + | |
| 849 | + | |
| 850 | + | |
| 851 | + | |
| 852 | + | |
| 853 | + | |
| 854 | + | |
| 855 | + | |
781 | 856 | | |
782 | 857 | | |
783 | 858 | | |
| |||
1536 | 1611 | | |
1537 | 1612 | | |
1538 | 1613 | | |
| 1614 | + | |
| 1615 | + | |
| 1616 | + | |
| 1617 | + | |
| 1618 | + | |
| 1619 | + | |
1539 | 1620 | | |
1540 | 1621 | | |
1541 | 1622 | | |
| |||
1632 | 1713 | | |
1633 | 1714 | | |
1634 | 1715 | | |
1635 | | - | |
| 1716 | + | |
| 1717 | + | |
| 1718 | + | |
| 1719 | + | |
1636 | 1720 | | |
1637 | 1721 | | |
1638 | 1722 | | |
| |||
0 commit comments