You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 0f3ee58
Browse filesBrowse the repository at this point in the historyBrowse files
fix(formula,lint): a date-arithmetic verdict in a flow condition says the run fails, not that the value reads null (#30240)
<!-- claude-projects-attribution: {"github_login":"os-bill"} -->
_Requested by **Bill** · [project
thread](https://claude.ai/code/project/chan_016iMXWSZDzqWRWvWzdNo8wg?thread=cmsg_016iMXWSZDzqWRWvWzdNo8wgPpByBofWLd4fRXKHA6v8SN)_
domain:server#4 · os-bill · session_01Utp6Ca5BRUDW37pk8jE1gW
## 维护者速读
- **改了什么**:流程条件(起始条件、连线条件、decision 分支)里对日期字段做加减(如 `close_date + 1 >
3`、`end_date - start_date > duration("1h")`),判词不再说「字段静默得到
null」,而是如实说明:条件出错时运行在此失败、流程要做的事没做。记录触发流程(及扫描本对象的定时相对触发)上说「运行失败」;其它流程(API、定时、动作或父流程启动)上说「只要这个名字在运行时拿到的是日期,运行就失败」。四个新拒绝码承载这两种句子。
- **为什么改**:#29953 / #30015 已让文本、布尔比较的判词说真话,日期判词被落下。引擎的
`evaluateCondition` 在每种流程上遇错都抛异常、运行失败,旧句子却告诉作者流程会继续往下走。
- **风险与回滚**:分级不变(日期判词在每个位置本来就是 error),发布门不收也不放。流程条件上的日期判词改用新码
`date-arithmetic-run-fails` /
`-run-may-fail`、`date-text-arithmetic-run-fails` / `-run-may-fail`,按旧码
`date-arithmetic` / `date-text-arithmetic` 识别流程站点的使用方需改认;公式字段、校验规则等
record 范围站点原码原句不动。回滚即 revert,无数据迁移。
- **先看**:`packages/formula/src/validate.ts`(`dateFlowArm` /
`dateFlowFault` 两个小函数和 `date-arith`
分支)、`packages/formula/src/expression-refusal.ts`(四个码)、`packages/lint/src/validate-expressions.test.ts`(三种流程
× 三个站点的钉子)。
- **两分钟验证**:`pnpm --filter @objectstack/lint exec vitest run
src/validate-expressions.test.ts -t 30016`,预期 2 条通过:记录触发、定时、API
三个流程的起始条件、连线条件、decision 分支都报 error 且文案说运行失败、不说 null;record 范围校验规则对照仍说
null。
- **需要你做的**:无,席位落地。
Fixes#30016
Clause-②: yes (widening) — four codes join @objectstack/formula's
ExpressionRefusalCode (date-arithmetic-run-fails,
date-arithmetic-run-may-fail, date-text-arithmetic-run-fails,
date-text-arithmetic-run-may-fail) and a flow condition's date verdicts
move to them from date-arithmetic / date-text-arithmetic (a consumer
keyed to those codes on a flow site re-keys); grading unchanged (error
at every site); record-scoped sites keep their code and sentence.
Metadata-protocol: none
## What changes
Measured on `main` at `dfafae81` (after PR #30015, merged
2026-11-04T08:28Z). The `date-arith` branch of `typeSoundnessIssue` and
the `fault` arm of `dateTextIssue` served one sentence, "this faults at
runtime, so the field silently evaluates to null", at every scope. A
`'flattened'` site is a flow condition (lint's flow walk, the engine's
registration advisory pass, MCP `flow_condition`), and
`dag-traversal.ts` `evaluateCondition` throws on a fault on every flow
(ADR-0032 §1c): the run fails at the condition, nothing reads null.
| site | before | now |
|:--|:--|:--|
| flow condition, `faultOutcome: 'run-fails'` (record-triggered start /
edge / `decision`; a time-relative sweep of the typed object),
`bareNamesUnproven` unset | `date-arithmetic` / `date-text-arithmetic`,
error, "silently evaluates to null" | `date-arithmetic-run-fails` /
`date-text-arithmetic-run-fails`, error: "this faults at runtime, and a
flow condition that cannot be evaluated fails the run: the flow stops at
this condition and the work the flow exists to do is not done (it does
not read null)." |
| any other flow condition (no outcome declared, or `bareNamesUnproven`)
| the same | `date-arithmetic-run-may-fail` /
`date-text-arithmetic-run-may-fail`, error: "this faults wherever
`close_date` holds the date (that text) when the condition runs, and a
flow condition that cannot be evaluated fails the run: …" |
| `record`-scoped site (formula field, validation rule, display
predicate) | `date-arithmetic` / `date-text-arithmetic` | unchanged,
code and sentence |
**Why two flow sentences, not one (measured).** On a flow that is not
record-triggered the bare name holds what the entrance hands the run
(`engine.ts` `celScope` docblock: the inbound hook's request body for
`trigger-api`, an action's loaded or `id`-only record, a parent's
record, or nothing). Through the built `@objectstack/formula` on this
head: `celEngine.evaluate({ dialect: 'cel', source: 'close_date + 1 > 3'
}, { extra: { close_date: 5 } })` answers `{ ok: true, value: true }`;
with `'2026-01-01'` it faults (cel-js `no such overload` for a dyn
string `+ int`). So "this faults at runtime" is not proven there, and a
code names one message template (`expression-refusal.ts`, the contract),
hence four codes, mirroring `type-mismatch-run-fails` /
`type-mismatch-run-may-fail`. The run-fails sentence carries no "the
write that fired it still lands" clause: `run-fails` also covers a
time-relative sweep, which no write fires.
**Routing.** No new mechanism: `dateFlowArm(scope, faultOutcome,
bareNamesUnproven)` reads the hint lint already passes
(`faultOutcomeOf`, `bareNamesUnproven` from #30025). The date verdicts
read bare names only, so `bareNamesUnproven` downgrades them to
`-run-may-fail`; a bare name a flow variable holds (`flowVariables`) is
still excluded from typing, as before. Grading stays `error` everywhere.
`@objectstack/lint` changes only the fault-outcome ledger's docblock.
## Tests
- `packages/formula/src/expression-refusal-codes.test.ts`: a `PINS`
entry for each new code (exact params and message); the flattened pins
that used to sit under `date-arithmetic` / `date-text-arithmetic` move
to `-run-may-fail` (their schema declares no outcome); the record-scoped
pins are untouched. `SWEEP_SCHEMAS` gains the flattened deal schema with
`faultOutcome: 'run-fails'` and `SWEEP_SOURCES` a flattened date
subtraction, so the sweep reaches all four codes and holds their params
to their messages.
- `packages/formula/src/validate.test.ts`: flattened `start_date + 1 >
3` under `run-fails` → `-run-fails`; with no outcome and with
`bareNamesUnproven` → `-run-may-fail`; neither says "evaluates to null";
`flowVariables: ['start_date']` → no verdict; control: a record-scoped
`fail-closed` rule keeps `date-arithmetic` and its null sentence.
- `packages/formula/src/validate-date-text-arithmetic.test.ts`: the
flattened case now asserts `-run-may-fail`, plus `-run-fails` under the
outcome and `-run-may-fail` under `bareNamesUnproven`.
- `packages/lint/src/validate-expressions.test.ts`: three flows
(record-triggered, `schedule`, `type: 'api'`), each with a start
condition, an edge condition (date arithmetic) and a `decision` branch
(date subtraction): every verdict `error`, the record-triggered one says
"this faults at runtime, and a flow condition …", the other two "this
faults wherever `close_date` holds …", none "evaluates to null".
Control: a record-scoped validation rule's date arithmetic keeps the
null sentence.
<details><summary>Suites (head f4501b7, under os-verify-lock, shared
box)</summary>
```
formula test Test Files 64 passed (64) Tests 1644 passed (1644)
lint test Test Files 193 passed (193) Tests 7996 passed (7996)
mcp test Test Files 56 passed (56) Tests 675 passed (675)
typecheck (tsc --noEmit + check:test-typecheck): formula 0, lint 0
```
</details>
<details><summary>Ablation (scripts/ablation-replace.mjs; restored: blob
== HEAD, git diff HEAD empty)</summary>
```
A1 formula: dateFlowArm always answers null (`if (scope !== 'flattened' || true /* ablated-30016-a1 */) return null;`)
— the old "silently evaluates to null" sentence and code come back on every flow site
× in a flow condition says the run fails, and keeps the null sentence on a record-scoped rule (#30016)
× judges a flattened (flow) condition the same way, under the flow codes (#30016)
× date-arithmetic-run-fails · × date-arithmetic-run-may-fail · × date-text-arithmetic-run-fails · × date-text-arithmetic-run-may-fail (PINS)
× the SWEEP (code set unreached)
Tests 7 failed | 197 passed (204)
```
</details>
## Acceptance notes
- **A record-scoped `fail-closed` validation rule still says "silently
evaluates to null".** There the fault refuses the write
(`rule-validator.ts` `checkPredicate`, the ledger's `fail-closed` row),
so the sentence is not true either. The card keeps that sentence and the
seat ruled it out of scope; reported as a finding, not fixed here.
- **`type-mismatch-run-fails` on a time-relative sweep says "the write
that fired it still lands".** Since PR #30015 the `run-fails` outcome
also covers a time-relative sweep of the typed object, which no write
fires. Pre-existing, outside this card's date scope; the date sentence
here avoids the clause. Reported as a finding.
- **The date verdicts stay errors on flows that are not
record-triggered,** where the type-mismatch verdict is a warning because
what the run binds is not proven. Grading was ruled unchanged; the
`-run-may-fail` sentence states the condition under which the run fails,
which is true at that grade.
- **`content/docs/data-modeling/formulas.mdx`** is outside the claimed
file surface; its two date rows make no flow-specific null claim, so it
is left as is.
## Verification
All at head `3eea4f73` (`git rev-parse --short HEAD`), the commit this
PR opens on (`origin/main` merged once).
- `node scripts/pm/dispatch-gates.mjs --commands --repo
objectstack-ai/objectstack`: 58 derived families (re-derived after the
merge of `origin/main`, the same 58), each run on this head after a full
`turbo run build` (`--filter='!@objectstack/docs'`, VERDICT command-exit
0), all **exit 0**. `--ran`: "58 derived famil(ies) accounted for — 58
run, 0 NOT-MEASURED". Among them `check-adr-0087-registration --base
origin/main` (exit 0: no semantic entry is required for this move, so
none is added), `check-changeset-no-major`, `check-empty-changeset`,
`check:docs-transcript-drift`, `check:doc-authoring`,
`check:test-source-alias`, `check:cross-package-test-inputs`,
`check:dts-closure`, `check:dual-build-cjs-loads`,
`check:lean-entry-closure`.
- `pnpm lint` (`eslint . --no-inline-config`): exit 0.
- Full dogfood: not run. The title has no `!` and `Clause-②` has no
`(narrowing)` arm.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
https://claude.ai/code/session_01Utp6Ca5BRUDW37pk8jE1gW
Co-authored-by: Claude <noreply@anthropic.com>
fix(formula,lint): a date-arithmetic verdict in a flow condition says the run fails, not that the value reads null
7
+
8
+
Clause-②: yes (widening)
9
+
Metadata-protocol: none
10
+
11
+
- **`@objectstack/formula`: four codes join `ExpressionRefusalCode`**: `date-arithmetic-run-fails`, `date-arithmetic-run-may-fail`, `date-text-arithmetic-run-fails` and `date-text-arithmetic-run-may-fail`, with the same params as `date-arithmetic` / `date-text-arithmetic`. A flow condition (a `'flattened'` site) that does arithmetic on a date field used to be told the field "silently evaluates to null", but the engine's `evaluateCondition` throws on the fault on every flow, so the run fails at the condition. Where the caller declares the run proven to hold the field (`faultOutcome: 'run-fails'`, with `bareNamesUnproven` unset) the verdict is served under `-run-fails` and says the run fails; anywhere else in a flow it is served under `-run-may-fail` and says the run fails wherever the name holds the field's date when the condition runs (a flow started by an API call, an action or a parent flow binds what its entrance hands over, which can be a number). The grade is unchanged: an error at every site. A `record`-scoped site (a formula field, a validation rule, a display predicate) keeps `date-arithmetic` / `date-text-arithmetic` and their sentence. A consumer keyed to the old codes on a flow condition re-keys to the new ones.
12
+
-**`@objectstack/lint`**: the fault-outcome ledger's docblock names the date verdicts' flow codes; the routing is the existing `faultOutcome` / `bareNamesUnproven` hint, unchanged.
0 commit comments