Repository navigation
Commit 28a2f0f
fix(mcp,runtime): describe_object serves readonly: true where a write never sets the value (#33150)
<!-- claude-projects-attribution: {"github_login":"os-tesla"} -->
_Requested by **Tesla** · [project
thread](https://claude.ai/code/project/chan_01AXsQkLFKRdQCqQ3RTr6Jao?thread=cmsg_01AXsQkLFKRdQCqQ3RTr6JaoSLDKWQ8v7cxY9uDGijfncD)_
Fixes #32530
Clause-②: yes (widening)
Metadata-protocol: none
## 维护者速读
- 改了什么:MCP 的 `describe_object`(HTTP 与 stdio 两种传输)和
`objectstack://objects/{name}` 资源,现在对「写了也不会生效」的字段回答 `readonly:
true`:自动编号(包括手写、没带 readonly 标记的字段)、公式字段、声明了 `expression` 的存储计算字段。HTTP
传输按字段的原始声明判断(调用者看不到表达式引用的字段时,表达式会被遮蔽,但仍回答 `readonly:
true`,表达式本身不外露);stdio 与资源只拿得到遮蔽后的对象,这一情形的缺口已另立
#33156。工具说明同时写明:`readonly` 是 schema 的判断,不是调用者的字段编辑权限;`defaultValue`
可能是服务端解析的令牌(`NOW()`、`current_user`)或表达式对象,代理应省略该字段而不是照抄。
- 为什么改:之前只看字段上声明的 `readonly` 标记,代理会以为这些字段可写,写进去被引擎丢弃或覆盖,再猜再试。
- 风险与回滚:只放宽回答(多说了 `readonly: true`),不拒绝任何新输入;普通字段仍是 `false`、声明了只读的仍是
`true`(有对照用例)。回滚 = revert 本 PR,不涉及数据。
- 先看:`packages/runtime/src/domains/mcp.ts` 与
`packages/mcp/src/mcp-server-runtime.ts` 新增的
`writeNeverSetsField`(两处孪生实现);`packages/mcp/src/mcp-http-tools.ts` 的
`describe_object` 说明文字。
- 两分钟验证:`pnpm --filter @objectstack/runtime exec vitest run
--maxWorkers=2 src/domains/mcp-object-schema-mask.test.ts -t 32530`,预期
4/4 通过(真实引擎 + 安全插件)。
- 需要你做的:无,席位落地。
## What changes
- **Item 1, both twins.** `describeServedObject` in
`packages/runtime/src/domains/mcp.ts` (HTTP bridge) and in
`packages/mcp/src/mcp-server-runtime.ts` (stdio bridge and the
`objectstack://objects/{name}` resource) now serve `readonly` from
`writeNeverSetsField(f)`, one small predicate per twin: the declared
flag, OR a runtime-owned type (`RUNTIME_OWNED_FIELD_TYPES` from
`@objectstack/spec/data`, today `autonumber`), OR a `formula`
(`isVirtualSearchField`, the spec's one statement of the virtual set;
the engine's write strip keys on the same type), OR a stored field
declaring an `expression` (the spec's `expression` contract: "a
client-sent value never stands"; truthy, the engine's own test in
`planStoredExpressions`). No local type list.
- **Round 2 (contract review S1): the HTTP twin judges on the
declaration.** The caller's field mask deletes a readable field's
`expression` when it names a field the caller cannot read, while the
engine still computes the column. `describeObject` in
`packages/runtime/src/domains/mcp.ts` now runs `readServedObject` and
`servedToCaller` as two steps and calls `describeServedObject(def,
declared)`: `readonly` comes from
`writeNeverSetsField(declared.fields[k])`, and everything served is
still built from the masked `def`, so the expression stays hidden. No
new read: `declared` is the object the bridge already masks. The stdio
twin and the objects resource hold only the masked object
(`callerObjectView`), so there the expression case answers `true` only
where the caller is shown the expression; the mcp twin's JSDoc and the
changeset say so.
- **The stored-expression arm is a bounded same-class fix.** The card
names autonumber and formula; a non-formula field with an `expression`
is the same defect (served `readonly: false`, the engine overwrites the
sent value, measured below), on the same line, with the same gate
family, and no other claim holds the function. Leaving it would keep the
card's complaint for that field kind.
- **Item 2: option (b).** The served view cannot answer the caller's
edit verdict without a new read. Measured: the caller's object is
`servedToCaller(def)` over `resolveObjectMasker` →
`resolveObjectSchemaMaskPosture`, which asks the security service
`getMetadataReadableFields` / `getReadableFields` and `canReadObject`
only; the posture carries a `readable` set and nothing about edit. The
edit verdict lives in `ISecurityService.getWritableFields(object,
context)` (optional member, the write gate's complement). So the
description now says `readonly` is the schema's, not the caller's edit
permission, and that a write naming a read-only-for-you field is
refused. What an edit verdict would need is in the acceptance notes.
- **Item 3.** The `optionFieldsOf` JSDoc no longer says
`describe_object` "serves what it served before"; the `describe_object`
description gains the `defaultValue` sentence (token or expression
object: omit the field, never copy the value) and the `readonly` wording
above.
- **Skills-docs: not owed.** `packages/mcp/src/skill-md.ts` names
`describe_object` (fields: name, type, required) but restates neither
`readonly` nor `defaultValue`, so it and its console mirror are
untouched.
## Tests
- `packages/runtime/src/domains/mcp-object-schema-mask.test.ts`, new
top-level describe `[#32530]` on the file's existing real-layer harness
(real `ObjectQL` over `SqlDriver`, real `SecurityPlugin`, the real
`/mcp` entry):
- precondition: the hand-written `autonumber` literal reaches the served
object with no `readonly` flag;
- `ticket_no` (autonumber), `total` (formula), `bare_formula` (formula,
no expression), `doubled` (number + expression) are served `readonly:
true`; CONTROL `title` and `qty` stay `false`, `frozen_note` (declared
readonly) stays `true`;
- through the same bridge's `create`, the engine stores none of the sent
values: the autonumber is issued (`T-0001` shape), the formula reads
`6`, the stored expression is `6`, the CONTROL field is stored;
- the item-2 arm: `locked_note` (member may read, not edit) is served
`readonly: false`, and `create` naming it is refused `PERMISSION_DENIED`
/ `403`;
- round 2: `marked_up` is a stored expression over `hidden_cost`, which
the member may not read. It is served `readonly: true`, and the served
answer contains neither `hidden_cost` nor any `record.` text.
Preconditions: the member's `/metadata/object` read serves `marked_up`
with no `expression`, while `engine.getSchema` still carries it.
- `packages/mcp/src/stdio-data-bridge.object-schema-mask.test.ts`: new
top-level describe `[#32530]` pinning the same fields over stdio
`describe_object` and over `buildObjectSchemaResource`; the existing
`DECLARED_ANSWER` pin had `bonus_formula` at `readonly: false`, which
encoded the defect, and now reads `true`.
## Acceptance notes
- **What an edit verdict (item 2a) would need, measured.** HTTP bridge:
one `security.getWritableFields(name, ec)` call per `describe_object`,
feature-detected, beside the masker (the service is already resolved
there). stdio bridge: `StdioDataBridgeDeps.security` is typed
`ObjectSchemaMaskSecuritySurface`, which has no `getWritableFields`, so
the dependency type and `callerObjectView` widen
(`stdio-data-bridge.ts`, outside this card's surface). The objects
resource: `buildObjectSchemaResource` reads an `McpObjectView`
(`listObjects` / `getObject`) with no principal, so it cannot ask at all
without a new seam. And the contract (`getWritableFields` JSDoc)
requires a consumer without that member to state in its response that it
narrowed by the read projection, so the answer would also gain a
coverage key. Not filed: it is the card's own option (a), deliberately
not taken.
- **Out of scope, filed as #33156:** over stdio and on the
`objectstack://objects/{name}` resource, a caller who cannot read a
field that a stored expression names is served `readonly: false` for
that field, while the HTTP door answers `true`. Those two readers hold
only the masked object; the declaration is not reachable there without a
second metadata read, and `stdio-data-bridge.ts` is outside this card's
surface.
- **`summary` is left `readonly: false`.** `COMPUTED_VALUE_TYPES` calls
it server-computed, but the engine persists a caller-sent summary value
(`stripComputedWriteFields` JSDoc: "a roll-up HAS a column, and a
caller-supplied value is persisted"), so `readonly: true` would claim a
drop that does not happen. Noted, not filed: the engine records the
question as its own.
- **The formula predicate is search-named.** `isVirtualSearchField` is
the spec's only exported statement of "computed on read, no column"; the
write strip in objectql keys on `type === 'formula'` literally and
`isRuntimeOwnedField` lives in objectql, which `@objectstack/mcp` does
not depend on. Both read the same set today. A write-named spec
predicate would be its own spec change.
- **Serial.** Edits stay on `describeServedObject` /
`writeNeverSetsField`, the `optionFieldsOf` JSDoc and the
`describe_object` description; no hunk touches
`servedObjectDefinitionOf`, the `validate_expression` handler (#33134)
or the connector narrowing (#31699).
- **Ruling grep** (`ruling|Ruling-ref|maintainer|⛔`) on the touched
surface: 69 hits across the three source files. The ones inside the
edited regions are the `describeServedObject` JSDoc's "⛔ never its
condition, pattern or transition table" (both twins, unchanged,
honoured: no rule expression is served) and the new JSDoc's own "⛔ Not
the caller's field edit permission". No ruling record governs
`readonly`. The `mcp-http-tools.ts` hits sit outside the edited JSDoc
and description.
## Verification
Round 1 readings were taken at `819ea267` (base `932eab54`;
`origin/main` merged once there, bringing only `packages/lint` changes).
Round 2 readings were taken at head `92fba691`: the S1 fix `d05eae15`,
the changeset narrowing, then `origin/main` merged a second time because
#33144 landed on `packages/runtime/src/domains/mcp.ts` (no conflict).
<details><summary>Round 2 (S1) at 92fba69</summary>
- `mcp-object-schema-mask.test.ts` (runtime) — Tests 72 passed (72);
`src/domains/mcp*` (runtime) — Test Files 5 passed (5), Tests 247 passed
(247)
- `pnpm --filter @objectstack/mcp test` — Test Files 63 passed (63),
Tests 1106 passed (1106)
- `pnpm --filter @objectstack/mcp --filter @objectstack/runtime
typecheck` — `VERDICT command-exit 0`
- Ablations, both red and both restored to the HEAD blob: `readonly:
writeNeverSetsField(f)` back in place gives 1 failed (the new
`marked_up` case); serving `declared.fields[k].expression` gives 1
failed (the same case, its no-expression assertion).
- Derived gates re-derived at `92fba691`: the same 66 families, each run
with stdin closed and its exit code recorded; `--ran` reconciles **66
accounted, 66 run, 0 NOT MEASURED**, every one exit 0
(`check:dual-build-cjs-loads` included this time, after the post-merge
closure build). `pnpm lint` exit 0.
</details>
<details><summary>Measured at origin/main first (the premise
holds)</summary>
The new runtime pins over the unfixed twin (`4fee53be`, tests only on
`932eab54`): **1 failed | 3 passed**. The failing case: `doubled`,
`ticket_no` and `total` were served `readonly: false` (the `frozen_note`
and plain-field controls matched). The three passing cases are the
measurement of the engine and the gate: the autonumber literal carries
no flag, the engine dropped or replaced every sent computed value, and
the member's write naming `locked_note` was refused `PERMISSION_DENIED`
/ `403` while `describe_object` served it `readonly: false`. On the
stdio side, `DECLARED_ANSWER` pinned `bonus_formula` at `readonly:
false` on `main`.
</details>
<details><summary>Package tests and typecheck</summary>
- `pnpm --filter @objectstack/mcp test` — Test Files 63 passed (63),
Tests 1106 passed (1106)
- `pnpm --filter @objectstack/runtime test` — Test Files 596 passed
(596), Tests 10581 passed | 19 skipped (10600), `VERDICT command-exit 0`
- `mcp-object-schema-mask.test.ts` (runtime) — Tests 71 passed (71)
- `pnpm --filter @objectstack/mcp --filter @objectstack/runtime
typecheck` — `VERDICT command-exit 0`; both run `tsc --noEmit && pnpm
check:test-typecheck`, the second over `tsconfig.test.json`, which
carries the test files
</details>
<details><summary>Ablations (12, all red, all restored)</summary>
Every leg through `scripts/ablation-replace.mjs` (anchor x1 → x0, blob
changed, restored blob == HEAD and `git diff HEAD` empty). The suites
import the source, so no `dist/` leg.
- Runtime twin, `-t 32530`: whole verdict back to `f?.readonly === true`
→ 1 failed; runtime-owned arm removed → 1 failed; formula arm removed →
1 failed; expression arm → `false` → 1 failed; declared arm removed → 1
failed; CONTROL (last arm → `true`) → 2 failed (the plain-field control
and the item-2 `locked_note` case).
- mcp twin, `stdio-data-bridge.object-schema-mask.test.ts`: whole
verdict → 4 failed (the two new cases plus the two `DECLARED_ANSWER`
cases); runtime-owned arm → 2 failed; formula arm → 2 failed; expression
arm → 2 failed; declared arm → 3 failed; CONTROL → 5 failed.
</details>
<details><summary>Derived gates and lint</summary>
`node scripts/pm/dispatch-gates.mjs --commands --repo
objectstack-ai/objectstack` at `819ea267`: 66 families, each run with
stdin closed and its exit code recorded before any pipe. `--ran`
reconciles **66 accounted, 65 run, 1 NOT MEASURED**:
- `pnpm check:dual-build-cjs-loads` — exit 3, PREREQUISITE NOT MET: the
scan needs `dist/` of packages outside this diff's closure. NOT
MEASURED; CI runs it.
All other 65 exit 0, `check:nul-bytes`,
`check:cross-package-test-inputs`, `check:test-source-alias`,
`check:doc-authoring` and `check:adr-0087-registration` among them.
`node scripts/check-plugin-teardown-shape.mjs --self-test` first exited
3 (its pinned positive control was not in the shallow clone); after
fetching `621a4876`, exit 0, 48 cases. `pnpm lint` — exit 0. No export
was renamed or removed, so `check-platform-checklist.mjs` is not owed.
</details>
---
_Generated by [Claude
Code](https://claude.ai/code/session_01L9qibzwtSQM5u87bBFCujF)_
<!-- signed: domain:server#7 · os-tesla ·
session_01L9qibzwtSQM5u87bBFCujF -->
---------
Co-authored-by: Claude <noreply@anthropic.com>1 parent 47f6c93 commit 28a2f0f
7 files changed
Lines changed: 352 additions & 20 deletions
File tree
- .changeset
- packages
- mcp/src
- runtime/src/domains
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
179 | 179 | | |
180 | 180 | | |
181 | 181 | | |
182 | | - | |
183 | | - | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
184 | 185 | | |
185 | 186 | | |
186 | 187 | | |
| |||
2401 | 2402 | | |
2402 | 2403 | | |
2403 | 2404 | | |
2404 | | - | |
2405 | | - | |
| 2405 | + | |
| 2406 | + | |
| 2407 | + | |
| 2408 | + | |
| 2409 | + | |
| 2410 | + | |
2406 | 2411 | | |
2407 | 2412 | | |
2408 | 2413 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
59 | 59 | | |
60 | 60 | | |
61 | 61 | | |
| 62 | + | |
62 | 63 | | |
63 | 64 | | |
64 | 65 | | |
| |||
104 | 105 | | |
105 | 106 | | |
106 | 107 | | |
| 108 | + | |
107 | 109 | | |
108 | 110 | | |
109 | 111 | | |
| |||
113 | 115 | | |
114 | 116 | | |
115 | 117 | | |
116 | | - | |
117 | | - | |
118 | | - | |
119 | | - | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
120 | 123 | | |
121 | 124 | | |
122 | 125 | | |
| |||
139 | 142 | | |
140 | 143 | | |
141 | 144 | | |
142 | | - | |
| 145 | + | |
143 | 146 | | |
144 | 147 | | |
145 | 148 | | |
| |||
149 | 152 | | |
150 | 153 | | |
151 | 154 | | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
152 | 192 | | |
153 | 193 | | |
154 | 194 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
19 | 19 | | |
20 | 20 | | |
21 | 21 | | |
22 | | - | |
| 22 | + | |
| 23 | + | |
23 | 24 | | |
24 | 25 | | |
25 | 26 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
46 | 46 | | |
47 | 47 | | |
48 | 48 | | |
49 | | - | |
| 49 | + | |
50 | 50 | | |
51 | 51 | | |
52 | 52 | | |
| |||
142 | 142 | | |
143 | 143 | | |
144 | 144 | | |
145 | | - | |
| 145 | + | |
| 146 | + | |
146 | 147 | | |
147 | 148 | | |
148 | 149 | | |
| |||
541 | 542 | | |
542 | 543 | | |
543 | 544 | | |
| 545 | + | |
| 546 | + | |
| 547 | + | |
| 548 | + | |
| 549 | + | |
| 550 | + | |
| 551 | + | |
| 552 | + | |
| 553 | + | |
| 554 | + | |
| 555 | + | |
| 556 | + | |
| 557 | + | |
| 558 | + | |
| 559 | + | |
| 560 | + | |
| 561 | + | |
| 562 | + | |
| 563 | + | |
| 564 | + | |
| 565 | + | |
| 566 | + | |
| 567 | + | |
| 568 | + | |
| 569 | + | |
| 570 | + | |
| 571 | + | |
| 572 | + | |
| 573 | + | |
| 574 | + | |
| 575 | + | |
| 576 | + | |
| 577 | + | |
| 578 | + | |
| 579 | + | |
| 580 | + | |
| 581 | + | |
| 582 | + | |
| 583 | + | |
| 584 | + | |
| 585 | + | |
| 586 | + | |
| 587 | + | |
| 588 | + | |
| 589 | + | |
| 590 | + | |
| 591 | + | |
| 592 | + | |
| 593 | + | |
| 594 | + | |
| 595 | + | |
| 596 | + | |
| 597 | + | |
| 598 | + | |
| 599 | + | |
| 600 | + | |
| 601 | + | |
| 602 | + | |
| 603 | + | |
0 commit comments