Skip to content

analytics: a cross-object leaf in a dataset measure's own filter served as the engine's semi-join (aggregations[].filter) #33878

Description

@objectstack-fleet

domain:server#5 · os-elon-musk · session_016WV4d1QwJJ5KGZTThP4fnq

Follow-up of #33626 (draft PR #33652). ⛔ Not a claim.

What exists

#33626 asks that the dataset's own filter and its per-measure filters compile through the same semi-join. PR #33652 serves the dataset's own definition-level filter (and a where leaf up to three relationships) on the analytics engine-aggregate path. A cross-object leaf in ONE MEASURE's own filter (measures[].filter: { 'account.region': 'West' }) is still refused INVALID_FIELD / 400 by ObjectQLStrategy.planCrossObject, and the engine itself refuses the nested form at aggregations[N].filter (INVALID_FILTER / 400, "which the engine serves in 'where'").

Why it did not fit #33652

The engine composes ReadableIds leaves only on where at its executor boundary (ADR-0139 D2). A per-aggregation filter is a conditional aggregate the driver compiles (or the engine evaluates over rows it holds); serving a semi-join there needs the boundary to compose leaves inside each aggregations[].filter, driver-sql to compile the subquery inside the conditional aggregate, and the in-memory bucketing path (non-UTC timezone) to evaluate it.

What lands

The engine serves the nested-relation condition at aggregations[N].filter on read verbs (planned related read, composed leaf, same read scope per hop); analytics respells a measure filter's dotted leaf as it now respells the dataset filter; both SQL-echo faces refuse in the where-door envelope. Tests: parity with the where route per measure, the related row scope under $ne.

Grade

p2.

Activity

  1. added
    enhancement
    priority:p2
    pm:queue
    domain:server
    on Nov 15, 2026
  2. objectstack-fleet commented on Nov 16, 2026

    @objectstack-fleet
    ContributorAuthor

    repo:objectstack#2 · os-steve · session_01ADHkmSLi1reMd27fT62jJ3

    Claim · #33878 · 2026-11-16T22:17Z

    Claim: PM loop, area o2-E of seat repo:objectstack#2 (seat post #34478); a large card (rule card #34424: size L across three packages, a lifted refusal, a metadata-visible widening), so it is built in its own card thread under this area
    Session: session_01ADHkmSLi1reMd27fT62jJ3
    Thread session: session_01ADHkmPzRZU1RhSdzaBZbzP
    Account: os-steve
    Branch: claude/project-thread-6nvljz
    Worktree: objectstack (the card thread's own container)
    Domain: domain:server
    Seat: repo:objectstack#2
    File surface: packages/objectql/src/** (composing leaves inside aggregations[].filter at the executor boundary, the in-memory bucketing path), the SQL driver's conditional-aggregate compiler under packages/plugins/driver-sql/**, the analytics service's ObjectQLStrategy measure-filter respelling, both SQL-echo faces, their tests, one changeset (stop on breach; explain in the report)
    Container & model: L, mode:thread, model: default (engine boundary + SQL driver conditional aggregate + in-memory bucketing + analytics; L2 routed by the seat), effort: high
    Clause-②: yes (a cross-object leaf in a measure's own filter, refused INVALID_FIELD / INVALID_FILTER 400 today, is served)
    Metadata-protocol: added (a dataset measure's filter may name a dotted cross-object leaf; the card thread confirms against the diff)
    Responsibility: n/a — not a defect card (a follow-up of #33626: a measure filter's cross-object leaf is served as the where route is)
    Pre-claim lane: repo:objectstack area o2-E — the fix lands in packages/objectql, the SQL driver and the analytics service (domain:server)
    Pre-claim deps: upstream PR #33652 MERGED (9a7f8c1); no Blocked-by: line. In-flight surface: no open PR touches the SQL driver's filter compiler or relation-semi-join.ts (open PR list read 2026-11-16T22:13Z). Same area, same family: #33876 and #33877 also touch the ReadableIds leaf path; each card thread names its hot file in its report and the area serialises a shared one
    Prior rulings read: analytics,cross-object,leaf,dataset,measure,filter,served,engine,semi-join,aggregations → 136 hits; ADR-0076 D10, ADR-0139 D3, ADR-0149 D6, ADR-0021 D1, ADR-0021 D2, ADR-0021 D3, ADR-0023 Decision §3; thread: none; repo: objectstack-ai/objectstack
    Thread-read: none
    Premise: holds (the card body's reading; the card thread re-measures on main first)
    Serial constraints cleared: none in flight on the named files; #33876 and the other card of this family (same area) serialised by the area on any shared file

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

    @objectstack-fleet
    ContributorAuthor

    repo:objectstack#2 · os-steve · session_01ADHkmPzRZU1RhSdzaBZbzP
    os-dev-report

    {
     "issue": 33878,
     "status": "needs_decision",
     "branch": "claude/project-thread-6nvljz",
     "pr": null,
     "session": "session_01ADHkmPzRZU1RhSdzaBZbzP",
     "premise_still_valid": true,
     "summary": "Premise holds on origin/main e8cba8fe: a cross-object leaf in one measure's own filter is still refused (analytics planCrossObject INVALID_FIELD/400, pinned by service-analytics crossobject-conjunct-refusal.test.ts case 7; the engine refuses the nested form at aggregations[N].filter INVALID_FILTER/400, pinned by objectql engine-nested-relation-lowering.test.ts). Stopped before code: serving it as the card's 'What lands' describes (planned related read, composed leaf) puts a ReadableIds leaf at aggregations[N].filter, a position ADR-0139 D1 rules out in writing ('The leaf is legal on find, findOne, count and aggregate (where only)'), and the code encodes that rule (filter-comparand-shape.ts collectComposableReadableIds: composable only when path === 'where'; its docblock names 'an aggregation's own filter' as refused). An accepted ADR binds until amended (AGENTS.md Prime Directive 13), docs/adr/** is outside an implementation card's file surface, and no ruling on this card or on #33626 widens the leaf's positions (Q1 6889549817 and Q2 6889543194 are about drivers, not positions). Three architectures follow from three readings; options below.",
     "tests": "No code written. Readings on origin/main e8cba8fe: ADR-0139 line 146 (D1 position rule); filter-comparand-shape.ts lines 154-170 and 200 (position rule in code); engine-delete-and-aggregate.ts aggregate(): the per-aggregation filter takes the where doors, composeReadableIdsAtBoundary runs on the final AST, then either driver.aggregate (driver declares supports.aggregationFilter; driver-sql compiles the measure predicate with the same where compiler as fn(CASE WHEN (pred) THEN arg END)) or the in-memory rows path (non-UTC timezone date bucket, or a driver without the bit: driver-memory, MongoDB, the Turso remote transport) where applyInMemoryAggregation evaluates the filter per row in JS; service-analytics objectql-strategy.ts: measure filters go to aggregations[].filter via scopedMeasureFilter, only the dataset filter and where are respelled (servedWhere/servedScope); native-sql-strategy.ts canHandle declines the nested form, so the ObjectQL path is the one that answers.",
     "gates": "NOT MEASURED: no diff, no derived gate list (dispatch-gates --commands needs a change set).",
     "dogfood_battery": "n/a — no PR",
     "mcp_calls": "3 — issue_read get #33878, issue_read get_comments #33878, pull_request_read get #33652 (reads only); plus gh api GET reads of #33626 and its comments",
     "api_writes": "1 — this os-dev-report comment on #33878 (post-stamped.mjs)",
     "open_questions": [
      {
       "question": "Governing text: ADR-0139 D1 ('The leaf is legal on find, findOne, count and aggregate (where only). On a write verb, in a having, or at any position but a $in comparand, the engine refuses it loudly.'), AGENTS.md Prime Directive 5 (SQL first, ruling record 6888468549) and Prime Directive 13. How should a cross-object leaf in one measure's own filter be served: by widening ADR-0139's leaf to aggregations[N].filter, by keeping the leaf in where only and splitting the measure into its own aggregate, or by the capped id read?",
       "options": [
        "A — Amend ADR-0139 D1/D2 first (a governed ADR card, Tier H, filed by the seat), then this card implements: the leaf becomes legal at aggregations[N].filter of aggregate only (never having, never a write verb); the executor boundary composes it there with the same per-object scope it composes for where; driver-sql (and Turso local, sqlite-wasm) compile it inside the conditional aggregate with no new code path, since the measure predicate already goes through the where compiler; analytics respells a measure filter's dotted leaf as it respells the dataset filter today; both SQL-echo faces refuse in the where envelope. Sub-choice A1/A2 for the engine's in-memory rows path (non-UTC timezone date bucket; drivers without supports.aggregationFilter): A1 evaluates a composed leaf in process (read P under the composed scope, member-test, as ADR-0139 D3 already has driver-memory do), A2 refuses that combination INVALID_FILTER/400 by name. Cost: one ADR amendment review cycle before code; engine boundary + rows-path evaluator + analytics respelling + parity tests (L). One SQL statement per query; no id cap.",
        "B — No ADR change: keep the leaf in where only. A measure whose filter carries a cross-object leaf is run as its own aggregate with that filter ANDed into where (already served as the semi-join by #33652), and its column is merged into the main rows by group key (a group missing from the split query reads count 0, other functions null, which is what the conditional aggregate yields; having applies after the merge). Done in the engine (every caller gets it) or only in analytics (the engine keeps refusing). Cost: one extra statement per distinct cross-object measure filter, the middleware chain runs once per split statement, merge logic to own and pin (M-L).",
        "C — Engine lowers the condition at aggregations[N].filter by the id read (related ids read as the caller, then $in, the 1,000 cap and its INVALID_FILTER/400 above it); no leaf, so no ADR change. Cost: small (S-M). Brings back for measures the cap #33626 exists to remove."
       ],
       "recommendation": "A with A1. Long-term reading first: A is the fastest SQL shape (one statement, the conditional aggregate the driver already compiles, the read scope carried as the subquery's own WHERE), which is what Prime Directive 5 and ruling record 6888468549 ask for, and it keeps one mechanism (ReadableIds) for every cross-object predicate instead of a second split-and-merge mechanism (B) or the capped id list (C); the cost is a governed ADR amendment, which is the honest price of widening an accepted decision. A1 over A2 because the rows path is the SQL drivers' own tier for a non-UTC timezone date bucket, not a parity path for MongoDB, and A1 reuses the in-process evaluation D3 and ruling Q1 6889549817 already accept for driver-memory; MongoDB stays refused under #33876. Business pull: the measured downstream pull behind #33626 (the margin dashboard and allocation tile) is on where; no in-repo dataset declares a measure filter with a cross-object leaf (grep of examples/ and packages/qa: zero), so the measure half's pull is unmeasured here, which argues for not paying more than one mechanism. AI-error axis: A and C keep one spelling (the dotted leaf served where the dataset filter is served), B adds a path whose wrong merge would read as a plausible number; C fails loudly at 1,000 but the author cannot predict the bound. Startup-scope axis: all three widen; B and C are cheaper now and costlier later."
      }
     ],
     "security_findings": "none",
     "out_of_scope_findings": [
      "carrier: seat — under option A, the ADR-0139 D1/D2 amendment (leaf legal at aggregations[N].filter of aggregate) is a governed docs/adr card, Tier H; dedupe words: ADR-0139 amendment aggregations filter ReadableIds position, measure filter semi-join, conditional aggregate subquery"
     ]
    }
  5. objectstack-fleet commented on Nov 16, 2026

    @objectstack-fleet
    ContributorAuthor

    repo:objectstack#2 · os-steve · session_01ADHkmQ2SN4K183oqAvUajA

    Release: needs a maintainer decision · 2026-11-16T22:30Z
    The card thread (session session_01ADHkmPzRZU1RhSdzaBZbzP, branch claude/project-thread-6nvljz, no commit) stopped before code with needs_decision; its os-dev-report is on this card. The claim of area o2-E (6931073214) is released: pm:dispatched → needs-user-decision, lease:o2-E and the assignee removed. Resume-from: none (no produce).

    维护者速读 · 待裁

    一句话问题: 数据集里某一个度量自己的过滤条件引用了关联对象的字段(例如「只算关联客户是 VIP 的订单金额」),今天被响亮拒绝(INVALID_FIELD/400);按卡上的做法支持它,会把跨对象叶子放进 aggregations[N].filter,而 ADR-0139 D1 原文写的是「aggregate (where only)」,代码也照此只允许 where。

    Governing text: ADR-0139 D1(「The leaf is legal on find, findOne, count and aggregate (where only)」);AGENTS.md 第 5 条(SQL 优先,裁决记录 6888468549)、第 13 条。

    选项 做什么 客户可感知后果 工作量
    A(子选 A1) 先修订 ADR-0139 D1/D2:叶子在 aggregate 的 aggregations[N].filter 也合法(having 与写操作仍拒);SQL 驱动在已有的条件聚合里直接编译;内存行路径(非 UTC 时区分桶、无该能力的驱动)A1 在进程内求值,A2 按名拒收 一条 SQL 出所有度量,无 id 上限 一张 ADR 修订卡(Tier H)+ 一张 L 代码卡(引擎边界、行路径求值、analytics 改写、对等测试)
    B 不改 ADR:带跨对象过滤的度量拆成独立 aggregate,把过滤并进 where(已走 #33652 的半连接),再按分组键合并 结果相同,每个这类度量多一条 SQL;合并错了会出看似合理的错数 M–L;无 ADR
    C 引擎在度量过滤里改走读 id + $in(1000 上限) 能用,但关联多时又撞 1000 上限 S–M;把 #33626 要去掉的上限带回度量

    业务含义直译: A 是把「按关联筛选」的快速通道开到单个度量上;B 是「拆开算再拼表」;C 是「先查出名单再筛」,名单太长就报错。

    os-decision-facets
    ① 项目长远合理性:A 一种机制(ReadableIds)覆盖所有跨对象条件,是最快的 SQL 形状;B 多一套拆分合并机制;C 带回上限。
    ② 实际业务拉动:#33626 背后的实测拉动(毛利看板、分配磁贴)在 where 上;仓内没有数据集在度量过滤里写跨对象叶子(examples/、packages/qa 检索为零)——度量这一半的拉动未实测。
    ③ 防 AI 犯错:A、C 只有一种写法;B 合并出错会给出看似合理的数字(静默错);C 在 1000 处响亮失败但作者无法预判。
    ④ 创业阶段不扩散:三者都扩;B、C 现在便宜、以后贵;零拉动下也可以不做。
    Prior rulings read: ADR-0139 D1/D2/D3; ruling record 6888468549; rulings Q1 6889549817 and Q2 6889543194 on #33626 (about drivers, not positions); thread: this card's comments.
    Analysis-tier: seat default (CONTRACT_REVIEW_TIER not used: the maintainer, 2026-11-15T21:53Z, 「fable 不多了」).

    推荐:A,子选 A1(卡线程与席位同)。只看①选 A;②③④ 是否翻转:否——度量这一半零实测拉动是置信缺口;您若要等拉动,本卡停放,写 Restart-when: 首个在度量过滤里写跨对象叶子的真实数据集。
    裁后执行: 选 A ⇒ 席位立 ADR-0139 修订卡(Tier H,可与 #33877 的修订合一张,若两张都选 A),本卡挂 Blocked-by: 它,修订落地后回 pm:queue(大卡,单开卡线程)。选 B ⇒ 本卡直接回队,大卡单开卡线程。选 C ⇒ 回队,按小卡进区。

  6. added
    needs-user-decision
    and removed
    pm:dispatched
    on Nov 16, 2026
  7. objectstack-fleet commented on Nov 17, 2026

    @objectstack-fleet
    ContributorAuthor

    repo:objectstack#2 · os-steve · session_01ADHkmQ2SN4K183oqAvUajA

    2026-11-17T08:36Z Ruled. Steve chose an option on this project's decision card for #33878 at 2026-11-17T08:26:56Z. Option text verbatim: 「两张停放,#34155 关闭」 — 「#33878 和 #33877 写明重启条件后停放,等第一个真实查询撞上再做;#34155 不加声明,关卡。」. It answers the release analysis 6931335436 (its fallback, not its first recommendation A). Freshness: no comment on this card is newer than that analysis, and the body was not edited after it.

    Ruled: hold

    • Measured pull is zero (no dataset in this repository writes it, nobody has hit it) and today's behaviour is a loud refusal, not a silent wrong answer. The card is parked, grade lowered to p3 in this stroke.

    Restart-when: a real dataset (an example app, hotcrm, or a customer report) writes a cross-object leaf in a dataset measure's own filter · Restart-grade: p2

  8. added
    pm:on-hold
    and removed
    needs-user-decision
    priority:p2
    on Nov 17, 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:datadomain:serverenhancementpm:on-holdpriority:p3

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions