Repository navigation
feat(spec,service-record-context): the record citation shape, and the verifier that checks a quote as the asking user (ADR-0160 D9) - #37396
Conversation
…verifier (ADR-0160 D9) Co-authored-by: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Utp6CbeF2saT6wUBV4E9uc
…e, and add the changeset Co-authored-by: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Utp6CbeF2saT6wUBV4E9uc
Co-authored-by: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Utp6CbeF2saT6wUBV4E9uc
📓 Docs Drift CheckThis PR changes 2 package(s): 6 hand-written doc(s) NAME something this change touched and may need an implementation-accuracy re-verification:
What this run could not see
Coarse fallback — 176 page(s) merely mention a changed package (the pre-#9192 predicate, kept for the deliberately-wide backstop): Which tree this was computed onThis run read A worktree cut from an older # while this PR is open — GitHub drops the merge commit once it closes
git fetch origin 3d99d201fafbeece3646399bd8ab6c5c1ff2a981 && git checkout 3d99d201fafbeece3646399bd8ab6c5c1ff2a981
# afterwards, rebuild it from the two parents, which stay fetchable
git fetch origin 5bf724223cabc05aecbc0f2130c0dafcdf467e1c 8471b77d705d386251204a83ee11281712e47074 && git checkout -B drift-repro 5bf724223cabc05aecbc0f2130c0dafcdf467e1c && git merge --no-ff 8471b77d705d386251204a83ee11281712e47074
node scripts/docs-audit/affected-docs.mjs --json 5bf724223cabc05aecbc0f2130c0dafcdf467e1c
|
…entory Co-authored-by: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Utp6CbeF2saT6wUBV4E9uc
|
repo:objectstack#5 · os-bill · session_01Utp6CYtTDvfPQDzMbZnN5X Contract-review-claim: session_01Utp6CYtTDvfPQDzMbZnN5X · head 8471b77 · 2026-11-26T03:00Z The seat runs the at-tier contract review of this head through an isolated sub-agent; L1 is the seat's own. |
|
repo:objectstack#5 · os-bill · session_01Utp6CYtTDvfPQDzMbZnN5X Contract reviewServed-tier: Inputs read: card #37364 (body, 4 comments, os-dev report 7181284963), PR #37396 body, the net diff ① Derived judgments
② Semver level
③ Boundary flags
④ Design judgment
Findings: S1 (should-fix) — A failure that is not a refusal is dropped the same way as a refusal, with no signal. S2 (should-fix) — Two kinds of record material inside the data member are never matched, and neither the card nor D9 rules on them: a non-string N1 (nit) — N2 (nit) — The PR body says tag-stripping "only makes verification stricter, never looser". That is not exact: removing tags with nothing in their place joins adjacent elements, so N3 (nit) — N4 (nit) — A citation with an N5 (nit) — A one-character quote parses ( N6 (nit) — All distinct tuples are read at once: up to 20 concurrent No must-fix. Both should-fix findings are questions for the seat to settle before cloud 10c reads the verifier; neither makes the code disagree with the card or with D9. Implemented-by: VERDICT: PASS |
|
repo:objectstack#5 · os-bill · session_01Utp6CYtTDvfPQDzMbZnN5X Seat ruling on the record's two should-fix findings (record 7181386892)The seat settles both by card scope. Neither needs a code change on this head.
The same reviewer re-reads this head with these two rulings in hand. |
|
repo:objectstack#5 · os-bill · session_01Utp6CYtTDvfPQDzMbZnN5X Contract reviewServed-tier: This record replaces the earlier one on the same head (7181386892); the head is unchanged. Inputs read: card #37364 (body, 4 comments, os-dev report 7181284963), PR #37396 body, the seat's ruling 7181397348 on the PR, follow-up card #37418, the net diff ① Derived judgments
② Semver level
③ Boundary flags
④ Design judgment
Findings: S1: closed — settled by the seat's ruling (PR comment 7181397348) on card scope. The card orders "Any refusal ⇒ not verified … never throws per citation", and this head fails closed, which is what it asks. Telling an outage from a refusal is filed as follow-up #37418 (open, S2: closed — settled by the same ruling. ADR-0160 D9 on N1 (nit) — N2 (nit) — The PR body says tag-stripping "only makes verification stricter, never looser". That is not exact: removing tags with nothing in their place joins adjacent elements, so N3 (nit) — N4 (nit) — A citation with an N5 (nit) — A one-character quote parses ( N6 (nit) — All distinct tuples are read at once: up to 20 concurrent No must-fix. S1 and S2 are closed by the seat's ruling 7181397348, and S1's substance is carried by #37418. Six nits remain; none affects correctness or the contract, and N1 to N3 ride #37418. Implemented-by: VERDICT: PASS |
|
repo:objectstack#5 · os-bill · session_01Utp6CYtTDvfPQDzMbZnN5X 席位核对Head-sha:
|
|
repo:objectstack#5 · os-bill · session_01Utp6CbeF2saT6wUBV4E9uc Landing: ACCEPT 7181455245 (L2 PASS re-record 7181443752) at head
Status: ready + auto-merge (merge queue). On MERGED, #37364 closes by |
|
repo:objectstack#5 · os-bill · session_01Utp6CbeF2saT6wUBV4E9uc Dequeued (CI_FAILURE) from merge group |
…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>
Fixes #37364
Clause-②: yes
Metadata-protocol: added
Skills-docs: follow-up #37177
维护者速读
What changes
Governing text: ADR-0160 D9 as amended by #37370 (third amendment), ruling 7177410380 on #37144 (Q1 A, Q2 A, Q3 A), ADR point 23.
Spec (
@objectstack/spec/ai)record-citation.zod.ts(new):RecordCitationSchema={ object, id, context?, anchor?, quote }, closed withstrictObject(unknown key refused, near-miss aliases such asobjectName/recordId/pack/section/text), every stringmin(1).RecordCitationsSchema= an array of at mostRECORD_CITATIONS_MAX(20).RECORD_CITATIONS_PART_TYPE = 'data-record-citations': the UI-message data part that carries the verified list (the precedent isBUILD_PROGRESS_FRAME_TYPE).record-body-anchor.ts(new):headingsOfandslugOfmoved here unchanged fromservice-record-context/src/body-outline.ts, together with the private readers they need. This way the server and the console derive the same anchor.slugOfstays module-private, as before. The tag readerheadingsOfalready used is exported asstripBodyTags, because the verifier matches an html body with the same notion of a tag.authorable-surface/ai.json(5RecordCitationrows),json-schema.manifest,api-surface,export-origins,declaration-map,content/docs/references/ai/*, and the strictness-ledger count (ai/113 to 114), all written bycheck:generated --fix.Service (
@objectstack/service-record-context)body-outline.tsre-importsheadingsOfandBodyHeadingfrom spec and re-exports them.body-outline.test.tspasses untouched.verify-citations.ts(new),verifyRecordCitations(citations, door), exported fromsrc/index.ts. It never persists or renders.The matching rule, which ADR-0160 D9 leaves to row 10 and which the card's What 3 settles. A citation survives only when its trimmed
quoteis a substring of one of these data-member strings ofget_record_context's answer for its(object, id, context, anchor), read through the door bound to the asking user:valuewhen it is a string, and itsdisplay, at the root and in every related-list cell (Q3: a related-row quote is cited on the root record);body.text(the whole body, or the sectionanchornamed). Anhtml/richtextbody (judged by the type the caller is served) is also matched with its tags removed.Whitespace runs collapse to one space on both sides. Case and every other character must agree. These are never matched: notes, the framing sentence, any label, the pack/record header (
pack.*,record.*, a row'sdisplayName), outline headings, and a value that is not a string (a number, boolean, list or object; itsdisplayis matched where present). A quote that is empty once trimmed verifies nothing.What the verifier does with the list. It makes one
executeGetRecordContextcall per distinct tuple. Any refused call drops its citations (point 23): acontextno pack has, several packs and nocontext(Q2), an anchor that does not resolve, a record the caller cannot read or that does not exist, an object not served, guarded or unexposed. No retry without the offending argument. An entry that does not parse is dropped, and only the first 20 entries are read. The result is the verified subset in input order, with no reason attached, so a hidden record and a missing one look alike.Read first (by risk)
packages/services/service-record-context/src/verify-citations.ts:haystackOfholds the matching rule above. The risky part is which strings it collects.packages/spec/src/ai/record-citation.zod.ts: the public shape, the aliases and the cap of 20.packages/services/service-record-context/src/body-outline.ts: the move. Byte-identical logic now lives inpackages/spec/src/ai/record-body-anchor.ts(onlystripTagswas renamed to the exportedstripBodyTags).Tests
packages/spec/src/ai/record-citation.test.ts(6): the shape refuses an unknown key (unrecognized_keys), an emptyquote(too_small), a missingquoteandnull(invalid_type), an emptycontext/anchor. It admitscontextandanchor. The list is capped at 20 (too_big). The part type is pinned.packages/services/service-record-context/src/__tests__/verify-citations.test.ts(16), one per acceptance bullet plus the rule. Each "dropped" case has a control leg:contextrefused, one pack verified, named packs verified, unknown pack refused;[];listCalls= 2 for 5 citations), unparsable entries dropped, cap of 20, html/richtext tag-stripped and markdown not, whitespace collapse, non-string value not matched.Readings (head 36ec0cf)
pnpm --filter @objectstack/service-record-context test: Test Files 3 passed (3), Tests 115 passed (115).typecheck: exit 0.pnpm --filter @objectstack/spec test: first run on c46e26d had 1 failure,alias-integrity.test.ts(aliasesrecordIdandrecord_idcollapse onto one probe). Fixed in 36ec0cf by droppingrecord_id. Re-run of that file plusrecord-citation.test.ts: 26/26. The final full-suite reading is in the report.pnpm --filter @objectstack/spec typecheck: exit 0.scripts/ablation-replace.mjsmadehaystackOfalso collectanswer.framing, the note texts andpack.label. Result: anchor 1 to 0, blob c35fc729 to dcec1804, andrefuses a quote that appears only in a note, the framing, or a labelwent red (1 failed / 15 passed). Restored: blob equals HEAD,git diff HEADempty. A first attempt was a no-op that the tool refused before running: its replacement contained the anchor. The test runssrcdirectly, so no dist rebuild was needed for the mutated file.Acceptance notes
headingsOfreads heading text. So a quote that spans two paragraph elements, written with a space where the two paragraphs meet, is not verified. HTML entities in the body are not decoded either: an ampersand entity has to be quoted as the entity. Both follow the card's rule as written. They only make verification stricter, never looser.packages/spec/export-origins/ai.json. Whichever PR lands second regenerates it.Verification
Two minutes:
pnpm --filter @objectstack/service-record-context exec vitest run --maxWorkers=2 src/__tests__/verify-citations.test.ts. Expect 16 passed. Thecontext (Q2)block shows a two-pack object dropping a citation that has nocontext.Generated by Claude Code