You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit e86bf99
Browse filesBrowse the repository at this point in the historyBrowse files
fix(service-record-context): a related object the stack does not define states nothing (#37751)
<!-- claude-projects-attribution: {"github_login":"os-elon-musk"} -->
_Requested by **Elon** · [project
thread](https://claude.ai/code/project/chan_01WedDzV26nniwxv7jC88B9D?thread=cmsg_01WedDzV26nniwxv7jC88B9DLCo5F2y7fgbM8tstGoyyUn)_Fixes#37486
Clause-②: no
Metadata-protocol: none
## 维护者速读
- 用户能看到什么变化:资料包里关联了一个系统中根本不存在的对象(作者写错名字)时,AI
工具不再对任何人说「部分资料对你不可见」,只是不给这一节;真有权限限制的对象照旧提示。
- 为什么做:属于「记录范围的 AI 问询」这一组后续,让工具行为与设计一致:作者写错由校验报给作者,不伪装成权限问题。
- 出错会怎样:最坏是某个确实存在、只是此人看不到的对象漏了「不可见」提示;两种情况都有真实内核测试守着,可直接撤回此改动。
- 要你做的:无。设计文档里对应的那一句已先行合入(随另一项设计文档修订),本改动不再欠设计文档。
## What changes
`executeGetRecordContext` step 4a
(`packages/services/service-record-context/src/record-context-tools.ts`):
a `related` child that passes the read guard and API exposure and that
this caller is not served is still left out and never read again. The
`not_visible` statement now fires only when the door's **published**
definition of the object exists (`door.publishedObjectDefinitionOf`). A
name the published definitions lack is an author defect (ADR-0160 D1,
`os validate` reports it as `ai-context-object-unknown`) and states
nothing (D3: "A name the published definition lacks is an author defect
([D1](#d1)) and fires nothing.").
Why this fact: it is the same for every caller. Both door
implementations were read on `origin/main` 579b857:
- HTTP (`packages/runtime/src/domains/mcp.ts`,
`publishedObjectDefinitionOf` → `readServedObject`): the protocol's
merged `getMetaItems({ type: 'object' })` listing, with no caller
argument, or the metadata service's `getObject`. No masker. An absent
name answers `undefined` → `null`, no throw.
- stdio (`packages/mcp/src/stdio-data-bridge.ts`,
`readObjectDeclaration`): `getMetaItemForExecution` / `getMetaItem` by
name, falling back to the metadata service's copy; no principal. An
absent name answers `undefined` → `null`. Its one rethrow is
`OBJECT_PACKAGE_DISABLED`, which API exposure has already refused one
step earlier.
- `assertApiExposed` on the HTTP door is `refuseUnexposedDataAction(...,
'refuse')`: on no declaration it falls open to schema defaults
(`apiEnabled` true), so an undefined object reaches step 4a's served
read on both doors, as the card said.
A throw from the new read is judged the way every other step-4a read is:
a coded refusal refuses the call unnamed, any other throw fails it
`INTERNAL_ERROR` 500 naming nothing (`refusedOrFailed`). The definition
is used as a boolean only; nothing of it is carried.
Comments in the same file that said a left-out child's definition is
never read are corrected to say what the code now does.
## ADR-0160 amendment
The ADR text this change implements has landed first, as ruling B on
this card ordered (record 7208943876): PR #37785 (merge commit
`031a19dc`) amended ADR-0160 a sixth time. D3 "Object level", the bullet
"A `related` child that this caller is not served is left out.", now
reads:
> Nothing of the child is read except its published definition, which is
asked once, for whether the stack defines the object at all (sixth
amendment, 2026-11-27): a name the published definitions lack is an
author defect ([D1](#d1)), left out with no statement for every caller.
The published definition is the same for every caller, so whether the
statement fires depends on this caller's served schema alone, and
nothing of the definition is carried.
That is the replacement this PR had proposed, with the amendment's date
added. The amendment record names this PR and says `main` reads nothing
of such a child until it merges. `docs/adr/**` is not touched here; this
branch carries the amended text by merging `origin/main` at `29804839`
(merge commit `3e30d721`).
## Tests
<details><summary>Measured first: the real-kernel case red on main (both
doors agree, both carry the note)</summary>
`pnpm --filter @objectstack/runtime exec vitest run --maxWorkers=2
src/mcp-record-context-tools-bridge.test.ts` at 7adbe2d (tests only,
`src/` = main 579b857):
```
× [ADR-0160 D1/D3] a related entry naming an object the stack does not define leaves its section out and states nothing: the same bytes for both callers, on both doors
AssertionError: expected [ { kind: 'not_visible', …(1) } ] to deeply equal []
+ "kind": "not_visible",
+ "text": "Some of the material this pack covers is not visible to you, so it is not given. Do not treat it as empty or absent, and do not guess it.",
Tests 1 failed | 29 passed (30)
```
The `/mcp`-vs-stdio byte equality held before the note assertion, so the
defect was on both doors. The two-caller defined-but-unserved case
passed on main, as it should.
</details>
<details><summary>Green after the fix, and the ablation</summary>
- `@objectstack/runtime` `src/mcp-record-context-tools-bridge.test.ts`:
Tests 30 passed (30).
- `@objectstack/service-record-context` `pnpm test`: Test Files 3 passed
(3), Tests 180 passed (180).
- Ablation (`scripts/ablation-replace.mjs`, fix committed first): `if
(published) hidden = true;` → `hidden = Boolean('ABLATION_37486');`;
`ablation-dist-preflight` found the marker in 2 built files; the runtime
case and the new unit case each went red (1 failed | 29 passed; 1 failed
| 132 passed); restore leg: marker absent from all 6 built files,
working tree clean against HEAD. A first attempt used a comment marker,
which the build strips: its dist reading failed, so that attempt counts
for nothing.
</details>
<details><summary>Merge round: re-measured on head 3e30d72 (origin/main
2980483 merged, no conflict)</summary>
- The merge brought no change to this PR's four files: `git diff --stat
cb1a47e..3e30d72` over them is empty, and the branch delta against
`origin/main` is still the same four files (+130 / -11). The two door
implementations read above (`packages/runtime/src/domains/mcp.ts`,
`packages/mcp/src/stdio-data-bridge.ts`) are unchanged between 579b857
and 2980483.
- `@objectstack/service-record-context` `pnpm test`: Test Files 3 passed
(3), Tests 180 passed (180); `typecheck`: exit 0 (test layer 0 errors).
- `@objectstack/runtime` `src/mcp-record-context-tools-bridge.test.ts`:
Tests 30 passed (30); `typecheck`: exit 0 (test layer at its ledger: 27
files / 183 errors / 66 pinned signatures).
- `dispatch-gates --commands` for this head: 66 of 67 derived families
exit 0; `check:dual-build-cjs-loads` not measured locally (it reads
every package's `dist/`, and only the closure was built); CI's `Lint &
Repo Gates` carries it.
- `overlap-check`: merges cleanly with `origin/main` 2980483; no open
PR shares a file.
</details>
New cases:
- Real kernel, both doors,
`packages/runtime/src/mcp-record-context-tools-bridge.test.ts` (shared
harness extended with object `rc_partner`, served to `usr_member`
through `rc_unmasker` and not to `usr_plain`, and packs
`rc_misspelt_child` / `rc_role_child`):
- an undefined `related` object (`rc_ghost`): no section, `notes` `[]`,
the name nowhere, for `usr_member` and `usr_plain`, and the two callers'
answers byte-identical;
- a defined child served to one caller and not the other: its section
for `usr_member` with no note; for `usr_plain` no section, one
`not_visible` note, `rc_partner` named nowhere.
- Unit, `src/__tests__/record-context-tools.test.ts`: the undefined
child states nothing while a hidden field or an unserved defined child
beside it still states; a left-out child's published read that throws
refuses unnamed (coded) or fails `INTERNAL_ERROR` (uncoded). Two pins
that said a left-out child's published definition is never asked now pin
the new order: guard, exposure, served read, published read, then
nothing.
## Acceptance notes
- The card's Acceptance asks to state the `Clause-②` line because the
tool's answer changes; the claim binds `Clause-②: no`, which is what
this PR and its changeset carry. Flagged in the report, not re-ruled
here.
- The card cites ADR-0160 point 20 (fields); the governing text for an
unknown object is D1 and D3.
## Verification
Read first (by risk):
1.
`packages/services/service-record-context/src/record-context-tools.ts`,
the `if (!served)` hunk of step 4a.
2. `packages/runtime/src/mcp-record-context-tools-bridge.test.ts`, the
two new cases and the fixture's `rc_partner` permissions.
3.
`packages/services/service-record-context/src/__tests__/record-context-tools.test.ts`,
the two re-pinned order assertions.
Two-minute check: `pnpm --filter @objectstack/runtime exec vitest run
--maxWorkers=2 src/mcp-record-context-tools-bridge.test.ts` after
building the closure: expect 30 passed, including "a related entry
naming an object the stack does not define …".
---
_Generated by [Claude
Code](https://claude.ai/code/session_016WV4cxBECSPtHxQMZDHSie)_
<!-- signed: repo:objectstack#1 · os-elon-musk ·
session_016WV4cxBECSPtHxQMZDHSie -->
---------
Co-authored-by: Claude <noreply@anthropic.com>
fix(service-record-context): `get_record_context` states nothing for a `related` object the stack does not define
6
+
7
+
Clause-②: no
8
+
Metadata-protocol: none
9
+
10
+
A context pack whose `related` entry names an object no package and no environment defines (a misspelt name, or a package removed after the pack was written) is an author defect: `os validate` reports it (`ai-context-object-unknown`), and ADR-0160 D1 says the tool answer says nothing about it. Until now the section was left out and every caller was told "Some of the material this pack covers is not visible to you", which reads as a permission narrowing nobody configured.
11
+
12
+
The section is still left out. The not-visible statement now fires only when the stack publishes the object and this caller is not served it, as it did before for a defined child. The judgement reads the published definition, which is the same for every caller, so the answer for one caller reveals nothing about another caller's access: two callers get the same bytes for a pack with an undefined `related` object, on the `/mcp` door and the stdio door alike. Nothing of the published definition is carried in the answer.
@@ -763,6 +775,38 @@ describe('[ADR-0149 D7 · ADR-0160 D4] get_record_context over one real kernel:
763
775
expect(answer.text).not.toContain('Hidden');
764
776
});
765
777
778
+
it('[ADR-0160 D1/D3] a related entry naming an object the stack does not define leaves its section out and states nothing: the same bytes for both callers, on both doors',async()=>{
779
+
// Precondition: no package and no environment defines it, so it is an author defect (`os validate`).
// Who asks changes nothing: one answer, byte for byte.
793
+
expect(plain.text).toBe(member.text);
794
+
});
795
+
796
+
it('[ADR-0160 D3 as amended] a defined child served to one caller and not the other: its section for the one, the not-visible statement for the other, on both doors',async()=>{
it('[ADR-0160 D1/D3] a left-out child\'s published-definition read that throws: a coded refusal refuses unnamed, a failure fails, never stated or dropped',async()=>{
0 commit comments