Skip to content

test(runtime): get_record_context answers one caller with the same bytes on the /mcp and stdio doors over a real kernel - #37350

Merged
objectstack-fleet[bot] merged 5 commits into
mainfrom
claude/issue-37175-record-context-http-rig
Nov 25, 2026
Merged

objectstack-fleet[bot] merged 5 commits into
mainfrom
claude/issue-37175-record-context-http-rig

Conversation

@objectstack-fleet

Copy link
Copy Markdown
Contributor

Part of #37175
Clause-②: no
Metadata-protocol: none

维护者速读

  • 用户能看到什么变化:用户无感。这是测试:外接 AI 读取一条记录资料的工具,在网页通道和本地命令行通道上,用真内核、真执行器对同一个人逐字节比对回答。
  • 为什么做:属于“在一条记录上问 AI”专题,补上网页通道只测了接线、没用真执行器的缺口。
  • 出错会怎样:只增加一组测试,不改任何产品代码;有问题直接撤回即可。
  • 要你做什么:无。

What changes

  • One new top-level describe in the shared harness file packages/runtime/src/mcp-record-context-tools-bridge.test.ts: get_record_context over one real kernel, asked through both MCP doors for one caller, every answer compared byte for byte (isError and the text content), refusals included.
    • The kernel: a real ObjectQL on SqlDriver (better-sqlite3), the real SecurityPlugin (a permission set with an object refusal, a field-level refusal and a row rule), the real ObjectStackProtocolImplementation, and the real RecordContextServicePlugin registered as the record-context service. Nothing of the metadata plane, the data plane or the executor is a double.
    • The /mcp door: HttpDispatcher.handleMcp into the real MCPServerRuntime, so the call goes through this package's HTTP data bridge (packages/runtime/src/domains/mcp.ts).
    • The stdio door: the real MCPServerPlugin's long-lived session (createStdioDataBridge) over an in-process transport, principal-bound to OS_MCP_STDIO_API_KEY.
    • One caller: the /mcp request carries the context resolveAuthzContext plus assembleExecutionContext build for the same key the stdio session resolves (owner usr_member, active in org_1). A precondition case checks that the stdio door's root read carried the same userId, tenantId, permissions and positions.
  • The cases (card What 2 and 3, and amendment 4):
    • the record through its package pack: the field-level-hidden field is not carried and is stated by the not_visible note; the lookup whose target is apiEnabled: false is answered notVisible: true, never expanded or named (amendment 4: the door decides an expansion target's API exposure); the related row the caller's row rule refuses is absent; the body is carried whole;
    • a root the caller may not read: PERMISSION_DENIED 403 before any pack is looked up, equal to get_record's answer for the same object and record on both doors;
    • a related child this caller is not served: today PERMISSION_DENIED 403 for the whole call, the child unnamed (see Acceptance notes for the gap to ADR-0160 as amended);
    • a related child its API exposure refuses: PERMISSION_DENIED 403, named;
    • a related child whose package is disabled (the protocol answers OBJECT_PACKAGE_DISABLED for it, checked in the case): PERMISSION_DENIED 403, unnamed;
    • an anchor the body does not resolve: RESOURCE_NOT_FOUND 404;
    • a pack saved at run time through protocol.saveMetaItem (served from the metadata registry, not shipped by the stack, no _packageId): read on both doors.
  • The WIP probe file is removed: packages/runtime/src/domains/mcp-record-context-37175.test.ts (console output, from the resumed backup 0fa37da2) is deleted. Its rig is now the describe above.
  • No production source changes. packages/runtime/package.json, the lockfile and packages/runtime/vitest.config.ts are unchanged: PR fix(mcp,runtime): get_record_context reads a package's context packs on both MCP doors #37255 already landed the two devDependencies and the two alias rows this rig needs.

Tests

Final head 9c9d8a634.

  • pnpm --filter @objectstack/runtime exec vitest run --maxWorkers=2 src/mcp-record-context-tools-bridge.test.ts under the verify lock: Tests 15 passed (15), VERDICT command-exit 0. Of the 15, 8 are this describe's; the 7 earlier ones are unchanged and still pass.
  • pnpm --filter @objectstack/runtime typecheck (tsc plus check:test-typecheck over tsconfig.test.json, which compiles this file, counted with --listFiles): exit 0, "test layer compiles … 27 file(s) / 183 error(s) … held in test-typecheck-debt.json", the ledger unchanged.
  • One-off fixture control, not committed: with the permission set's row rule removed, the main case answers rows ["r1","r2"] and its test goes red. So r2 is absent because of the row rule, and the case can fail. The file was restored with git checkout HEAD --; git diff HEAD is empty and the blob hash equals HEAD's.

Acceptance notes

  • Card acceptance. "For one fixture and one caller, the HTTP bridge and the stdio bridge give byte-identical answers, refusals included": every case goes through one helper that asks both doors and requires stdio to equal http (isError and text). "The registry-served pack is read": the last case.
  • Gap to ADR-0160 as amended 2026-11-25 (point 2). A related child this caller is not served should be "left out and stated, not refused". executeGetRecordContext still refuses the whole call (refuseObject(entry.object, false), step 4a). The case pins today's answer and says so in its title. When the executor changes, this case goes red on purpose. Routed by the seat, not fixed here: packages/services/service-record-context/** is outside this card's fence.
  • Amendment 4, the docblock half is not in this PR. The amendment asks for a sentence in packages/services/service-record-context/src/door.ts (query): a door decides each expansion target's API exposure. That file is fenced off for this card, because sibling work is in flight there. The behaviour half is pinned here (the vault lookup case). That is why this PR says Part of: the sentence is the half left open.
  • The WIP's two open readings, measured again on main a182fbe37:
    • (a) The stdio door answered RECORD_NOT_FOUND for a row the HTTP door read. Cause: the WIP's key resolved to a caller with no organization, while the row is in org_1. It was the rig, not a door defect. With the key active in org_1 and the same context handed to /mcp, both doors read the row.
    • (b) A private-OWD row owned by another user came back on HTTP. Not a row-security defect. The WIP rig composed no sharing service, and the private-OWD read filter is that service's (resolveSharingReadFilter in plugin-security returns null when resolveKernelService('sharing') has no buildReadFilter). The rig now uses an authored row rule on the permission set. Both doors honour it.
  • Placement. The file is the shared harness file (AGENTS.md: a new pin for a component that already has a shared harness file goes into that file as a top-level describe). The claim named packages/runtime/src/domains/** for a new file; this is a declared change of surface, and the deleted WIP file under domains/ is the only change there.
  • The file's wall time is collection. Shared box: Duration 18.59s (… import 17.77s, tests 655ms). The 8 new cases take under a second.

Verification

Derived gates (dispatch-gates --commands, 50 families) — local

48 exit 0. Two are NOT MEASURED, each exit 3 PREREQUISITE NOT MET, so they belong to CI: node scripts/check-plugin-teardown-shape.mjs --self-test (its positive control is pinned to a commit this shallow clone does not hold) and pnpm check:dual-build-cjs-loads (it needs every package built). dispatch-gates --ran with recorded exit codes: "50 derived famil(ies) accounted for — 48 run, 2 NOT-MEASURED (2 DERIVED from a recorded exit 3)". node scripts/pm/overlap-check.mjs --branch=HEAD: VERDICT clean exit 0 before each push.

Read first (by risk): packages/runtime/src/mcp-record-context-tools-bridge.test.ts, the last describe. The risky hunk is the keyedQl proxy, which stands in for the key's auth tables, and the caller assembly beside it.

Two-minute check: pnpm --filter @objectstack/runtime exec vitest run --maxWorkers=2 src/mcp-record-context-tools-bridge.test.ts should print Tests 15 passed (15).

Not run locally (declared): the runtime package's full pnpm test (653 files). The diff is this one test file, and CI's Test Core runs the suite. No changeset: the diff is a test file under src/, and packages/runtime publishes dist, README.md and CHANGELOG.md only, with tests excluded from its build tsconfig, so skip-changeset.

repo:objectstack#5 · os-bill · session_01Utp6CbeF2saT6wUBV4E9uc


Generated by Claude Code

…io plugin from runtime tests

Co-Authored-By: Claude <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01WGufzi13yZRqVcp2mGonWK
…ot a deliverable)

Co-Authored-By: Claude <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01WGufzi13yZRqVcp2mGonWK
…cp and stdio answer one caller with the same bytes

Co-authored-by: Claude <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Utp6CbeF2saT6wUBV4E9uc
@objectstack-fleet objectstack-fleet Bot added the skip-changeset PR has no user-facing published change; bypasses the changeset gate label Nov 25, 2026
@github-actions

Copy link
Copy Markdown
Contributor

📓 Docs Drift Check

Nothing in this diff resolved to a documentable surface (no symbol, route or SDK anchor derived from 0 changed package(s)), so this run has no opinion about the docs.

What this run could not see

Coarse fallback — 0 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 ebac615f77137aa6abd7fa78955467b7527112ec → packageMentionDocs.

@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

repo:objectstack#5 · os-bill · session_01Utp6CYtTDvfPQDzMbZnN5X

维护者速读

  • 改了什么:只加测试。外部 AI 读记录情境包时,网页通道和命令行通道在同一个真实内核上逐字节给出相同答案,拒绝的情况也一样;运行时保存的情境包也能读到。
  • 为什么:记录范围 AI 问答专题要求两条通道行为一致,之前只在命令行通道上验过。
  • 风险:无产品代码改动,不发版。
  • 要你做什么:无,由专题区自行落地。

席位意见:ACCEPT。

席位核对

Head-sha: 9c9d8a6349
ACCEPT — L1, seat repo:objectstack#5

  1. Shape: open draft against main; Part of #37175 is right: the card's remaining piece (the door.ts docblock sentence, fenced in service-record-context this round) rides 37178 跟进:资料包目录被截断时,没列出的章节也要能读到 #37233, and 37140 跟进:get_record_context 在运行时 HTTP 通道上用真执行器测一遍(含拒绝) #37175 closes when 37178 跟进:资料包目录被截断时,没列出的章节也要能读到 #37233 lands. 37140 跟进:get_record_context 在运行时 HTTP 通道上用真执行器测一遍(含拒绝) #37175 keeps pm:dispatched until then (landing rule B). l1-face: one flag, judged below.
  2. Premise measured: card items 1–3 are pinned in one new top-level describe: /mcp and stdio give equal payloads for one caller across the root refusal, a hidden field, an unopenable lookup, an unreadable related row, an unexposed and a disabled-package related child, an unresolved anchor, and a registry-served pack. The case titled [today; ADR-0160 as amended …] pins current behaviour where the amended ADR says otherwise; that gap is the amendment's implementation, not this card's.
  3. Gates: check-runs at 9c9d8a6349: 37 success, 21 expected skip, 0 failed, 0 pending; Lint & Repo Gates and TypeScript Type Check success; mergeable clean.
  4. Accepted deviations: the rig is a describe in the existing bridge test file instead of a new file under domains/ (declared in the PR body). skip-changeset is right: @objectstack/runtime ships dist, README.md and CHANGELOG.md only, so the one .test.ts file publishes nothing.
  5. Out of scope and where it went: the docblock sentence goes to 37178 跟进:资料包目录被截断时,没列出的章节也要能读到 #37233. A1(b) in the dev report is not a security defect (the rig has no sharing service).
  6. Landing terms: Tier default, ungoverned, Clause-②: no, so no L2 is owed. The area lands it: ready, then auto-merge.

@objectstack-fleet
objectstack-fleet Bot marked this pull request as ready for review November 25, 2026 21:25
@objectstack-fleet
objectstack-fleet Bot added this pull request to the merge queue Nov 25, 2026
Merged via the queue into main with commit 134b71d Nov 25, 2026
59 checks passed
@objectstack-fleet
objectstack-fleet Bot deleted the claude/issue-37175-record-context-http-rig branch November 25, 2026 21:48
Nenzyz pushed a commit to Nenzyz/objectstack that referenced this pull request Dec 1, 2026
… (ADR-0160 row 11) (objectstack-ai#37354)

Fixes objectstack-ai#37203

Clause-②: yes
Metadata-protocol: added
Skills-docs: follow-up objectstack-ai#37177

## 维护者速读
- 用户能看到什么变化:AI
读取记录资料包时,关联列表可以按作者写的条件筛选、排序并限制条数;条件或排序用到提问人不能查询的字段时,这一段被省略并附一句「部分资料对你不可见」,不再整次报错。
- 为什么做:记录范围 AI 问询专题的第 11 行(关联列表的筛选和排序),按维护者已同意的设计修订实现。
- 出错会怎样:最坏是某个关联段落被省略或条数不对,AI 回答少了资料;不会多给提问人无权看的数据;撤回此 PR 即恢复原行为。
- 要你做什么:无。

## What changes

**Spec (`packages/spec/src/ai/ai-context.zod.ts`).** A `related` entry
gains three optional keys, per ADR-0160 D1 (second amendment):
- `where`: the object filter form on the child's own fields, held to
`AI_CONTEXT_WHERE_OPERATORS` (`$eq $ne $in $nin $gt $gte $lt $lte $null
$exists`) joined by `$and` / `$or`. A bare value is `$eq`. Refused at
parse: any other operator, a dotted path, a condition on a lookup's
target, `{ $field }`, a `$now` anchor, a formula/object comparand, and a
comparand that is one whole brace placeholder (matched by
`FILTER_TOKEN_WRAPPED_RE`). Built as `FilterConditionSchema` plus one
refinement walk, so the base form's own comparand refusals still apply.
- `orderBy`: `SortNodeSchema[]` (`{ field, order }`, `direction` refused
by name), with the field held to a snake_case own-field name.
- `limit`: positive integer up to `AI_CONTEXT_MAX_RELATED_ROWS` (20).
This is the one number. `RECORD_CONTEXT_RELATED_MAX_ROWS` in the service
now reads it (ADR-0160 row 11: "the schema that bounds `limit` and the
service that cuts the list read one number").
- `aiContextWhereFields(where)`: lists the fields a `where` names. The
service and the lint rule both use it.
- Near-miss aliases: `filter` → `where`, `sort` / `sortBy` → `orderBy`.
The schema-level `guidance.filter` now points at the entry's `where`.

**Render service (`packages/services/service-record-context`).**
- The one capped child query is `where: { $and: [linkFilter,
entry.where] }`, with `orderBy` and `limit: (entry.limit ?? cap) + 1`. A
cut at `limit` is marked `truncated` and stated (`related_truncated`).
Still one query.
- Before that query, each `where` / `orderBy` field is judged. A field
the child's published definition lacks leaves the section out with
nothing stated (ADR point 20). A field the caller cannot query on drops
the section with the one `not_visible` statement, and the field is never
named (D3, point 19). Neither case refuses the call.
- "Cannot query on" is the door's new optional `queryableFieldsOf` (the
security service's `getQueryableFields`). Without that answer, the
contract's fallback applies (`ISecurityService.getQueryableFields`): the
field must be served, must not be withheld (`fieldVisibilityOf`), and
must declare no `maskingRule`. A probe that throws drops the section
with the statement.
- Triage row 7154563681 on the card (a related child that *this caller*
is not served is left out, not refused) is **not** in this PR. It was
implemented and then reverted in `aa76b901b`, because turning it on
flips the real-kernel parity pin in `packages/runtime` (landed in
objectstack-ai#37350, case titled "[today; ADR-0160 as amended says left out and
stated]"), and `packages/runtime` is fenced here. Today's behaviour (the
whole call is refused) is unchanged. It moves to a follow-up card.
- The read set (`recordContextReadSet` / `planObjectsOf`) does not
change (D4), and a test pins it with and without the keys.

**Author surfaces (`packages/lint/src/validate-ai-context.ts`).** This
extends the objectstack-ai#37176 rule rather than adding a validator. A `where` or
`orderBy` field the child does not define is reported as
`ai-context-field-unknown` (warning) at save and by `os validate`, and
the message says the list is left out.

**Review delta S1/S2 (contract record 7177225249, on bb0107c).**
- S1: `AI_CONTEXT_WHERE_MAX_DEPTH` (32) bounds `$and` / `$or` nesting in
`where` at parse, refused at the list that would carry a condition past
it. `aiContextWhereFields` walks to that same constant, so every field
of a `where` that parsed is judged by the service and the lint rule. A
test pins the bound: 32 parses and names the innermost field, 33 is
refused once.
- S2: an `orderBy` field the child's sortability projection calls
unsortable (`resolveObjectSortability`: a formula, or `sortable: false`)
is an author defect. The executor leaves the section out and states
nothing, matching the "field the definition lacks" arm and ADR D1,
instead of letting the door refuse the whole call with `INVALID_SORT`.
`validateAiContext` reports it at save and by `os validate` as the new
warning `ai-context-sort-field-unsortable`, with an `os explain` entry.
HTTP door, read only (runtime is fenced): `recordContextMembers` →
`bridge.query` → `callData('query')` → `protocol.findData` →
`assertSortFieldsExist` refuses it with `400 INVALID_SORT` too (formula
by the unmaterialized-type verdict, `sortable: false` by
`assertSortFieldsAreOffered`), so before this fix both transports
refused the call. After it, neither door is asked.

**Liveness, example, generated.** `liveness/ai_context.json` gains
`related.where`, `related.orderBy.{field,order}` and `related.limit`.
The showcase `KIND_COVERAGE` pack `showcase_project_brief` now carries
open tasks filtered by `status $ne done`, ordered by `due_date`, `limit:
10`. Regenerated: `dropped-refinements.baseline.json` (the `where` walk
and the `orderBy` field check are refinements JSON Schema cannot carry;
the build printed these rows), authorable-surface, api-surface,
export-origins, declaration-map, reference docs, state-counts.

## Tests
<details><summary>Local runs (final head bb0107c; the derived gate
sweep re-run on bb0107c)</summary>

- `pnpm --filter @objectstack/service-record-context test`: 2 files, 99
tests passed. The new describe block "a related list's where, orderBy
and limit" has 18 cases.
- `pnpm --filter @objectstack/spec exec vitest run
src/ai/ai-context.zod.test.ts`: 23 passed (parse admits and refuses
every bullet of What 1, and the nesting bound).
- `pnpm --filter @objectstack/lint exec vitest run
src/validate-ai-context.test.ts`: 18 passed. Whole package `pnpm
--filter @objectstack/lint test`: 235 files, 9633 tests passed.
- `pnpm --filter @objectstack/mcp exec vitest run
src/mcp-record-context-tools.test.ts` (read-only run of the objectstack-ai#37140
parity harness against the rebuilt service, at 16b86ef): 14 passed. CI
Test Core at bb0107c runs it and the runtime real-kernel harness:
green.
- Typecheck: `@objectstack/spec`, `@objectstack/service-record-context`
and `@objectstack/lint` all exit 0.
- `pnpm --filter @objectstack/spec check:generated`: all 14 artifacts up
to date.

Ablations: five, each through `scripts/ablation-replace.mjs` with the
blob restored to HEAD. Each suite imports `src`, so there is no dist
step.
1. Skip `queryableAmong`: 6 cases red (the four unqueryable cases, the
masking fallback, the throwing probe).
2. Drop the `$and` join: 4 cases red, including "no where reaches
another root's rows".
3. S2, skip the executor's sortability check: 2 cases red (`sortable:
false`, formula), the door's `INVALID_SORT` reached.
4. S1, drop the parse depth bound: 1 case red (the bound test).
5. S2, skip the lint verdict: 2 cases red (the rule test and its
save-door family). A first attempt was refused by the tool as a no-op
(ambiguous replacement) and re-run with a unique one.
</details>

## Acceptance notes
- **Parity on both transports with a `where` pack is not pinned here.**
The objectstack-ai#37140 harness is
`packages/mcp/src/mcp-record-context-tools.test.ts`, which was fenced
for this PR while sibling objectstack-ai#37175 was in flight in `packages/runtime/**`
and `packages/mcp/**`. Both doors hand the one executor a door whose
`query` passes the options through (`recordContextMembers`, the stdio
bridge's `query` already takes `orderBy`), and the existing harness runs
green against this build. The pin is a follow-up for the report.
- **Neither MCP door hands `queryableFieldsOf` yet**, so on real doors
the contract fallback decides (masking-declared, hidden and withheld
fields count as not queryable). A field that the security service's
answer would exclude but the fallback admits (an agent acting on
someone's behalf, or a computed field reading a hidden one) still
reaches the engine guard, and the guard refuses the call. This is
reported as a finding for the door lane.
- Studio's `ContextPackRelatedEntries` does not offer the three keys
yet; it preserves them on edit (note 7168171718). That goes to objectstack-ai#37143.
- `RecordContextNoteKind`'s doc line still says `related_truncated` is
"cut at the row cap". It now also fires at `limit`. This is spec prose
outside the claim's one spec file and is left as is.
- A door whose own page cap is below `limit + 1` cuts silently. That is
pre-existing for the cap too, and left as is.
- `where` nesting is bounded (S1). No bound on the number of conditions
or `$in` members was set; ADR row 11 allows one, but none was needed.

## Verification
Two-minute check: `pnpm --filter @objectstack/service-record-context
exec vitest run src/__tests__/record-context-tools.test.ts`. Expect it
green, with the "a related list's where, orderBy and limit" block green.

Read first: (1) `record-context-tools.ts`, the 4b block that judges
`queried` fields before `relatedPlans.push`, and the `$and` query; (2)
`ai-context.zod.ts`, `checkRelatedWhere`.

---
_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>
Nenzyz pushed a commit to Nenzyz/objectstack that referenced this pull request Dec 1, 2026
…d related child; both MCP doors supply queryableFieldsOf and their page cap (objectstack-ai#37412)

Fixes objectstack-ai#37361
Fixes objectstack-ai#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 objectstack-ai#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 objectstack-ai#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 objectstack-ai#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 objectstack-ai#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 objectstack-ai#37175 now names this branch
(re-claim 7181502252), since the round-2 rig branch landed as PR objectstack-ai#37350.
Final-head readings (a50181d) are in the os-dev report 7181466841 on
objectstack-ai#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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/m skip-changeset PR has no user-facing published change; bypasses the changeset gate tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants