Repository navigation
Commit 8d60333
fix(service-record-context): get_record_context leaves out an unserved related child; both MCP doors supply queryableFieldsOf and their page cap (#37412)
Fixes #37361
Fixes #37175
Clause-②: yes (widening)
Metadata-protocol: none
## 维护者速读
- 用户能看到什么变化:外接 AI
读一条记录的资料包时,提问人无权看的关联子对象改为省略并说明,其余部分照常返回;筛选或排序用到提问人不能查询的字段时同样省略并说明,不再整次报错。
- 为什么做:记录级 AI 问答专题,按已同意的设计(无权的关联对象省略而非拒绝)补齐真实通道的行为。
- 出错会怎样:最坏是资料包少一段或多一段说明,提问人仍只能读到自己有权读的数据;可以直接撤回本次改动。
- 要你做的:无。
## What changes
ADR-0160 D3 "Object level" as amended, and its second amendment; triage
row 7154563681 on #37203.
- **A related child this caller is not served is left out**
(`executeGetRecordContext`, step 4a). The answer carries the root and
every served section with the one `not_visible` note, and names the
child nowhere (D3 wins over the triage row's "names the child"). Nothing
of the child is read after its object-level judgement, its published
definition included: the plan reads a left-out child as having no
definition, so a lookup target reached only through it is never judged
either.
- **Order inside 4a is now: read guard, then API exposure, then the
served definition.** Measured on the real kernel (assumption A2 holds):
a disabled-package child answers `servedObjectDefinitionOf` as `null`,
so judging exposure first is what keeps its refusal. API-exposure and
`OBJECT_PACKAGE_DISABLED` refusals still refuse the whole call with
`PERMISSION_DENIED`, the one code ADR-0160 point 12 gives an
object-level refusal. An API-exposure refusal names the child only when
the caller's served schema shows it (the naming bound, unchanged). A
served-definition read that throws refuses the call, unnamed; it is
never read as this caller's narrowing.
- **Both real doors supply `queryableFieldsOf`** from the security
service's `getQueryableFields`, for the caller each already resolves
(assumption A1 holds: no new service dependency on either door). `/mcp`:
`recordContextMembers` reads it from this request's `security` service
with the request's execution context. stdio: `createStdioDataBridge`
reads it from the `security` service it already holds for the
object-schema mask, with the per-call principal; its dependency type now
declares the optional method.
- **N2, the smaller design: the door reports its cap, and the executor
asks for at most it.** A new optional door member `pageCap()` answers
the most rows one `query` may ask for. The executor cuts a list at
`min(limit or row cap, pageCap - 1)`, reads with the probe row, and
states the cut, so no door cuts or refuses a list the answer does not
say was cut. Both doors answer the deployment's smaller read limit
(`OS_DATA_MAX_PAGE_SIZE`, `OS_DATA_QUERY_ROW_BUDGET`), which the data
door refuses past. Before, under a max page size below 21, the `/mcp`
door refused the whole call `MAX_RECORDS_EXCEEDED` and the stdio door
read the full list (the ablation below shows both).
- **N1:** the `RecordContextNoteKind` doc line now says
`related_truncated` fires at the entry's `limit`, at the row cap, or at
the door's page cap.
- **Rework N3:** the `.describe()` texts of
`RecordContextRelatedListSchema.rows` and `.truncated` (what a model
reads in the tool's output schema) now name the entry's `limit` and the
door's page cap, not the row cap alone. Generated reference docs
regenerated with `check:generated --fix`
(`content/docs/references/ai/record-context-tools.mdx`, 2 rows twice).
- **Rework N4:** one page cap. `@objectstack/types` exports
`resolveQueryReadPageCap()`, the smaller of `OS_DATA_MAX_PAGE_SIZE` and
`OS_DATA_QUERY_ROW_BUDGET`, `undefined` when neither is set; both doors
answer `pageCap` from it, and their two local copies are gone.
`deleteRecordsCap` is not changed.
- **Rework S1, the declaration:** `Clause-②: yes (widening)`. The
published surface widens by optional members only:
`RecordContextDoor.pageCap?()`, `StdioDataBridgeDeps.security` may carry
`getQueryableFields`, and the new `resolveQueryReadPageCap` export.
Precedent #35137. The level stays `patch` (now also on
`@objectstack/types`); `Metadata-protocol: none` stands.
- **N5:** an `orderBy` on a registry-injected field (`created_at`) is
pinned on the service and on both doors: the executor's own-field check
(the child's published definition) and both doors accept it. See the
acceptance notes for the authoring lint, which does not.
- **Carried from #37175 (item 4 of its card amendment, comment
7151678330):** `door.ts` `query`'s docblock now says the door decides
each expansion target's API exposure. Rework S3: the sentence, which
ships in the `.d.ts`, cites ADR-0160 D3 "Object level" (its last
paragraph: a lookup whose target the caller may not read is left
unexpanded); the earlier "(ADR-0160 D3, amendment 4)" named an ADR
amendment that does not exist.
## Tests
Whole suites of every touched package, at head `88a1447c9` (local, under
the shared verify lock; per-package exit captured before any pipe):
| package | command | result |
|:--|:--|:--|
| `@objectstack/types` | `pnpm --filter @objectstack/types test` | exit
0 · Test Files 41/41 · Tests 934/934 |
| `@objectstack/service-record-context` | `pnpm --filter
@objectstack/service-record-context test` | exit 0 · Test Files 2/2 ·
Tests 106/106 |
| `@objectstack/mcp` | `pnpm --filter @objectstack/mcp test` | exit 0 ·
Test Files 85/85 · Tests 1515/1515 |
| `@objectstack/runtime` | `pnpm --filter @objectstack/runtime test`
(`--project local`) | exit 0 · Test Files 649/649 · Tests 12041 passed,
25 skipped |
| `@objectstack/spec` | `pnpm --filter @objectstack/spec test` | exit 0
· Test Files 896/896 · Tests 28442 passed, 1 todo |
`pnpm --filter X typecheck` for the same five packages: exit 0 each.
`pnpm --filter @objectstack/spec check:generated --fix` after a spec
build: 1 of 14 artifacts stale (`content/docs/references/**`, the N3
texts), regenerated, re-checked green.
Real-kernel harness
(`packages/runtime/src/mcp-record-context-tools-bridge.test.ts`), every
case through `both()` (same bytes on `/mcp` and stdio for one caller),
22 cases:
- rework S2, new: a second caller, `usr_plain`, the same key's door but
without `rc_unmask` (the baseline set no longer carries it; `usr_member`
holds it through its own grant of `rc_unmasker`, resolved by the real
`resolveAuthzContext`). For `usr_plain` an `orderBy` on the masked
`serial` drops the section with the one `not_visible` note on both
doors: no refusal, no `related` key, nothing of `rc_step` in the text,
`getQueryableFields` lacks `serial` for it. Control leg in the same
case: the same pack as `usr_member` reads `[s4, s2, s3, s1]`. The stdio
door re-resolves the key's owner per call, and the case asserts it read
as `usr_plain`;
- flipped: the case titled "[today; ADR-0160 as amended says left out
and stated]" now pins left out and stated, with a served control child
(`rc_revision`) in the same answer;
- unchanged and green: the API-exposure child (named) and the
disabled-package child (`OBJECT_PACKAGE_DISABLED`, unnamed) still
refuse;
- new: the where/orderBy/limit parity case (filtered, ordered, cut at
`limit`, stated);
- new: a `where` field outside the security service's answer drops the
section with the note, never refuses, with a served control; the field
is served, readable and declares no masking rule, so the fallback would
admit it;
- new: an `orderBy` on a masked field whose unmask capability the caller
holds is read (the service lists it as queryable, the fallback never
would);
- new: `orderBy: created_at` reads in that order on both doors;
- new: under `OS_DATA_MAX_PAGE_SIZE=3` both doors cut the list at 2 and
state it;
- the door-member unit case now lists `pageCap` and `queryableFieldsOf`,
and a new case pins that the door's queryable fields are the security
service's answer for the caller and its cap the smaller read limit.
Service (`record-context-tools.test.ts`): left out with a served control
and no further read of the child; a lookup target reached only through a
left-out child refuses nothing; unexposed and unserved child refused
unnamed; disabled-package child refused before its served definition is
asked; a throwing served-definition read refuses; the door cap cuts one
row under it and states it, and a cap at or above the probe, absent,
zero or fractional changes nothing; `orderBy: created_at` reads.
<details><summary>Ablations (each committed first, mutated with
scripts/ablation-replace.mjs, dist-preflighted where the subject
resolves through dist, restored to the HEAD blob)</summary>
- **A** (left-out child refused instead, the old behaviour; service
rebuilt, dist preflight `--absent` on `leftOut.add(entry.object)`):
service suite 3 red (the left-out case, the lookup-through-left-out
case, the gate-order case); runtime harness 1 red (the flipped left-out
case). Restored to blob `c4cd29690aa1`, rebuilt, marker present again.
- **E** (no API-exposure gate on a related child, `if (false) try`; dist
preflight hit): runtime harness red on the API-exposure child and on the
disabled-package child, which then answers left out instead of refused.
This is the measurement behind A2: on the real kernel a disabled-package
child reaches `servedObjectDefinitionOf` as `null`, so only judging
exposure first keeps its refusal. Service suite 6 red.
- **B** (`/mcp` door hands over no `queryableFieldsOf`; runtime source,
no build): 4 red, among them the narrowed-answer case and the
unmasked-serial case (the two doors' bytes differ).
- **C** (stdio door hands over no `queryableFieldsOf`; mcp rebuilt, dist
preflight hit): 2 red, the same two parity cases.
- **D** (executor never asks the door's cap; service rebuilt, dist
preflight hit): service N2 case red; runtime page-cap case red with the
`/mcp` door answering `MAX_RECORDS_EXCEEDED` for the whole call where
stdio read the list. The first attempt at D (replacing the cut
expression) left `doorCap` unused and did not build, so it ran no test;
it was redone with a mutation that builds.
- **F** (rework, for the S2 pin: the executor admits a field served OR
queryable, `served.has(n) || queryable.has(n)`; committed first at
`88a1447c9`, service rebuilt, anchor counts 1/0 on disk, dist preflight
hit): runtime harness 2 red. The new second-caller case turns red with
the whole call refused (`isError` true: the engine guard refuses the
masked sort), and the spy-narrowed `where` case answers the dropped
section. Restored to blob `c4cd29690aa1`, `git diff HEAD` empty,
rebuilt, preflight `--absent` green.
- Every leg restored with `git checkout HEAD -- ABSOLUTE_PATH`, proven
by blob equal to HEAD and an empty `git status --porcelain`.
</details>
## Acceptance notes
- **Premise, measured:** the card's example of the fallback admitting a
field the security service excludes is not reachable with
plugin-security on these doors. Its read projection
(`getReadableFields`) already leaves out every computed field the read
mask deletes, so the fallback and `getQueryableFields` agree except for
masked fields. There the fallback is the stricter one: it dropped a
section ordered by a masked field whose unmask capability the caller
holds, which this PR fixes and pins. The "excluded" direction is pinned
by narrowing the real service's answer by one field with a spy.
- **N5, half outside this card's surface (now #37415):** the authoring
lint's own-field check (`validateAiContext` in `packages/lint`, run by
`os validate` and the save door) warns `ai-context-field-unknown` for
`orderBy: created_at` on an object that does not declare it, saying "the
list is left out of every answer", while the executor and both doors
read the list (pinned here). `packages/lint` is not in this claim's file
surface, so it is reported to the seat, not changed.
- The stdio door's own query path plans no deployment read window (it
calls the engine directly), so `OS_DATA_MAX_PAGE_SIZE` does not refuse
there as the data door does. For `get_record_context` both doors now cut
at the same row; for other stdio reads this is an observation, not
measured here.
- A disabled-package child keeps the `PERMISSION_DENIED` code (unnamed),
the one code ADR-0160 point 12 gives an object-level refusal; the card's
acceptance line "refuses with OBJECT_PACKAGE_DISABLED" is read as naming
the case, and the existing pin is kept.
## Verification
Two-minute check: `pnpm --filter @objectstack/runtime exec vitest run
--maxWorkers=2 src/mcp-record-context-tools-bridge.test.ts` (after
building the runtime's dependency closure) shows 22 passed, including "a
related child this caller is not served is left out" and "an orderBy on
a masked field whose rule is NOT lifted for the caller drops the
section".
Read first, by risk:
1.
`packages/services/service-record-context/src/record-context-tools.ts`,
step 4a: the reordered gates and the `leftOut` set feeding
`publishedOf`.
2. `packages/runtime/src/domains/mcp.ts` and
`packages/mcp/src/stdio-data-bridge.ts`: the two `queryableFieldsOf` /
`pageCap` members.
3. `packages/runtime/src/mcp-record-context-tools-bridge.test.ts`: the
second caller (`keyOwner`, `plainCaller`, `bothAsPlain`) and the
narrowed-answer case (a spy on the real security service).
<details><summary>Local gates</summary>
`node scripts/pm/dispatch-gates.mjs --commands --repo
objectstack-ai/objectstack` derived 117 commands for this diff (tree
`objectstack-ai/objectstack` at `88a1447c9`); all 117 run, each exit
captured before any pipe; `--ran` reconciliation: "117 derived, 115 run,
2 NOT-MEASURED, 0 UNRUN".
- `pnpm --filter @objectstack/spec run check:skill-examples` first
answered exit 3 (client-react not built); after building
`@objectstack/client-react` and its closure it answered exit 0 ("351
prose examples type-check across 3 surface(s)").
- NOT MEASURED: `node scripts/check-plugin-teardown-shape.mjs
--self-test` (exit 3, its pinned fixture commit is outside this shallow
checkout); `pnpm check:dual-build-cjs-loads` (exit 3, reads every
package's dist, and this worktree built only the runtime and mcp
closures). Both are CI's.
- Local-only `node scripts/check-dev-prereqs.mjs`: exit 1, "the
workspace is not built" (35 of 110 packages, `ui/**` among them, unbuilt
in this worktree); a reading about this checkout, not the diff.
- `node scripts/pm/overlap-check.mjs --branch=HEAD` before each push:
VERDICT clean (origin/main merges cleanly); not merged, as ordered.
</details>
_Seat note: the governing Claim on #37175 now names this branch
(re-claim 7181502252), since the round-2 rig branch landed as PR #37350.
Final-head readings (a50181d) are in the os-dev report 7181466841 on
#37361._
---
_Generated by [Claude
Code](https://claude.ai/code/session_01Utp6CbeF2saT6wUBV4E9uc)_
<!-- signed: repo:objectstack#5 · os-bill ·
session_01Utp6CbeF2saT6wUBV4E9uc -->
---------
Co-authored-by: Claude <noreply@anthropic.com>1 parent 7291c6f commit 8d60333
11 files changed
Lines changed: 573 additions & 60 deletions
File tree
- .changeset
- content/docs/references/ai
- packages
- mcp/src
- runtime/src
- domains
- services/service-record-context/src
- __tests__
- spec/src/ai
- types/src
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
137 | 137 | | |
138 | 138 | | |
139 | 139 | | |
140 | | - | |
141 | | - | |
| 140 | + | |
| 141 | + | |
142 | 142 | | |
143 | 143 | | |
144 | 144 | | |
| |||
221 | 221 | | |
222 | 222 | | |
223 | 223 | | |
224 | | - | |
225 | | - | |
| 224 | + | |
| 225 | + | |
226 | 226 | | |
227 | 227 | | |
228 | 228 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
135 | 135 | | |
136 | 136 | | |
137 | 137 | | |
138 | | - | |
| 138 | + | |
139 | 139 | | |
140 | 140 | | |
141 | 141 | | |
| |||
172 | 172 | | |
173 | 173 | | |
174 | 174 | | |
175 | | - | |
| 175 | + | |
176 | 176 | | |
177 | 177 | | |
178 | 178 | | |
| |||
250 | 250 | | |
251 | 251 | | |
252 | 252 | | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
253 | 257 | | |
254 | | - | |
| 258 | + | |
255 | 259 | | |
256 | 260 | | |
257 | 261 | | |
| |||
1917 | 1921 | | |
1918 | 1922 | | |
1919 | 1923 | | |
| 1924 | + | |
| 1925 | + | |
| 1926 | + | |
| 1927 | + | |
| 1928 | + | |
| 1929 | + | |
| 1930 | + | |
| 1931 | + | |
| 1932 | + | |
| 1933 | + | |
| 1934 | + | |
| 1935 | + | |
| 1936 | + | |
| 1937 | + | |
1920 | 1938 | | |
1921 | 1939 | | |
1922 | 1940 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
11 | | - | |
| 11 | + | |
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
| |||
1739 | 1739 | | |
1740 | 1740 | | |
1741 | 1741 | | |
| 1742 | + | |
| 1743 | + | |
| 1744 | + | |
| 1745 | + | |
| 1746 | + | |
| 1747 | + | |
| 1748 | + | |
| 1749 | + | |
| 1750 | + | |
| 1751 | + | |
| 1752 | + | |
| 1753 | + | |
| 1754 | + | |
| 1755 | + | |
| 1756 | + | |
| 1757 | + | |
| 1758 | + | |
| 1759 | + | |
1742 | 1760 | | |
1743 | 1761 | | |
1744 | 1762 | | |
| |||
1795 | 1813 | | |
1796 | 1814 | | |
1797 | 1815 | | |
| 1816 | + | |
| 1817 | + | |
1798 | 1818 | | |
1799 | 1819 | | |
1800 | 1820 | | |
| |||
0 commit comments