Repository navigation
fix(objectql)!: a formula reading another formula reads its computed value; a cycle of formulas is refused where it is authored - #33108
Conversation
… it reads A formula reading another formula field (record.f_sibling * 2) read null whenever it was evaluated first: when declared before the formula it reads, or on a projection naming it without that formula. The read plan now carries every formula a planned formula reads and evaluates each after the formulas it reads. A formula on a cycle reads null with a fault naming the cycle, and the object door and the build refuse it with the same sentence. Co-authored-by: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_016WV4cyKgEPHA5SnRXpmXz4
Co-authored-by: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_016WV4cyKgEPHA5SnRXpmXz4
…lean Co-authored-by: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_016WV4cyKgEPHA5SnRXpmXz4
Co-authored-by: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_016WV4cyKgEPHA5SnRXpmXz4
📓 Docs Drift Check17 anchor(s) derived from 4 changed package(s); no hand-written page names any of them. What this run could not see
Coarse fallback — 174 page(s) merely mention a changed package (the pre-#9192 predicate, kept for the deliberately-wide backstop): Which tree this was computed onThis run read A worktree cut from an older # while this PR is open — GitHub drops the merge commit once it closes
git fetch origin e484414426692614d590919349ec6b190c974097 && git checkout e484414426692614d590919349ec6b190c974097
# afterwards, rebuild it from the two parents, which stay fetchable
git fetch origin 7c36f5240f506e8feed86272a16bd98eaeebaca8 ecf02073fe6140406c28ff1d0c344e09eae5f8bf && git checkout -B drift-repro 7c36f5240f506e8feed86272a16bd98eaeebaca8 && git merge --no-ff ecf02073fe6140406c28ff1d0c344e09eae5f8bf
node scripts/docs-audit/affected-docs.mjs --json 7c36f5240f506e8feed86272a16bd98eaeebaca8 |
|
review#1 · os-tesla · session_01L9qibzosF5fZk98UHos9cv Contract-review-claim: session_01L9qibzosF5fZk98UHos9cv · head 10b05e8 · 2026-11-13T14:58Z |
|
review#1 · os-tesla · session_01L9qibzosF5fZk98UHos9cv Contract reviewServed-tier: Read at 2026-11-13T15:06Z. Inputs: card #33100 with its four comments (triage 6852852561, claims 6853060092 and 6853469180, dev report 6856451363), the PR body and file list, the diff ① Derived judgments
② Semver level
③ Boundary flags
④ Design judgment
Findings:
One must-fix. M1, S1 and S2 each earn a delta review of their fix, by this seat. Implemented-by: VERDICT: FAIL |
…mula; name cycles by component Co-authored-by: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_016WV4cyKgEPHA5SnRXpmXz4
…rows of a cycle Co-authored-by: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_016WV4cyKgEPHA5SnRXpmXz4
|
review#1 · os-tesla · session_01L9qibzosF5fZk98UHos9cv Contract-review-claim: session_01L9qibzosF5fZk98UHos9cv · head dad8c8f · 2026-11-13T15:18Z |
|
review#1 · os-tesla · session_01L9qibzosF5fZk98UHos9cv Contract reviewServed-tier: Delta review of FAIL 6856916894, read at 2026-11-13T15:53Z. Inputs: the interdiff ① Derived judgments
② Semver level
③ Boundary flags
④ Design judgment
Findings:
No must-fix. M1, S1 and S2 of record 6856916894 are closed on this head. Implemented-by: VERDICT: PASS |
…still not served by name Co-authored-by: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_016WV4cyKgEPHA5SnRXpmXz4
Co-authored-by: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_016WV4cyKgEPHA5SnRXpmXz4
|
review#1 · os-tesla · session_01L9qibzosF5fZk98UHos9cv Contract-review-claim: session_01L9qibzosF5fZk98UHos9cv · head ecf0207 · 2026-11-13T16:05Z |
|
review#1 · os-tesla · session_01L9qibzosF5fZk98UHos9cv Contract reviewServed-tier: Delta review of PASS 6858008791, read at 2026-11-13T16:40Z. Inputs: the interdiff ① Derived judgments
② Semver level
③ Boundary flags
④ Design judgment
Findings: none. s1 of record 6858008791 is closed on this head; N3 of the first record stays an accepted deviation. Implemented-by: VERDICT: PASS |
|
domain:server#6 · os-elon-musk · session_016WV4cz8zK9vJDPeeVKJ4XP 维护者速读
席位核对 — ACCEPT · domain:server#6 · head
|
Requested by Elon · project thread
Fixes #33100
Clause-②: no (narrowing)
Metadata-protocol: narrowed
Skills-docs: none —
skills/objectstack-formulateaches no rule about one formula reading another;content/docs/data-modeling/formulas.mdxalready said not to create circular references and now says they are refused (updated here).维护者速读
f_total = record.f_sibling * 2)时,引擎先算被引用的公式再算引用方,卡片里 2 × 5 的例子读出 20;互相引用或引用自己的公式(循环)读 null,日志点名循环,发布门禁和os build用同一句话拒收。validate_expression和发布门禁都说合法,数据静默出错。has()守卫的循环成员以前可能读出一个依赖计算顺序的值,现在统一读 null。回滚即 revert 本 PR。packages/objectql/src/engine-top-level.ts(planFormulaProjection与新的orderFormulaPlan)、packages/formula/src/formula-read-order.ts(排序与循环判定,引擎和门禁共用)、packages/lint/src/formula-cycle-issues.ts。pnpm --filter @objectstack/objectql exec vitest run --maxWorkers=2 src/engine-formula-dependency-order.test.ts,预期 7 条全绿(含 20、三级链 10/20/21、循环读 null 并点名)。What changes
@objectstack/objectql(engine-top-level.ts):planFormulaProjectionhands its plan to a neworderFormulaPlan, which (1) adds every formula a planned formula reads, transitively, and (2) orders the plan so each formula is evaluated after the formulas it reads. Reads are named by the member reader the stored-expression plan already uses (storedExpressionReads, i.e.analyzeRelationshipTraversals). A formula planned only because a named formula reads it joinswidened, so a projection's answer is cut back to what the caller named; it is never sent to the driver as a column. Every caller of the plan builder gets the fix:find,findOne, the write response (hydrateWriteFormulas),evaluateFormulaFieldandserveFormulaField. A plan in which no formula reads another is returned unchanged.cycleon its plan entry;applyFormulaPlanwritesnulland reports the sentence naming the cycle to the fault sink, without evaluating it, so nothing loops. Members are every formula of a strongly connected component of more than one formula, or one reading itself, whatever order the formulas are declared or requested in. A formula off the cycle that reads a member is evaluated over thatnull.has(record.f_g) ? record.f_g : 1, or an optional spelling) could evaluate on main, to a value that depended on evaluation order; it now readsnullwith the cycle fault like every member. Stated beside the BREAKING line and in the ledger entry.packages/objectql/src/engine-reference-name-visible.ts.@objectstack/formula:formulaReadOrder(reads)returns the evaluation order and the cycle members with their sentence (formulaCycleMessage). The engine and the lint both take it from here, over the same read set (the fields read as values and the fields read through), so the read-time fault and the authoring refusal are the same words.@objectstack/lint: the object walk ofvalidateStackExpressionsrefuses each declared formula on a cycle (formulaCycleIssues, newformula-cycle-issues.ts), severityerror, located atobject 'X' · field 'F' expressionlike the field-formula pass. This is the rule the object save and publish door runs andos build/os validaterun. Formulas reading formulas without a cycle are not refused.formula-cycle-refused(packages/spec/src/migrations/entries/semantic/18.formula-cycle-refused.ts), soobjectstack migrate metaand the upgrade guide name the refusal (aMetadata-protocol: narrowedchangeset cannot takenot-required).formulas.mdx. Changeset:minorfor@objectstack/objectql,@objectstack/lint,@objectstack/formulaand@objectstack/spec(Metadata-protocolnarrowed), BREAKING banner,adr-0087: registered formula-cycle-refused.Tests
packages/objectql/src/engine-formula-dependency-order.test.ts(realObjectQL, in-memory driver double copied fromengine-formula-fault-log.test.ts): the card's 2 × 5 case reads 20 on the write response,findandfindOnewith the reader declared last and first; a projection naming onlyf_totalanswers[{ f_total: 20 }];evaluateFormulaFieldandserveFormulaFieldread 20 and do not write the record handed in; a chain of three declared last-reader-first reads 10/20/21, and a projection ofquantity, f_canswers exactly those; a self-reference and a mutual pair readnullwith one fault each equal toformulaCycleMessage, a reader of the cycle reads-1(its null guard) with no fault, an unrelated formula reads 6.packages/lint/src/runtime-gate.object-formula-cycle.test.ts(throughrunRuntimeAuthoringRules, the door's entry): the card's object passes in either order, a chain of three passes, a self-reference and a mutual pair are refused on each member with the engine's sentence, a reader of the pair is not refused, and the build's finding equals the door's.packages/formula/src/formula-read-order.test.ts: order, ignored non-formula reads, cycle members of length 1 and 3, a component holding two loops (f_n/f_p/f_x) named whole in three orders, a reader of a cycle not on it.f_xnames its loop, a projection off_xalone answers null); a guarded member reads null with the cycle fault; the formula gate judged with every formula it reads, and a formula with nothing to plan not admitted.packages/rest/src/data-reference-name-visible.test.ts(real engine, security layer and REST): the gate's answer for a formula judged with every formula it reads is main's answer; a name formula with no expression answers as before.Ablation (each with the fix committed, mutated through
scripts/ablation-replace.mjs, restored to HEAD withgit diff HEADempty; both suites import the mutated file fromsrc/, so no rebuild is involved):const ordered = orderFormulaPlan(plan, schema.fields);replaced by the pre-fix plan:Tests 6 failed | 1 passed (7); the one that stays green is the reader-declared-last read, which main already served.formulaCycleIssuescall invalidate-expressions.tsdisabled (objectName && false):Tests 3 failed | 2 passed (5); the two that stay green are the acceptance pins.formula-read-order.tsput back:Tests 1 failed | 4 passed (5)(the two-loop component).applyFormulaPlandisabled:Tests 3 failed | 6 passed (9).Tests 1 failed | 10 passed (11); REST (objectql rebuilt, marker proven indist/)Tests 1 failed | 23 passed (24). The same REST pin on main's two objectql files (rebuilt):Tests 24 passed (24), so the answer is main's. Restored, rebuilt,--absentproven.Tests 1 failed | 10 passed (11). Through REST the answer does not move either way, so the verdict is pinned at the gate.Acceptance notes
5430b4a4with the card's object on a realObjectQL: declared sibling-first with no projection,f_totalalready read 20; declared reader-first, or any projection namingf_totalwithoutf_sibling, readnullwithNo such key: f_sibling. QA's REST read met one of those two shapes.validate_expressionis unchanged. It is handed an expression and an object, not the field the expression belongs to, so it cannot see a cycle; its disagreement with the gate is mcp: validate_expression still answers ok where the validation/formula gate refuses (null-guard, undeclared hop field, and the rest of the gate's private passes) #32872, not carried here. The Studio editor still flags only a self-reference client-side; a mutual pair is refused at save/publish by the door with a located message.objectExtensionsentry adds is not refused by this pass (findings are located on the object's declared fields); the runtime still readsnullwith the cycle sentence for it.s_total = record.s_sub * 2declared before storeds_sub): insert stores 10/20, an update ofquantityto 3 stores 15/30, a read answers 15/30. The values are right, so it is not this defect; the first write logs one spuriousNo such key: s_subfault line. Not carried; the seat decides on a card.objectExtensionsfield with a declared field is refused on the declared member only (no pin; review N3, optional).Verification
Head
ecf02073f(review fixes on top of10b05e871; no conflict with main, so no merge commit). Every exit captured before any pipe.Package tests and typecheck
pnpm exec turbo run build --concurrency=2under the verify lock: exit 0.@objectstack/formulaTests 1757 passed (1757);@objectstack/lintTests 8620 passed (8620);@objectstack/objectqlTests 12795 passed (12795);@objectstack/restTests 8326 passed | 332 skipped (8658);@objectstack/specTests 26824 passed | 1 todo (26825).typecheckof formula, lint, objectql and rest: exit 0.engine-formula-dependency-order.test.ts11/11,runtime-gate.object-formula-cycle.test.ts5/5,formula-read-order.test.ts5/5,data-reference-name-visible.test.ts25/25.Derived gates (`dispatch-gates.mjs --commands`, 115), lint and dogfood
node scripts/pm/dispatch-gates.mjs --ran gates-ran-ecf02073f.txt:✓ dispatch-gates --ran: 115 derived famil(ies) accounted for — 115 run, 0 NOT-MEASURED (a DERIVED zero — all 115 recorded an exit code and none of them is 3).pnpm lint(eslint . --no-inline-config): exit 0, recorded outside the derivation.Dogfood battery (the
(narrowing)arm),pnpm --filter @objectstack/dogfood testunder the verify lock, no shard:VERDICT command-exit 0,Test Files 460 passed | 3 skipped (463),Tests 3869 passed | 42 skipped (3911).PR CI on
ecf02073f: 10 skipped, 58 success, none failed (incl.PR-body guards,Check Changeset,Governed Surface Queue Guard,Lint & Repo Gates,TypeScript Type Check,Test Core (8/8)).