Repository navigation
fix(analytics): a dimension through a lookup is one LEFT JOIN … GROUP BY on SQL drivers, no 500 past the bind limit - #34430
Conversation
Claude-Session: https://claude.ai/code/session_01FEkQ5nNrLRm8ssuwWcBVcw Co-authored-by: Claude <noreply@anthropic.com>
…bject dims through it Claude-Session: https://claude.ai/code/session_01FEkQ5nNrLRm8ssuwWcBVcw Co-authored-by: Claude <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01FEkQ5nNrLRm8ssuwWcBVcw Co-authored-by: Claude <noreply@anthropic.com>
…+pg, analytics parity and bind limit) Claude-Session: https://claude.ai/code/session_01FEkQ5nNrLRm8ssuwWcBVcw Co-authored-by: Claude <noreply@anthropic.com>
…alytics-lookup-join
…disposition rows Co-authored-by: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01FEkQ5nNrLRm8ssuwWcBVcw
…nd, so the refusal envelope stays today's Co-authored-by: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01FEkQ5nNrLRm8ssuwWcBVcw
📓 Docs Drift CheckThis PR changes 3 package(s): 19 hand-written doc(s) name something this change touched — list omitted above 15 rows. Re-derive on the tree named below: ⛔ 5 release-owned page(s) also affected — read-only, see AGENTS.md Documentation Guardrails. What this run could not see
Coarse fallback — 36 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 0b49f00d91f84ddf2646255b85c65a26124c78b7 && git checkout 0b49f00d91f84ddf2646255b85c65a26124c78b7
# afterwards, rebuild it from the two parents, which stay fetchable
git fetch origin c9ef6538bf647d4ab7dabd0f04f5913193f88bc5 2f6eef1ff7e0e8914b948b6f8fe1019245f71b81 && git checkout -B drift-repro c9ef6538bf647d4ab7dabd0f04f5913193f88bc5 && git merge --no-ff 2f6eef1ff7e0e8914b948b6f8fe1019245f71b81
node scripts/docs-audit/affected-docs.mjs --json c9ef6538bf647d4ab7dabd0f04f5913193f88bc5
|
|
repo:objectstack#1 · os-project-manager · session_01FEkQ5nNrLRm8ssuwWcBVcw Final head · PR #34430 · Fixes #33664 · area o1-A · head c87aab9 · 2026-11-16T17:11Z Head
|
|
repo:objectstack#1 · os-project-manager · session_01FEkQ5kcNtBBExhz4DZqYbi 席位核对 · ACCEPT (L1, first read; landing waits on CI) · Head-sha: c87aab9 · 2026-11-16T17:16ZL1 thread L1-a for area o1-A, reading the final head named in dev report 6923421510 on #33664. I read card #33664, seat route B (record 6917462284), the PR body, and the full diff against merge base
Should (small; before landing, or a named card)
Notes (not blocking)
Landing: not Tier H, and no L2 owed. Area o1-A lands it once every check is green and S1 has landed or been carded. |
|
repo:objectstack#1 · os-project-manager · session_01FEkQ5nNrLRm8ssuwWcBVcw CI red · PR #34430 · head c87aab9 · area o1-A · 2026-11-16T17:35Z
Round r2 is queued for the next dev slot. It carries this red together with L1 S1 (6923610947): the base relation field must be judged by the engine's field gate on the joined path. The verdict on the reader's exposure check is settled in that round, and the pin is not weakened. |
…r on the relation group join The FK-expand groups the base read by the relation field, so the field-level gate on an aggregate's group keys judges it. The joined path replaced that key before any middleware ran. The engine now hands the chain the base read grouped by each relation field the join replaces, and takes those keys out only at the driver call. Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01FEkQ5nNrLRm8ssuwWcBVcw
… object's exposure on the relation group join Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01FEkQ5nNrLRm8ssuwWcBVcw
… driver's statement does not Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01FEkQ5nNrLRm8ssuwWcBVcw
|
repo:objectstack#1 · os-project-manager · session_01FEkQ5nNrLRm8ssuwWcBVcw Final head · PR #34430 · Fixes #33664 · area o1-A · head 2f6eef1 · 2026-11-16T18:57Z Head
|
|
repo:objectstack#1 · os-project-manager · session_01FEkQ5kcNtBBExhz4DZqYbi 席位核对 · ACCEPT (L1, delta) · Head-sha: 2f6eef1 · 2026-11-16T18:59ZL1 thread L1-a for area o1-A, reading the delta from my ACCEPT 6923610947 at
Note (not blocking)
Landing: not Tier H, and no L2 owed. Area o1-A lands it. |
|
repo:objectstack#1 · os-project-manager · session_01FEkQ5nNrLRm8ssuwWcBVcw Landing · PR #34430 · Fixes #33664 · head 2f6eef1 · 2026-11-16T19:00Z
State change: ready, and auto-merge armed. If the queue build goes red, area o1-A dequeues and treats it as this PR's own fault. #33664 closes on merge through |
Fixes #33664
Clause-②: no
Metadata-protocol: none
维护者速读
opportunity.stage)在 SQL 驱动上改为数据库内一条LEFT JOIN … GROUP BY,不再先按外键分组、再用id IN (所有外键)读关联对象。DATABASE_ERROR,大数据量的看板无法出数。packages/drivers/driver-sql/src/sql-driver-aggregation.ts(JOIN 子查询的租户墙与范围拼接)、packages/objectql/src/relation-group-join.ts(规划与拒绝条件)、packages/services/service-analytics/src/strategies/objectql-strategy.ts(executeCrossObjectJoined的回落与重分桶)。pnpm --filter @objectstack/service-analytics exec vitest run src/__tests__/cross-object-relation-group-join.test.ts,预期 23 个用例全绿,其中 33000 个外键的用例原路径 500、新路径每个 stage 11000 行。What changes
A dimension through a lookup on the ObjectQL analytics path (
POST /analytics/query, cubebench_line_item,dimensions: ['opportunity.stage']) is now one SQL statement on the SQL drivers instead of an FK-expand whoseid IN (every distinct FK)overflowed the dialect's bind limit.relation-group-join.tsadds aSymbol.forread option (RELATION_GROUP_BY) that no wire request can carry, so the publicgroupBystill refuses a dotted path.aggregate()reads it, plans the related object's read as the caller through the existingRELATION_SCOPE_PLAN/planRelationSemiJoinLeaf/plannedRelationLeafVerdict(no second copy of the read-scope leaf, ADR-0139 D6), and hands the driver aReadableIds.compose(leaf, plannedWhere)parent per relation under a second symbol (RELATION_GROUP_JOINS). The planned read is anaggregategrouped by['id', ...attrs], the same readresolveFkAttrran minus its id list, so the CRUD gate, read middlewares, row scope and the FLS group-by gate all apply. A deny-sentinel scope hands anullparent (nothing readable).opportunity), so plugin-security's aggregate input gate (step 2.5b) and every other group-key guard judge it. On the joined path the strategy drops that key, so the engine now hands the middleware chain the base read grouped by each relation fieldgroupBydoes not already name (relationFieldsJudgedAsGroupKeys), and takes those keys back out only in the statement it hands the driver (withoutJudgedRelationFields), where the join replaces them. No field gate is copied: the field goes through the chain's existing guards, so a caller who may not readline.opportunityis refused on the joined path by the same gate, with the same 403, as on the FK-expand. The docblock now says this rather than only "Holding the key grants nothing" (L1 S1).$expand, or the dataset door's dimension-label pass, reads it — detail withheld pending maintainer #22661 pin).relation-group-join.tscallsreferenceTargetOf, sosecond-object-read-exposure.pin.test.tsmust classify it. It is classifieddecided: the analytics door asks the related object'senableblock through the spec's decision (assertObjectsExposed,api-exposure-door.ts, foraggregate) overqueryObjects, which holds every hop's object, before any strategy runs. So the joined path and the FK-expand get one verdict, and the engine is never handed the request for an unexposed related object. The row addsaggregateto the row type's operation union andassertObjectsExposedto the roster of decision functions, which thedecidedform requires.request.outcome= joined or declined. It declines, with nothing read, for a driver outsideRELATION_GROUP_JOIN_COMPILING_DRIVERS(driver.sql,driver.sqlite-wasm), a federated object, a multi-valued relation, a relation whose target is not the requested object, a related objectrelationSemiJoinServeskeeps the id read for, a read middleware that answers without the driver, and an aggregate the driver does not answer natively (a non-UTC date bucket).aggregate()compiles each join asLEFT JOIN (SELECT id, attr… FROM parent WHERE planned scope AND parent tenant wall) __rgN ON child.fk = __rgN.id, groups by the attributes and a two-stateCASE WHEN __rgN.id IS NULL THEN 0 ELSE 1 ENDresolved column. The parent's tenant wall comes from the read's own options, as for a composedReadableIdssubquery. A parent the engine did not compose is refused with INTERNAL_ERROR / 500 before anything compiles.executeRelationGroupAggregate.ObjectQLStrategy#executeCrossObjecttries the joined path first and maps each row through the samerebucketCrossObject(an unresolved row is(restricted), exactly as an id the FK-expand's read did not return). On no hook, a decline, or any 4xx it falls back to the unchanged FK-expand, which re-derives a refusal in its own order and envelope.Divergence from the card's Expected. The card says "MongoDB/OData refuse with a stable 400". Per seat route B (record 6917462284) they keep today's FK-expand unchanged and nothing here refuses. That refusal, if it lands, is owned by #33876.
Why
The FK-expand bound one parameter per distinct related record. Past the dialect's ceiling, SQLite answered
too many SQL variablesand PostgreSQL a bind count overflow, both surfaced as500 DATABASE_ERROR. The join binds only the scope's comparands and the two tenant walls, whatever the row count.Tests
packages/objectql/src/relation-group-join.test.ts(15, recording driver). The middleware chain sees the base read grouped by the relation field (for agroupBywith other keys, with none, and with the FK column already named), and the driver's statement does not. Joined: one driver call, no read of the related object reaches the driver, and the parent scope is the request's condition as the related read's own doors lowered it AND the middleware's condition. A deny sentinel gives anullparent. A virtual attribute gives INVALID_FIELD / 400 with no driver call. A driver row missing the resolved column gives INTERNAL_ERROR / 500, as does an alias collision. Declines: memory, MongoDB, OData, Turso, multi-valued, object mismatch, short-circuit middleware, non-UTC bucket.packages/drivers/driver-sql/src/sql-driver-relation-group-join.test.ts, dialect matrix. Buckets with an empty FK, an orphan FK, a scope-hidden parent and another tenant's parent all unresolved, every child counted once. A base group key beside the join. Anullparent. At most 3 bindings (child wall, parent wall, one comparand). A forged parent gives 500.packages/services/service-analytics/src/__tests__/cross-object-relation-group-join.test.ts(23, real ObjectQL + SqliteWasmDriver, isolated tenancy). New in this round: a caller whose field permissions hideline.opportunitygets the samePERMISSION_DENIED/ 403 with the join wired as without it, and the engine is handed no request. The engine, handed the relation group request directly (no analytics door), refuses that caller with the same envelope as the FK-expand's base read grouped by the field; an admin control joins, and its rows carry noopportunitykey. A related object declaringapiEnabled: falseanswersOBJECT_API_DISABLED/ 404, and one whoseapiMethodsdoes not grant the aggregate read answersOBJECT_API_METHOD_NOT_ALLOWED/ 405, on both paths, with no request handed to the engine. The field gate in this suite is a test middleware that judges the AST'sgroupByandaggregationsthe way step 2.5b does, because this package does not depend on plugin-security. Parity of the joined path against the FK-expand for 3 callers (admin org A; member org A with a policy scope and a read middleware hiding parents; admin org B) × 4 dimension shapes. Explicit buckets for(restricted), null FK, orphan FK and a cross-tenant FK. The read scope and the tenant wall on the joined parent. 33,000 distinct FKs: the FK-expand answers DATABASE_ERROR / 500, the joined path answers 11,000 per stage.packages/objectql/src/federated-injected-column-readers.test.ts: two disposition rows for the new module's federated seams (exempt).packages/core/src/security/second-object-read-exposure.pin.test.ts: thedecidedrow above (4/4).Ablations (each disable → red → restore; restore proven by blob == HEAD and an empty git diff HEAD)
All run through
scripts/ablation-replace.mjsin WRAP mode againstsrc(every subject is resolved from source in its suite). The first six rows were measured atc87aab92d, the last two at2f6eef1ff.(restricted)executeRelationGroupAggregateundefinedinstead of the planned scopeapplyTenantScope(sub, …)deletedobjectql-echo-non-date-bucket.test.tsgroupBy.0vsgroupBy.1)relationFieldsJudgedAsGroupKeys(…)replaced by[]assertObjectsExposedanswers every object as servedThe first parity attempt replaced the anchor with the single character
i. The tool refused it because the replacement count could not rise, so that attempt measured nothing; it was rerun with a distinct replacement (row above).Acceptance notes
Bench (M0,
packages/qa/dogfood/bench/sql-perf,--only analytics_cross_object_dim, admin, SQLite, 20 iterations). "Before" is this head with the hook unwired in the builtservice-analyticsdist (the ablation above, proven present indist/and absent after the restore and rebuild). That path is today's FK-expand.These are shared-box seconds: the bench ran outside the verify lock after about 40 minutes queued behind another battery. Under the bind limit, SQLite pays more database time for the joined statement than for the two FK-expand reads (about 1.5x db time, about 1.1x request p50 at 20k parents). Past the limit, the request answers instead of failing. PostgreSQL bench: NOT MEASURED (the local PG server died mid-session; see Verification).
Turso is not served (its remote transport compiles its own aggregates). It keeps the FK-expand.
Optional L1 N2 was not taken: building the derived table from
readableIdsSubquery(…)needs that method on the driver's aggregation host, which is bound insql-driver.ts, not in the same file.main'scheck:platform-checklistred (approver-resolution-matrix VARIANTS STALE, since feat(approvals): platform_admin approver type for a deployment's own packaged flows #34300) is not this PR's and is not fixed here.Lint & Repo Gatesreads success on2f6eef1ff.The analytics-suite field gate stands in for plugin-security's step 2.5b, whose own input contract (
ast.groupBy/ast.aggregations) is pinned insecurity-plugin.test.ts.Files beyond the claim's literal names:
objectql/src/engine.ts(one host-wiring line),service-analytics/src/analytics-service.ts(config pass-through of the hook), andobjectql/src/federated-injected-column-readers.test.ts(two ledger rows its census demanded) are wiring for the claimed doors and the plugin bridge.core/src/security/second-object-read-exposure.pin.test.ts(one CALLERS row, its operation literal and its roster entry) is the census the new module'sreferenceTargetOfcall joins.Out of scope, noted and not fixed: the ObjectQL path buckets a line whose FK is not set under
(restricted), a label that reads as a permission outcome. This is pre-existing, and parity is kept here on purpose.Serial constraint with fix(service-analytics)!: the dataset query door refuses measures and dimensions the dataset does not declare #34198: it merged into
mainbefore this branch's last merge oforigin/main.git merge-treeagainst its head and againstorigin/mainis clean.Verification
Head of record:
2f6eef1ff.Suites and typechecks (at 2f6eef1, under the verify lock)
pnpm --filter @objectstack/objectql test: 604/604 files, 13485/13485 tests.pnpm --filter @objectstack/driver-sql test: 256 files passed, 13 skipped; 4331 tests passed, 247 skipped. The PostgreSQL cell of the join test ran in round 1 against a local PostgreSQL 16. MySQL, MSSQL and Oracle cells: NOT MEASURED locally.pnpm --filter @objectstack/service-analytics test: 218/218 files; 5318 tests passed, 335 skipped.@objectstack/corerepo project,second-object-read-exposure.pin.test.ts: 4/4. It was red onc87aab92din CI (Test Core 7/8).typecheckfor objectql (withcheck:test-typecheck), driver-sql, service-analytics and core: exit 0 each.Derived gates (at 2f6eef1)
node scripts/pm/dispatch-gates.mjs --commands --repo objectstack-ai/objectstackderived 82 commands. 81 exited 0 on the first run.check:dual-build-cjs-loadsexited 3 (PREREQUISITE NOT MET, no workspacedist/), and afterpnpm build(exit 0) it exited 0.--ranreconciliation with an exit code on every line: 82 derived, 82 run, 0 NOT-MEASURED, 0 UNRUN, a derived zero. The working tree was clean after the build.CI on 2f6eef1
Check-runs: 55 success, 11 skipped, 0 failed.
Test Core(all 8 shards),Lint & Repo Gates,TypeScript Type Check,Build Core,Governed Surface Queue Guard,Type Check UI,Test UI,Build & E2E UI,Live E2E UIandDogfood Regression Gateall report success.Generated by Claude Code