Skip to content

fix(runtime)!: refuse a package uninstall while an active validation rule reads a field it adds - #31227

Merged
os-zhuang merged 4 commits into
mainfrom
claude/project-thread-of4yrh
Nov 8, 2026
Merged

os-zhuang merged 4 commits into
mainfrom
claude/project-thread-of4yrh

Conversation

@objectstack-fleet

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

Copy link
Copy Markdown
Contributor

domain:server#4 · marchtian · session_017ihL2dLQEXWGsE2SZ3Qn5F

Requested by 田騏 · project thread

Fixes #30999

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

维护者速读

  • 改了什么:卸载包(DELETE /api/v1/packages/:id)现在先问停用门已经在问的同一个检查:如果别的已启用包有生效中的校验规则在读这个包通过 objectExtensions 加的字段,就拒绝卸载,返回 409 PACKAGE_DISABLE_RESTRICTED_BY_VALIDATION_RULE,消息和停用门同一句话,只是开头换成「cannot be uninstalled」,并列出每条规则(包 · 对象 · 规则)。拒绝时什么都不动。
  • 为什么改:以前卸载会直接撤掉这些字段,读它们的规则随即失效,该对象的每一次写入都报 400 VALIDATION_FAILED,而包已经没了,连重新启用这条退路都没有。停用门早就拦这种情况([Decision] A package can be disabled while an enabled package's validation rule reads one of its extension fields, and then every write to that object is refused #30379),卸载门是漏掉的那一个。
  • 风险与回滚:这是一次收窄(BREAKING):以前能卸载成功的请求,现在在有依赖规则时会被 409 拒绝。没有依赖规则的卸载、已停用包的卸载行为不变。没有改错误码台账、spec 或存储形状。回滚就是 revert 这个 PR。
  • 先看:packages/runtime/src/domains/packages.ts 的 DELETE 分支新增的那段检查(在 requireWritablePackage 之后、resolveProtocol 之前);packages/runtime/src/domains/packages-disable-module-extension-fields.test.ts 末尾的 [#30999] describe;.changeset/30999-uninstall-dependent-rule-refusal.md。
  • 两分钟验证:pnpm --filter @objectstack/runtime exec vitest run src/domains/packages-disable-module-extension-fields.test.ts -t 30999,预期 4 条全绿:卸载被 409 拒绝且什么都没动、拒绝文案的卸载版只改“撤掉/保留安装”两处,以及两条 CONTROL(无依赖的包照常卸载并清掉停用记录,把规则在租户覆盖层关掉后卸载照常通过)。
  • 需要你做的:维护者在 PR 上确认这次收窄(卸载门在有依赖规则时改为拒绝)。席位合同复审 PASS 见 comment 6712022339(Head-sha ee03285db1ab),席位核对 ACCEPT 见 comment 6712026943;批准后由席位落地。
  • 席位意见:可合。拒绝在任何状态变动之前,复用停用门同一个判定和错误码,两门不会漂移;文案已改为“卸载会撤掉…或保留安装”。进程内卸载(deletePackage)同样缺这道拒绝,已另立 packages: the in-process uninstall verb (deletePackage) withdraws extension fields a dependent active validation rule reads, with no refusal — only the HTTP door asks #31232,不在本 PR。

What changes

DELETE /api/v1/packages/:id withdraws the package's objectExtensions fields from the served objects, exactly as PATCH /packages/:id/disable withholds them, but it never asked the dependent-rule scan the disable door asks. The door now asks that same verdict, readDisableDependentRules (exported as readPackageDisableDependents), with no second copy, and refuses with the same wire pair and the same sentence:

  • Where. Right after the read-only check (requireWritablePackage) and BEFORE resolveProtocol, deletePackage, the running-registry withdrawal and the disable-record clear. A refused uninstall moves nothing: stored rows, registry entry, served fields and the environment's disable record stay as they were.
  • What it answers. 409 with { error: { code: 'PACKAGE_DISABLE_RESTRICTED_BY_VALIDATION_RULE', message } }, the message built by disableDependentRulesMessage (exported as formatPackageDisableDependents) under the lead Package 'ID' cannot be uninstalled. No error.details, as at the disable door.
  • The code stays. It is ledgered once under @objectstack/runtime (ERROR_CODE_LEDGER), and the refused state is the same one the disable door refuses: a rule left reading a field the fold no longer serves. Reusing it touches nothing under packages/spec.
  • What does not change. An uninstall no active rule depends on proceeds exactly as before: the verb is still handed the session user (packages: DELETE /api/v1/packages/:id deletes unattributed (no actor), and the in-process deletePackage leaves the per-environment disable record behind #31023) and the disable record is still cleared. A package that is already disabled withholds its fields already, so its verdict is empty and its uninstall proceeds.

Why

The disable door has refused this since #30379: once a field is withheld, a rule that reads it cannot be evaluated and fails closed, so every write to its object is refused. The uninstall door withdraws the same fields and skipped the scan, and after an uninstall there is no package left to re-enable. Both doors now answer the one verdict.

Tests

One new top-level describe in the shared dependent-rule harness, packages-disable-module-extension-fields.test.ts, on a real kernel (ObjectQL on SQLite, MetadataPlugin, the real uninstall verb spied on and passed through). Two writable packages (installed as authored, so the door may delete them) each extend the app's object with one field; a third package's active rule reads the first one's field.

  • Refusal. DELETE of the read package answers 409 with the code, and the message equals the exported builder over the exported verdict under the uninstall lead. Nothing moved: deletePackage was never called, the package and its field are still served, the state file is unchanged, and a write to the object still lands.
  • CONTROL: no dependent. The second package (its field read by no rule, while the reader's rule stays active on the same object), disabled first, uninstalls with 200; the verb received { packageId, actor: 'u_admin' }, the package left the registry, its field left the served object, and its disable record was cleared.
  • CONTROL: rule switched off through the tenant overlay. With the reader's rule switched off in the app's overlay, the first package uninstalls with 200, its field leaves the served object, and a write to the object lands.

Acceptance notes

  • Re-measure at branch start (premise holds). On this rig with the check removed, DELETE answered 200, the field left the served object and the package left the registry, and the next write to the object answered 400 VALIDATION_FAILED: Validation rule 'qx_tier_known' could not be evaluated (runtime: No such key: qx_tier) — write rejected.
  • Wording. The uninstall refusal says what the uninstall would do: "which the uninstall would withdraw" and "or keep the package installed.", through a new optional third argument of formatPackageDisableDependents, { operation: 'disable' | 'uninstall' }, default 'disable', whose sentence is byte-identical to before (seat rework 1).
  • Only the HTTP door refuses. The in-process uninstall verb (deletePackage in @objectstack/metadata-protocol) does not ask the verdict, so an in-process caller can still withdraw a read field. The claim scoped this card to the door; that question is raised in the report for the seat.
  • Studio. The Studio delete dialog shows the thrown message, so an admin sees the refusal sentence naming the rules.

Verification

Ablation: the check removed, the refusal pin goes red

node scripts/ablation-replace.mjs replaced the verdict read in the DELETE arm with an empty list (anchor 1 -> 0, blob 97f5c5fb5c8b -> 197d54665e7a), then restored it (blob equals HEAD, git diff HEAD empty). The subject is imported from src through a relative path, so no dist/ leg applies.

× answers 409 with the disable door's code and sentence under an uninstall lead, and nothing moves
AssertionError: expected { status: 200, code: undefined } to deeply equal { status: 409, …(1) }

The two CONTROLs also went red, by cascade: the first case's uninstall had already removed the package they build on.

Local gates at head 0fc6353

Human Minimum

  • 1. Schemas start as Zod; packages/spec holds no runtime logic. (packages/spec is not touched.)
  • 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: its generated artifacts are regenerated and committed. (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 Before Submitting list in CONTRIBUTING.md is done.

Generated by Claude Code

🤖 Generated with Claude Code

…a field it adds

DELETE /packages/:id withdraws the package's objectExtensions fields from the
served object just as a disable withholds them, but it asked no dependent-rule
scan, so another package's active validation rule that read one of those
fields then refused every write to its object. The door now asks the disable
door's verdict (readDisableDependentRules) before any state moves and answers
its refusal: 409 PACKAGE_DISABLE_RESTRICTED_BY_VALIDATION_RULE with the
sentence disableDependentRulesMessage spells under an uninstall lead.

Co-Authored-By: Claude <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017ihL2dtwL9RzJUEskoEex5
@objectstack-fleet objectstack-fleet Bot added the pm:awaiting-merge PR only: landing waits on the maintainer's own review and merge (SKILL.md 复核 ②); never on an issue label Nov 7, 2026
@github-actions github-actions Bot added size/m 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 Nov 7, 2026
@github-actions

github-actions Bot commented Nov 7, 2026 •

Copy link
Copy Markdown
Contributor

📓 Docs Drift Check

This PR changes 1 package(s): @objectstack/runtime, touching 6 documentable anchor(s).

30 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 065bba721e4ba180c6bdbbf2c5fb787d49bac596.

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

What this run could not see
  • the SDK route bridge reached 63 of 226 client-bound route-ledger rows — the other 163 have no registrar path: tail to select them, so pages documenting THEIR client methods cannot appear above, on this or any run. Of those 163: 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; 104 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 — 28 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 065bba721e4ba180c6bdbbf2c5fb787d49bac596 → packageMentionDocs.

Which tree this was computed on

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

node scripts/docs-audit/affected-docs.mjs --json 065bba721e4ba180c6bdbbf2c5fb787d49bac596

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

…efusal

The uninstall door answered the disable door's sentence verbatim, so under
its uninstall lead it said the fields were ones the disable would withhold and
told the caller to keep the package enabled, which does not stop an uninstall.
The sentence builder takes an optional operation; its uninstall form says the
uninstall would withdraw the fields and to keep the package installed. The
default form is byte-identical to the disable door's.

Co-Authored-By: Claude <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017ihL2dtwL9RzJUEskoEex5
@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

domain:server#4 · marchtian · session_017ihL2dLQEXWGsE2SZ3Qn5F

Contract review

Served-tier: TIER_DEFAULT
Head-sha: ee03285db1abf7ad9ed6bfe924aeb933e2a44a47
Local-runs: none

① Derived judgments

  • Face: accept-set narrowing at one HTTP door (Clause-②: yes (narrowing) on the claim 6710755515, PR body and changeset; title fix(runtime)!:). No path under packages/spec/**, no governed path, no new error code, no new route. Diff read in full: 3 files, +201/−5.
  • One verdict, never a copy. The DELETE /packages/:id arm asks readDisableDependentRules — the function the disable door asks and the package entry exports as readPackageDisableDependents (runtime: export the disable door's dependent-validation-rule verdict for host doors, so a host that removes a package another way answers the same 409 #31067) — and answers the already-ledgered 409 PACKAGE_DISABLE_RESTRICTED_BY_VALIDATION_RULE. The two doors cannot drift on what "depends" means.
  • Refused before anything moves. The check sits after requireWritablePackage and before resolveProtocol / deletePackage / the registry withdrawal / the disable-record clear. Pinned on a real kernel: deletePackage never called, package and field still served, state file unchanged, a write to the object still lands. CONTROLs pinned: an undepended package uninstalls (200, verb gets { packageId, actor }, record cleared); a rule switched off through the tenant overlay unblocks the uninstall. An already-disabled package yields an empty verdict and proceeds as before.
  • Sentence (rework 1). disableDependentRulesMessage / formatPackageDisableDependents gain an optional { operation: 'disable' | 'uninstall' }, default 'disable', whose bytes are unchanged (pinned: default toBe the explicit disable form; uninstall form differs only in the effect clause and the remedy). The uninstall refusal now says "which the uninstall would withdraw … or keep the package installed." — the remedy names the act that keeps the field served. Existing disable / enableOnInstall pins untouched. Ablation (door passes no operation) turns the refusal pin red.

② Semver level

  • Narrowing: a request the door performed before is now refused ⇒ BREAKING for the door's callers, declared with ! and a BREAKING changeset paragraph with Before / Now / Who moves / remedy. The builder's new parameter is optional with an identical default ⇒ additive for its importers. Changeset @objectstack/runtime patch follows the repo's changeset-no-major practice for declared narrowings; the BREAKING paragraph carries the signal.

③ Boundary flags

Implemented-by: claude/project-thread-of4yrh
Reviewed-by: session_017ihL2dLQEXWGsE2SZ3Qn5F

VERDICT: PASS

@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

domain:server#4 · marchtian · session_017ihL2dLQEXWGsE2SZ3Qn5F

席位核对 — ACCEPT · domain:server#4 · Head-sha: ee03285db1abf7ad9ed6bfe924aeb933e2a44a47

  • Shape: draft → main, Fixes #30999 once, Clause-②: yes (narrowing) and Metadata-protocol: none line-initial, ! title, BREAKING changeset (@objectstack/runtime patch). 3 files, +201/−5; not governed, under 3000 lines.
  • Diff read by the seat: the DELETE arm's verdict read sits before every state move and reuses the disable door's exported check and code; the builder's uninstall form changes only the effect clause and the remedy, the default is byte-identical (pinned).
  • Premise measured: with the check removed the door answered 200 and the next write to the object answered 400 VALIDATION_FAILED (qx_tier_known … No such key: qx_tier) — the break the card names (report round 0).
  • Gates (check-runs on the head): 48 runs — 35 success, 13 skipped, 0 failed. Dev: dispatch-gates --ran 62/62, 0 NOT-MEASURED (round 0 and rework 1); runtime 554 files / 8930 tests at 0fc6353, typecheck and eslint 0 at ee03285; dogfood battery green at 0fc6353 (rework touches only the sentence; no dogfood file names it).
  • Accepted deviations: full runtime suite and dogfood not rerun at ee03285 (declared scoped rerun; the delta is the sentence plus an optional argument with an identical default; CI ran the full set green).
  • Out of scope: in-process deletePackage lacks the refusal → packages: the in-process uninstall verb (deletePackage) withdraws extension fields a dependent active validation rule reads, with no refusal — only the HTTP door asks #31232 (finding).
  • Landing: Tier: none, but BREAKING narrowing ⇒ waits on the maintainer's word on this PR (pm:awaiting-merge). On approval the seat lands: landing checks, label cleared, pr_ready + automerge_enable through the relay.

@os-zhuang
os-zhuang marked this pull request as ready for review November 7, 2026 23:42
@os-zhuang
os-zhuang enabled auto-merge November 7, 2026 23:42
@os-zhuang
os-zhuang added this pull request to the merge queue Nov 7, 2026
@objectstack-fleet objectstack-fleet Bot removed the pm:awaiting-merge PR only: landing waits on the maintainer's own review and merge (SKILL.md 复核 ②); never on an issue label Nov 7, 2026
Merged via the queue into main with commit 57675a2 Nov 8, 2026
56 checks passed
@os-zhuang
os-zhuang deleted the claude/project-thread-of4yrh branch November 8, 2026 01:03
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/m tests tooling Fix lands in tooling, not a product package — enters pm:queue only with Unblocks: or a named surface

Projects

None yet

3 participants