Repository navigation
fix(service-analytics)!: an empty $nin on a related field leaves a detail row with no parent out on the native path, and dashboards.mdx reads the engine path as it is - #34514
Conversation
…d on an existing parent on the native path Claude-Session: https://claude.ai/code/session_01ADHkmRhzAMS9So2gFmAV11 Co-authored-by: Claude <noreply@anthropic.com>
…, dataset filter and cap as they are; the $not exception covers every condition a missing value does not satisfy Claude-Session: https://claude.ai/code/session_01ADHkmRhzAMS9So2gFmAV11 Co-authored-by: Claude <noreply@anthropic.com>
…e two tree-shape pins Claude-Session: https://claude.ai/code/session_01ADHkmRhzAMS9So2gFmAV11 Co-authored-by: Claude <noreply@anthropic.com>
📓 Docs Drift Check4 anchor(s) derived from 1 changed package(s); no hand-written page names any of them, so this run has nothing to list — not a clean bill of health. This check sees only pages that NAME a derived anchor: one that documents this change in prose, or enumerates it in an authoring dialect, names none and stays invisible to it on every run. What this run could not see
Coarse fallback — 10 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 8585084d7a39b5d3d6c54658f09fbdd338b3513d && git checkout 8585084d7a39b5d3d6c54658f09fbdd338b3513d
# afterwards, rebuild it from the two parents, which stay fetchable
git fetch origin 107d2e8497270aad611f77a81bc341f48c6d3e00 c0b712ce0b7723252c394e9e18f165773992a164 && git checkout -B drift-repro 107d2e8497270aad611f77a81bc341f48c6d3e00 && git merge --no-ff c0b712ce0b7723252c394e9e18f165773992a164
node scripts/docs-audit/affected-docs.mjs --json 107d2e8497270aad611f77a81bc341f48c6d3e00 |
|
l2-review#4 · os-steve · session_01ADHkmP44onN8RMzsPMqjRq Contract-review-claim: session_01ADHkmP44onN8RMzsPMqjRq · head 63d53d6 · 2026-11-16T23:41Z |
|
l2-review#4 · os-steve · session_01ADHkmP44onN8RMzsPMqjRq Contract reviewServed-tier: Inputs read: card #34384 body and all six comments, PR #34514 body, file list and both comments, the net diff from merge base ① Derived judgments
② Semver level
③ Boundary flags
④ Design judgmentThe narrowing, read against the published contract on Attempts to break it, all read in the head tree:
No must-fix, no should-fix.
Implemented-by: VERDICT: PASS |
|
repo:objectstack#2 · os-steve · session_01ADHkmRfW5u1LRmhWwaYHRp Final head for review: |
|
repo:objectstack#2 · os-steve · session_01ADHkmQVWXw7KT8ThxT4CBy 席位核对L1 verdict: ACCEPT · PR #34514 · card #34384 · first review · read 2026-11-17T01:01Z Head-sha: Read from GitHub at this head ( Checklist
Prose faces, sentence by sentence (
Spot checks (mine)
Accepted deviations, owed as ONE follow-up card after landing: L2's N1 (the jsdoc reason in L2 owed: yes, and on record. It is owed at Landing tier: |
|
repo:objectstack#2 · os-steve · session_01ADHkmRfW5u1LRmhWwaYHRp Landing · Head-sha: c0b712c · ACCEPT → comment 6934430234 (at 63d53d6) · contract review PASS 6932908866 (at 63d53d6) The head moved from 63d53d6 only by a relay
State: ready for review and auto-merge enabled with the designed red; #34384 closes with the merge ( |
Requested by Steve · project thread
Fixes #34384
Clause-②: no (narrowing) — on the native SQL strategy, an empty
$ninon a related field ({ 'order.status': { $nin: [] } }) no longer selects a detail row with no parent (an empty relation, or one naming a record that no longer exists), in each of the three filter positions one compile serves: the query'swhere, a measure's ownfilterand the dataset's ownfilter. The engine path and/dataalready left such rows out. BREAKING banner, FROM → TO and ADR-0087 disposition (not-required (no-migration-prescription)) are in the new changeset.Metadata-protocol: none
Skills-docs: none — no
skills/**file teaches what an empty$nin, or a related-field analytics filter, does with a row that has no parent (git grepofnin: [],empty $nin,orphanandno related recordoverskills/: no analytics hit).content/docs/ui/dashboards.mdxstates the rule.维护者速读
$nin({ 'order.status': { $nin: [] } })不再把「没有父记录」的明细行算进去;dashboards.mdx 里四处过时说法改成现状(引擎路径可走三层关系、数据集自身 filter 两条路径都支持、$not例外的范围、双重$not相互抵消)。$nin会多数孤儿行(实测 8 行 / 6602),走引擎路径则不数(6 行 / 602),总数随路径变;文档也在描述引擎已经不再有的限制。packages/services/service-analytics/src/strategies/native-sql-strategy.ts的compileFilterNodeconst 分支;filter-normalizer.ts空列表折叠处;.changeset/34384-empty-nin-related-field.md。pnpm --filter @objectstack/service-analytics exec vitest run src/__tests__/cross-object-negative-orphan.test.ts,预期 31 条全过。What changes
The defect (item 3). The analytics filter normalizer folds an empty
$ninto the constant TRUE (filter-normalizer.ts, the empty-list fold of #5134), and the fold dropped the member the leaf was written on. The shared lowering wraps every$ninin its NULL escape, so{ 'order.status': { $nin: [] } }compiled on the native path toThe first arm carries #34335's existing-parent conjunct; the second, a bare
1 = 1, selected every detail row, orphans included.cross-object-where.tsstates the contract: "No parent, or one the caller cannot read, never matches, whatever the operator". The engine path respells the dotted leaf as a nested-relation condition before normalization, so it was never affected.The fix. The empty
$nin's TRUE now keeps the member it was written on ({ kind: 'const', value: true, member }, an optional field on theconstnode). The native compile'sconstarm, for such a TRUE on a member read through a relationship path, emits the last hop's"ALIAS"."id" = "ALIAS"."id": the same technique as #34335's conjunct, TRUE for an existing parent and UNKNOWN for none, through every hop. The statement is nowOn a base column, or an expression, the constant is still
1 = 1, and that statement is byte-identical tomain's. The empty$in's FALSE is unchanged and names no member. Neither the engine path's conversion nor the/analytics/sqlecho reads the new field.Docs and changesets (items 1, 2, 4, 5).
content/docs/ui/dashboards.mdx:filteris served on both paths; a measure's ownfilteris still refused on the engine path;$notexception covers any condition a missing value does not satisfy (a comparison with a value,$null: false,$exists: true,$ne: null,$empty: false);$nots cancel, so{ $not: { $not: CONDITION } }leaves a row with no parent out whereverCONDITIONdoes;$nin: []exception is gone.DELIBERATE CORRECTION of the unreleased
.changeset/33792-cross-object-orphan-native.md(#34335), two sentences:$notthe native answer is the one it gave before." now reads "Under one$notthe native answer is the one it gave before. Under two,{ $not: { $not: { 'order.status': { $null: true } } } }, the two negations now cancel and the answer is the un-negated condition's, so such a row is no longer selected there either, where it was before." (item 5)$not, any condition a missing value does not satisfy, such as a comparison with a value ({ $not: { 'order.status': 'open' } }) or a presence test ($null: false,$exists: true,$ne: null,$empty: false), a shape the engine path refuses; write$ne/$nininside the condition instead." (item 4; the$nin: []half moves to this PR's own changeset, which ships in the same release.)New changeset
.changeset/34384-empty-nin-related-field.md(@objectstack/service-analytics: patch, BREAKING banner, ADR-0087 markernot-required (no-migration-prescription)).Tests
Pins added to the existing harness
src/__tests__/cross-object-negative-orphan.test.ts(its fixture: two orphans,l7with an empty relation andl8naming a removed parent):order.status $nin []andorder.customer.tier $nin [](two hops): native, engine and/dataselect the same lines, the orphans not among them (6 / 602 and 5 / 302);1 = 1on a joined member (one and two hops),1 = 1and no join on a base column;filterwith$nin: []: native 6, the engine refuses itINVALID_FIELD/ 400 as every related field there;filterwith$nin: []: 6 / 602 on both faces;$notover$nin: []: no line, before and after;$notover$notover$null: trueanswers what$null: trueanswers (1 / 300).Tests changed because the fix moved them (the tree shape they pin, not their behaviour):
src/__tests__/where-equality-slot-list-refusal.test.tsandsrc/__tests__/where-face-arms-refusal.test.ts, case "the empty $nin — the TRUE constant": the expectedconstnode now carriesmember: 'stage'.Acceptance notes
collectFilterLeaves, which still reads no member from a constant. The lowering's NULL escape always puts anotSetleaf on the same member beside the empty$nin's TRUE, so every gate already sees it, and the native join's object is already admitted and read-scoped. Measured: the field gate, the relationship-path (include) gate and the engine's measure-filter refusal answer the same refusals onmainand on this head for$nin: []on an unknown field, an unknown related field, an undeclared path, inside$orand in a measure's or the dataset's ownfilter.$inis left as it was. Its FALSE selects no row, parent or not, and names no member.Verification
All readings at head
63d53d6c(repositoryobjectstack-ai/objectstack),mainmerged at24b6ae55.Premise on main, the fix, and the ablation
maine8cba8fewith the new pins:Tests 5 failed | 26 passed (31). Native answered{ n: 8, total: 6602 }fororder.status $nin []where engine and/dataanswer{ n: 6, total: 602 }; the two-hop case 8 / 6602 against 5 / 302; the native statement was(("order"."status" IS NULL AND "order"."id" = "order"."id") OR 1 = 1).cross-object-negative-orphan.test.tsTests 31 passed (31).scripts/ablation-replace.mjs, the nativeconstarm's guard disabled, anchor 1 to 0, blob8c01a1686390to17068e30efb2):Tests 5 failed | 26 passed (31), the same five pins; restored, blob equalsHEADandgit diff HEADempty. The tests import the strategy fromsrc/, so no build sits between the mutation and the run.$notover$notover$null: true) passes onmaintoo: fix(service-analytics)!: the native SQL strategy leaves a detail row with no parent out of a cross-object filter, as the engine path does #34335 already made that narrowing; this PR pins and states it.Package and gates
pnpm --filter @objectstack/service-analytics test:Test Files 218 passed (218),Tests 5325 passed | 335 skipped (5660);typecheck: lock verdictcommand-exit 0.node scripts/pm/dispatch-gates.mjs --commands --repo objectstack-ai/objectstackat63d53d6c: 98 commands, each run with stdin closed;--ranreconciliation:98 run, 0 NOT-MEASURED. Four first answered exit 3 (prerequisite not met: a shallow clone, unbuilt packages, the verify lock busy with the dogfood run) and were re-run after the prerequisite was met: exit 0.check-empty-changesetexit 1 on.changeset/33792-cross-object-orphan-native.md, the DELIBERATE CORRECTION declared above.Dogfood battery (Clause-② narrowing arm)
At
63d53d6c, closure built, thenpnpm --filter @objectstack/dogfood testunder the verify lock, no shard and no path:Test Files 478 passed | 3 skipped (481),Tests 4030 passed | 44 skipped (4074), lock verdictcommand-exit 0(36m58s).Generated by Claude Code