Skip to content

feat(objectql): planReadScope scopes a pointer column by a caller-run read of its target object - #39100

Merged
objectstack-fleet[bot] merged 9 commits into
mainfrom
claude/project-thread-7aatw7
Dec 2, 2026
Merged

objectstack-fleet[bot] merged 9 commits into
mainfrom
claude/project-thread-7aatw7

Conversation

@objectstack-fleet

@objectstack-fleet objectstack-fleet Bot commented Dec 2, 2026 •

Copy link
Copy Markdown
Contributor

Requested by Yibo Wang · project thread

Fixes #39080

Clause-②: yes (widening)
Metadata-protocol: none

维护者速读

  • 用户暂时看不到变化:这是列表页评论专题的服务端打底,引擎多了一个只供服务端内部调用的入口,能按「评论所指的记录满足某个条件」一次查出评论,全程按看的人的权限算。
  • 属于「列表页对象评论」专题(第一批四张打底卡之一),后面的「按视图取评论串」读取口等它。
  • 出错时只影响后面要接它的读取口,现有接口和页面行为不变,撤回即删掉这个入口。
  • 数据引擎主文件行数上限已按你的裁决(选 A)从 6860 提到 6861(只多一行转发),本 PR 已同步改登记表,不再需要你做什么。

What changes

  • ObjectQL#planReadScope(object, target, { where, context }) — a new public member on the published engine, for in-process callers. It answers the $in comparand that scopes a column of object to the ids of the target records the caller reads and where matches. Placed in a read verb's where on object under the same context, the read reaches a SQL driver as one statement: column IN (SELECT id FROM target WHERE target's read scope AND where AND tenant wall).

  • It is the planned read the single-valued nested-relation condition already runs (relation-semi-join.ts, planRelationSemiJoinLeaf / relationSemiJoinServes), entered by name, so a column that is NOT a declared relation (the platform-stamped sys_comment.record_id) can be scoped. Outcomes are a relation condition's: the planned leaf where it is provably the id read; otherwise the ids the caller reads under the 1,000 cap, refused INVALID_FILTER / 400 past it; refused INVALID_FILTER / 400 before anything is read when the driver of object lacks readableIdsLeaf (MongoDB, OData); OBJECT_NOT_FOUND for an unregistered object. No new error code, no filter operator, no wire key.

  • Layout, per the facade rule on engine.ts (check:facade-delegation-only): the class gets ONE forwarder line (the getRecordLock shape, through the delete-and-aggregate host); the body and the contract docblock live in engine-query-lowering.ts (planReadScope, PlanReadScopeOptions, ReadScopeComparand); the two refusal texts live beside the mechanism in relation-semi-join.ts (readScopeDriverRefusal, readScopeCapError), whose header gains a section naming this second in-process consumer.

  • packages/objectql/src/index.ts is untouched (it is on Setup navigation has ten new group anchors; a contribution to a retired group id still lands in the right group (#39050) #39053's claim): the member rides the already-exported class. No packages/spec change; IObjectQLEngine is untouched.

  • ADR-0139 consumer note: not in this PR. Per the epic ruling (专题:列表页右上角的评论入口——看当前视图里各条记录的评论串,可回复、可解决,不能写新评论 #39077 comment 7338398195, item 6), the landing seat records it under the ADR bookkeeping rule.

  • Facade ceiling: engine.ts grows by the one forwarder line, 6860 → 6861. Maintainer ruling 7340529355 (option A, the shape of ruling 7314474264) raises its row in scripts/facade-delegation-registry.json: baseLines 6861 measured at c7fc35317b, maxLines 6861, ruling 7340529355. That row is the only change to the registry.

Tests

  • packages/objectql/src/engine-read-scope-leaf.test.ts (new, 14 cases, recording driver): planned path (target never read, one composed leaf scoped by the target read's final where); the caller's context reaches the target read and the scope a global middleware injects lands in the subquery; target refusals propagate; OBJECT_NOT_FOUND; the up-front driver refusal across names and bit values, nothing read, plus the bit-not-name control; afterFind and object-keyed middleware fallbacks answer the id list (the lowering's exact read: condition, id only, cap + 1); the cap refusal and its exactly-the-cap control; no cap on the planned path; JSON and spread copies refused INVALID_FILTER; a hand-written ReadableIds.of is not the planned scope; a write verb refuses the leaf with ADR-0139's composition-fault envelope (INTERNAL_ERROR / 500, as for any leaf).
  • packages/plugins/plugin-security/src/comment-read-scope-semi-join.integration.test.ts (new, 7 cases per dialect cell): the real AuditPlugin (comment object, parent-pair stamp, read gate) and the real SecurityPlugin over SqlDriver, with three permission sets on the parent: full read, read narrowed by a row-level rule with one unreadable field, none.
    • Unrestricted and row-scoped members, five filters each: the planned route's comment ids equal the two-step route's (read ids as the caller, then $in) and the rows the filter means; never a comment on another object.
    • Statements: the parent is never read; the comment statements equal the two-step route's one for one, and the threads statement carries the composed leaf, with no id list anywhere (control: the two-step route reads the parent and hands the driver a list).
    • A member with no read on the parent: the same answer as the two-step route, PERMISSION_DENIED, nothing read.
    • A filter on a field the caller cannot read: PERMISSION_DENIED, the same as the two-step route (control: a member who may read it is served).
    • A JSON copy of the scope in a where: INVALID_FILTER.
    • 1,005 matching parents: served, no id list, the same row as the two-step route.

Acceptance notes

  • The card says the scoped read "reaches the driver as one statement". Measured: the scope adds no statement, and the threads read is one statement carrying the subquery. The comment gate itself also issues its existing probe for rows its parent pair has not reached (object_name IS NULL, limit 2000), on the planned route and the two-step route alike. That probe is the gate's, not this card's; S3 (Comments: one read returns the threads on the records a list filter selects, as the caller #39084) will see it in its query log.
  • "A member with no read on the target (zero rows)": with the real security layer the target read is refused outright (PERMISSION_DENIED), and so is the two-step route's first read; the planned route gives exactly that answer. The comment read by that member serves no comment on the parent (the gate's own answer), which is the zero rows a list page would show.
  • The PostgreSQL cell keys on OS_TEST_POSTGRES_URL, creates its own database and drops it. No CI job provisions that variable for plugin-security, so it is un-run in CI; its local run is below.

Verification

Two-minute check: cd packages/objectql && pnpm exec vitest run src/engine-read-scope-leaf.test.ts — expect 14 passed.

Read first, by risk:

  1. packages/objectql/src/engine-query-lowering.ts — planReadScope: the order of the checks and that the planned and id reads are the relation lowering's exact read.
  2. packages/objectql/src/engine.ts — the one forwarder line and the host it borrows.
  3. packages/plugins/plugin-security/src/comment-read-scope-semi-join.integration.test.ts — the parity and statement assertions.
Local readings (code head c7fc353, on main 7814822 + merge of origin/main; later commits: changeset grade, typed test options, the ceiling row)
  • pnpm exec vitest run src/engine-read-scope-leaf.test.ts (objectql): 14 passed.
  • OS_TEST_POSTGRES_URL=postgres://…@127.0.0.1:5432/postgres pnpm exec vitest run src/comment-read-scope-semi-join.integration.test.ts (plugin-security, PostgreSQL 16.x local): 14 passed (7 SQLite + 7 PostgreSQL), 0 skipped.
  • Ablation: the planned branch of planReadScope disabled on disk (falls back to the id read every time): unit 7 of 14 red, integration 8 of 14 red; restored from the commit, git status clean.
  • tsc --noEmit -p tsconfig.json (objectql): exit 0.
  • Derived gate set (dispatch-gates.mjs --commands, 76 commands): run locally; results and NOT MEASURED lines are in the report on objectql: a server read scopes a pointer column by a caller-run read of its target object #39080. check:facade-delegation-only green after the ceiling row (44 self-test cases, N6 green, ObjectQL 0 named exceptions); check:query-options-erasure green, test surface at its ceiling of 236.

🤖 Generated with Claude Code

https://claude.ai/code/session_01WGufziSQiNb9xKWTy1uFgY

…as one $in comparand (WIP)

Claude-Session: https://claude.ai/code/session_01WGufziSQiNb9xKWTy1uFgY
Co-authored-by: Claude <noreply@anthropic.com>
… security layer, SQLite and PostgreSQL

Claude-Session: https://claude.ai/code/session_01WGufziSQiNb9xKWTy1uFgY
Co-authored-by: Claude <noreply@anthropic.com>
…y and contract in the query-lowering facet

engine.ts is in facade form (check:facade-delegation-only): its members are
one forwarding call and the file does not grow. The method's docblock and body
move to engine-query-lowering.ts; engine.ts grows by the one forwarder line,
which still needs its ceiling raised by maintainer ruling.

Claude-Session: https://claude.ai/code/session_01WGufziSQiNb9xKWTy1uFgY
Co-authored-by: Claude <noreply@anthropic.com>
@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 Dec 2, 2026
@github-actions

github-actions Bot commented Dec 2, 2026 •

Copy link
Copy Markdown
Contributor

📓 Docs Drift Check

This PR changes 1 package(s): @objectstack/objectql, touching 8 documentable anchor(s).

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

  • content/docs/api/data-api.mdx (via sys_comment (literal, a string literal in a comment on a changed line))
  • content/docs/deployment/cli.mdx (via sys_comment (literal, a string literal in a comment on a changed line))
  • content/docs/frontend/plugins/plugin-detail.mdx (via sys_comment (literal, a string literal in a comment on a changed line))
  • content/docs/kernel/contracts/data-engine.mdx (via sys_comment (literal, a string literal in a comment on a changed line))
  • content/docs/permissions/attachments-access.mdx (via sys_comment (literal, a string literal in a comment on a changed line))
  • content/docs/permissions/system-context.mdx (via sys_comment (literal, a string literal in a comment on a changed line))
  • content/docs/plugins/packages.mdx (via sys_comment (literal, a string literal in a comment on a changed line))
  • content/docs/upgrading.mdx (via sys_comment (literal, a string literal in a comment on a changed line))

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

  • content/docs/releases/v14.mdx (via sys_comment (literal, a string literal in a comment on a changed line))
  • content/docs/releases/v16.mdx (via sys_comment (literal, a string literal in a comment on a changed line))
  • content/docs/releases/v17/17-0.mdx (via sys_comment (literal, a string literal in a comment on a changed line))
  • content/docs/releases/v17/17-1.mdx (via sys_comment (literal, a string literal in a comment on a changed line))
  • content/docs/releases/v17/17-5.mdx (via sys_comment (literal, a string literal in a comment on a changed line))
  • content/docs/releases/v17/17-6.mdx (via sys_comment (literal, a string literal in a comment on a changed line))
  • content/docs/releases/v18/18-0.mdx (via sys_comment (literal, a string literal in a comment on a changed line))

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
  • 1 name(s) were too generic to anchor anything (single lowercase words)
  • the SDK route bridge reached 71 of 254 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 — 21 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 4b8a67d8fabe96eac4110a418ae53cb1e0f6f025 → packageMentionDocs.

Which tree this was computed on

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

node scripts/docs-audit/affected-docs.mjs --json 4b8a67d8fabe96eac4110a418ae53cb1e0f6f025

⚠️ 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 4b8a67d8fabe96eac4110a418ae53cb1e0f6f025 → pass the list as
args.docs, on the commit named under Which tree this was computed on.

…col none

The level follows the metadata protocol alone (pr-automation.yml, WHICH LEVEL);
this diff changes nothing a metadata author can write.

Claude-Session: https://claude.ai/code/session_01WGufziSQiNb9xKWTy1uFgY
Co-authored-by: Claude <noreply@anthropic.com>
…e integration test

Seven find() calls take EngineQueryOptions instead of an any cast, and the
JSON-copy refusal call, whose input is off-contract on purpose, names the
contract it bypasses (as unknown as EngineQueryOptions). The test surface of
check:query-options-erasure stays at its ceiling of 236.

Claude-Session: https://claude.ai/code/session_01WGufziSQiNb9xKWTy1uFgY
Co-authored-by: Claude <noreply@anthropic.com>
…eadScope forwarder

Maintainer ruling 7340529355 (option A): one forwarder line on the ObjectQL
class, the shape of ruling 7314474264. baseLines 6861 measured at c7fc353.

Claude-Session: https://claude.ai/code/session_01WGufziSQiNb9xKWTy1uFgY
Co-authored-by: Claude <noreply@anthropic.com>
@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

repo:objectstack@os-support-ai · os-support-ai · session_01WGufzhGA3zoCFquQgku4pm

Contract-review-claim: session_01WGufzhGA3zoCFquQgku4pm · head fa986c2 · 2026-12-02T09:17Z

@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

repo:objectstack@os-support-ai · os-support-ai · session_01WGufzhGA3zoCFquQgku4pm

Contract review

Served-tier: CONTRACT_REVIEW_TIER
Head-sha: fa986c2ec8e27c04bdbd03e125708313c327671f
Local-runs: none
Scope: packages/objectql/src/engine.ts, packages/objectql/src/engine-query-lowering.ts, packages/objectql/src/relation-semi-join.ts + packages/objectql/src/engine-read-scope-leaf.test.ts, packages/plugins/plugin-security/src/comment-read-scope-semi-join.integration.test.ts, scripts/facade-delegation-registry.json, .changeset/39080-objectql-plan-read-scope.md
Security-touching: yes
Rule-change-verified: none

PR #39100 for card #39080, net diff against merge-base 6354509427 (7 files, +913 −6). Read: the card body and its five comments (ruling-ref 7338426216, card-thread 7338445699, claim 7338665819, dev report 7339945871, ruling and claim amendment 7340529355), the PR body and file list, the net diff, and the cited code in the tree at the head. Nothing was built or run.

Check-runs on the head, read twice (09:18Z and 09:23Z, 2026-12-02); not waited for:

  • Concluded success at 09:23Z: Check Changeset (both runs), Lint · repo & tooling gates (the facade ceiling gate lives here), Lint · ESLint, Lint · docs & code guards, Lint · scoped · query-options erasure, Lint · scoped · tooling self-tests, Lint · PM dispatch-gates, Type Check · source gates, Plan Test Core shards, Test UI, Dogfood Regression Gate, Governed Surface Queue Guard, PR-body guards (both), Check PR Size, Flag docs affected by code changes.
  • Still in progress at 09:23Z, so NOT a verdict this record can cite: Build Core, Test Core 1/12 to 12/12 (the two new suites and the REST suites run here), Type Check · workspace, Type Check · consumer gates, Type Check · debt ledger, Lint · CI, release & engine gates, Lint · scoped · slot lookup & corpus, Live E2E UI.
  • None concluded failure. The verdict below is on the design and the contract; the landing seat reads the pending runs before it lands anything. A red among them is a gate verdict this record does not overrule.

① Derived judgments

  • Public surface, @objectstack/objectql: one new public method on the already-exported class, ObjectQL#planReadScope(object, target, options?), answering a promise of a ReadableIds leaf or an id array. RIGHT that it is a widening and nothing else: packages/objectql/src/index.ts and core.ts are untouched, no export is added, removed or retyped, and IObjectQLEngine in packages/spec is untouched.
  • The two new types (PlanReadScopeOptions, ReadScopeComparand) and the two refusal builders (readScopeDriverRefusal, readScopeCapError) are module exports only; the barrel does not re-export them. RIGHT for this card's claimed surface (the barrel is on Setup navigation has ten new group anchors; a contribution to a retired group id still lands in the right group (#39050) #39053's claim); see N3.
  • Accept-set of a request where: unchanged. RIGHT. No operator, no wire key, no change to assertListComparandShapes; the leaf the method returns is the existing ADR-0139 branded leaf, whose brand is a non-enumerable symbol key, and the planned scope is held in the module-private WeakMap keyed by the leaf's identity. A JSON, structured-clone or spread copy is a plain object in a $in slot and is refused INVALID_FILTER as before.
  • Accept-set of an in-process read's where: a planned leaf may now arrive in the caller's own where at the verb's entry, where before the lowering alone inserted one after token resolution. RIGHT that no door needed a change: the token resolver returns an engine-internal leaf by reference (packages/core/src/utils/filter-tokens.ts), the comparand door already admits a branded leaf as $in on the four read verbs, and the executor boundary (composeReadableIdsChain) already answers a planned leaf by plannedRelationLeafVerdict. A leaf that loses identity anywhere on the way loses its brand too and is refused, never composed as "every readable row of the target".
  • New refusals: INVALID_FILTER / 400 (driver without the bit; fallback past the cap), OBJECT_NOT_FOUND (unregistered object), and whatever the target read raises. RIGHT that no new code is introduced: both builders go through the existing invalidFilterError.
  • scripts/facade-delegation-registry.json: the engine.ts row alone, 6860 to 6861, base re-measured, ruling 7340529355. RIGHT against the tree: engine.ts is 6,861 lines at the head, and the ceiling gate's job concluded success.
  • packages/plugins/plugin-security: one new src/*.integration.test.ts file; files[] ships dist, README.md and CHANGELOG.md; no package.json or lockfile change (the imported workspace packages are already declared). RIGHT that it publishes nothing and takes no changeset.

② Semver level

  • Clause-②: yes (widening) is right: a new public member on a published package's exported class, nothing removed or narrowed. Present line-initial in the PR body and in the changeset body.
  • Metadata-protocol: none is right: nothing a metadata author can write changes. Present in both places.
  • Level patch on @objectstack/objectql is right under AGENTS.md Post-Task step 3: the level follows the metadata-protocol kind alone, none takes patch, and a non-protocol widening ships patch. The earlier minor was corrected at b53d0ed7; Check Changeset concluded success on this head.
  • The changeset names @objectstack/objectql only. Right: no other released package's published files move.
  • The changeset, sentence by sentence, against the tree: the method and its arguments, true; "the planned read a single-valued nested-relation condition already runs", true (same planRelationSemiJoinLeaf and relationSemiJoinServes, same query shape); "read as the caller ... refused PERMISSION_DENIED, never answered empty", true where a security service is installed (the refusal is the target read's own); the cap of 1,000, true (RELATION_FILTER_ID_CAP); the up-front driver refusal "before anything is read", true; "no filter operator and no wire key ... a JSON copy ... refused as before", true. One sentence is unqualified where it stands: N1.

③ Boundary flags

  • Dev open question (the engine.ts ceiling, options A/B/C): answered by comment 7340529355, which records the maintainer's 「A 提到 6861」 at 09:09Z and amends the claim's file surface. The row in the diff matches that comment field for field. I can read the relayed record on the card, not the project thread it quotes; the row's ruling id resolves to that comment, and that is what the gate asks for. Rule-change-verified: none because the PR touches no .claude/** path and no hunk changes what an agent may do without the maintainer: the one maintainer-only act in the diff (the ceiling) carries its ruling.
  • Dev flag, "one statement" versus the comment gate's own probe (object_name IS NULL, limit 2000): answered, accepted. The probe is AuditPlugin's read gate, issued on the two-step route alike; the integration test pins "the scope adds no statement" and "no id list reaches the driver", which is what this card can own. Carrier Comments: one read returns the threads on the records a list filter selects, as the caller #39084, as the dev names.
  • Dev flag, "a member with no read on the target (zero rows)" is answered PERMISSION_DENIED: answered, accepted, and to be carried forward. The card's governing clause is "exactly the rows the two-step route returns", and both routes raise the target read's own refusal; the parenthetical was a prediction the real security layer does not make. Swallowing it into an empty scope here would contradict the method's own contract ("a refusal from that read is the answer") and the relation lowering's. The door in Comments: one read returns the threads on the records a list filter selects, as the caller #39084 must therefore decide what a list page shows such a member; this record does not decide it.
  • Dev flag, the PostgreSQL cell is un-run in CI: answered, accepted with N5. The card's acceptance names PostgreSQL; on this head no check-run witnesses it, and the PR body's local run is an account, not a gate. What it would witness is the dialect compilation of an ADR-0139 composed leaf, which is driver-sql's existing surface and not in this diff.
  • ADR-0139 consumer note not in this PR: answered by the card itself (epic ruling 7338398195 item 6, the landing seat's bookkeeping). No docs/adr/** path is in the diff.
  • security_findings: none in the dev report: consistent with what I found.
  • SQL push-down (Prime Directive 5). The method's first outcome is the semi-join in one statement. It also has an id-materialising outcome, and a reason is given for each case, each of them the relation lowering's existing fallback set and none new: a read rule the target applies after its driver call (an afterFind hook, an object-keyed middleware), another datasource, a federated target, a different tenancy class under a walled posture, a plan that did not reach exactly one driver call, and outer driver options that are not the planned read's own. In none of these is the subquery provably the caller's read, so no push-down is being declined for convenience. A driver that cannot compile the leaf is REFUSED with a stable code and is not served by the id read: the directive's own rule, and the ruling on analytics: on SQL drivers compile a cross-object where into an in-database semi-join (no 1000-id cap), each hop read-scoped; non-SQL drivers refuse #33626 Q2 the lowering already follows. No finding.

④ Design judgment

No must-fix, no should-fix.

packages/objectql/src/engine-query-lowering.ts (planReadScope), against lowerRelationConditions in the same file.

  • Check order. object registered, else OBJECT_NOT_FOUND; then the driver of object must declare readableIdsLeaf, else INVALID_FILTER; then relationSemiJoinServes(object, target); then the planned read; then the id read. That is the lowering's order (driver verdict for every site before any related read, then per site serves, plan, fallback). Before the driver refusal only the registry and the driver router are consulted, so "nothing was read" in its text is true; the unit suite pins an empty read log across three driver names and three bit values, with the bit-not-name control.
  • The read is the lowering's read. The planned call and the id call are both engine.find(target, { where, fields: ['id'], limit: cap + 1, context }), the planned one with the symbol-keyed plan option: the same four keys, in the same call shape, as the lowering's two calls. Like the lowering's, the read is dispatched before any outer verb's middleware chain, so it sits in no enclosing operation scope. The captured where is the final driver where after the doors, the middleware chain, beforeFind and the recorded wall, and the capture is RLS_DENY_FILTER when the wall denied, which the boundary answers $in: [].
  • Attempts to make it admit a record the caller's own find on target would not return:
    • a copy of the leaf (JSON, spread, structured clone): loses the brand, refused; it cannot degrade into an ordinary leaf scoped by the target's read scope without the where;
    • a where carrying a placeholder beside the leaf in the outer read (the one stage a caller-placed leaf crosses that a lowering-placed one does not): the resolver keeps the leaf by reference;
    • the leaf placed on another object than object: another datasource or an object-keyed middleware on the target is refused at the boundary by name; a different tenancy class changes the driver options, so the boundary reads the ids as the planning caller instead of composing. Closed or loud in each case I could construct (a carrying object whose driver lacks the bit is outside what the method judged, and outside its stated use);
    • the leaf placed under another caller's context: it still carries the PLANNING caller's scope, and a $in comparand can only narrow the outer read, whose own read scope still applies. It reveals nothing the in-process code that planned it could not already read as that caller;
    • a write verb: refused with ADR-0139's composition-fault envelope, pinned by the unit suite.
      None admits a record. Refusing a record the caller's find would return: only past the cap on a fallback, which is the stated contract, and the 1,005-parent integration case pins that the planned path has no cap.
  • The cap. readIds asks for one id past the cap and refuses on receiving it, before any comparand is returned; the exactly-the-cap control is pinned. The same closure is what the executor boundary calls when the outer options differ, so a refusal there is the same code and words.
  • where on a field the caller may not read. The filter-oracle guard runs in the target read's middleware chain, which the planned read runs in full before the capture point; the integration test pins PERMISSION_DENIED on the planned path for the row-scoped member, the two-step route's same refusal, and the control for a member who may read the field.

packages/objectql/src/relation-semi-join.ts. The two refusal builders agree with their docblocks and with the relation refusals they mirror (reason, route, "NOT applied", which drivers run it). The driver text claims nothing was read, which holds; the cap text does not claim it, which is right, since the target read ran. The header section naming the second consumer is accurate against the body.

packages/objectql/src/engine.ts. One forwarder line in the getRecordLock shape, through deleteAndAggregateHost, which declares the four members the body picks (_registry, getDriver, relationSemiJoinServes, facade). The method adds no logic to the facade.

Tests. The unit suite (14 cases, recording driver) and the integration suite (7 cases per dialect cell, real AuditPlugin, SecurityPlugin and SqlDriver) assert what the card's acceptance names, with controls on the two-step route. The integration suite is collected by the package's ordinary vitest run, so its SQLite cell runs in Test Core, pending on this head.

Nits. None affects correctness or the contract; each is for a prose face, an accepted deviation or a follow-up card, since a fix elsewhere moves the head.

  • N1 (nit) — changeset, second sentence, and the docblock's lead: "that read reaches a SQL driver as one statement ... with no id list read first and no cap" is stated without condition, and is true only of the planned outcome; the fallback cases two sentences later read an id list under the cap. The paragraph as a whole is right; the sentence alone is not. A leading "where it can be planned" would make it true where it stands.
  • N2 (nit) — the contract says "under the same context" but neither says nor enforces that the answer is a snapshot: the planned leaf holds the caller's scope, the resolved placeholders and the registry facts (afterFind hook, federation) as they stood at planning. A door that plans and reads in one request, as Comments: one read returns the threads on the records a list filter selects, as the caller #39084 will, is unaffected; a holder that kept the leaf across requests would serve a stale scope, exactly as a kept id list would. One sentence in the docblock ("plan per read; do not keep the answer") closes it.
  • N3 (nit) — PlanReadScopeOptions and ReadScopeComparand cannot be named from the package, and the method is not on IObjectQLEngine, so the first consumer reaches it through the class type (as the integration test does with getService typed to the class). Deliberate for this card's surface; a follow-up once Setup navigation has ten new group anchors; a contribution to a retired group id still lands in the right group (#39050) #39053 releases the barrel.
  • N4 (nit) — planReadScope hands object and target to the registry, the driver router and relationSemiJoinServes as written, where every verb first runs resolveObjectName. With object name equal to table name (Prime Directive 6) the two agree; only a legacy double-underscore name differs, and the lowering passes a field's reference the same way. Recorded so the next reader does not rediscover it.
  • N5 (nit) — the card's acceptance says "SQLite and PostgreSQL"; the PostgreSQL cell keys on OS_TEST_POSTGRES_URL, which no job provisions for this package, so nothing on the head witnesses it. The dev reported it with no carrier; it wants one.
  • N6 (nit) — the unit case titled "an unregistered target, a bad comparand, an unknown field" asserts the first two only. QueryLoweringHost's docblock ("every one of them, and no other") no longer covers every function in the module, since planReadScope reads through the delete-and-aggregate host; its own docblock says why. The docblock lists findOne, count and aggregate as carrying verbs, and both suites carry the planned leaf through find alone; those three compose through the same boundary function.

Implemented-by: claude/project-thread-7aatw7
Reviewed-by: session_01WGufzhGA3zoCFquQgku4pm

VERDICT: PASS

@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

repo:objectstack@os-support-ai · os-support-ai · session_01WGufzhGA3zoCFquQgku4pm

L1 review — ACCEPT on fa986c2ec8e27c04bdbd03e125708313c327671f

The in-house contract L2 at CONTRACT_REVIEW_TIER is record 7340860054 on this head: PASS, no must-fix, no should-fix, nits N1–N6. Check-runs: 41 success, 20 expected-skip, 0 failed, 0 pending; Test Core 1–12 and the workspace type checks, still running when the L2 read them, are all green. Not governed, 919 lines.

Verified on the tree:

  • The forwarder. engine.ts gains one line that forwards planReadScope to engine-query-lowering.ts through deleteAndAggregateHost. The facade registry row (6860 → 6861, baseCommit c7fc35317b, ruling 7340529355) matches maintainer ruling A in claim amendment 7340529355.
  • Parity. The two reads are the relation lowering's exact find(target, { fields: ['id'], limit: cap + 1, context }), checked in the same order as lowerRelationConditions. So the comparand admits only what the caller's own find on target would return. The L2 tried to break this six ways (a JSON/spread copy, a placeholder beside the leaf, the leaf on another object, a foreign context, a write verb) and none got through. Integration parity with the two-step route is pinned for full, row-scoped and no-read members on SQLite.
  • Refusals. Past the cap and on a driver without readableIdsLeaf, the answer is INVALID_FILTER (400), and the driver refusal comes before anything is read. A where on an unreadable field gives PERMISSION_DENIED from the target read's own guard.
  • Declaration. Clause-②: yes (widening), patch. ObjectQL gains a public method; index.ts, core.ts and IObjectQLEngine are untouched.
  • l1-face's changeset flag covers @objectstack/plugin-security, but the only file there is the integration test, and that package ships dist, so nothing changes in it.

Relation. Fixes #39080 (S1 of #39077). The member with no read gets PERMISSION_DENIED rather than "zero rows". That matches the two-step route, and the list-page door that decides what that member sees is #39084's job.

Carried to the seat (nits, not owed):

Not Tier H: the seat lands it, as the card thread says.

@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

repo:objectstack@os-support-ai · os-support-ai · session_01WGufzhPdWmTd47Fi2bKYZS

席位核对

ACCEPT — PR #39100 @ fa986c2ec8 (Fixes #39080, epic #39077 S1; card thread of seat os-support-ai, claim 7338665819, ruling and amendment 7340529355).

落地

reading value
check-governed-merges.mjs --pr 39100 NOT governed (0 of 7 paths); 919 changed lines ≤ 3000
pr-state.mjs on fa986c2e 41 success · 20 expected skip · 0 failed · 0 pending; mergeable_state clean
landing-k.mjs --pr 39100 K = 4 < 15
l1-face.mjs --pr 39100 FLAGGED, one item, changeset, which does not hold: the one @objectstack/plugin-security file is a new integration test, so nothing that ships there changes; @objectstack/objectql's patch entry covers the member

State change: ready for review + auto-merge, by the owning seat; on merge it closes #39080.

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.

objectql: a server read scopes a pointer column by a caller-run read of its target object

2 participants