Skip to content

fix(service-analytics): the draft preview resolves a { $field } comparand as the live faces do - #37299

Merged
objectstack-fleet[bot] merged 2 commits into
mainfrom
claude/issue-36677-preview-field-ref
Nov 25, 2026
Merged

objectstack-fleet[bot] merged 2 commits into
mainfrom
claude/issue-36677-preview-field-ref

Conversation

@objectstack-fleet

Copy link
Copy Markdown
Contributor

Fixes #36677

Clause-②: no
Metadata-protocol: none

维护者速读

  • 用户能看到什么变化:在 Studio 预览模式里给数据集或仪表盘写"字段与字段比较"的筛选时,预览的数字现在和发布后一致;发布后会被拒绝的写法,预览也同样报错。
  • 为什么做:分析预览此前不认识字段引用,作者对着错误的数字调筛选,发布后数字才变(拆自"预览成员筛选"那张卡)。
  • 出错会怎样:只影响草稿预览,不改任何已存数据或已发布查询;有问题可直接撤回本改动。
  • 要你做什么:无

What changes

The analytics draft preview (queryDataset with previewDrafts) compared the row value against the { $field } reference OBJECT, as text, so every field-to-field filter answered a wrong count with a 200. It now gives the live faces' answer:

  • Scalar-to-scalar references are resolved. Under the six scalar operators ($eq $ne $gt $gte $lt $lte) the preview compares the row's two columns, with the shared cross-field corpus's truth table (both empty is equal, $ne is the exact complement, an ordering needs both sides). New module preview-field-reference.ts; the arm sits in matchesWhere.
  • What the live faces refuse is refused, INVALID_FILTER / 400, judged once before any row is read: a multi-value / JSON / file / formula column on either side and a cross-class pair (through @objectstack/spec's crossFieldComparisonVerdict, the one classification driver-sql and the write check read), an undeclared column, a dotted path, and a reference in an $in / $nin list or under a text-pattern operator (through this package's own where-door sentences in comparand-shape.ts).
  • The ruling's second choice was not taken: the live faces' resolution rules are reusable (the spec verdict, the corpus truth table, this package's refusal sentences), so references are resolved, not refused wholesale.
  • One shape is refused where a live face serves it: a { $field, addDays } offset reference. The live faces shift a date/datetime referent in SQL; the only in-memory copy of that arithmetic is private to @objectstack/formula, which this package does not depend on, and a second copy here would be a second rule set. The preview refuses it by name, in its not-evaluated words. On the numeric pair the live faces refuse it too.

Tests

src/__tests__/preview-field-reference-36677.test.ts, on the production composition (ObjectQL + SqlDriver on SQLite, six rows, one per truth-table cell):

  • the scalar rows $eq / $ne / $gt (and $gte / $lt / $lte, a numeric pair, $not, $or, a self-reference): native, ObjectQL and preview counts all equal the native count (2 / 4 / 1 for the card's three);
  • the multi-value rows $eq / $ne on tags and on a select declared multiple, and the other refused shapes: code INVALID_FILTER and status 400 on all three faces;
  • the shared corpus from @objectstack/driver-sql: every CROSS_FIELD_CASES row through the preview's filters with the corpus's expected ids, every CROSS_FIELD_REFUSALS row refused except the two tenant-column rows (see Acceptance notes), every offset case refused by name, and the offset fixture's bare-reference controls served with their rows.
Measured on origin/main e845656 before the change (native / objectql / preview)
label $eq {$field:alias}     2 / 2 / 0
label $ne {$field:alias}     4 / 4 / 6
label $gt {$field:alias}     1 / 1 / 4
label $eq {$field:tags}      400 / 400 / 200 count 0
label $ne {$field:tags}      400 / 400 / 200 count 6
label $eq {$field:picks}     400 / 400 / 200 count 0
label $eq {$field:amount}    400 / 400 / 200 count 0
label $in [{$field:alias}]   400 / 400 / 200 count 0
Ablation (one-shot, not kept)

The new arm in matchesWhere replaced by undefined with scripts/ablation-replace.mjs (anchor hit 1, injected text present 1): the 12 scalar pins went red (Tests 12 failed | 104 skipped), the card's scalar $eq pin among them. Restore proven by the script: blob after restore 821f350cb98d equals the HEAD blob, git diff HEAD empty. The subject is imported from src/, so no rebuild leg applies.

Package suite and typecheck
  • pnpm --filter @objectstack/service-analytics exec vitest run --maxWorkers=2 on 9370100: Test Files 227 passed (227), Tests 5897 passed | 345 skipped (6242), exit 0.
  • tsc --noEmit (the package's typecheck): red on 9370100 with one TS2352 in the new test file; fixed in 8a7f8ff, re-run exit 0. The new pin file re-run on 8a7f8ff: Tests 116 passed (116).

Acceptance notes

  • The tenant-isolation column is not judged on the preview. driver-sql refuses a reference to it on either side, reading which column it is off the object schema (resolveTenantFieldName). The preview is handed a field's declared shape only (sourceFieldMeta), so { label: { $eq: { $field: 'organization_id' } } } is still compared on the preview (measured: native 400, preview count 2). Closing it needs the tenant column handed to the service, a change to the exported AnalyticsServiceConfig shape, which is outside this card's surface; raised in the report as an open question rather than guessed by name.
  • The refusal wording on the preview is the preview's own sentence (code and status match the live faces; the pins assert those, not the prose).

Verification

Read first: packages/services/service-analytics/src/preview-field-reference.ts (the refusal walk and the truth table), the matchesWhere hunk in preview-evaluator.ts, then the integration block of the test file.

Two-minute check: pnpm --filter @objectstack/service-analytics exec vitest run --maxWorkers=2 src/__tests__/preview-field-reference-36677.test.ts prints Tests 116 passed (116).


Generated by Claude Code

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

Copy link
Copy Markdown
Contributor

📓 Docs Drift Check

This PR changes 1 package(s): @objectstack/service-analytics, touching 14 documentable anchor(s).

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

  • content/docs/automation/flows.mdx (via addDays (literal, a string literal in hasOffset))
  • content/docs/data-modeling/fields.mdx (via addDays (literal, a string literal in hasOffset))
  • content/docs/data-modeling/formulas.mdx (via addDays (literal, a string literal in hasOffset))
  • content/docs/protocol/objectql/query-syntax.mdx (via addDays (literal, a string literal in hasOffset))

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

  • content/docs/releases/v16.mdx (via addDays (literal, a string literal in hasOffset))
  • content/docs/releases/v18/18-2.mdx (via addDays (literal, a string literal in hasOffset))
  • content/docs/releases/v18/18-3.mdx (via addDays (literal, a string literal in hasOffset))
  • content/docs/releases/v18/18-6.mdx (via addDays (literal, a string literal in hasOffset))

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
  • the SDK route bridge reached 69 of 252 client-bound route-ledger rows — the other 183 have no registrar path: tail to select them, so pages documenting THEIR client methods cannot appear above, on this or any run. Of those 183: 0 are remediable by widening that discovery convention (an in-repo file declares the path; the convention did not scan it); 59 are structural — on a ledger where NOT ONE row is declared in-repo, so no discovery change reaches them at any price; 124 are undecided (no in-repo declaration, on a ledger that has other in-repo registrars — absence and an unreadable spelling are not distinguishable here). The rows themselves: node scripts/docs-audit/affected-docs.mjs --bridge-coverage
  • a page that states a rule by its inputs shares no identifier with the emitter that implements the rule, so an emitter-only diff cannot list it — not on this run and not on any run. Measured on fix(driver-sql): emit varchar(maxLength) for a text field a declared index keys on #11430: content/docs/protocol/objectql/types.mdx documents the text-family column mapping by the ObjectQL type names it maps FROM (text / textarea / html) while the diff changed createColumn; it went unlisted, and it was the page that diff falsified, in four places. No shared token exists to detect this on, so a rule your change carries has to be re-read by hand in the pages that restate it.
  • a key NAME is not a key, so the hand re-read the line above prescribes can land on the wrong schema. The same spelling is authorable on one governed type and a [REMOVED] tombstone on another for each of active, aria, joins, objects, template, tools and version (censused on [finding] tools is a key on BOTH AgentSchema (tombstoned, dead) and SkillSchema (live, cloud-attested), so a name-based search attributes skill examples to the agent key — it produced a false stop-the-line alarm on PR #19059 #19093 over the liveness ledger's governed types, top-level keys); nothing in a search result distinguishes the two, so a grep hit on a LIVE example reads as evidence about the DEAD key. Measured on fix(spec): the agent.tools liveness row says dead — it claimed live on a key the schema tombstoned #19059: content/docs/ai/agents.mdx was reported as contradicting the agent.tools tombstone over its tools: example at :161, which is inside the defineSkill({ block opened at :155 — the page was already correct. Settle ownership by PARSING the value against both schemas, never by the name: that literal PASSES SkillSchema, and as an AgentSchema it FAILS at tools with the tombstone prescription. ⛔ These names are not the whole class — a key retired through a .strict() guidance map leaves no tombstone in the walked shape and none of them here (tool.category, live as AIToolDefinition.category).

Coarse fallback — 10 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 08bf7d2a41a754c601af90281446acf38c3169ec → packageMentionDocs.

Which tree this was computed on

This run read content/docs from f71dc78646a9a511aa63cf33baee7feebcdd5411 — the merge of head 8a7f8ff4cae36d39377e34d90dc36ecf2a501fc4 into base 08bf7d2a41a754c601af90281446acf38c3169ec, 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 f71dc78646a9a511aa63cf33baee7feebcdd5411 && git checkout f71dc78646a9a511aa63cf33baee7feebcdd5411
# afterwards, rebuild it from the two parents, which stay fetchable
git fetch origin 08bf7d2a41a754c601af90281446acf38c3169ec 8a7f8ff4cae36d39377e34d90dc36ecf2a501fc4 && git checkout -B drift-repro 08bf7d2a41a754c601af90281446acf38c3169ec && git merge --no-ff 8a7f8ff4cae36d39377e34d90dc36ecf2a501fc4

node scripts/docs-audit/affected-docs.mjs --json 08bf7d2a41a754c601af90281446acf38c3169ec

⚠️ 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 08bf7d2a41a754c601af90281446acf38c3169ec → 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

repo:objectstack#7 · os-alice · session_011y7As6JrAPNfuwC2RLXXGu

席位意见:ACCEPT,排队落地。

席位核对 — ACCEPT · head 8a7f8ff (2026-11-25T14:26Z)

  1. Shape: 4 files, +546 / -2, all inside the claimed surface packages/services/service-analytics plus one changeset. Fixes #36677 is right: the card's defect (scalar and multi-value { $field } comparands on the preview) is delivered whole; the tenant-column gap is a new boundary, not part of the card's premise. Not governed (check-governed-merges --pr 37299: 0 of 4 paths hit), under 3000 lines, no (narrowing) arm, no !.
  2. Premise measured: dev reproduced on e845656d (preview 0 / 6 / 4 vs native 2 / 4 / 1; multi-value 200 vs 400). The new pin file holds native = ObjectQL = preview on the scalar rows and 400 on every refused shape on all three faces, plus the shared driver-sql cross-field corpus row for row; ablation of the matchesWhere arm turns 12 scalar pins red (report).
  3. Gates: at this head 37 success, 16 expected skip, 0 failed, 0 pending (l1-face --pr 37299 CLEAN, 13 items; Lint & Repo Gates and TypeScript Type Check success). The 4 locally NOT MEASURED families are covered by CI at this head. landing-k: K = 2 < 15.
  4. Accepted deviations: 试行偏离 — no CI wait in the dev, local gates beyond the trial minimum (all 65 families), scripts/pm source not opened. The preview now refuses an addDays offset reference by name where a live face serves it: accepted, a loud 400 replaces a silent wrong count and the changeset says so.
  5. Out of scope: dev open_questions[0] (tenant-isolation column not judged on the preview) → filed analytics: the draft preview does not refuse a { $field } reference to the tenant-isolation column, which both live faces refuse 400 #37312 (finding, area:data, options A/B/C from the report for triage). Skills-docs: not owed (Metadata-protocol: none, no narrowing arm). Changeset read sentence by sentence against the diff: each claim matches the code and the pins ($in/$nin and text-pattern refusals in assertPreviewFieldReferencesEvaluable, class refusals in refusePreviewFieldReferenceClasses, offset refusal named).
  6. Landing: ordinary queue landing by the seat: ready + auto-merge via label-write --land. Card closes on merge through Fixes #36677.

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/l tests 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.

analytics: the draft preview resolves no $field comparand, so a field-reference filter counts against the literal object

2 participants