Skip to content

[Decision] Formula inspector: prove a quantity read through a relationship, or keep the declared currency as an accepted limit (hop arm of #35815) #38111

Backlog

Description

@objectstack-fleet

repo:objectstack#8 · sunhaolin · session_017xRBcSAaBEfQpU2yJexSJ8

Filing gate ②, Source: fleet. Carries the relationship-hop arm of #35815; #35815 keeps the field-over-field arm and rider N3 (PR #38108).

维护者速读

  • 问题:作者在 Studio 里把一个"金额"公式改成"经关联对象读到的数量"(例如客户的员工数乘以二)后,这个字段仍带着货币符号显示;只影响显示,存的数不变。自带示例和平台对象里今天没有一条公式是这种写法。
  • 选项:A 维持现状,作者手动把结果类型改回数字,不需要新 PR;B 让系统读取关联对象的字段后自动撤掉货币标记,约两个 PR,并且要扩大一个已对外发布的接口。
  • 推荐 A:没有人撞上这个写法,而 B 要为这一种写法永久多维护一段对外接口。
  • 不定会怎样:现状就是 A 的效果,已合入修复的"本对象字段相乘/相除"不受影响;只是这一支一直挂着没有结论。

Background

After #35631 (PR #35774) Studio's formula inspector withdraws a declared currency only when inferFormulaReturn answers number ("proved not money"). PR #38108 makes it answer number for field-over-field quantity arithmetic and same-currency ratios. One shape #35815 named is left: a quantity read through a lookup or master-detail hop, record.account.employee_count * 2. The function is handed the host object's field map only, so the leaf's unit cannot be read; it answers {} and the declared currency stays. PR #38108 records this in the producer header as an accepted limit and reports it as a decision.

One-sentence question: an author who rewrites a money formula into a number read from a related record still sees a currency symbol on that field until they change the result type by hand; should the platform prove that case or leave it to the author?

Governing text: packages/spec/src/data/field.zod.ts:2731-2746 on origin/main 93fa9118: "Authoring stamps it from the inferred CEL type; absent when the type can't be proven (an ambiguous/dyn expression), except that a declared percent or currency stays", and authoring "withdraws a declared currency … when an edit leaves it answering number". packages/formula/src/formula-return.ts:99-103: "returnType — absent means NO verdict, never "declares nothing": the expression proves no type ({}, unproven), and a stamp keeps what the author declared (a currency, a percent). number means proved not money." Same file :64-65 lists the hop among the unproven reads: "a hop through a reference (record.account.balance) — the leaf's type is not on this object". ADR: none found (git grep -nE "inferFormulaReturn" origin/main -- docs/adr → 0 lines; git grep -ciE "returnType" origin/main -- docs/adr → one file, ADR-0079, unrelated).

Protocol: neither option conflicts with the governing text. A changes nothing. B changes no packages/spec schema and no metadata key, but widens the published @objectstack/formula surface (inferFormulaReturn input or FormulaSourceField): Clause-②: yes (widening), Metadata-protocol: none.

Premises (each with its re-check)

  1. The hop answers {} on the PR head. git grep -n "employee_count" b9bc5f06 -- packages/formula/src/formula-return.test.ts → line 279 pins toEqual({}).
  2. Zero first-party pull. git grep -nE "returnType:\s*['\"]currency['\"]" origin/main -- examples packages/platform-objects skills | grep -vE "CHANGELOG|\.test\." → 2 declarations (examples/app-crm/src/objects/opportunity.object.ts:81, examples/app-showcase/src/data/objects/project.object.ts:99); both read only same-object fields. Control (the population is reachable): hop reads in first-party formulas, git grep -nE "(cel|F)\`[^\`]*record\.[a-z_0-9]+\.[a-z_]+[^(a-z_]" origin/main -- examples packages/platform-objects skills | grep -vE "CHANGELOG|\.test\." → 6 lines, all returnType: 'text' display-name formulas in packages/platform-objects/src/identity/. Numeric-or-money formulas declared in the same paths: 5. Numeric formulas through a hop: 0.
  3. The inspector hands the producer the host object's fields only. git grep -n "inferFormulaReturnDeclaration(source, siblingDefs)" origin/main -- ui/packages/app-shell/src/views/metadata-admin/inspectors/ObjectFieldInspector.tsx → line 1154.
  4. The developer's "Studio condition builder: a sharing-rule (filter-compiled) condition is not told to the builder, so list membership is written in a CEL spelling the validator prescribes as .contains there #37847 reads this export" constraint has lapsed: gh api repos/objectstack-ai/objectstack/issues/37847 --jq .state → closed. It is not a cost of B any more.
  5. PR fix(formula): a proven quantity typed dyn answers number, so Studio withdraws a stale currency #38108 is open, draft, head b9bc5f06: gh api repos/objectstack-ai/objectstack/pulls/38108 --jq '[.state,.draft,.head.sha]'.

Options, real cost, workload

What is done What the author sees Workload
A Nothing further; the limit stays in the producer header as PR #38108 writes it After such an edit the field still draws a currency symbol until the author sets the result type to number in the inspector; stored values unaffected 0 PRs
B The producer takes related objects' field maps (or a reference-target member plus a resolver); the inspector loads each referenced object's fields before it asks The currency mark is dropped on that edit, as it now is for same-object arithmetic server + ui lanes, about 2 PRs (producer with a minor changeset; inspector). No precedent for widening the producer's inputs or for a hop-driven field load: git log -S is unusable here (shallow clone, 356 commits), so read from the PR list instead. Nearest landed sizes: PR #22733 introduced the producer, +715/−60, 29 files; PR #35774 wired the inspector to it, +475/−62, 10 files

A and B differ by more than 3× in workload (0 against two PRs of the #35774 class); axis ① reads the same way, so the gap does not drive the letter.

Business meaning. A: the result type is the author's declaration, like a column format in a spreadsheet; the platform corrects it only when it is certain, and tells the truth about where its certainty ends. B: the platform follows the formula across objects to keep the label right, like a spell-checker that also opens the other document.

Four axes

  • Long-term soundness. End state in two years: a formula's result type is a declaration the author owns, and authoring help covers what can be proved from the object in hand. Salesforce and Airtable both model it that way: the formula's return type or format is chosen by the author and is never withdrawn by the platform when the expression changes, cross-object formulas included. A keeps one input (the host object's fields) and one stated limit. B adds a second input and a resolver to a published function, for one shape, and every multi-hop, polymorphic-reference and unpublished-draft case becomes a new edge the producer must define.
  • Business pull. Nobody hits it today: 0 of 2 first-party currency formulas and 0 of 5 numeric ones read through a hop; all 6 hop formulas are text. The failure is a display label on an authoring edit, corrected in one click, and it only arises on a specific rewrite (money into hop quantity).
  • AI-mistake resistance. Under A the wrong state is silent but narrow: an AI or human author who rewrites the expression and leaves currency declared gets a money face on a number; no door refuses it. B fixes it only inside Studio's inspector; an agent writing metadata files never passes through the inspector, so B does not close the silent case for AI-authored apps either. A loud fix would be a publish-time check, which is a new gate and not proposed.
  • Startup focus. B is a declared, published surface with no consumer asking for it; once exported it is a permanent obligation. A declares nothing.

os-decision-facets
① Long-term soundness: A shrinks nothing and grows nothing; B grows the published producer contract (a second input or a resolver) for one shape. Reads A.
② Business pull: zero measured (0/2 currency formulas, 0/5 numeric formulas through a hop; 6 hop formulas, all text). Zero pull defaults to defer. Reads A.
③ AI-mistake resistance: both leave the file-authoring path silent; B is loud nowhere, it only corrects inside Studio. No difference that favours B. Reads A.
④ Startup focus: B adds a public surface and an inspector metadata read to maintain; A adds none. Reads A.
Prior rulings read: label:needs-user-decision formula currency, inferFormulaReturn related object fields, formula currency relationship hop → 0 rulings (1 / 12 issue hits, only #35815 on topic); ADR none; thread: #35815 (4 comments, no ruling)

Recommendation

A. By ① alone: the declared-type model is the end state, and B's added input is contract growth for a shape nobody writes. B is not taken because it buys a display correction for zero measured users at the price of a permanent export.

Confidence gaps, stated and not used to change the letter: (a) the zero is measured over this repository's examples, platform objects and skills only; third-party and cloud tenant apps are outside the radius and were not read. (b) The symptom is read from code and the test pin, not driven in a browser. (c) B's size is the developer's estimate plus the two nearest landed PRs, not a precedent of the same change; the inspector already loads one related object's fields elsewhere (useObjectFields(reference), ObjectFieldInspector.tsx:2868), so the async read is not new to the file, which may make B's inspector half smaller than stated.

只看①选 A;②③④ 是否翻转:否

Execution after the answer

Related

#35815 (parent card, field-over-field arm and N3), PR #38108 (open draft, +162/−20), #35631 and PR #35774 (the currency verdict), PR #22733 (introduced inferFormulaReturn), #37847 (closed; no longer constrains the export).

Dedupe: formula currency relationship hop → 12 hits, inferFormulaReturn related object fields → 1 hit; only #35815 is on topic, and it is this card's parent.

Grade: area:data · Feature · p3 · reach: Studio authors who edit a currency formula into a lookup-hop quantity; display only · evidence read (0 first-party formulas of this shape)

Activity

  1. added
    needs-user-decision
    on Nov 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:dataneeds-user-decisionpriority:p3

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions