Skip to content

docs(spec): the FlowSchema example guards its nullable amount comparisons - #31416

Merged
objectstack-fleet[bot] merged 4 commits into
mainfrom
claude/project-thread-ao69dp
Nov 8, 2026
Merged

objectstack-fleet[bot] merged 4 commits into
mainfrom
claude/project-thread-ao69dp

Conversation

@objectstack-fleet

Copy link
Copy Markdown
Contributor

Requested by 田騏 · project thread

Fixes #31367

Clause-②: no
Metadata-protocol: none

维护者速读

  • 改了什么: FlowSchema 文档注释里的审批流示例:开始节点绑定到 order(记录更新后触发),自动审批边改为 record.amount != null && record.amount < 500,送审边改为默认边(isDefault: true)。只改注释文字,外加一个 patch changeset。
  • 为什么改: 原示例对可空的 amount 直接做 < / >= 比较;作者照抄并绑定到金额可选的对象时,发布期空值保护规则会拒收两条边,运行时金额为空会让流程失败。现在金额为空的订单走人工审核,而不是失败或被自动通过。
  • 风险与回滚: 无 schema 形状变化、无接受集变化、无参考页再生成(该示例不进入任何生成产物);回滚即 revert。
  • 先看: packages/spec/src/automation/flow.zod.ts 的 @example Simple Approval Logic(约 L1048–1078);.changeset/31367-flow-example-amount-null-guard.md。
  • 两分钟验证: 打开上述示例,确认 e2 带 != null 保护、e3 为 isDefault: true、开始节点有 config: { objectName: "order", triggerType: "record-after-update" }。
  • 需要你做的: 无,席位落地。

What changes

The FlowSchema TSDoc @example in packages/spec/src/automation/flow.zod.ts:

  • The start node now carries config: { objectName: "order", triggerType: "record-after-update" }. Before, it named no object, so the example was never record-triggered (resolveFlowTriggerKind reads start.config.triggerType) and the null-guard rule never judged it.
  • Edge e2 (auto-approve): record.amount < 500 becomes record.amount != null && record.amount < 500, the != null && idiom from the formula skill and the precedent PR docs(spec): guard the nullable amount in the docs examples and the validation condition example #31358.
  • Edge e3 (review): record.amount >= 500 becomes isDefault: true with no condition. It takes every order e2 does not, including one with no amount.
  • Three comment lines: on a record-triggered flow an optional field reads null when unset, < on null aborts the condition, test != null first (has() does not); and why e3 is the default edge.

Plus a '@objectstack/spec': patch changeset.

The choice the card asked for: guard the condition, not required: true

The FlowSchema example defines no object, so it has nowhere to declare required: true. #31358 chose required only where the object was defined in the same snippet (common-patterns.mdx). An author copying a flow example binds it to an object they already have, and on that object amount is usually optional. So the example teaches the guard they need to write.

For the review edge, the schema's own isDefault docblock (a few lines above the example) says the "otherwise" branch should be a default edge, not a hand-written negation of every sibling condition. The first draft used record.amount == null || record.amount >= 500. That also passes the rule, but the review asked for the default edge, and this version uses it. Routing with the decision node's out-edges (exclusive, first condition that holds, else the default): amount 499 goes to auto_approve, while 500 and null go to submit_for_approval. The routing is exhaustive and exclusive.

Tests

Proof against the real rule: a scratch vitest file in packages/lint/src (not committed). It evaluated the @example object literal verbatim from the file (from origin/main for "before", from the branch for "after") and ran validateStackExpressions (the gate os validate, os build and the publish gate run) with order.amount declared { type: 'currency' } (nullable):

Readings
BEFORE verbatim (start unbound) null-guard findings 0   (the premise: it passes only because the start names no object)
BEFORE bound to order(amount optional) null-guard findings 2
   - error flow 'approve_order_flow' · edge 'e2' (check_amount→auto_approve) condition :: … applies `<` to `record.amount`, which 'order' declares as nullable …
   - error flow 'approve_order_flow' · edge 'e3' (check_amount→submit_for_approval) condition :: … applies `>=` to `record.amount`, which 'order' declares as nullable …
AFTER verbatim null-guard findings 0
AFTER verbatim ALL expression issues 0
AFTER FlowSchema.safeParse success true

I added no permanent test. The guard semantics (!= null &&, == null ||, has() is not a guard) and the edge wiring are already pinned in packages/lint/src/validate-null-guards.test.ts and validate-expressions.flow-null-guards.test.ts, and this diff changes only doc-comment text.

Acceptance notes

  • gen:schema + gen:docs produce no diff: build-docs.ts renders .describe() text, not TSDoc @example, and no file under content/docs/references/** or packages/spec/json-schema embeds this example.
  • Out of scope, the same unguarded idiom elsewhere (no card filed; listed for the seat): skills/objectstack-automation/references/state-machines-and-approvals.md (record.amount > 500000 / <= 500000), and packages/services/service-automation/README.md (record.amount > 500).

Verification

Local gate union on the final head f6f11f22 (merge of origin/main into 8c1cc37), derived by node scripts/pm/dispatch-gates.mjs --commands --repo objectstack-ai/objectstack:

  • 79 families derived, 79 run, all exit 0. dispatch-gates --ran: "79 derived famil(ies) accounted for, 79 run, 0 NOT-MEASURED (a DERIVED zero)".
  • Prerequisites cleared before the run: a ./packages/** turbo build (81 tasks, for check:dual-build-cjs-loads, check:lean-entry-closure and lint's check:doc-formula-expressions), plus the fetched positive-control commit for check-plugin-teardown-shape --self-test.
  • After the merge: pnpm install --frozen-lockfile, spec gen:schema + gen:docs (no diff), check:generated. Its first run hit a heap-limited tsc in check:test-typecheck ("failed without diagnostics"). Rerun alone with NODE_OPTIONS=--max-old-space-size=6144: exit 0, "52 file(s) / 240 error(s) / 131 pinned signature(s) held". All 14 artifacts are current, and the tree is clean.
  • eslint --no-inline-config packages/spec/src/automation/flow.zod.ts: exit 0. node scripts/check-nul-bytes.mjs: exit 0.
  • The proof (Tests above) was re-run on f6f11f22 with the same readings.
  • CI owns the repo-wide pnpm lint, test:repo and the full check farm.

Fable review of the spec diff (the maintainer's standing rule for spec changes): round 1 PASS with nits, with two should-fixes: use isDefault instead of the hand-written negation, and bind the start node / qualify the comment. Both are fixed in 8c1cc37. The incremental re-review of the delta: PASS. The verdict comment is posted on this PR.

Human Minimum

  • 1. Schemas start as Zod; packages/spec holds no runtime logic.
  • 2. Every name I added uses the casing for its kind.
  • 3. No formatter ran; pnpm lint passes.
  • 4. One issue, one branch off an up-to-date main, one pull request.
  • 5. A change that publishes carries a changeset, and both declaration lines are filled in here and in the changeset.
  • 6. packages/spec touched: its generated artifacts are regenerated and committed (none changed).
  • 7. No hand edits to content/docs/references/, packages/*/CHANGELOG.md or content/docs/releases/.
  • 8. Title, body and comments are in English (the 维护者速读 block is the repo's own Chinese reader section).
  • The Before Submitting list in CONTRIBUTING.md is done.

🤖 Generated with Claude Code

https://claude.ai/code/session_017ihL2ejruuhep9NDrZsCT7

…sons

The example's two decision edges compared record.amount with < and >=
unguarded. Bound to an object whose amount is optional, the publish-time
null-guard rule refuses both. Guard e2 with `!= null &&` and route a
missing amount to review on e3 with `== null ||`.

Co-Authored-By: Claude <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017ihL2ejruuhep9NDrZsCT7
…the default edge

Review follow-up. The example's start node named no object, so the
null-guard rule never judged it; bind it to `order` on
record-after-update so it is judged as written. Replace the hand-written
negation on the review edge with `isDefault: true`, the spelling the
schema's own isDefault doc prescribes for "otherwise", and qualify the
comment to record-triggered flows.

Co-Authored-By: Claude <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017ihL2ejruuhep9NDrZsCT7
@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

domain:spec#4 · marchtian · session_017ihL2ejruuhep9NDrZsCT7

Fable review of the spec diff

Reviewed at 2026-11-08T06:53Z. The maintainer's standing rule for spec changes: an independent full review of the whole diff by an isolated subagent, which was given the diff and the card, not the author's conclusion.

Round 1 (head 38b3ef2): PASS with nits.

  • Rule acceptance confirmed: findUnguardedNullableOperands returns no finding for record.amount != null && record.amount < 500 or record.amount == null || record.amount >= 500. It flags has(record.amount) && …. Edge conditions take the same path through both doors (os validate and the runtime publish gate). The two doors differ only on a bare start guard.
  • should-fix 1: e3 hand-wrote the negation (record.amount == null || …), which the schema's own isDefault docblock disfavours. Use isDefault: true. Routing is unchanged: null and 500-plus fall through to the default edge.
  • should-fix 2: "an optional field reads null" holds only on a record-triggered flow. The example's start node had no config, so resolveFlowTriggerKind never classed it record-triggered. Qualify the comment, and bind the start node.
  • No change needed: guard over required: true (the example defines no object); the changeset level and declaration lines; generated artifacts (build-docs.ts does not render TSDoc @example).
  • Out of scope, for the seat: the same unguarded idiom in skills/objectstack-automation/references/state-machines-and-approvals.md and packages/services/service-automation/README.md.

Fixes: commit 8c1cc37. The start node now carries config: { objectName: "order", triggerType: "record-after-update" }, e3 is isDefault: true, and the comment is qualified to record-triggered flows.

Incremental re-review (38b3ef2..8c1cc37): PASS.

  • FlowSchema.safeParse of the example passes, and resolveFlowTriggerKind returns record_change.
  • validateStackExpressions against an order with optional amount gives 0 issues on the example as written. With the original record.amount < 500 on e2 it gives 1 error, so the gate now judges the example.
  • The isDefault edge trips neither flow-default-edge-with-condition nor flow-multiple-default-edges. The runtime takes the default edge only when no conditioned sibling matched.
  • The comment and the changeset prose are accurate.
  • One nit, not taken: the changeset's "refuses both edges" describes the pre-change example.

Final head after merging origin/main: f6f11f2. That merge changed no file in this diff.

@github-actions github-actions Bot added documentation Improvements or additions to documentation tooling Fix lands in tooling, not a product package — enters pm:queue only with Unblocks: or a named surface labels Nov 8, 2026
@github-actions

github-actions Bot commented Nov 8, 2026 •

Copy link
Copy Markdown
Contributor

📓 Docs Drift Check

This PR changes 1 package(s): @objectstack/spec, touching 3 documentable anchor(s).

4 hand-written doc(s) NAME something this change touched and may need an implementation-accuracy re-verification:

  • content/docs/automation/approvals.mdx (via auto_approve (literal, a string literal in a comment on a changed line))
  • content/docs/automation/flows.mdx (via auto_approve (literal, a string literal in a comment on a changed line), check_amount (literal, a string literal in a comment on a changed line))
  • content/docs/getting-started/common-patterns.mdx (via auto_approve (literal, a string literal in a comment on a changed line), check_amount (literal, a string literal in a comment on a changed line))
  • content/docs/protocol/objectui/actions.mdx (via submit_for_approval (literal, a string literal in a comment on a changed line))

⛔ 2 release-owned page(s) also name something this change touched. These are read-only:

  • content/docs/releases/v17/17-0.mdx (via auto_approve (literal, a string literal in a comment on a changed line))
  • content/docs/releases/v18/18-2.mdx (via auto_approve (literal, a string literal in a comment on a changed line))

content/docs/releases/ is RELEASE-OWNED (AGENTS.md "Documentation Guardrails"): release
notes are written centrally at release time, and a code PR that edits them is the exact PR
that guardrail exists to stop. They are still audited — read-only. If one of them is actually
wrong, file an issue or open a dedicated docs-only PR; do not edit it here.

What this run could not see

Coarse fallback — 171 page(s) merely mention a changed package (the pre-#9192 predicate, kept for the deliberately-wide backstop): node scripts/docs-audit/affected-docs.mjs --json 383c3530304dfa2cdb08d031ab0b1e5b044b35e1 → packageMentionDocs.

Which tree this was computed on

This run read content/docs from 8bd0acf826c9843c0e5d4af0af21a10368bbca9e — the merge of head 0ec8e99a119c37e9d15985adde102a3b125a745a into base 383c3530304dfa2cdb08d031ab0b1e5b044b35e1, which is what actions/checkout gives a pull_request run. Not the PR head.

A worktree cut from an older main holds a different content/docs, so re-deriving there can legitimately return a different list — that is a different tree, not a wrong row. To answer on the same tree:

# while this PR is open — GitHub drops the merge commit once it closes
git fetch origin 8bd0acf826c9843c0e5d4af0af21a10368bbca9e && git checkout 8bd0acf826c9843c0e5d4af0af21a10368bbca9e
# afterwards, rebuild it from the two parents, which stay fetchable
git fetch origin 383c3530304dfa2cdb08d031ab0b1e5b044b35e1 0ec8e99a119c37e9d15985adde102a3b125a745a && git checkout -B drift-repro 383c3530304dfa2cdb08d031ab0b1e5b044b35e1 && git merge --no-ff 0ec8e99a119c37e9d15985adde102a3b125a745a

node scripts/docs-audit/affected-docs.mjs --json 383c3530304dfa2cdb08d031ab0b1e5b044b35e1

⚠️ That checkout carried uncommitted changes, so the commit above does not fully identify what was read.

Advisory only, and a precision-first one (#9192): a page is listed because it names a
symbol, wire route or SDK method this diff touched — not because it mentions a changed
package. Each row says which anchor put it there, so a wrong row is reportable rather than
merely annoying. To re-verify, run the docs-accuracy-audit workflow scoped to these files:
node scripts/docs-audit/affected-docs.mjs 383c3530304dfa2cdb08d031ab0b1e5b044b35e1 → pass the list as
args.docs, on the commit named under Which tree this was computed on.

@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

domain:spec#4 · marchtian · session_017ihL2eAG5J8aqAyPZif4BJ

Contract review

Served-tier: CONTRACT_REVIEW_TIER
Head-sha: f6f11f22bfe2b9994bcfbba5d06097f9f4e2dfd7
Local-runs: none
Scope: packages/spec/src/automation/flow.zod.ts (hit) + .changeset/31367-flow-example-amount-null-guard.md (implementing) + read-only: packages/lint/src/validate-null-guards.ts, packages/lint/src/validate-expressions.ts, packages/lint/src/lint-flow-patterns.ts, packages/spec/src/automation/flow-trigger-kind.ts, packages/spec/src/automation/flow-start-config-refusals.ts, packages/services/service-automation/src/dag-traversal.ts, packages/services/service-automation/src/builtin/logic-nodes.ts, packages/services/service-automation/src/builtin/decision-overlapping-edge-conditions.pin.test.ts, packages/triggers/trigger-record-change/README.md, skills/objectstack-formula/SKILL.md, content/docs/getting-started/common-patterns.mdx

① Derived judgments

  • The rule accepts e2, by reading: the flow is judged only when triggerKind === 'record_change' (validate-expressions.ts:2921), which resolveFlowTriggerKind derives from start.config.triggerType starting record- (flow-trigger-kind.ts). record.amount != null is a truth guard (validate-null-guards.ts:512 != arm) and && propagates only the LEFT conjunct's proofs rightward (:687), so record.amount != null && record.amount < 500 is unflagged; the guard order matches the rule. e3 carries no condition, so nothing to judge. Bare has() is not a guard (:38-41); the comment is accurate.
  • isDefault is the FlowEdgeSchema boolean (flow.zod.ts:1037): BPMN default flow, taken only when no sibling conditional edge matched, exclusive with condition. The engine honours it (dag-traversal.ts:716 runs default edges only when !anyConditionMet); a decision with no config.conditions is the plain-gateway path (logic-nodes.ts:38-45), exclusive first-match (decision-overlapping-edge-conditions.pin.test.ts:20). Lint refuses isDefault+condition (lint-flow-patterns.ts:1183), not this shape; gated edges = 2, ungated = 0, so no flow-decision-unconditional-branch finding.
  • Routing: amount < 500 (non-null) → auto_approve; ≥ 500 or null → submit_for_approval. Exclusive and exhaustive; null → review is the conservative branch, and the comment says so.
  • Start config: config is an open record (flow.zod.ts:695); objectName/triggerType are the keys the resolver and engine read (flow.zod.ts:1103); record-after-update is a listed token (trigger-record-change/README.md:37); flowStartConfigRefusals judges only filter-beside-timeRelative and schedule (flow-start-config-refusals.ts:135-160). Valid.
  • should-fix (design): binding the start to record-after-update with no start condition makes the example self-refire. auto_approve writes order.status, which is an afterUpdate on order, and the approvals-desk callback for ≥500 orders re-submits on every later update. Only skipTriggers seed writes are suppressed (record-change-trigger.ts:341-349). Precedent common-patterns.mdx:337-339 gates the start (record.status == 'submitted' && previous.status != 'submitted'); a one-line condition in the same config makes the example faithful.

② Semver level

@objectstack/spec patch: correct. TSDoc @example only; .describe() text and JSON schema unchanged. The changeset carries Clause-②: no / Metadata-protocol: none in the repo's form.

③ Boundary flags

The diff touches only the two files. No generated page embeds the example: approve_order_flow / Check Amount / record.amount < 500 hit only different examples (content/docs/automation/flows.mdx:31 uses order_amount; common-patterns.mdx:345 is the #31358 site, required: true at :313). Leftovers confirmed present: skills/objectstack-automation/references/state-machines-and-approvals.md:133,135 (filed #31417); packages/services/service-automation/README.md:192 (named in #31417). PR author objectstack-fleet[bot]; the body's run claims are unverified here, and this verdict rests on reading the rule.

④ Design judgment

Guarding the condition rather than required: true is right: the example defines no object. Using the default edge over a hand-written negation matches the isDefault docblock. Holds against the cited code, with the should-fix above.

Implemented-by: claude/project-thread-ao69dp
Reviewed-by: session_017ihL2eAG5J8aqAyPZif4BJ

VERDICT: PASS

…not relaunch itself

Contract review follow-up. The start node binds record-after-update with
no condition, so the auto-approve write (itself an update) would launch
the flow again. Launch only on the transition into 'submitted', as the
common-patterns approval example does.

Co-Authored-By: Claude <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017ihL2ejruuhep9NDrZsCT7
@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

domain:spec#4 · marchtian · session_017ihL2eAG5J8aqAyPZif4BJ

Contract review

Served-tier: CONTRACT_REVIEW_TIER
Head-sha: 0ec8e99a119c37e9d15985adde102a3b125a745a
Local-runs: none
Scope: packages/spec/src/automation/flow.zod.ts (hit, delta f6f11f2→0ec8e99a) + .changeset/31367-flow-example-amount-null-guard.md (unchanged) + read-only: packages/services/service-automation/src/engine.ts, packages/triggers/trigger-record-change/src/record-change-trigger.ts, packages/lint/src/validate-null-guards.ts

① Derived judgments (delta review f6f11f2 → 0ec8e99; round 1: 6718493750)

  • Fixes the self-refire: the engine evaluates start.config.condition before any node (engine.ts:6234-6246); the auto-approve write sets status: approved, so the re-fire sees record.status == 'submitted' false and is skipped, as is the approvals desk's later update. The re-entrancy breaker sits after this gate (engine.ts:6250-6262), so the condition is the declared suppression, not the breaker.
  • Read where the engine reads it: the same config.condition key the flow docblock names (flow.zod.ts:1103); the trigger does not evaluate it, the engine does for every entrance (engine.ts:6228-6233).
  • Passes the null-guard rule: ==/!= are never flagged (validate-null-guards.ts:43-44), so status nullability is moot.
  • previous exists: on record-after-update the trigger binds ctx.previous and materialises it over declared fields (record-change-trigger.ts:461-462, 532-533); previous is null only on a create leg, which this trigger type never takes.

② Semver level

Unchanged: docblock-only, @objectstack/spec patch stands.

③ Boundary flags

The delta touches one file, four comment lines; no generated page embeds the example.

④ Design judgment

Mirrors the common-patterns.mdx:337-339 precedent; the comment states the reason. Holds.

Implemented-by: claude/project-thread-ao69dp
Reviewed-by: session_017ihL2eAG5J8aqAyPZif4BJ

VERDICT: PASS

@objectstack-fleet
objectstack-fleet Bot marked this pull request as ready for review November 8, 2026 07:33
@objectstack-fleet
objectstack-fleet Bot enabled auto-merge November 8, 2026 07:33
@objectstack-fleet
objectstack-fleet Bot added this pull request to the merge queue Nov 8, 2026
Merged via the queue into main with commit 18ed2db Nov 8, 2026
65 checks passed
@objectstack-fleet
objectstack-fleet Bot deleted the claude/project-thread-ao69dp branch November 8, 2026 07:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation size/s tooling Fix lands in tooling, not a product package — enters pm:queue only with Unblocks: or a named surface

Projects

None yet

Development

Successfully merging this pull request may close these issues.

spec: the FlowSchema @example in flow.zod.ts compares a nullable record.amount unguarded on two edges (sibling of #31334)

2 participants