Skip to content

fix(metadata-protocol): leave a denied audit row for every documented refusal code at the save, publish, rollback and delete doors - #28393

Merged
objectstack-fleet[bot] merged 8 commits into
mainfrom
claude/project-thread-bdj57c
Oct 31, 2026
Merged

objectstack-fleet[bot] merged 8 commits into
mainfrom
claude/project-thread-bdj57c

Conversation

@objectstack-fleet

Copy link
Copy Markdown
Contributor

Requested by Sam · project thread
Fixes #28355

Clause-②: no
Metadata-protocol: none

维护者速读

  • 改了什么:元数据的保存、发布、回滚、删除四个入口,遇到 NOT_OVERRIDABLE / NOT_CREATABLE / INVALID_METADATA / DESTRUCTIVE_CHANGE 拒绝时,会在 sys_metadata_audit 里写一条 denied 记录。
  • 为什么改:审计表文档一直写着这四个拒绝码,但从没有任何代码写过,读 /audit 的人会以为被拒的尝试从未发生。
  • 风险与回滚:调用方拿到的错误(码、状态、文案)完全不变;审计写入是尽力而为,失败不影响请求。回滚即 revert 本 PR。
  • 先看:packages/metadata-protocol/src/protocol-refusal-audit.ts(映射表与去重标记),protocol.ts 四个入口的包装段,protocol.refusal-audit-rows.test.ts。
  • 两分钟验证:pnpm --filter @objectstack/metadata-protocol exec vitest run --maxWorkers=2 src/protocol.refusal-audit-rows.test.ts,预期 12 个用例全绿。
  • 需要你做的:无,席位落地。

What changes

  • New module protocol-refusal-audit.ts. A closed map from the four catalogued refusal codes to the lower-case values sys_metadata_audit.code already documents (not_overridable, not_creatable, invalid_metadata, destructive_change), refusalAuditEntry (the row a refusal owes at a door, or none), and withRefusalAudit (run the door, record the row on such a refusal, rethrow the same error).
  • The four single-item doors are wrapped. saveMetaItem, publishMetaItem, rollbackMetaItem and deleteMetaItem keep their names and signatures; each is now a short wrapper over a protected …Unaudited body holding the unchanged code. The row is written where the door hands the refusal back, so a refusal raised by any gate inside the door (including shared helpers such as the ADR-0131 D6 organization-scoped refusal) is covered, and so is one added later.
  • The row. outcome: 'denied', operation the door, actor / source as the door's allowed row records them, note = clientFacingFailureText (the sentence the caller was already shown; the column is wire-visible), and type folded to the canonical singular (the writer refuses anything else).
  • What still writes no row. Any other code (INVALID_REQUEST, RESOURCE_CONFLICT, driver faults, 5xx) writes nothing; the column's set stays closed. item_locked and metadata_conflict are not in the map, so their own gates' rows are not duplicated. A refusal handed back through two wrapped doors is recorded once (a marker on the error). The batch publish keeps its batch_aborted row.
  • Nothing removed from the vocabulary. All five codes the card lists are refused by a real door; item_locked was already stamped (see Acceptance notes), so nothing is trimmed.

Why

sys_metadata_audit promised denial rows that never appeared, so an operator or agent reading /audit for a metadata name concluded that a refused authoring attempt never happened. Triage's lean (enforce at the refusing door, beside metadata_conflict) is followed.

Tests

  • protocol.refusal-audit-rows.test.ts (new, 12 cases), driven through the real doors with a fake engine that persists audit inserts: one denied row per enforced code on the save door (not_creatable, not_overridable, destructive_change, invalid_metadata), the plural spelling filed under the canonical type, the publish / rollback / delete doors each stamping their own operation, plus an allowed control (one allowed / ok row, no denied row), an out-of-map refusal (INVALID_REQUEST) writing nothing, the closed map, and a refusal through two doors recorded once.
  • Five existing pins asserted that a refusal touches the engine not at all, or scanned the door's source by member name. Each is reconciled to the new truth rather than loosened:
  • scripts/engine-double-contract.pinned.json: the new test's fake engine is recorded, as check:engine-double-contract requires.

Acceptance notes

  • item_locked (the dispatch asked): it is already stamped. assertLockAllowsWrite / assertLockAllowsDelete / lockWriteRefusal in protocol-lock-version-gates.ts write code: 'item_locked' with lock_state on all four doors, and the batch publish re-records it outside its transaction (recordPendingDenialAudit). Not measured: whether the repository's own read-only-base refusal (SysMetadataRepository.readOnlyBaseOverrideError, ITEM_LOCKED with lockSource: 'package') is ever reached past that gate without a row; it is deliberately not in the map, so a lock-gate refusal cannot be written twice.
  • sys-metadata-audit.object.ts is unchanged: its documented vocabulary is now true, so no trim was needed.
  • One file outside the claimed surface: scripts/engine-double-contract.pinned.json, the gate's own ledger entry for the new test double.

Verification

All readings are on head 7e9960c8da (merged with origin/main at fc5d5093b), in a dedicated worktree.

  • Package suite: pnpm --filter @objectstack/metadata-protocol exec vitest run --maxWorkers=2 (under the verify lock) → Test Files 285 passed | 4 skipped (289), Tests 21872 passed | 26 skipped (21898). Before the five pins were reconciled the same run was 15 red in exactly those five files.
  • Typecheck: pnpm --filter @objectstack/metadata-protocol typecheck → exit 0 (its tsconfig.json includes src/**/*, so the test files are compiled).
  • Gates: node scripts/pm/dispatch-gates.mjs --commands --repo objectstack-ai/objectstack derived 69 commands; all 69 ran and exited 0. --ran reconciliation: 69 derived, 69 run, 0 NOT-MEASURED, 0 UNRUN, every family carrying its exit code. The two real reds on the first pass were fixed in this PR (check:objectql-double-limit: the new find double now applies limit; check:engine-double-contract: the double is recorded in the ledger).
  • Lint: pnpm lint → exit 0.
  • check:platform-checklist not run: no exported symbol is renamed or removed (the four doors keep their names and signatures).
  • Dogfood battery: n/a (no ! in the title, no (narrowing) arm).
Ablation of the audit write (one-off, not kept)

Predicted before running: the nine denied-row cases red, the allowed control, the INVALID_REQUEST no-row case and the closed-map case green.

node scripts/ablation-replace.mjs on packages/metadata-protocol/src/protocol-refusal-audit.ts, anchor if (entry) {, replaced by a guard that is always false (entry && Date.now() is negative), running vitest run src/protocol.refusal-audit-rows.test.ts under it.

  • mutation landed: anchor 1 → 0, blob 4b5d1b1c9c20 → 35ebe7c00ab9
  • Tests 9 failed | 3 passed (12), exactly as predicted
  • restored: blob after restore 4b5d1b1c9c20 == HEAD, git diff HEAD empty

The unit suite imports ./protocol.js from source, so no rebuild was involved.

Human Minimum

  • 1. Schemas start as Zod; packages/spec holds no runtime logic.
  • 2. Every name I added uses the casing for its kind.
  • 3. No formatter ran; pnpm lint passes.
  • 4. One issue, one branch off an up-to-date main, one pull request.
  • 5. A change that publishes carries a changeset, and both declaration lines are filled in here and in the changeset.
  • 6. packages/spec touched: n/a, not touched.
  • 7. No hand edits to content/docs/references/, packages/*/CHANGELOG.md or content/docs/releases/.
  • 8. Title, body and comments are in English (the 维护者速读 block is the repo's required Chinese maintainer summary).
  • The Before Submitting list in CONTRIBUTING.md is done.

Generated by Claude Code

@github-actions github-actions Bot added size/l documentation Improvements or additions to documentation tests tooling Fix lands in tooling, not a product package — enters pm:queue only with Unblocks: or a named surface labels Oct 31, 2026
@github-actions

github-actions Bot commented Oct 31, 2026 •

Copy link
Copy Markdown
Contributor

📓 Docs Drift Check

This PR changes 1 package(s): @objectstack/metadata-protocol, touching 48 documentable anchor(s).

29 hand-written doc(s) name something this change touched — list omitted above 15 rows. Re-derive on the tree named below: node scripts/docs-audit/affected-docs.mjs --json 8c8c5b5255109a7d039225e48e8f6b718247a9af.

⛔ 11 release-owned page(s) also affected — read-only, see AGENTS.md Documentation Guardrails.

What this run could not see
  • 1 cross-cutting symbol(s) contributed no route anchor: packageId (4 routes)
  • 3 name(s) were too generic to anchor anything (single lowercase words)
  • the SDK route bridge reached 60 of 212 client-bound route-ledger rows — the other 152 have no registrar path: tail to select them, so pages documenting THEIR client methods cannot appear above, on this or any run. Of those 152: 0 are remediable by widening that discovery convention (an in-repo file declares the path; the convention did not scan it); 55 are structural — on a ledger where NOT ONE row is declared in-repo, so no discovery change reaches them at any price; 97 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 — 10 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 8c8c5b5255109a7d039225e48e8f6b718247a9af → packageMentionDocs.

Which tree this was computed on

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

node scripts/docs-audit/affected-docs.mjs --json 8c8c5b5255109a7d039225e48e8f6b718247a9af

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

…t shapes from local aliases; mark the D6b audit codes in the pins

Claude-Session: https://claude.ai/code/session_01QUs3Bs2hELyx9Go8Efyui5
Co-authored-by: Claude <noreply@anthropic.com>
…ssert it instead of no insert

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

Copy link
Copy Markdown
Contributor Author

domain:server#4 · os-zhuang · session_01QUs3BtyH9zgxKzYrJiH18J

ACCEPT · PR #28393 · Head-sha b50e93b45477292c07f9f6df12749cfe2aeae615 · 2026-10-31T11:01Z

维护者速读

  • 改了什么: 元数据的保存、发布、回滚、删除四个入口,遇到 NOT_OVERRIDABLE / NOT_CREATABLE / INVALID_METADATA / DESTRUCTIVE_CHANGE 拒绝时,会在 sys_metadata_audit 里写一条 denied 记录(码用表里已文档化的小写值)。
  • 为什么改: 审计表文档一直写着这四个拒绝码,但从没有代码写过,读 /audit 的人会以为被拒的尝试从未发生。
  • 风险与回滚: 调用方拿到的错误(码、状态、文案)不变;审计写入尽力而为;四个入口的公开签名不变,内部拆成公开包装加私有主体。回滚即 revert 本 PR。
  • 先看: packages/metadata-protocol/src/protocol-refusal-audit.ts(封闭映射表与去重标记);protocol.ts 四个入口的包装段。
  • 两分钟验证: pnpm --filter @objectstack/metadata-protocol exec vitest run --maxWorkers=2 src/protocol.refusal-audit-rows.test.ts。
  • 需要你做的: 无,席位落地。

席位意见:在入口出口统一记账,覆盖以后新加的拒绝点;映射表封闭、不铸新值,item_locked 与 metadata_conflict 不重记;可合。

席位核对

  • Form: 12 files, +706/-119. check-governed-merges.mjs --pr 28393: NOT governed, 825 lines ≤ 3000, Tier S. Clause-②: no holds: no packages/spec/src/** path; the four door signatures are unchanged (the request shapes are local, unexported aliases of the old inline types); the audit column's value set is unchanged (each written value is one it already documents). Metadata-protocol: none holds.
  • Premise measured: the dev found every code the card lists refused by a real door, so nothing is removed from the vocabulary; item_locked was already stamped by the lock gates on all four doors. Seat read the diff: withRefusalAudit wraps each door's private body, writes a row only for a code in the closed map with a non-empty type and name, marks the error so a refusal passing two doors is recorded once, and rethrows the same error. Rows carry organizationId: null, as the ledger's type requires and every existing denied row does.
  • Gates (check-runs at the pinned head): 48 runs: 35 success, 13 skipped, 0 failed, 0 pending. The seat's REWORK (private ...Unaudited bodies; the adr0112-ok: D6b marks on the lower-case values) is in bfad1b20b. The Test Core red at that head was five objectql pins asserting "no insert" on a refused save; b50e93b45 makes each assert that the only insert is the refusal's sys_metadata_audit row, so "no metadata row is written" is still pinned.
  • Accepted deviations: the file surface grew by test-only edits in packages/objectql/src/** and scripts/engine-double-contract.pinned.json, each forced by a gate; sys-metadata-audit.object.ts is untouched because nothing is removed.
  • Out of scope and where it goes: whether the repository's own read-only-base refusal (ITEM_LOCKED, lockSource: 'package') is ever reached past the lock gate without a row is unmeasured, and recorded in the PR's acceptance notes. Skills-docs: none.
  • Landing clause: Tier S ordinary queue landing. The seat flips ready and enables auto-merge through the relay, then confirms MERGED and closes out metadata audit: sys_metadata_audit documents denied codes (not_overridable, not_creatable, invalid_metadata, destructive_change) that no audit write stamps — enforce or remove #28355.

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 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

1 participant