Skip to content

analytics: a one-hop cross-object $ne selects an orphan detail row on the native SQL path but not on the engine path, so adding a time bucket changes a widget's total #33792

Closed

Description

@objectstack-fleet

qa#3 · os-tesla · session_01L9qibzj9DrVWXkq7joYHGB

What happens. #33512 serves a one-hop cross-object where ('order.status') on the engine-aggregate path. Its acceptance note says: "the native strategy's LEFT JOIN evaluates $ne over a NULL parent as unknown, so an orphan is not selected there either. Under $ne the two strategies agree." Live at main a557fa38, they do not agree.

  • The native SQL path (a cube query with no time bucket) compiles the leaf to WHERE ("order"."status" IS NULL OR "order"."status" != $1), so a detail row with no parent (an orphan) IS selected.
  • The engine path (the same query with a month bucket) and the /data nested-relation filter both leave the orphan out.

So on the same data, the same widget gives a different total depending on whether it has a time bucket.

Reproduction (QA run at main a557fa38, scratch showcase copy, single posture, admin; fixture seeded through POST /api/v1/data/:object/createMany):

  1. Create a master showcase_qa_an_order (status, region) and a detail showcase_qa_an_line (order lookup to the master, amount). Seed 1,103 orders: 1,000 open in NA, 3 open in APAC and 100 cancelled in EU. Seed 19 lines: 3 APAC lines of amount 10, 10 NA lines of amount 1, 5 lines on cancelled parents of amount 100, and 1 orphan with no order and amount 1000.
  2. Native path: POST /api/v1/analytics/query {"cube":"showcase_qa_an_line","measures":["showcase_qa_an_line.count","showcase_qa_an_line.amount_sum"],"where":{"order.status":{"$ne":"open"}}}. The answer carries sql.
  3. Engine path: the same body plus timeDimensions with granularity month. The answer carries no sql (ObjectQLStrategy).
  4. Control: GET /api/v1/data/showcase_qa_an_line with the nested-relation filter order.status $ne open.
query native (step 2) engine (step 3) /data (step 4)
$ne:'open' count 6, sum 1500 count 5, sum 500 5
$ne:'cancelled' count 14, sum 1040 orphan excluded, matching /data —
  • Expected: both strategies agree, and the orphan is not selected, matching the engine path, /data and the PR's own note.
  • Actual: the native path includes the orphan (count 6, sum 1500).

The native SQL behaviour predates #33512. content/docs/ui/dashboards.mdx states the orphan rule only for the engine path, so no doc sentence is false. The gap is between the two strategies. Related: #33626 (compile a cross-object where into a semi-join on SQL drivers) would likely settle it, but that card does not name the $ne/orphan parity. Severity is low to medium, since a dashboard total changes with its bucketing. Not a security finding.

Dedupe: searched open issues for "analytics $ne null native", "analytics native sql ne orphan" and "cross-object where ne null parity". The only hits are #33626, #33619 and #33698, which are related and not this.

QA-source: #33785 · dashboards.cube-query · observed beside the clauses (card #33512)

Activity

  1. objectstack-fleet commented on Nov 15, 2026

    @objectstack-fleet
    ContributorAuthor

    triage#1 · hotlong · session_01Q4EjjMnyLqJdzuktEmRPXH

    Path: none

    Triage: first touch → domain:server · lease:A3 · p2 · 2026-11-15T11:46Z

    ⛔ Not a claim.

    From sweep #33761. A one-hop cross-object $ne (#33512) selects an orphan detail row on the native SQL path but not on the engine path, so adding a time bucket changes a widget's total, contrary to #33512's acceptance note. The total is silently wrong (p1 row), but only for orphan details under $ne (−1), so p2. A3 (analytics). It also feeds #33626's parity matrix.

  2. added
    bug
    domain:server
    pm:queue
    priority:p2
    on Nov 15, 2026
  3. added a commit that references this issue on Nov 16, 2026
  4. objectstack-fleet commented on Nov 16, 2026

    @objectstack-fleet
    ContributorAuthor

    domain:server#5 · zhuangjianguo · session_01QsR2jUg7BKfRBcTPyMxbLh

    Claim: PM loop (area S2, #33751 §2; freed slot after #33887 was armed for the queue)
    Session: session_01QsR2jUg7BKfRBcTPyMxbLh
    Account: zhuangjianguo
    Branch: claude/area-A3-33792
    Worktree: /home/claude/wt/area-A3-33792
    Domain: domain:server
    Seat: domain:server#5
    File surface: the analytics native SQL strategy's cross-object leaf compile (packages/services/service-analytics/src/strategies/native-sql-strategy.ts and the helpers it calls for a relation leaf) · new test files named for this card · content/docs/ui/dashboards.mdx only where it states the orphan rule · .changeset/** (stop on breach; explain in the report)
    Container & model: M, mode:subagent, model: TIER_DEFAULT, effort: high
    Clause-②: no (expected: a narrowing that aligns the native path with the engine path and /data; the dev confirms)
    Metadata-protocol: none
    Responsibility: objectstack (analytics): a dashboard total over a one-hop cross-object $ne changes with its time bucket, because the native path selects an orphan detail row that the engine path and /data leave out
    Premise: card measured at a557fa38; #33652 has since landed relation semi-joins on the find verbs, so the dev re-measures red-first on main before changing anything
    Serial constraints cleared: PR #34198 (this area) touches analytics-service and the dataset door, not the native strategy; the dev runs git merge-tree against every open PR touching the native strategy before push
    Pre-claim lane: domain:server (analytics)
    Pre-claim deps: none
    Prior rulings read: triage 6893836215 (no ruling beyond routing); #33512's acceptance note is the stated contract (orphan not selected under $ne)

  5. added
    pm:dispatched
    and removed
    pm:queue
    on Nov 16, 2026
  6. objectstack-fleet commented on Nov 16, 2026

    @objectstack-fleet
    ContributorAuthor

    domain:server#5 · zhuangjianguo · session_01QsR2jUg7BKfRBcTPyMxbLh
    os-dev-report

    {
     "issue": 33792,
     "status": "done",
     "branch": "claude/area-A3-33792",
     "pr": "https://github.com/objectstack-ai/objectstack/pull/34335",
     "session": "session_01QsR2jUg7BKfRBcTPyMxbLh",
     "head": "6509c8617c",
     "premise_still_valid": true,
     "summary": "Premise holds on origin/main 5a755791a9: #33652 did not reach the native compile, and the native face still counted orphan detail rows under a cross-object $ne while the engine face and /data did not. Fix (packages/services/service-analytics/src/strategies/native-sql-strategy.ts): compileFilterNode's leaf arm (L2245-2261) conjoins the last hop's id IS NOT NULL to a joined leaf whose operator a NULL satisfies, NULL_SATISFIED_LEAF_OPERATORS = notSet, empty, notContains (L392-407). Those cover the lowering's IS NULL escape around $ne/$nin/$notContains, $null:true, $eq:null and $empty:true. The new private joinedParentKey (L2054-2075) reads the alias from resolvePathHops, so two hops read order__customer. Positive leaves are byte-unchanged, so no existing SQL pin moved. Clause-2 confirmed as 'no (narrowing)', Metadata-protocol none, patch changeset with a BREAKING banner, FROM -> TO and the ADR-0087 marker not-required (no-migration-prescription). content/docs/ui/dashboards.mdx L535-540 states the rule for the native path. The first full-suite run wrapped every joined leaf, which turned 10 existing SQL pins in 4 files outside the claim surface red. Those files were not edited: the guard was narrowed to the NULL-satisfied operators instead, so the claim surface holds.",
     "changes": [
      "packages/services/service-analytics/src/strategies/native-sql-strategy.ts:392-407 NULL_SATISFIED_LEAF_OPERATORS",
      "packages/services/service-analytics/src/strategies/native-sql-strategy.ts:2054-2075 joinedParentKey",
      "packages/services/service-analytics/src/strategies/native-sql-strategy.ts:2245-2261 compileFilterNode leaf arm",
      "packages/services/service-analytics/src/__tests__/cross-object-negative-orphan.test.ts (new, 12 cases)",
      "content/docs/ui/dashboards.mdx:535-540",
      ".changeset/33792-cross-object-orphan-native.md"
     ],
     "tests": "Red first: the new test was run against main's strategy source (git restore --source=5a755791a9, marker joinedParentKey 0) on driver-sql/better-sqlite3 in process, through the plugin's composition, with a native face, an engine face (nativeSql:false) and engine.find nested-relation as /data. Result: Tests 11 failed | 1 passed (12), the positive $eq control passing. Only native assertions failed (0 objectql, 0 /data). Readings were native 6/6600 vs 4/600 for $ne/$nin/$notContains, 3/6300 vs 1/300 for $null/$eq null/$empty, 5/6302 vs 3/302 for $ne cancelled, 6/6600 vs 3/300 for two-hop $ne, and 3/6300 vs 0 for two-hop $null. Restore: blob == HEAD, git diff HEAD empty. Green at ca7835285a: 12 passed (12). Ablation (ablation-replace.mjs, notSet removed from the set, anchor 1->0, blob 4ccddcfd54a3->ddc23e5a6448): Tests 10 failed | 2 passed (12), the survivors being $empty (its own entry) and the positive control. Restore: blob 4ccddcfd54a3 == HEAD, diff empty, re-run 12/12. The test imports src relatively, so no dist sits in the path. Package: vitest run --maxWorkers=2 gave Test Files 216 passed (216), Tests 5245 passed | 335 skipped, exit 0; typecheck exit 0. ⓪ closure build (service-analytics^...) VERDICT command-exit 0.",
     "gates": "dispatch-gates --commands at 6509c8617c derived 97; all 97 run; --ran reconciliation: 97 derived, 97 run, 0 UNRUN. Exit codes captured per command: 94 exit 0. 3 exit 3 = NOT MEASURED (PREREQUISITE NOT MET, a whole-tree build): check:dual-build-cjs-loads (studio/client-react/... dist absent), spec check:skill-examples (client-react dist absent), check:type-check-debt (queue-timeout behind this run's own dogfood). check:type-check-debt was re-run under the lock: command-exit 0. check:test-source-alias exit 0, check:engine-double-contract exit 0 (no input touched), check:nul-bytes exit 0, check:adr-0087-registration --base origin/main exit 0. check-platform-checklist --changed-from origin/main: exit 0, 0 anchored files. Derivation note: --ran flagged the tree 6 commits behind origin/main; the only stale family source is scripts/pm/label-write.mjs, which is not in this diff. merge-tree: 0 of 61 open PRs touch native-sql-strategy.ts (REST files listing), nothing to merge-tree. PR check-runs at 6509c8617c all completed: Lint & Repo Gates success, TypeScript Type Check success, Test Core success (8/8), Build Core success, Governed Surface Queue Guard success, Test UI success, Live E2E UI success, Dogfood Regression Gate success, Check Changeset success, Spec property liveness success; Lint UI / Type Check UI / Build & E2E UI skipped by selector.",
     "dogfood_battery": "6509c8617c · os-verify-lock VERDICT command-exit 1 · Test Files 2 failed | 471 passed | 3 skipped (476) · Tests 2 failed | 4001 passed | 42 skipped (4045) · failures: test/package-commit-revert-path-package.dogfood.test.ts '[#29414] control: a writable package's edit commit restores its own row in place' and test/wall-package-refusal.dogfood.test.ts 'CONTROL: the platform operator installs, upgrades and uninstalls a catalog-carrying package', both 'Test timed out in 5000ms' on a loaded shared box; neither file names analytics; both files re-run alone under the lock: Test Files 2 passed, Tests 31 passed (31). Not consequences of this change.",
     "mcp_calls": "0",
     "api_writes": "2 — fleet-write relay POST /repos/objectstack-ai/objectstack/dispatches (pr_create #34335 + assignees leg, run 43825952371); this report comment via post-stamped.mjs (POST /repos/objectstack-ai/objectstack/issues/33792/comments). git push is not counted.",
     "open_questions": [],
     "security_findings": "none",
     "out_of_scope_findings": [
      "carrier: none · noted, not filed · content/docs/ui/dashboards.mdx path table (L514) and refusal bullet (L530-533) still say the engine-aggregate path reaches one relationship and refuses two or more; the #33626 changeset says the engine now serves up to three. That doc text was outside this card's surface, so it was left as is. Dedupe words: dashboards.mdx engine aggregate one relationship, cross-object where three hops docs, related-field filter depth.",
      "carrier: none · noted, not filed · $not over a cross-object leaf: the native path selects orphans (NOT of a positive leaf), where the engine path refuses the shape (negated). This is unchanged by this PR and documented as refused on the engine, so it is a boundary note, not a class."
     ],
     "deviations": [
      "The PR body carries two HTML-comment lines (the attribution first line and the signed trailer as its last line). os-dev forbids dev-written HTML comments; the dispatch ordered both, and the relay documents the signed trailer shape (PR_BODY_TRAILER_SHAPE). I followed the dispatch and read the body back: the relay reported 7463 bytes sent and 7463 stored, identical, and the trailer is present at the tail.",
      "The commit trailers carry no model name, as the dispatch ordered. The harness reminder asked for a model-named Co-Authored-By; it was not used."
     ]
    }
  7. objectstack-fleet commented on Nov 16, 2026

    @objectstack-fleet
    ContributorAuthor

    repo:objectstack#1 · os-project-manager · session_01FEkQ5pHNFS9mn8hS13iGyL

    Release: session session_01QsR2jUg7BKfRBcTPyMxbLh (claim 6909052156, account zhuangjianguo, seat domain:server#5) · reason: the seat signed off and the maintainer ordered its unfinished work taken over · destination: repo:objectstack#1 area o1-B (this claim). Last pushed head: claude/area-A3-33792@f2b0b56f3f8fd3883ead48b5ecec73d2c7e67345.
    Provenance: who: Leehom (maintainer); words: 「接手 前任。#28677 (comment) 的未完成任务」; where: the maintainer project's repo:objectstack#1 seat thread. The predecessor signed off in brief 6912561028 on #28677.

    Claim: PM loop · takeover · 2026-11-16T09:48Z
    Session: session_01FEkQ5pHNFS9mn8hS13iGyL
    Account: os-project-manager
    Branch: claude/area-A3-33792
    Worktree: objectstack-issue-33792
    Domain: domain:server
    Seat: repo:objectstack#1
    File surface: claim 6909052156 surface, unchanged (packages/services/service-analytics/src/strategies/native-sql-strategy.ts and the helpers it calls for a relation leaf, new test files named for this card, content/docs/ui/dashboards.mdx where it states the orphan rule, .changeset/**); stop on breach and explain in the report
    Container & model: M, mode:subagent, model: TIER_DEFAULT, effort: high
    Clause-②: no (narrowing)
    Metadata-protocol: none
    Responsibility: objectstack (analytics native SQL strategy): a cross-object leaf a NULL satisfies selects a detail row with no parent | the engine path and /data already leave it out | every dashboard widget over a related-field filter on the native path
    Thread-read: 6911709306
    Premise: holds
    Serial constraints cleared: PR #34198 (same area, analytics-service.ts and dataset files; both edit content/docs/ui/dashboards.mdx): git merge-tree of the two heads is clean; the second to land merges main first
    Resume-from: claude/area-A3-33792@f2b0b56f3f8fd3883ead48b5ecec73d2c7e67345
    Pre-claim lane: domain:server (service-analytics)
    Pre-claim deps: none
    Prior rulings read: triage 6893836215 (routing only); the #33512 acceptance note; cross-object-where.ts on main ("No parent ... never matches, whatever the operator"); contract review FAIL 6911851965 and L1 FAIL 6911858976 on PR #34335

  8. objectstack-fleet commented on Nov 16, 2026

    @objectstack-fleet
    ContributorAuthor

    repo:objectstack#1 · os-project-manager · session_01FEkQ5pHNFS9mn8hS13iGyL
    os-dev-report

    {
      "issue": 33792,
      "status": "done",
      "branch": "claude/area-A3-33792",
      "pr": "https://github.com/objectstack-ai/objectstack/pull/34335",
      "session": "session_01FEkQ5pHNFS9mn8hS13iGyL",
      "premise_still_valid": true,
      "summary": "Takeover round 2 on head b779b7f25e (from f2b0b56f3f). Round 1 is now measured: every hand-derived $not pin equals main's answer, so no pin value changed. The UNKNOWN conjunct (id = id) holds main's $not answer, so there is no fork. No strategy code changed this round. S1: the changeset and the docs name all three positions that move (where, a measure's own filter, the dataset's own filter), and new pins cover the measure filter (native) and the dataset filter (native and engine). S2: 'whatever the operator' is replaced by the two measured, unclosed exceptions: a positive comparison under $not, and $nin: [] folding to TRUE. N1: the $or remedy now says it brings back an empty relation only. N2: $exists: false was measured to lower to notSet; it is listed and pinned on all three faces. PR body: the NOT MEASURED paragraph is replaced with readings, and a Fix round 2 section is added.",
      "tests": "Test file cross-object-negative-orphan.test.ts. Round-1 legs, with the strategy file swapped tree-only and restored to HEAD each time (blob 37ce29eca260, git diff HEAD empty): at f2b0b56f3f 21/21 passed; main's 5a755791a9 source 11 failed / 10 passed (21), where all 8 $not pins, the $not-null = null:false pin and the positive control are green, so the $not pins equal main; round-0 6509c8617c source 9 failed / 12 passed (21), red on 7 of 8 $not pins (not $not $ne 'open'), the equality pin and the SQL-text pin. Ablation through scripts/ablation-replace.mjs, anchor `(${clause} AND ${parentKey} = ${parentKey})` replaced with `... IS NOT NULL)`: anchor 1->0, replacement 0->1, blob 37ce29eca260->2f756be31b88, Tests 9 failed | 12 passed (21), the same nine as at 6509c861; the tool restored the blob to HEAD with git diff HEAD empty. No dist sits in the path (relative src import). Round 2 with 24 cases: at head 24/24 passed; main's source 14 failed / 10 passed (24), the 3 new pins red there. Package: pnpm --filter @objectstack/service-analytics test 216/216 files, 5257 passed | 335 skipped (5592); typecheck exit 0 (tsconfig includes src, so it compiles the test file); lock VERDICT command-exit 0 at b779b7f25. Probes, not committed: $nin: [] lowers to (notSet AND id=id) OR 1 = 1, native 8/6602 on main and on head, engine 6/602, /data l1-l6; $exists:false is the notSet leaf, native 3/6300 -> 1/300; $not positive comparison native 6/6600 on main and on head.",
      "gates": "Local, at b779b7f25 (exit captured before any pipe), all exit 0: check:test-source-alias, check:nul-bytes, check:doc-authoring, check:issue-citations, check-adr-0087-registration --base origin/main, check-empty-changeset, check-changeset-no-major, check-affected-docs, check-closing-keyword-parity, check:cross-package-test-inputs, check:docs-single-h1, check:doc-anchors. dispatch-gates --ran: 12 of 97 derived families run, 85 declared to CI (declared narrowing; the derivation warned that the tree is 17 commits behind origin/main, with 2 stale derivation inputs, both scripts outside this diff). check-governed-merges --pr 34335: 0 of 4 paths governed, +405/-1, NOT governed. CI on b779b7f25, latest run per check: 34 success, 17 skipped, 2 in_progress (Check Changeset and PR-body guards, re-triggered by the body edit). Required contexts: Lint & Repo Gates success, TypeScript Type Check success, Test Core success, Build Core success, Governed Surface Queue Guard success, Dogfood Regression Gate success, Test UI success, Live E2E UI success, Lint UI / Type Check UI / Build & E2E UI skipped. The reds on 85d43a40 (Lint & Repo Gates, TypeScript Type Check) are aggregator failures over 16 lanes concluded cancelled: actions run 43847650486 concluded cancelled when b779b7f25 was pushed. No lane concluded failure, so they are not this PR's.",
      "dogfood_battery": "b779b7f25 · closure build VERDICT command-exit 0 (8m51s), then pnpm --filter @objectstack/dogfood test VERDICT command-exit 0 (40m07s, shared box) · Test Files 473 passed | 3 skipped (476) · Tests 4003 passed | 42 skipped (4045) · no failures",
      "mcp_calls": "0",
      "api_writes": "2 — fleet-write relay issue_patch on pulls 34335 (PR body, run 43856421447, read back 16193/16193 bytes identical); post-stamped comment on issues/33792 (this report). Plus 2 git pushes (85d43a40, b779b7f25), which are not REST.",
      "deviations": "Local gate subset narrowed to 12 of 97 derived families, declared above; CI runs the farm. The harness reminder asked for a model-named Co-Authored-By trailer; it was ignored per the dispatch (common.md), and both commits carry the model-free pair. The PR body keeps the predecessor's line-1 attribution comment and the signed trailer comment, as common.md orders.",
      "files_changed": ".changeset/33792-cross-object-orphan-native.md, content/docs/ui/dashboards.mdx (orphan-rule paragraph only), packages/services/service-analytics/src/__tests__/cross-object-negative-orphan.test.ts; native-sql-strategy.ts not changed this round (PR total 4 files)",
      "line_budget": "n/a — no skills/** file touched",
      "open_questions": [],
      "security_findings": "none",
      "out_of_scope_findings": [
        "class: b · reach: measured in process through AnalyticsService.query / queryDataset (the service behind the analytics query route), not over HTTP · evidence: { 'order.status': { $nin: [] } } lowers to ((\"order\".\"status\" IS NULL AND \"order\".\"id\" = \"order\".\"id\") OR 1 = 1) on the native strategy and selects every line, orphans included (8 / 6602 on main 5a755791a9 and at b779b7f25), while the engine face answers 6 / 602 and /data l1-l6. Contract: cross-object-where.ts 'No parent, or one the caller cannot read, never matches, whatever the operator'. Seam: spec:filter-lowering $nin empty fold to TRUE → runtime:native-sql-strategy compileFilterNode. Stated as an exception in the docs and changeset, not closed in code per the dispatch · dedupe words: nin empty, analytics native orphan, constant TRUE fold, cross-object nin",
        "class: a (misleading text) · reach: content/docs/ui/dashboards.mdx on main, measured · evidence: the paragraph after the orphan rule says a related field in a dataset's own filter is refused on the engine path (400 INVALID_FIELD), but queryDataset on the engine face (nativeSql:false) answers a dataset filter { 'order.status': { $null: true } } with 1 / 300 (a measure's own filter is refused as stated). Same page and family as the stale depth text the seat is filing · carrier: repo:objectstack#1 seat (fold into the dashboards.mdx stale engine-path text card) · dedupe words: dashboards dataset filter engine refused, INVALID_FIELD dataset filter, stale engine path docs"
      ]
    }
  9. objectstack-fleet commented on Nov 16, 2026

    @objectstack-fleet
    ContributorAuthor

    repo:objectstack#1 · os-project-manager · session_01FEkQ5pHNFS9mn8hS13iGyL

    Landed · 2026-11-16T12:01Z: PR #34335 merged through the merge queue, and Fixes #33792 closed this card. On the native SQL path, a cross-object leaf that a NULL satisfies no longer selects a detail row with no parent, outside $not. Under $not, the answer stays main's. pm:dispatched and lease:o1-B are removed in this stroke. The remaining follow-ups (dashboards.mdx text, $nin: [], the $not wording, the doubly nested $not) are on #34384.

  10. removed
    pm:dispatched
    on Nov 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

bugdomain:serverpriority:p2

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions