Skip to content

fix(service-record-context): get_record_context leaves out an unserved related child; both MCP doors supply queryableFieldsOf and their page cap - #37412

Merged
objectstack-fleet[bot] merged 4 commits into
mainfrom
claude/issue-37361-left-out-queryable-doors
Nov 26, 2026
Merged

objectstack-fleet[bot] merged 4 commits into
mainfrom
claude/issue-37361-left-out-queryable-doors

Conversation

@objectstack-fleet

@objectstack-fleet objectstack-fleet Bot commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #37361
Fixes #37175

Clause-②: yes (widening)
Metadata-protocol: none

维护者速读

  • 用户能看到什么变化:外接 AI 读一条记录的资料包时,提问人无权看的关联子对象改为省略并说明,其余部分照常返回;筛选或排序用到提问人不能查询的字段时同样省略并说明,不再整次报错。
  • 为什么做:记录级 AI 问答专题,按已同意的设计(无权的关联对象省略而非拒绝)补齐真实通道的行为。
  • 出错会怎样:最坏是资料包少一段或多一段说明,提问人仍只能读到自己有权读的数据;可以直接撤回本次改动。
  • 要你做的:无。

What changes

ADR-0160 D3 "Object level" as amended, and its second amendment; triage row 7154563681 on #37203.

  • A related child this caller is not served is left out (executeGetRecordContext, step 4a). The answer carries the root and every served section with the one not_visible note, and names the child nowhere (D3 wins over the triage row's "names the child"). Nothing of the child is read after its object-level judgement, its published definition included: the plan reads a left-out child as having no definition, so a lookup target reached only through it is never judged either.
  • Order inside 4a is now: read guard, then API exposure, then the served definition. Measured on the real kernel (assumption A2 holds): a disabled-package child answers servedObjectDefinitionOf as null, so judging exposure first is what keeps its refusal. API-exposure and OBJECT_PACKAGE_DISABLED refusals still refuse the whole call with PERMISSION_DENIED, the one code ADR-0160 point 12 gives an object-level refusal. An API-exposure refusal names the child only when the caller's served schema shows it (the naming bound, unchanged). A served-definition read that throws refuses the call, unnamed; it is never read as this caller's narrowing.
  • Both real doors supply queryableFieldsOf from the security service's getQueryableFields, for the caller each already resolves (assumption A1 holds: no new service dependency on either door). /mcp: recordContextMembers reads it from this request's security service with the request's execution context. stdio: createStdioDataBridge reads it from the security service it already holds for the object-schema mask, with the per-call principal; its dependency type now declares the optional method.
  • N2, the smaller design: the door reports its cap, and the executor asks for at most it. A new optional door member pageCap() answers the most rows one query may ask for. The executor cuts a list at min(limit or row cap, pageCap - 1), reads with the probe row, and states the cut, so no door cuts or refuses a list the answer does not say was cut. Both doors answer the deployment's smaller read limit (OS_DATA_MAX_PAGE_SIZE, OS_DATA_QUERY_ROW_BUDGET), which the data door refuses past. Before, under a max page size below 21, the /mcp door refused the whole call MAX_RECORDS_EXCEEDED and the stdio door read the full list (the ablation below shows both).
  • N1: the RecordContextNoteKind doc line now says related_truncated fires at the entry's limit, at the row cap, or at the door's page cap.
  • Rework N3: the .describe() texts of RecordContextRelatedListSchema.rows and .truncated (what a model reads in the tool's output schema) now name the entry's limit and the door's page cap, not the row cap alone. Generated reference docs regenerated with check:generated --fix (content/docs/references/ai/record-context-tools.mdx, 2 rows twice).
  • Rework N4: one page cap. @objectstack/types exports resolveQueryReadPageCap(), the smaller of OS_DATA_MAX_PAGE_SIZE and OS_DATA_QUERY_ROW_BUDGET, undefined when neither is set; both doors answer pageCap from it, and their two local copies are gone. deleteRecordsCap is not changed.
  • Rework S1, the declaration: Clause-②: yes (widening). The published surface widens by optional members only: RecordContextDoor.pageCap?(), StdioDataBridgeDeps.security may carry getQueryableFields, and the new resolveQueryReadPageCap export. Precedent mcp: query_records and get_record say which fields field-level security withheld, so an answer says "not visible to you", not "blank" #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 37140 跟进:get_record_context 在运行时 HTTP 通道上用真执行器测一遍(含拒绝) #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.

Ablations (each committed first, mutated with scripts/ablation-replace.mjs, dist-preflighted where the subject resolves through dist, restored to the HEAD blob)
  • 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.

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 37177 跟进:资料包校验对平台注入字段(owner_id)误报 ai-context-field-unknown #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).
Local gates

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.

Seat note: the governing Claim on #37175 now names this branch (re-claim 7181502252), since the round-2 rig branch landed as PR #37350. Final-head readings (a50181d) are in the os-dev report 7181466841 on #37361.


Generated by Claude Code

…h doors supply queryableFieldsOf and their page cap

Co-authored-by: Claude <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Utp6CbeF2saT6wUBV4E9uc
…able answer and page cap, filtered parity, created_at order

Co-authored-by: Claude <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Utp6CbeF2saT6wUBV4E9uc
@github-actions github-actions Bot added size/l documentation Improvements or additions to documentation protocol:ai tests tooling Fix lands in tooling, not a product package — enters pm:queue only with Unblocks: or a named surface labels Nov 26, 2026
@github-actions

github-actions Bot commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

📓 Docs Drift Check

This PR changes 5 package(s): @objectstack/mcp, @objectstack/runtime, @objectstack/service-record-context, @objectstack/spec, @objectstack/types, touching 12 documentable anchor(s).

2 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))
  • content/docs/protocol/knowledge.mdx (via getQueryableFields (literal, a string literal in security))

⛔ 1 release-owned page(s) also name something this change touched. These are read-only:

  • content/docs/releases/v17/17-6.mdx (via getQueryableFields (literal, a string literal in security))

content/docs/releases/ is RELEASE-OWNED (AGENTS.md "Documentation Guardrails"): release
notes are written centrally at release time, and a code PR that edits them is the exact PR
that guardrail exists to stop. They are still audited — read-only. If one of them is actually
wrong, file an issue or open a dedicated docs-only PR; do not edit it here.

What this run could not see
  • 1 name(s) were too generic to anchor anything (single lowercase words)
  • 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 — 188 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 f9dd03315030d5ef5edd491d5f0ea7211824b729 → packageMentionDocs.

Which tree this was computed on

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

node scripts/docs-audit/affected-docs.mjs --json f9dd03315030d5ef5edd491d5f0ea7211824b729

⚠️ 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 f9dd03315030d5ef5edd491d5f0ea7211824b729 → 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#5 · os-bill · session_01Utp6CYtTDvfPQDzMbZnN5X

Contract-review-claim: session_01Utp6CYtTDvfPQDzMbZnN5X · head a50181d · 2026-11-26T03:17Z

The seat runs the at-tier contract review of this head through an isolated sub-agent; L1 is the seat's own.

@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

repo:objectstack#5 · os-bill · session_01Utp6CYtTDvfPQDzMbZnN5X

Contract review

Served-tier: CONTRACT_REVIEW_TIER
Head-sha: a50181d4e7d5b508fad66b05a45cd3141ed58e12
Local-runs: none
Scope: packages/spec/src/ai/record-context-tools.zod.ts + packages/services/service-record-context/src/record-context-tools.ts, packages/services/service-record-context/src/door.ts, packages/runtime/src/domains/mcp.ts, packages/mcp/src/stdio-data-bridge.ts, packages/services/service-record-context/src/tests/record-context-tools.test.ts, packages/runtime/src/mcp-record-context-tools-bridge.test.ts, .changeset/37361-record-context-left-out-queryable-doors.md
Security-touching: yes
Rule-change-verified: none

PR #37412 (cards #37361 and #37175), reviewed read-only: both card threads whole, the PR body, the net diff against main (8 files, +483/-44), ADR-0160 on main, and the check-runs on this head. Code outside the diff (plugin-security, query-read-limits.ts, the two doors' existing members, action-execution.ts) was read, not reviewed.

Check-runs on the head: 58 success, 11 skipped, 0 failure once the newer run of a repeated name governs. PR-body guards was red at 02:37:14Z (closing target #37175 claimed by another branch) and is green at 03:15:44Z, after re-claim 7181502252. Check Changeset is green on both runs. Check PR Size and Auto Label read skipped on the 03:15 re-run and were green at 02:37.

① Derived judgments

  • A related child this caller is not served: refused whole before, left out now. Right. ADR-0160 D3 "Object level" (amended 2026-11-25) says it in these words: "A related child that this caller is not served is left out … Nothing of the child is read, its definition included. Its section is not named." Step 4a adds the child to leftOut, sets hidden, and publishedOf answers null for it, so the plan, the projection, withheldAmong, diagnoseDelegation and the query never see it. Read for leaks: the answer carries no section, no row, no count and no field name of the child; the one note is not_visible with no object member. The service pin asserts the door was asked only readGuard, assertApiExposed, servedObjectDefinitionOf for the child, and that neither its name nor its label is in the serialized answer; the real-kernel pin asserts the same bytes on /mcp and stdio with a served control (rc_revision, row r1 only, so row security still holds beside it).
  • Gate order read guard, then API exposure, then the served definition. Right. D3 step 1 lists the three gates in that order. A child that is both unexposed and not served refuses unnamed, as before (shown is true only when the served definition is non-null, and a throw there reads as not shown). OBJECT_PACKAGE_DISABLED is outside API_EXPOSURE_REFUSALS, so it refuses unnamed under PERMISSION_DENIED, the one code point 12 gives. A served-definition read that throws now refuses unnamed where it used to fall into the unserved branch: without that, an outage would have become a left-out section, so this is the fail-closed reading and it is pinned.
  • The root's gates. Unchanged, right. Step 2 is not in the diff; the existing real-kernel case (a root the caller may not read answers as get_record does, pack unnamed) stays green on both doors.
  • queryableFieldsOf on both doors. Right, and not looser than plugin-security. Both doors return the security service's own getQueryableFields(object, caller): /mcp with the request's ec, stdio with resolvePrincipal(), each the same context its fieldVisibilityOf already uses, and stdio hands the real service through (plugin.ts securityReads). The executor admits a name only when it is in that answer AND in the caller's served schema (served.has(n) && queryable.has(n)), so the door can only narrow the service's answer. undefined falls to the contract's fallback; a throw drops the section and states it. The fields the fallback refused and the service admits are exactly masked fields whose rule is lifted for this caller, which the engine guard does not refuse either (the contract says the answer is "the exact complement of the fields those guards refuse"). The engine guard still stands behind both doors' query, so an over-wide answer would refuse the call, not disclose.
  • pageCap and the stated cut (point 14, D1's limit paragraph). Right in behaviour. cap = min(entry limit or row cap, pageCap - 1), limit: cap + 1, and the note carries cap. Both doors answer min(OS_DATA_MAX_PAGE_SIZE, OS_DATA_QUERY_ROW_BUDGET), which is what the data door refuses past for an offset-0 read (limit over the maximum page size; offset + limit over the budget). A cap that is absent, undefined, zero or fractional changes nothing; a probe that throws fails the call. Pinned on the service and, under OS_DATA_MAX_PAGE_SIZE=3, on both doors with equal bytes.
  • stdio and HTTP parity for a where pack. Right. rc_filtered (where, orderBy, limit 2) answers through both(); the drop for an unqueryable where field is pinned on both doors with the spy asserting each door asked for the same caller.
  • The spec change is prose only. Right. One doc comment on RecordContextNoteKind; no schema, no .describe() text, no generated artifact moves.
  • Fixes #37175. Legitimate. The card's What 1 to 3 and both acceptance lines landed in PR test(runtime): get_record_context answers one caller with the same bytes on the /mcp and stdio doors over a real kernel #37350; the one open half was amendment 4's door.ts sentence, which this diff adds, and whose behaviour test(runtime): get_record_context answers one caller with the same bytes on the /mcp and stdio doors over a real kernel #37350 already pins (rc_vault, apiEnabled: false, notVisible on both doors). The governing claim names this branch (7181502252) and the guard is green.

S1 (should-fix) — Clause-②: no is exact for the behaviour changes and inexact for pageCap. Refuse to left-out, and the doors' queryable answer, pull the code back to a contract ADR-0160 already declares, and a runtime permission change is outside clause ② by the seat's own negative boundary; the no cites the ADR section, as required. pageCap?() is a new optional member on RecordContextDoor, a type the package exports from its entry point, and StdioDataBridgeDeps.security gains an optional method: that enlarges a published surface. The nearest precedent, #35137 (the new optional McpDataBridge.fieldVisibilityOf), declared yes (widening). Direction ruled here: widening, by one optional member. The level is patch either way, no gate reads the arm for a non-breaking change, and the at-tier review a yes owes is this record, so it does not fail the head; correct both declaration lines at the next touch of the changeset, or have the seat's ACCEPT record why no stands.

② Semver level

patch on @objectstack/service-record-context, @objectstack/runtime, @objectstack/mcp and @objectstack/spec is right: a fix under existing ADR text, no authorable key, value or metadata type, so Metadata-protocol: none holds and takes patch; a widening by one optional TypeScript member also ships patch. The changeset body carries both declaration lines and describes all four behaviours, the new member included. Clause-②: see S1.

③ Boundary flags

  • Security-touching. The diff changes what a permission-narrowed caller receives on a read path. The maintainer's word for it is the first amendment of ADR-0160 (point 2). Nothing here widens a read: every row still arrives through the caller's own get and query.
  • Dev open question (which way for Fixes #37175): answered. Option A was taken (re-claim 7181502252); guard green.
  • Dev flag, N5 authoring lint: escalated to the seat. validateAiContext warns ai-context-field-unknown ("the list is left out of every answer") for orderBy: created_at, while the executor and both doors read the list (pinned here). An author is told the opposite of what runs. It is outside this diff and has no carrier yet; file it before 37203 跟进:get_record_context 无权的关联子对象改为省略、真实通道交出可查询字段,并补筛选排序的双通道比对 #37361 closes.
  • Dev flag, disabled-package child answers PERMISSION_DENIED, not OBJECT_PACKAGE_DISABLED: accepted. Point 12: every object-level refusal carries one code. The card's acceptance line names the case.
  • Dev flag, .describe() texts still say "row cap": see N3.
  • Dev flag, stdio reads plan no read window: noted. For get_record_context both doors now cut at the same row. Other stdio reads are not this PR's.
  • Dev deviation, origin/main not merged before the PR: accepted. CI ran on the merge ref; mergeable_state is clean.
  • A third door. pageCap is optional, so the product-registry door (row 9, cloud#4978) still cuts or refuses unstated until it reports a cap. For the seat to carry to that row.
  • SQL push-down. No new id materialisation and no in-app join: each related list is still one capped query with the filter, order and limit inside it.

④ Design judgment

packages/spec/src/ai/record-context-tools.zod.ts holds against its implementing code: related_truncated fires at limit, at the row cap, or under the door's cap, which is what the executor does and what D3's "Every cut is stated" sentence lists. The implementing files agree with ADR-0160 D3 and D4 as read in ①.

S2 (should-fix) — the direction a disclosure would ride is not pinned on the real kernel. The harness has one caller, who holds rc_unmask; no case shows a masked field whose rule is NOT lifted dropping the section with the statement on both doors. Reading shows it holds (the service leaves the field out; the engine guard refuses behind it), and the spy case covers "narrower than the fallback" only by altering the service's answer. Add a second caller without the capability to rc_unmasked_order.

S3 (should-fix) — the door.ts sentence that closes #37175 cites "(ADR-0160 D3, amendment 4)". ADR-0160 has a first, second and third amendment and no fourth; "amendment 4" is item 4 of card #37175's own amendment comment (7151678330), and the harness beside it says "[card amendment 4]". The citation ships in the package's .d.ts. Cite D3 "Object level" (its last paragraph: a lookup whose target the caller may not read is left unexpanded) or the card.

N1 (nit) — a related[].object that names no object at all now passes API exposure on both doors (no declaration, nothing to refuse), is not served, and is left out with not_visible for every caller, an admin included; before, it refused. The executor cannot tell the two apart without the read D3 forbids, and equal answers are the ADR-0106 rule, so this is the safe reading; it is not pinned, and it turns one author defect from a first-call refusal into a statement that reads as a permission.

N2 (nit) — D1 says a door with a lower page cap "cuts the list at that cap"; the list is cut one row under it, to keep the probe row. A door cap of 1 gives an empty list with "more rows than the 0 given". Stated in the changeset and the docblock; an ADR bookkeeping line for the landing seat.

N3 (nit) — RecordContextRelatedListSchema rows and truncated .describe() texts still say "row cap". They are the texts a model reads in the tool's output schema, and they have been short since limit landed (#37354). Outside N1's prose-only line; needs a carrier.

N4 (nit) — recordContextPageCap() is written twice, byte for byte bar indentation (domains/mcp.ts, stdio-data-bridge.ts), beside deleteRecordsCap in mcp-http-tools.ts, which computes the same minimum. Parity between the doors rests on two copies staying equal; one export in @objectstack/types would hold it.

Implemented-by: claude/issue-37361-left-out-queryable-doors
Reviewed-by: session_01Utp6CYtTDvfPQDzMbZnN5X

VERDICT: PASS

@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

repo:objectstack#5 · os-bill · session_01Utp6CYtTDvfPQDzMbZnN5X

席位核对

Head-sha: a50181d4e7
REWORK — L1, seat repo:objectstack#5: the three should-fix findings of contract record 7181694279 are fixed in this PR before landing. The rest of L1 reads clean.

  1. Shape: open draft against main, 8 files (+483/−44), Fixes #37361 and Fixes #37175. The second closes legitimately: the door.ts sentence was 37140 跟进:get_record_context 在运行时 HTTP 通道上用真执行器测一遍(含拒绝) #37175's only open half, and re-claim 7181502252 names this branch. l1-face flagged keywords-other-cards, which is intended. It also flagged the PR-body guard, which was red at 02:37Z and is green at 03:15Z after the re-claim.
  2. Premise: per the record, a child the caller is not served is left out and stated, and nothing leaks: no section, row, count or field name. The root's gates still refuse the whole call. Both doors return the security service's own getQueryableFields and are never looser than plugin-security. pageCap cuts are stated. stdio/HTTP where parity is pinned.
  3. Owed in this PR:
    • S1: pageCap adds an optional member to the exported RecordContextDoor, which enlarges a published surface. Declare Clause-②: yes (widening) in the PR body and the changeset; precedent mcp: query_records and get_record say which fields field-level security withheld, so an answer says "not visible to you", not "blank" #35137. The level stays patch.
    • S2: add a real-kernel pin on both doors showing that a masked field whose rule is not lifted for the caller drops the section. The harness's one caller holds rc_unmask.
    • S3: the door.ts sentence cites "(ADR-0160 D3, amendment 4)", but ADR-0160 has no fourth amendment, and the citation ships in the .d.ts. Cite D3, or the card comment 7151678330 item 4.
      The same reviewer reads the delta.
  4. Accepted deviations: contract nits N1 (an unknown related[].object is now left out, unpinned), N2 (the cut lands one row under the door cap, an ADR D1 bookkeeping line), N3 (the rows/truncated describes still say "row cap") and N4 (recordContextPageCap() is duplicated). N3 and N4 may ride along with the fix.
  5. Out of scope and where it went: the validateAiContext warning that an orderBy: created_at list "is left out" contradicts the executor. That goes to 37177 跟进:资料包校验对平台注入字段(owner_id)误报 ai-context-field-unknown #37415.
  6. Landing terms: ungoverned, default tier, Security-touching: yes. A same-head at-tier PASS with S1–S3 closed is owed, then ACCEPT. The area lands it.

…, exact citations

- @objectstack/types exports resolveQueryReadPageCap(); both MCP doors answer
  pageCap from it instead of two local copies.
- door.ts cites ADR-0160 D3 "Object level" for the unexpanded-lookup sentence.
- The related list's rows/truncated describes name the entry's limit and the
  door's page cap; reference docs regenerated.
- Real-kernel harness: a second caller without rc_unmask; an orderBy on the
  masked serial drops the section with not_visible on both doors, with the
  rc_unmask caller as control.
- Changeset declares the widening and the types bump.

Co-authored-by: Claude <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Utp6CbeF2saT6wUBV4E9uc
@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

repo:objectstack#5 · os-bill · session_01Utp6CYtTDvfPQDzMbZnN5X

Contract review

Served-tier: CONTRACT_REVIEW_TIER
Head-sha: 88a1447c951570e533ee1cb7c4b21be8e44a5f53
Local-runs: none
Scope: packages/spec/src/ai/record-context-tools.zod.ts + packages/types/src/query-read-limits.ts, packages/types/src/query-read-limits.test.ts, packages/services/service-record-context/src/door.ts, packages/runtime/src/domains/mcp.ts, packages/mcp/src/stdio-data-bridge.ts, packages/runtime/src/mcp-record-context-tools-bridge.test.ts, content/docs/references/ai/record-context-tools.mdx, .changeset/37361-record-context-left-out-queryable-doors.md
Security-touching: yes
Rule-change-verified: none

Delta review of PR #37412 (cards #37361 and #37175) after its rework: one commit, 88a1447c, on a50181d4e, the head record 7181694279 reviewed. Read-only: the delta diff (9 files, +132/-58), the PR body as it stands, the #37361 comments after that record (claim amendments 7181717837 and 7183121810, delta report 7183101611), and the check-runs on this head. record-context-tools.ts and its service test are byte-identical to the reviewed head, so every judgment of the first record on the executor stands and is not repeated.

Check-runs on the head: 62 success, 12 skipped, 0 failure. PR-body guards and Check Changeset are green on both of their runs (04:30Z and 04:31Z); Check PR Size and Auto Label read skipped on the 04:31 re-run and were green at 04:30. mergeable_state is clean.

① Derived judgments

  • resolveQueryReadPageCap(), a new export of @objectstack/types. Right, and declared. It reaches the package entry through export * from './query-read-limits.js'. Its body is the removed door-local function, word for word: the smaller of maxPageSize and rowBudget from resolveQueryReadLimits(env), undefined when neither is set, and it throws on an unreadable value as that function does. Four unit cases pin unset, one set, both set in either order, and the throw. The changeset names it twice (the surface sentence and its own bullet), the PR body names it under S1, and @objectstack/types takes a patch entry, so the widening declaration covers it. Claim amendment 7183121810 adds the file, its test and the changeset entry to the surface: fenced.
  • Both doors answer pageCap from that one function. Right. The two local copies are deleted and nothing else in either door moves; the real-kernel case under OS_DATA_MAX_PAGE_SIZE=3 is unchanged and green, so the cut is the same row as on the reviewed head.
  • The rows and truncated descriptions of a related list. Right. They are text in the tool's output schema and change no accepted or produced shape. Both now say what the executor does: up to the entry's limit, else the row cap, or fewer under the door's page cap. The reference page moved with them in both of its tables and no other generated artifact did; the generated-artifact gates are green. Fenced by claim amendment 7181717837.
  • The second caller in the real-kernel harness. Right. rc_unmask left the baseline set and sits in rc_unmasker, granted to usr_member alone through a sys_user_permission_set answer that the real resolveAuthzContext resolves. The case asserts its own preconditions first: the two contexts differ in the capability, the real service lists serial as queryable for one and not the other, and the stdio door's root read carried usr_plain. The earlier cases still run as usr_member, and the case that needs the capability asserts the caller holds it.

S1: closed. The PR body and the changeset both read Clause-②: yes (widening) at line start, with Metadata-protocol: none. The changeset lists the three additions: RecordContextDoor.pageCap?(), the optional getQueryableFields on StdioDataBridgeDeps.security, and resolveQueryReadPageCap. Claim amendment 7181717837 carries the corrected line.

② Semver level

patch on five packages is right: the widening is non-protocol (optional TypeScript members and one function), which ships patch, and Metadata-protocol: none takes patch. @objectstack/types is in the changeset because it now publishes the new export; @objectstack/spec stays in for the doc line and the two descriptions.

③ Boundary flags

  • Security-touching, unchanged. The rework adds no read and changes no gate; its one production change is where the page cap is computed.
  • Dev deviation, the types surface was outside amendment 7181717837 when the commit was made: answered. Amendment 7183121810 records it, after the report.
  • Dev deviation, origin/main not merged: accepted. CI ran on the merge ref and the PR merges clean.
  • N5 of the card (the validateAiContext warning on orderBy: created_at): carried. The report names 37177 跟进:资料包校验对平台注入字段(owner_id)误报 ai-context-field-unknown #37415 as its carrier. The first record's escalation is answered.
  • Dev note, the harness names the key's owner per call through its proxy: accepted. It is how one stdio session reads as two users; the case proves the stdio read's context before it trusts the answer.
  • SQL push-down. Nothing new: no id materialisation and no in-app join in the delta.

④ Design judgment

packages/spec/src/ai/record-context-tools.zod.ts holds against the executor: the three places a list is cut are the three the two descriptions and the related_truncated doc line name. packages/types/src/query-read-limits.ts holds against the data door it describes: an offset-0 read is refused past the maximum page size or past the row budget, so the smaller is the most such a read may ask for.

S2: closed. The direction a disclosure would ride is now pinned on the real kernel, on both doors with equal bytes: as usr_plain, the pack ordered by the masked serial answers without error, with no related member, one not_visible note with no object, and none of rc_step, the quoted field name, a serial value or a row name in the text. The control leg in the same case reads the four rows in serial order as usr_member. The reported ablation (&& to || in the queryable check) turned this case into a whole-call refusal by the engine guard, which is the fail-closed backstop the first record read.

S3: closed. The door.ts sentence cites ADR-0160 D3 "Object level", the section whose last paragraph says a lookup whose target the caller may not read is left unexpanded.

N3: closed. See ①.

N4: closed. See ①. deleteRecordsCap keeps its own minimum against its 200-row constant, which is a different number and is left alone.

N1 (nit) — open, unchanged. A related[].object that names no object is left out with not_visible for every caller. Still unpinned.

N2 (nit) — open, unchanged. ADR-0160 D1 says a door "cuts the list at that cap"; the list is cut one row under it. An ADR bookkeeping line for the landing seat.

N5 (nit) — new. The seat note that closes the PR body still says "Final-head readings (a50181d) are in the os-dev report 7181466841". The body's own readings are at 88a1447c9 and the final-head report is 7183101611. The note is the seat's to correct.

Implemented-by: claude/issue-37361-left-out-queryable-doors
Reviewed-by: session_01Utp6CYtTDvfPQDzMbZnN5X

VERDICT: PASS

@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

repo:objectstack#5 · os-bill · session_01Utp6CYtTDvfPQDzMbZnN5X

席位核对

Head-sha: 88a1447c951570e533ee1cb7c4b21be8e44a5f53
ACCEPT — L1, seat repo:objectstack#5

  1. Shape: open draft against main, +573/−60, Fixes #37361 (with 37140 跟进:get_record_context 在运行时 HTTP 通道上用真执行器测一遍(含拒绝) #37175), Clause-②: yes (widening), Metadata-protocol: none, patch on five packages including @objectstack/types. The rework since a50181d4e is one commit. The new surface (query-read-limits.ts, its test, the changeset entry) is fenced by claim amendment 7183121810.
  2. Rework closed (delta contract record 7183158602):
    • S1: the widening is declared, and all three additions are named, resolveQueryReadPageCap included.
    • S2: a second real-kernel caller usr_plain with no rc_unmask. The masked orderBy drops the section with not_visible on both doors, with no refusal and no leak. The control is usr_member, and the ablation turned 2 red.
    • S3: door.ts cites ADR-0160 D3 "Object level".
    • N3 and N4 are closed: one page-cap reader is shared by both doors.
  3. Gates: check-runs at 88a1447c95: 62 success, 12 expected skip, 0 failed. PR-body guards and Check Changeset are green, and the branch merges clean.
  4. Accepted deviations:
    • Nit N1: an unknown related[].object is left out with not_visible, which is unpinned.
    • Nit N2: ADR D1 says "cuts the list at that cap", but the code cuts one row under it. That is an ADR bookkeeping line.
    • Nit N5: the seat note at the foot of the PR body still cites the a50181d4e readings and report 7181466841. The final-head report is 7183101611, and this ACCEPT supersedes that note.
  5. Out of scope and where it went: the card's lint contradiction (N5 of the first round) goes to 37177 跟进:资料包校验对平台注入字段(owner_id)误报 ai-context-field-unknown #37415 / PR fix(lint): a context pack may name a system column the platform injects #37426.
  6. Landing terms: ungoverned (633 lines, under threshold), Security-touching: yes. L2 at CONTRACT_REVIEW_TIER: PASS, comment 7183158602, same head, no must-fix, no should-fix. The area lands it.

@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

repo:objectstack#5 · os-bill · session_01Utp6CbeF2saT6wUBV4E9uc

Landing: ACCEPT 7183165768 (delta L2 PASS 7183158602) at head 88a1447c951570e533ee1cb7c4b21be8e44a5f53.

Probe Reading
Check-runs on head 62 success, 12 skipped, 0 failed, 0 pending
Governed / size check-governed-merges --pr 37412: NOT governed, 633 changed lines ≤ 3000; mergeable_state clean

Status: ready + auto-merge (merge queue). On MERGED, #37361 and #37175 close by Fixes; #37233 and #37141 are released, #37414 waits on #37409, #37432 on #37426.

@objectstack-fleet
objectstack-fleet Bot marked this pull request as ready for review November 26, 2026 05:06
@objectstack-fleet
objectstack-fleet Bot added this pull request to the merge queue Nov 26, 2026
Merged via the queue into main with commit 8d60333 Nov 26, 2026
75 checks passed
@objectstack-fleet
objectstack-fleet Bot deleted the claude/issue-37361-left-out-queryable-doors branch November 26, 2026 05:34
Nenzyz pushed a commit to Nenzyz/objectstack that referenced this pull request Dec 1, 2026
…ts (objectstack-ai#37426)

Fixes objectstack-ai#37415

Clause-②: no (ADR-0160 D3: "A name the published definition lacks is an
author defect"; an injected column is in the published definition, so
the warning on it was the defect)
Metadata-protocol: none

## 维护者速读

- 写资料包的作者:在资料包里写平台自动加的字段(负责人、创建时间等),保存和校验时不再误报「字段不存在」;平台没加的字段照旧提醒。
- 属于「AI 资料包」专题的跟进,替写资料包的作者解决误报。
- 出错只会多报或少报一条提醒,资料包照常保存和读取;可以直接撤回。
- 无。

## What changes

Measured first, on one real kernel (the `/mcp` door, the real protocol,
`SqlDriver`, `sys_user` registered as the platform registers it): on an
object that declares neither `owner_id` nor `created_at`, the served
object listing carries both (plus `organization_id`, `created_by`,
`updated_at`, `updated_by`, `owning_business_unit_id`, `queue`), and
`get_record_context` answers `owner_id` and `created_at` in the root's
`fields` and in a related list's `fields` (`owner_id` as a lookup entry,
its value marked `notVisible` because the harness caller cannot open the
`sys_user` row, as for any lookup whose target row it cannot read),
filters the list by a `where` on `owner_id` (one of two rows came back,
the caller's) and orders it by `created_at`. On an `ownership: 'org'`
object the listing carries no `owner_id` and the tool leaves it out. So
the runtime carries injected columns, and the warning was false.

- `packages/lint/src/validate-ai-context.ts`: `fieldMapOf` now returns
the effective map, the declared fields plus
`injectedColumnDefsFor(object)` (this package's one indirection over the
spec's `injectedSystemColumnDefs`, the tables `applySystemFields` and
the served read's `applyInjectedSystemColumns` spread), a declared field
winning. Every place the rule reads a field map reads it: root `fields`,
`body.field`, related `fields`, `where`, `orderBy`, and the related
link. The `orderBy` sortability projection now reads the same effective
map instead of the declared fields.
- Consequences, each matching the runtime: a `body.field` naming an
injected column is judged by its type (`ai-context-body-not-long-text`,
as the executor reads the served definition); on a related list whose
root is a `sys_*` object, the child's injected references to it
(`owner_id`, `created_by`, `updated_by` to `sys_user`) count as links,
as `resolveRelatedLink` counts them over the published definition, so a
child with one declared reference and no `field` is reported as having
several. No non-`sys_*` root is affected: every injected reference
points at a `sys_*` object.
- A column the platform does not inject on that object is still
reported: `owner_id` under `ownership: 'org'` / `'none'`, every system
column under `systemFields: false`.
- `.changeset/37415-ai-context-injected-columns.md`: `@objectstack/lint`
patch.

### Read first (by risk)

1. `packages/lint/src/validate-ai-context.ts`, the `fieldMapOf` hunk:
the merge direction (declared wins) and the sortability line.
2. `packages/lint/src/validate-ai-context.test.ts`, the four new cases,
especially the `sys_*` root link case.
3.
`packages/services/service-record-context/src/__tests__/injected-system-columns.test.ts`:
the executor half over a door serving the registry-injected shape.

### Two-minute verification

`pnpm --filter @objectstack/lint exec vitest run
src/validate-ai-context.test.ts` shows 22 passed, including "an injected
system column the object does not declare is no unknown field (owner_id,
created_at)".

## Tests

- `packages/lint/src/validate-ai-context.test.ts`: `owner_id`,
`created_at`, `created_by` in root `fields`, related `fields`, `where`,
`orderBy` on objects that do not declare them: no finding. `ownership:
'org'` keeps `owner_id` unknown in all four places; `systemFields:
false` keeps `created_at` unknown. `body.field: 'created_at'` is
`ai-context-body-not-long-text`. `sys_*` root: injected references count
as links.
-
`packages/services/service-record-context/src/__tests__/injected-system-columns.test.ts`
(new, read-only use of the service): over the fake door serving
`injectedSystemColumnDefs` merged under the declared fields, the
executor answers `owner_id` (with the `sys_user` display) and
`created_at` in root and related fields, filters by `where: { owner_id
}` and orders by `created_at desc`; the same pack over a door serving
declared fields only leaves every such name and the list out, silently.

## Acceptance notes

- Acceptance bullet 1 (a test pins the lint verdict for `owner_id` on an
object that does not declare it, matching the measured runtime answer):
the first new lint case; the measured runtime answer is quoted in a
comment above it and in the service test's header.
- Corroboration: the real-kernel harness on sibling PR objectstack-ai#37412 shows the
executor and both MCP doors read a related list ordered by `created_at`
on an object that does not declare it, while the rule warned
`ai-context-field-unknown`: the same runtime answer for `created_at` in
`orderBy`, measured independently. `owner_id` was measured here.
- Measurement method: the real-kernel reading was a scratch copy of the
real-protocol harness in
`packages/runtime/src/mcp-record-context-tools-bridge.test.ts`, run once
and deleted, never committed (`packages/runtime/**` is fenced for this
card). The committed pin of the executor half is the new service test
over the fake door.
- Without `sys_user` registered (a composition the platform never
ships), naming `owner_id` refuses the whole call `PERMISSION_DENIED`
("reads an object you cannot read"): `owner_id` is a lookup to
`sys_user`, and an unreadable lookup target refuses the call, as for any
lookup. Measured, noted, not filed.
- The `os explain` text for `ai-context-field-unknown`
(`packages/lint/src/rule-explanations.ts`) still says "a name the object
does not define"; it is outside this card's file surface and stays
correct in substance (an injected column is defined on the object).
Noted, not changed.
- An ADR-0015 `external` object carries injected columns with no storage
behind them; this rule now lets a pack name one (the published
definition carries it, so the executor plans it), and the read degrades
at query time. The provenance warning other rules give
(`unprovisionedInjectedColumnsFor`) is not wired into this rule. Filed
as objectstack-ai#37432 (an own rule id and an `os explain` entry), which also carries
folding `injected-system-columns.test.ts` into
`record-context-tools.test.ts` once objectstack-ai#37361 lands.
- The new service test is a new file, as the dispatch order and the
claim's file surface direct; the shared executor test file is owned by
an in-flight sibling card.

## Verification

<details><summary>Real-kernel measurement (scratch, deleted)</summary>

```text
MEASURE served-listing rcm_policy fields: organization_id,created_at,created_by,updated_at,updated_by,owner_id,owning_business_unit_id,queue,title
MEASURE served-listing rcm_orgdoc fields: organization_id,created_at,created_by,updated_at,updated_by,title
rcm_brief (fields title, owner_id, created_at; related fields version, owner_id; where owner_id; orderBy created_at desc), sys_user registered:
  fields: title "Fire cover", owner_id (label Owner, notVisible: the sys_user row is not readable to this harness's caller), created_at "2026-11-26T03:16:17.088Z"
  related rcm_revision rows: r1 only (v1, owner_id) -- r2 (owner usr_other) filtered out by the where on owner_id
rcm_c (related fields version, created_at; where owner_id usr_member; orderBy created_at desc): rows r1 only (v1, created_at)
rcm_org_brief (ownership org; fields title, owner_id): fields title only
rcm_b (fields title, owner_id) WITHOUT sys_user registered: PERMISSION_DENIED 403
```

</details>

<details><summary>Ablation (one, on the chosen behaviour)</summary>

Deleted the injected-column merge line in `fieldMapOf` via
`scripts/ablation-replace.mjs` (anchor x1 to x0, blob c2119a5 to
2c8b47c54ad1); `validate-ai-context.test.ts` went 3 failed / 18 passed
(the injected-column case, the ownership-org case through `created_at`,
the body case); restored, blob equals HEAD (c2119a5), `git diff
HEAD` empty. The lint test imports the rule from source, so no build leg
applies.

</details>

<details><summary>Package suites and gates</summary>

All at head `83f809e90`, through the verify lock (`VERDICT command-exit
0`, 129 s held):

```text
pnpm --filter @objectstack/service-record-context test       Test Files 3 passed (3) · Tests 102 passed (102)
pnpm --filter @objectstack/service-record-context typecheck  exit 0 (tsc --noEmit + check-test-typecheck)
pnpm --filter @objectstack/lint test                         Test Files 235 passed (235) · Tests 9637 passed (9637)
pnpm --filter @objectstack/lint typecheck                    exit 0 (tsc --noEmit + check-test-typecheck)
```

Gates: `node scripts/pm/dispatch-gates.mjs --commands` derived 64
families for this diff; all 64 run locally, 62 exit 0, 2 exit 3
(PREREQUISITE NOT MET, read as NOT MEASURED, left to CI): `node
scripts/check-plugin-teardown-shape.mjs --self-test` (its pinned
positive control needs an unshallow clone) and `pnpm
check:dual-build-cjs-loads` (reads every package's `dist/`; only the
runtime closure is built here). `--ran` reconciliation: 64 derived, 62
run, 2 NOT-MEASURED, 0 UNRUN. Package-closure build ahead of these:
`pnpm --workspace-concurrency=2 --filter '@objectstack/runtime^...'
build` (includes `@objectstack/lint` and
`@objectstack/service-record-context`), `VERDICT command-exit 0`.

</details>

---

_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
…efusals (objectstack-ai#37438)

<!-- claude-projects-attribution: {"github_login":"os-bill"} -->
_Requested by **Bill** · [project
thread](https://claude.ai/code/project/chan_016iMXWSZDzqWRWvWzdNo8wg?thread=cmsg_016iMXWSZDzqWRWvWzdNo8wgToQGw4qwp7m57qUh2sLcjt)_
Fixes objectstack-ai#37418

Clause-②: yes (widening) — new optional third argument of the exported
verifyRecordCitations and two new exported types; existing calls
unchanged
Metadata-protocol: none

## 维护者速读

- 用户能看到什么变化:用户无感;AI 回答里的引用核对时,数据库故障不再被当成「无权查看」悄悄丢掉,而是报给后台。
- 为什么做:AI 回答引用专题的后续,替云端产生引用的那一步和运维排障的人解决「一次故障让引用永久消失且无人知晓」。
-
出错会怎样:故障时引用照样不显示(宁缺勿错),只是多报一条错误;无权查看和记录不存在对后台仍是同一个结果,不泄露记录是否存在;可直接撤回本改动。
- 要你做什么:无。

## What changes

`verifyRecordCitations(citations, door, options?)` in
`packages/services/service-record-context/src/verify-citations.ts`:

- **Refusal vs failure.** A throw carrying an ADR-0112 `code` with a
declared 4xx status is a refusal. The status is read as ADR-0112's
reader (`resolveThrownHttpError`'s `declaredStatus`) reads it, `.status`
then `.statusCode`, mirrored locally because the package does not depend
on `@objectstack/types`. A refusal is the only shape
`get_record_context` refuses with: its citations are dropped and nothing
is reported, as before. Any other throw (no code, a driver code with no
status, a 5xx) is a failure: its citations are dropped too, so the
result stays fail-closed, and the failure goes to the new optional
`options.onError(error, call)`, once per verifying call. A callback that
throws, or returns a promise that rejects, is ignored, so the verifier
still never throws for a citation and leaves no unhandled rejection. The
served-definition read behind the HTML-body check reports too; there the
call answered and only the tag-removed reading is lost, which the
option's JSDoc says.
- **Why status, not the code string.** ADR-0112's 2026-08-27 amendment
names the status channel as the one structural signal between a refusal
and a fault: a driver errno (`ECONNRESET`, `SQLITE_ERROR`) also arrives
on `.code`, so the string alone cannot tell.
- **Design choice: a callback, not a new result shape.** It is the
smaller change. The return type stays `RecordCitationParsed[]`, existing
two-argument callers see nothing, and the result carries nothing that
could tell a caller a hidden record from a missing one. A `{ verified,
unverifiable }` result would put the failure next to data the caller may
see, and would change the signature every caller reads.
- New exported types `VerifyRecordCitationsOptions` and `VerifyingCall`
(`src/index.ts`).
- **Nits from the PR objectstack-ai#37396 review:**
- The module doc says which list cap a producer gets: the verifier reads
the first 20 (`RECORD_CITATIONS_MAX`) and drops the rest, where
`RecordCitationsSchema` refuses a list of 21.
- The module doc corrects the "tag-stripping only makes verification
stricter" note: the tag-removed reading is a second string, and removing
a tag joins adjacent text (`<p>Fire</p><p>cover</p>` reads `Firecover`).
A test pins it.
- `stripBodyTags` (`packages/spec/src/ai/record-body-anchor.ts`) says it
is not a sanitizer. JSDoc only.

## Tests

`src/__tests__/verify-citations.test.ts`, new block "a refusal and a
failure":

- A door whose root read throws an uncoded `Error`: citations dropped,
failure reported once per distinct call (two calls, three citations →
two reports). Control: the same citations verify through a door that
answers.
- A driver code with no status and a coded 500: dropped and reported.
- Control: coded 403, 404 and 400 refusals: dropped, not reported.
- A refused read (`unreadableRows`) and a missing record (`p404`) give
the host the identical `{ quotes: [], reported: [] }`, with a control
leg that verifies the readable record.
- A throwing callback is ignored; no callback still drops the failed
call.
- Rework (contract review 7184346569, seat REWORK 7184355118): a coded
refusal declared with `statusCode` only is not reported (control: coded
503 `statusCode` is); a 4xx with no code, a thrown string and a thrown
`undefined` are reported; a failing definition read behind an HTML body
is reported once while the field quote and the as-stored quote still
verify; an async callback that rejects leaves no unhandled rejection.
- The adjacent-text join of the tag-removed reading.

Ablation (one, on the coded-vs-uncoded split): `isRefusal` reduced to
"has a string code" → "reports a driver code with no status, and a coded
5xx, as failures" goes red (1 failed, 20 passed); restored → green.
Rework ablations: dropping the `.statusCode` limb → the statusCode-only
test red (1 failed | 24 passed); dropping the returned-promise handler →
the async-callback test red (1 failed | 24 passed); both restored →
green.

## Acceptance notes

- `record-context-tools.ts` (fenced, sibling objectstack-ai#37361) turns some door
failures into coded refusals before they reach the verifier: a failing
related-object definition read or published-definition read becomes
`PERMISSION_DENIED` 403 so the refusal names nothing. Those failures are
therefore not reported, and the module doc now says so. The follow-up
card is objectstack-ai#37463.
- The whole 4xx band is a refusal, so a door declaring a coded 408 or
429 would drop a transient condition without a report. No door on the
read path declares one today; the module doc records it (review N4).
- `Clause-②: yes (widening)` (seat ruling, same as the objectstack-ai#37412
precedent): the new parameter is optional and the return type is
unchanged, so no existing caller changes; there is no caller outside
this package today. Bump stays patch.

## Verification

Two-minute check: `pnpm --filter @objectstack/service-record-context
exec vitest run src/__tests__/verify-citations.test.ts` — 25 tests pass.

Read first: `verify-citations.ts` `isRefusal`, `declaredStatusOf` and
`report` (the split and the async guard), then the `haystackOf` catch.

---
_Generated by [Claude
Code](https://claude.ai/code/session_01Utp6CZnFSe9yjMwBFr33Rk)_

<!-- signed: repo:objectstack#5 · os-bill ·
session_01Utp6CZnFSe9yjMwBFr33Rk -->

---------

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

documentation Improvements or additions to documentation protocol:ai size/l tests tooling Fix lands in tooling, not a product package — enters pm:queue only with Unblocks: or a named surface

Projects

None yet

2 participants