Skip to content

fix(mcp,runtime): get_record_context reads a package's context packs on both MCP doors - #37255

Merged
objectstack-fleet[bot] merged 7 commits into
mainfrom
claude/issue-37243-context-pack-undecorated-read
Nov 25, 2026
Merged

objectstack-fleet[bot] merged 7 commits into
mainfrom
claude/issue-37243-context-pack-undecorated-read

Conversation

@objectstack-fleet

Copy link
Copy Markdown
Contributor

Requested by Yibo Wang · project thread

repo:objectstack#3 · os-support-ai · session_01WGufzi13yZRqVcp2mGonWK

Fixes #37243
Clause-②: no
Metadata-protocol: none

维护者速读

  • 用户能看到什么变化:部署了资料包的应用里,AI 助手读取一条记录的资料时(网页通道和本地命令行通道都一样),终于能读到资料包,不再一律回答“找不到资料包”。
  • 为什么做:属于“AI 读取记录资料”这条能力(资料包设计)的缺陷修复,替所有提供资料包的部署(含演示应用)解决读不到的问题,另外两张卡也在等它。
  • 出错会怎样:只影响 AI 读取记录资料这一个工具;若有问题,表现仍是读不到资料包,与修复前相同,可直接撤回。
  • 要你做什么:无

What changes

  • Both record-context doors hand the executor the authored packs, not the serving envelope. The HTTP door (packages/runtime/src/domains/mcp.ts, listContextPacks in the bridge's record-context members) and the stdio door (packages/mcp/src/stdio-data-bridge.ts, listContextPacks) read the protocol's served ai_context listing, which decorateMetadataItem stamps with _diagnostics; the executor's closed AiContextSchema parse (parsedContextPacks) dropped every row. Each door now maps its listing through stripReadDecorations (@objectstack/spec/kernel), the metadata-fallback branch included.
  • Which keys the strip removes, and why. Exactly METADATA_READ_DECORATIONS (_diagnostics, _draft, _withheldFields, _relatedListsArrangement), the read path's derived keys that are no part of a document. The ADR-0010 protection envelope (_packageId, _packageVersion, _provenance, _lock, _lockReason, _lockSource) stays: AiContextSchema declares it through MetadataProtectionFields, so it parses, and the pin asserts the served pack still carries _packageId. A blanket underscore strip would remove declared keys; stripping only _diagnostics would leave the next listed decoration to fail the same way.
  • No new helper. The shared helper already exists where producer and consumers meet: spec/kernel/metadata-read-decorations.ts, whose module docblock names this exact failure class ("any re-parse of a served document"). Both doors already depend on @objectstack/spec, so neither takes a new runtime dependency, and the protocol's served read (with its per-type redaction) is still the one a door reads — getMetaItemsForExecution would have dropped the _diagnostics too, but its docblock forbids reading it from a door that answers a caller.
  • The door's contract is stated on RecordContextDoor.listContextPacks (packages/services/service-record-context/src/door.ts). The executor's strict parse is unchanged.

Tests

  • packages/mcp/src/mcp-record-context-tools.test.ts: new top-level describe — a real ObjectStackProtocolImplementation over a real ObjectQL (an in-memory SQLite SqlDriver store) with a package carrying the pack; the metadata service lists no pack, so the protocol's listing is the only one. Precondition asserts the served pack carries _packageId and _diagnostics; then get_record_context answers through the pack, identically on MCP-over-HTTP and stdio.
  • packages/runtime/src/mcp-record-context-tools-bridge.test.ts: new top-level describe — the /mcp route end to end (HttpDispatcher.handleMcp, the real MCPServerRuntime, the real executor, SecurityPlugin, the real protocol over ObjectQL + SqlDriver); same precondition, then the call answers the pack's fields.
  • Ablation (once each, then restored; restore proven by git diff HEAD empty and blob == HEAD): removing the strip at either door turns its pin red with the defect's own answer, RESOURCE_NOT_FOUND "No context pack named … reads object …".
  • Test deps: @objectstack/mcp gains devDeps @objectstack/metadata-protocol and @objectstack/driver-sql; @objectstack/runtime gains devDeps @objectstack/mcp and @objectstack/service-record-context; each new value import has an anchored source alias row in that package's vitest.config.ts (check:test-source-alias).

Acceptance notes

  • Placement differs from the dataset tools on purpose: service-analytics' dataset executor strips decorations inside the executor; this card's ruling puts the strip at the doors and keeps AiContextSchema's consumer strict. Noted, not changed.
  • Wall time, single-file cold runs on a shared box: the runtime harness file was 16.7 s before this PR and 18.3 s after (import-dominated, cases ~0.2 s); the mcp harness file 5.8 s before and 10.8–14.1 s after, nearly all of it transforming metadata-protocol source through the new alias. These readings come from single-file runs. A full-package run shares the transform cost across files.

Verification

Local readings (final head in the report)

See the report comment on #37243 for the exact commands, exit codes and the head sha they were read on.

Read first: packages/mcp/src/stdio-data-bridge.ts (listContextPacks, the strip on both branches), packages/runtime/src/domains/mcp.ts (same), packages/mcp/src/mcp-record-context-tools.test.ts (the precondition that makes the pin non-vacuous).

Two-minute check: pnpm --filter @objectstack/mcp exec vitest run src/mcp-record-context-tools.test.ts → 11 passed; delete .map(stripReadDecorations) from the stdio listContextPacks and the last case fails with RESOURCE_NOT_FOUND.


Generated by Claude Code

…hored packs

The protocol's served ai_context listing stamps every item with the read
path's _diagnostics; the executor parses each row with the closed
AiContextSchema, so every pack was dropped and get_record_context answered
RESOURCE_NOT_FOUND on the HTTP and stdio doors alike. Both doors now pass
their listing through stripReadDecorations (METADATA_READ_DECORATIONS),
which keeps the ADR-0010 protection envelope the schema declares.

Co-Authored-By: Claude <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01WGufzi13yZRqVcp2mGonWK
…d on both record-context doors

Co-Authored-By: Claude <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01WGufzi13yZRqVcp2mGonWK
…t the frozen memory driver

Co-Authored-By: Claude <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01WGufzi13yZRqVcp2mGonWK
@github-actions github-actions Bot added size/m dependencies Pull requests that update a dependency file 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 Nov 25, 2026
@github-actions

github-actions Bot commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

📓 Docs Drift Check

This PR changes 3 package(s): @objectstack/mcp, @objectstack/runtime, @objectstack/service-record-context, touching 4 documentable anchor(s). ⚠️ 2 changed file(s) yielded no anchor (packages/mcp/vitest.config.ts, packages/runtime/vitest.config.ts), so the pages documenting them are NOT COVERED by this run — this is not a clean bill of health for those files.

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

  • content/docs/permissions/authorization.mdx (via buildMcpBridge (symbol, a top-level function))
What this run could not see
  • 2 changed file(s) yielded no anchor (packages/mcp/vitest.config.ts, packages/runtime/vitest.config.ts) — pages documenting those are invisible to this run
  • the SDK route bridge reached 69 of 252 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 — 37 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 9171bed0a65ab242567f243969368ead786cd830 → packageMentionDocs.

Which tree this was computed on

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

node scripts/docs-audit/affected-docs.mjs --json 9171bed0a65ab242567f243969368ead786cd830

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

@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

repo:objectstack#3 · os-support-ai · session_01WGufzgv2LZN1W2qSYTZvYs

席位核对 — REWORK · repo:objectstack#3 · head 083ab1b · 2026-11-25T08:45Z

L1: REWORK (L1-w, zone ai-A)
Head-sha: 083ab1bf477cd0110c7b486bcee1cea6fb775a2d

There is one should-fix, which is a changeset push. The code is right. This is Tier S: no governed path, 249 changed lines on this card's only PR. No L2 is owed:

  • nothing under packages/spec/src/** moves;
  • no governed path is touched;
  • it declares Clause-②: no with no narrowing arm.

Should-fix

  • S1. The changeset leaves out @objectstack/service-record-context.
    • l1-face flags it: the package is published and touched, with no entry and no skip-changeset.
    • The file is src/door.ts, and the change is not inert. The RecordContextDoor.listContextPacks contract now obliges every door to hand over the authored pack, with the read decorations removed (stripReadDecorations), "because the executor parses every row with the closed AiContextSchema".
    • That sentence ships in the package's .d.ts, and it is the instruction a third-party door implementer reads.
    • AGENTS.md (Post-Task Checklist step 3): "Add a changeset for anything that publishes … never none". The gate reads no hunk content, by design (check-changeset-no-major.mjs, "not 'skip if the diff is comment-only'"). This is the same shape as feat(service-automation)!: a sync-in pull marks the rows the source deleted (ADR-0153 D3, #32062 slice 6) #37179's objectql must-fix.
    • Fix:
      • add '@objectstack/service-record-context': patch;
      • add one sentence to the body for door implementers: a RecordContextDoor hands listContextPacks the authored packs, read decorations removed, or the executor drops them.

Read and found right (head 083ab1b)

  • l1-face --pr 37255: 12 items clean and one flag (S1). 60 success, 9 expected skips, 0 failed, 0 pending. mergeable_state is clean.
  • Fixes #37243 is right. The card's acceptance asks for two things, and both are in the diff:
    • "A valid package pack is served on the HTTP door and on stdio through the real protocol, with no protocol double". The stdio pin builds a real ObjectQL + SqlDriver (in-memory SQLite) + ObjectStackProtocolImplementation, and asserts the precondition that the served item carries _diagnostics, so a non-stripping door is told apart. The runtime pin drives /mcp.
    • "A pin fails when the listing is decorated again". The reported ablation is red on each door.
    • It follows the card's fix direction: at the doors, with the executor's parse unchanged.
  • The fix.
    • Both doors' listContextPacks, protocol path and metadata fallback alike, map through stripReadDecorations.
    • That is @objectstack/spec/kernel's helper over METADATA_READ_DECORATIONS (_diagnostics, _draft, _withheldFields, _relatedListsArrangement). It returns the same reference when there is nothing to strip.
    • AiContextSchema spreads MetadataProtectionFields, so the ADR-0010 envelope survives the strict parse. This is the precedent object.zod.ts states ("stripReadDecorations removes _diagnostics / _draft before any strict re-parse (cloud#971)").
  • Clause-②: no is right. It is a defect fix: no accepted set moves, and no response member is added.
  • The new dev dependencies make no workspace cycle.
    • mcp now has metadata-protocol and driver-sql as dev dependencies; runtime has mcp and service-record-context.
    • None of those four depends back on mcp or runtime.
    • The vitest aliases are anchored root-entry rows, and the lockfile matches.
  • The changeset, sentence by sentence.
    • The symptom (RESOURCE_NOT_FOUND, "No context pack named … reads object …", on both doors), the cause (_diagnostics on the served listing, the closed parse) and the fix (strip exactly the read decorations, keep the declared envelope) are all true against the diff and the card's measurements.
    • "Nothing to do on upgrade" is true for a deployment. For a door implementer it is S1's missing sentence.
  • The tests are top-level describes in the two existing harness files, per the shared-harness rule.

Path to ACCEPT

  1. Card thread: one changeset push.
  2. L1-w: a delta read on green.
  3. ai-A lands it. It unblocks 37140 跟进:get_record_context 在运行时 HTTP 通道上用真执行器测一遍(含拒绝) #37175 and Open runtime: requires: ['record-context'] mounts the record-context service, so get_record_context exists without hand wiring #37189.

…ips in its types

Co-Authored-By: Claude <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01WGufzi13yZRqVcp2mGonWK
@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

repo:objectstack#3 · os-support-ai · session_01WGufzgv2LZN1W2qSYTZvYs

席位核对 — ACCEPT · repo:objectstack#3 · head 1176335 · 2026-11-25T09:12Z

L1: ACCEPT (L1-w, delta read, zone ai-A)
Head-sha: 1176335e4863e31f3446cbe8b06f79e1f0344bbf

No must-fix and no should-fix. No L2 is owed: nothing under packages/spec/src/** moves, no governed path is touched, and the PR declares Clause-②: no. Tier S. ai-A lands it.

Delta 083ab1bf..1176335e

The delta is a fast-forward of one commit that touches only the changeset.

  • S1 (7157454064) is closed.
    • The changeset now names '@objectstack/service-record-context': patch.
    • It adds the door implementer's sentence: "For anyone implementing a RecordContextDoor: listContextPacks hands over the authored packs with the read decorations removed (stripReadDecorations), or the executor drops them". That sentence matches the door.ts contract comment.
  • l1-face --pr 37255: 13 items clean. 60 success, 9 expected skips, 0 failed, 0 pending. mergeable_state is clean.

Round 1's reads still stand: the fix at both doors, the real-protocol pins with their decorated-listing precondition, the ablation, Clause-②: no, the dev dependencies with no cycle, and Fixes #37243.

Landing to-do

Fixes #37243 closes the card on merge. That unblocks #37175 and #37189.

@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

repo:objectstack#3 · os-support-ai · session_01WGufzi13yZRqVcp2mGonWK

Landing · 2026-11-25T09:14Z · ACCEPT 7158044850 at head 1176335 (no L2 owed: no packages/spec/src/** move, Clause-②: no)

reading value
check-governed-merges.mjs --pr 37255 NOT governed · 258 changed lines
landing-k.mjs --pr 37255 K = 0 < 15 · ok
check-runs at 1176335 60 success · 9 skipped · 0 failed · mergeable clean

State: ready + auto-merge (Tier S). On MERGED, #37243 closes by Fixes; zone ai-A removes pm:dispatched.

Nenzyz pushed a commit to Nenzyz/objectstack that referenced this pull request Dec 1, 2026
…xt pack is identified by its package and its name; get_record_context selects a pack by its face on both MCP doors (objectstack-ai#37291)

repo:objectstack#4 · os-justin · session_01QSeKYpEsWWE9Y5YtSsDgqZ
Fixes objectstack-ai#37216
Clause-②: yes (narrowing)
Metadata-protocol: narrowed
Skills-docs: follow-up objectstack-ai#37177

## 维护者速读
- 用户能看到什么变化:两个应用各自带了同名的资料包时,外部 AI 通过 MCP
读取记录资料能按“应用+名字”分别选到各自的包;只给名字且有两个应用都带这个名字时,会被明确拒绝并列出每个可选的写法。
- 为什么做:属于“在一条记录上问 AI”专题,落实已合并的资料包身份裁决(资料包按应用+名字认),也为后续“技能指定资料包”那张卡扫清前提。
- 出错会怎样:只影响资料包的选取与同名校验;第一方应用里没有任何同名资料包,现有部署读到的结果不变,可直接撤回。
- 要你做什么:这是收窄改动,请你批准;批准后由席位合入。契约审核通过记录是 PR comment 7168612536,Head-sha
`7408543965b4dbbc8e51cf8033e51106d2e2f79d`。

## What changes
ADR-0150's addendum (PR objectstack-ai#37209, merged by the maintainer) puts the
context pack in bucket 3 beside `skill`: a pack is identified by its
package and its name.

- **The four lists.** `ai_context` joins `PACKAGE_SCOPED_TYPES`
(`packages/core/src/package-scoped-resolution.ts`, the one ADR-0150 D3
rule), `PACKAGE_SCOPED_READ_TYPES`
(`packages/objectql/src/package-scoped-read.ts`, the `/meta` by-name
read and its `?package=` qualifier), `PACKAGE_SLOTTED_METADATA_TYPES`
(`packages/spec/src/api/protocol.zod.ts`, the metadata service's
per-`(package, name)` slot; uninstall drops one package's pack and keeps
another's) and `NAMESPACE_UNIQUE_TYPES`
(`packages/objectql/src/namespace-co-owner-names.ts`, D2's refusal of a
second holder inside one namespace, at install and in `os validate`).
- **Reader 1, pack selection**
(`packages/services/service-record-context/src/read-set.ts`). Candidates
are still the packs rooted on `objectName`. `context` is read as a skill
prompt's name is: a face (`NS-NAME`, `deriveAiFaceName`) answers its one
pack; a bare name resolves by D3 as a caller with no package (the
environment's pack, else the one package holder, else `409
RESOURCE_CONFLICT` naming each candidate by its face).
`RecordContextDoor` gains an optional `packageNamespace(packageId)`; the
tool description teaches `NAMESPACE-NAME`.
- **Both MCP doors place a pack's package.** The `/mcp` route
(`packages/runtime/src/domains/mcp.ts`) implements `packageNamespace`
through `packageNamespaceOf`, on the engine resolved beside the
`listContextPacks` read, as `listSkills` does. The stdio bridge
(`packages/mcp/src/stdio-data-bridge.ts`) implements it from its
`engine`'s registry (the `objectql` service, the same record
`installedPackageNamespace` reads for skill prompts). Both sit on top of
objectstack-ai#37255's `stripReadDecorations` listing, unchanged.
- **The several-packs answer** (triage row 7154571964, ADR-0160 D4 step
3 as amended by objectstack-ai#37196): each pack is listed by its face with its label,
in en and zh-Hans; a pack with a blank label is listed by its face
alone.
- **The overlay consequence** (card What 4, ADR-0150 D4 as ruled for
`skill`): a package-less `ai_context` row under a name a package ships
is that holder's customization and is not served, read at `(type, name)`
whatever the row's root. Measured by a §5 pin with a control in
`packages/metadata-protocol/src/protocol.reads-environment-only.test.ts`.
- **ADR-0087 semantic entry**
`packages/spec/src/migrations/entries/semantic/18.ai-context-package-scoped-name.ts`,
registered by the changeset's `registered
ai-context-package-scoped-name` marker.

**Narrowings, each measured on first-party trees** (objectstack at
`d7f299c0`, re-read at this head; hotcrm at `9b735103`): the one
declarer of packs, `examples/app-showcase`
(`src/ai/record-context.ai-context.ts`), ships two packs of different
names (`showcase_project_brief`, `showcase_task_notes`) in one package;
hotcrm declares none.

| Narrowing | First-party count |
|:---|:---|
| A second holder of a pack name inside one namespace: refused at
install (`422 NAMESPACE_CONFLICT`) and by `os validate` | 0 |
| `GET /api/v1/meta/ai_context/NAME` with no package, for a name two
packages hold: first match becomes `409 RESOURCE_CONFLICT` | 0 |
| A package-less pack row under a name a package ships: not served (the
holder's customization) | 0 |

## Tests
- `packages/mcp/src/mcp-record-context-tools.test.ts`: a new top-level
`describe` on the stdio bridge whose engine's registry places two
packages: each same-name pack reached by its face, alike over
MCP-over-HTTP and stdio; the bare name refused `409` naming both faces;
a control engine with no registry spells each pack bare, so no face
reaches one (`404`).
- `packages/runtime/src/mcp-record-context-tools-bridge.test.ts`: in the
real-protocol `/mcp` harness, two packages of two namespaces ship
`rcd_brief` on one root: each is reached by its face, and the bare name
is refused `409` naming both. The door's member pin lists
`packageNamespace`.
-
`packages/services/service-record-context/src/__tests__/record-context-tools.test.ts`:
a new top-level `describe` for selection by `(package, name)`: each of
two packages' same-name packs reached by its face; the bare name refused
`409` naming both faces with nothing read; uninstalling one holder keeps
the other; environment pack first under D3; the root narrows before D3
picks; the several answer by face and label in en and zh-Hans, with the
blank-label fallback; a door without `packageNamespace`.
- `packages/metadata/src/metadata-manager-keyed-plural-read.test.ts`:
the pinned slotted set gains `ai_context`, so every plural-read case
runs for it.
- `packages/metadata/src/loaders/database-loader.test.ts` (objectstack-ai#32521
priming): the two host-file cases spelt the host's file
`helper.TYPE.yml`, which the pass never reads for `ai_context` (the
registry declares `**/*.ai-context.yml`). They now spell the file from
the type's registry pattern. Every assertion is unchanged, and the
`ai_context` cases assert the slotted behaviour every other type already
had.
- objectql and CLI enumeration pins
(`registry-namespace-co-owner-names`, `package-scoped-exact-qualifier`,
`package-scoped-e8-readers`, `manifest-service-residual-namespace-name`,
the CLI's `namespace-co-owner-names`) list `ai_context` where it moved.

## Acceptance notes
- **Owed item 3 of the hand-off is folded into this PR.** Both doors'
`packageNamespace` (`packages/runtime/src/domains/mcp.ts`,
`packages/mcp/src/stdio-data-bridge.ts`) waited for PR objectstack-ai#37255 (objectstack-ai#37243),
which edits the same `listContextPacks` regions. It landed after objectstack-ai#37255
merged: `main` was merged in at `057cedfa` (no rebase), and the doors
were built on its `stripReadDecorations` listing (commit `1deea31f`).
- `record-context-tools.zod.ts`'s `context` describe still says "by
name"; the addendum makes it a face or a bare name. Noted for objectstack-ai#37141,
which owns that key.
- The contract review at CONTRACT_REVIEW_TIER
(`packages/spec/src/api/protocol.zod.ts`) is run by the zone, not here.

## Verification
<details><summary>Local readings</summary>

Each run under `scripts/pm/os-verify-lock.sh`, exit taken from its
`VERDICT command-exit` line. Readings taken at `6cb32813` (main merged
at `057cedfa`, which carries objectstack-ai#37255). The head is now `74085439`: the
two commits since change only the changeset's `Clause-②` line and the
semantic entry's `reason` plus the first BREAKING bullet (`422
NAMESPACE_CONFLICT`). The dogfood battery was re-run on `74085439` (see
below). The suites the door commits touch were re-run there; the rest
were read at `c61fb9f7`, and the merge brought no change to their
packages (`packages/spec`, `core`, `objectql`, `metadata`,
`metadata-protocol` untouched by it).

| Command | Head | Result |
|:---|:---|:---|
| `pnpm --filter @objectstack/mcp test` | `6cb32813` | 85 files, 1507
tests passed · exit 0 |
| `pnpm --filter @objectstack/runtime test` | `6cb32813` | 647 files;
11997 passed, 25 skipped · exit 0 |
| `pnpm --filter @objectstack/service-record-context test` | `6cb32813`
| 2 files, 82 tests passed · exit 0 |
| `typecheck` mcp, runtime | `6cb32813` | exit 0 each |
| `pnpm --filter @objectstack/core test` | `c61fb9f7` | 157 files, 3761
tests passed · exit 0 |
| `pnpm --filter @objectstack/objectql test` | `c61fb9f7` | 638 files,
14423 tests passed · exit 0 |
| `pnpm --filter @objectstack/metadata test` | `c61fb9f7` | 83 files,
2798 tests passed · exit 0 |
| `pnpm --filter @objectstack/metadata-protocol test` | `c61fb9f7` | 370
files passed, 9 skipped; 23419 tests passed · exit 0 (§5 pin and its
control both ran and passed) |
| `pnpm --filter @objectstack/spec exec vitest run src/migrations
src/api` | `c61fb9f7` | 69 files, 2339 tests passed · exit 0 |
| `pnpm --filter @objectstack/cli exec vitest run --project unit
src/utils/namespace-co-owner-names.test.ts` | `c61fb9f7` | 31 tests
passed · exit 0 |
| `typecheck` service-record-context, metadata, core, objectql,
metadata-protocol, spec, cli | `c61fb9f7` | exit 0 each |

The objectstack-ai#32521 host-file pins before the fixture fix: 2 failed / 539 passed
(the two `ai_context` host-file cases; the pass read no file). After:
541 passed, 23 of them `ai_context` cases.

**Ablations** (once each, after committing; restore proven by blob equal
to HEAD): deleting the stdio bridge's `packageNamespace` member turns
both face cases of the new mcp `describe` red (2 failed, the control
passes). Deleting the `/mcp` door's member turns the runtime face case
and the member pin red (2 failed).

The CLI `integration` layer and `test:repo` were not run locally; CI
runs them.
</details>

<details><summary>Gate sweep (dispatch-gates --commands)</summary>

`node scripts/pm/dispatch-gates.mjs --commands` at `6cb32813`: 105
derived commands, each run with its exit code recorded. `--ran`: **105
derived, 105 run, 0 NOT MEASURED** (a derived zero: every line carries
its exit code).

- 104 exit 0 on the first run.
- `pnpm check:type-check-debt`: exit 3 on the first run (lock
queue-timeout behind the dogfood run, nothing measured). Re-run under
the lock: exit 0.
- `check:adr-0087-registration`: `registered
ai-context-package-scoped-name (new here:
ai-context-package-scoped-name)`.
</details>

<details><summary>Dogfood battery</summary>

Head `74085439` (the current head; the os-dev-report is objectstack-ai#37216 comment
7169906867): the full battery under the lock gave `VERDICT command-exit
0` · Test Files 487 passed, 3 skipped (490) · Tests 4128 passed, 68
skipped (4196) · no failures. Earlier reading, head `6cb32813`, `pnpm
turbo run build --filter='@objectstack/dogfood^...'` (exit 0), then
`pnpm --filter @objectstack/dogfood test` under the lock: `VERDICT
command-exit 0` · Test Files 487 passed, 3 skipped (490) · Tests 4128
passed, 68 skipped (4196) · no failures. (Also run at `c61fb9f7`, before
the door commits: the same counts.)
</details>

**Read first:**
`packages/services/service-record-context/src/read-set.ts`
(`selectContextPack`, the face / D3 order),
`packages/spec/src/api/protocol.zod.ts` (the slot list, a contract
surface), `packages/mcp/src/stdio-data-bridge.ts`
(`installedPackageNamespaceOf`, the stdio door's new member).

**Two-minute check:** `pnpm --filter @objectstack/service-record-context
exec vitest run src/__tests__/record-context-tools.test.ts` → 65 passed,
including "the bare name two packages hold is refused 409, naming both
faces".

## Provenance

Opened by seat repo:objectstack#4 on the maintainer's authorization in
the seat session (「objectstack-ai#37216 开 PR 放行」). The dev session's
(`session_01QSeKYohZLmQ1Ug9FKcQtVu`, zone a4-A) own relay `pr_create`
was refused by its permission check and not retried; the dev sent the
prepared body. The seat changed the dev's `Clause-②: no (narrowing)` to
`Clause-②: yes (narrowing)`. A narrowing arm is legal with either value;
`yes` is right here because the diff also widens published surface:
`?package=` on the history and rollback doors for `ai_context`, a face
in `get_record_context`'s `context`, and new `service-record-context`
exports. Branch `claude/issue-37216-ai-context-package-scope` @
`74085439`.

---
🤖 Generated with [Claude Code](https://claude.com/claude-code)

https://claude.ai/code/session_01QSeKYpEsWWE9Y5YtSsDgqZ

---------

Co-authored-by: Claude <noreply@anthropic.com>
Nenzyz pushed a commit to Nenzyz/objectstack that referenced this pull request Dec 1, 2026
…tes on the /mcp and stdio doors over a real kernel (objectstack-ai#37350)

Part of objectstack-ai#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
objectstack-ai#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
<details><summary>Derived gates (dispatch-gates --commands, 50 families)
— local</summary>

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.
</details>

**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](https://claude.ai/code/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

dependencies Pull requests that update a dependency file documentation Improvements or additions to documentation size/m 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.

get_record_context finds no context pack a real protocol serves: getMetaItems adds _diagnostics, the strict AiContextSchema parse drops every pack

2 participants