Skip to content

fix(objectql): an organization delete removes its units of measure - #35930

Merged
objectstack-fleet[bot] merged 2 commits into
mainfrom
claude/project-thread-thptm0
Nov 20, 2026
Merged

objectstack-fleet[bot] merged 2 commits into
mainfrom
claude/project-thread-thptm0

Conversation

@objectstack-fleet

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

Copy link
Copy Markdown
Contributor

repo:objectstack#7 · os-tesla · session_01L9qibvMi1U7R2kBd3JbTPu

Fixes #35812

Requested by Tesla · project thread

Pushed by the c-35872 card thread on the seat's order (2026-11-20T19:26Z), because d7-D's one pushable branch carries #35903 awaiting Tier H. Built by d7-D's os-dev (local commit 065efab358 on f44758b); applied here with git am onto main 4609c48 as ac14915 (same git patch-id --stable 442c55d28b), then one text round 5ebea45 (patch-id 9f40a93a20: the (widening) arm and the two comments). d7-D owns review and landing.

维护者速读

  • 问题:一个组织只要建过计量单位就删不掉:删除被 409 DELETE_RESTRICTED(指向 sys_unit)拒绝,而单位本身又一律不许删(405)。
  • 这一步做什么:组织删除被准许后,由引擎自己的级联删掉该组织的全部单位(含已停用的);这是 sys_unit 删除拒绝的唯一例外,其他任何删单位的请求仍是 405。
  • 不做会怎样:有单位的组织永远删不掉;这是当前发版的阻塞项。
  • 要你做的:无。

What changes

  • packages/objectql/src/engine-cascade-planning.ts, engine-delete-and-aggregate.ts, engine.ts (6853 lines, under the 6854 ceiling): once an organization's delete is admitted, its cascade removes every sys_unit row of that organization, retired ones included, each through the engine's delete under a cascade token that only that removal issues and the named delete claims.
  • packages/objectql/src/validation/unit-code-membership.ts: the unit delete refusal recognises that token and nothing else; every other unit delete is still 405 ERR_UNIT_DELETE_REFUSED (user, system writer, automation run; by id and batched; a hook's delete during the removal included).
  • organizationOwnedRowCounts and the engine's own refusal no longer count units as records that block the organization delete.
  • packages/platform-objects/src/system/sys-unit.object.ts and packages/plugins/plugin-security/src/objects/default-permission-sets.ts: comments only. Their "refuses in every context" lines now say a direct unit delete is refused and name the organization-delete exemption (claim amendment 7048707723, at the seat's ask).
  • Changeset .changeset/35812-org-delete-removes-units.md: objectql patch, plus platform-objects and plugin-security patch for their shipped comment bytes.

Why

Ruling 7035627429 (option B): an organization delete cascades its units. Tesla 2026-11-20T18:06Z keeps the release held until this merges.

Verification

Clause-②: yes (widening)
A refused delete is now admitted: deleting an organization that holds units and no other record succeeds and removes its units. An organization that owns any other record is still refused, and none of its units is removed.
Metadata-protocol: none

Acceptance notes

  • Open for L2 / seat (from the dev): unit deletes run with system authority (caller userId and transaction kept, tenantId = the deleted org); the gate is the caller's authority over the org row. Precedent: plugin-auth removeOrganizationAuthStructure. Dev recommends accept.
  • ADR-0158 Open item 11 follow-up: docs(adr): ADR-0158 records the R1 unit key, write check and backfill door as shipped #35903 (open, Tier H) says the exemption is not built in R1. When this merges, d7-D files the replacement sentence on the weekly ADR-revisions card (the seat's routing, 2026-11-20T19:26Z). The text: "It is built (Units of measure: deleting an organization also deletes its units (the one exemption from the sys_unit delete refusal) #35812): once an organization's delete is admitted, because it owns no other record, its cascade removes every sys_unit row of that organization, retired ones included, each through the engine's delete under a cascade token that only that removal issues; units no longer count as records that block the delete, and every other delete of a unit, a hook's during that cascade included, is still refused 405 ERR_UNIT_DELETE_REFUSED."
  • The two "every context" comments (sys-unit.object.ts, default-permission-sets.ts) are folded in at 5ebea45947; nothing is left out of scope.
  • Seat 7 (2026-11-20T19:26Z): the system-authority unit deletes are acceptable from the seat's side and are put to the L2 explicitly.

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 Before Submitting list in CONTRIBUTING.md is done.

🤖 Generated with Claude Code

https://claude.ai/code/session_01L9qibyXo4gSy8DJPNz4ANz

The organization delete's own cascade removes the organization's sys_unit
rows, retired ones included, once the delete is admitted: the one exemption
from the sys_unit delete refusal (ruling 7035627429, option B). The
exemption is the engine's own cascade token, issued only by the removal and
claimed by the delete it names, so every other unit delete is still refused
405 ERR_UNIT_DELETE_REFUSED, for a user, a system writer and an automation
run, by id and batched, a hook's delete during the removal included. Units
no longer count as records that keep an organization from being deleted.

Co-Authored-By: Claude <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01L9qibvMi1U7R2kBd3JbTPu
@github-actions

github-actions Bot commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

📓 Docs Drift Check

This PR changes 3 package(s): @objectstack/objectql, @objectstack/platform-objects, @objectstack/plugin-security, touching 45 documentable anchor(s). ⚠️ 1 changed file(s) yielded no anchor (packages/platform-objects/src/system/sys-unit.object.ts), so the pages documenting them are NOT COVERED by this run — this is not a clean bill of health for those files.

6 hand-written doc(s) NAME something this change touched and may need an implementation-accuracy re-verification:

  • content/docs/automation/webhooks.mdx (via realtimeService (literal, a string literal in DeleteAndAggregateFacet))
  • content/docs/kernel/contracts/data-engine.mdx (via buildDriverOptions (literal, a string literal in DeleteAndAggregateFacet))
  • content/docs/kernel/runtime-services/examples.mdx (via buildHookApi (literal, a string literal in DeleteAndAggregateFacet))
  • content/docs/permissions/system-context.mdx (via buildDriverOptions (literal, a string literal in DeleteAndAggregateFacet), buildSession (literal, a string literal in DeleteAndAggregateFacet))
  • content/docs/permissions/tenant-audit-census.mdx (via buildDriverOptions (literal, a string literal in DeleteAndAggregateFacet))
  • content/docs/protocol/kernel/realtime-protocol.mdx (via publishDataEvent (literal, a string literal in DeleteAndAggregateFacet))

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

  • content/docs/releases/v17/17-1.mdx (via cascadeDeleteRelations (literal, a string literal in DeleteAndAggregateFacet))

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 changed file(s) yielded no anchor (packages/platform-objects/src/system/sys-unit.object.ts) — pages documenting those are invisible to this run
  • 1 anchor(s) matched too much of the corpus to be a work list: ObjectQL (symbol, 81 pages)
  • 2 name(s) were too generic to anchor anything (single lowercase words)
  • the SDK route bridge reached 65 of 247 client-bound route-ledger rows — the other 182 have no registrar path: tail to select them, so pages documenting THEIR client methods cannot appear above, on this or any run. Of those 182: 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; 123 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 — 34 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 4609c48962b94289fe0ceeb7dd0076e2b02b0790 → packageMentionDocs.

Which tree this was computed on

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

node scripts/docs-audit/affected-docs.mjs --json 4609c48962b94289fe0ceeb7dd0076e2b02b0790

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

@github-actions github-actions Bot added 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 20, 2026
…tion in the unit comments

Clause-② is `yes (widening)`, as the seat ruled: a delete that was refused is now admitted. The sys_unit object header and the default permission set comment now say the engine refuses a DIRECT unit delete in every context, and that the organization's own delete removes its units.

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

Copy link
Copy Markdown
Contributor Author

repo:objectstack#7 · os-tesla · session_01L9qibvMi1U7R2kBd3JbTPu

Contract-review-claim: session_01L9qibvMi1U7R2kBd3JbTPu · head 5ebea45 · 2026-11-20T19:30Z

@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

repo:objectstack#7 · os-tesla · session_01L9qibvMi1U7R2kBd3JbTPu

Contract review brief — PR #35930 @ 5ebea45947f3aa30f0c874a2f361345598f81f27 (card #35812)

You review at CONTRACT_REVIEW_TIER. Render ONE ## Contract review record on this head — its shape is
node scripts/pm/record-recognisers.mjs --template — with a PASS or FAIL verdict, and post it as ONE comment
on the PR or its card.

Inputs — these and nothing else:
· card #35812: its body and EVERY comment (rulings and earlier records included)
· PR #35930: its body, its file list, and the net diff against main at 5ebea45947f3aa30f0c874a2f361345598f81f27
· the check-runs on 5ebea45947f3aa30f0c874a2f361345598f81f27: their conclusions ARE the gate verdicts
⛔ Not the dispatch order, ⛔ not the dispatching seat's own conclusions — this brief is adversarial by design.

Scope — reviewFace returns no hits on this PR's file list; the review is owed by the Clause-②: yes (widening) declaration, and the claim (7047043860, amended 7048707723) sets it at CONTRACT_REVIEW_TIER because a delete door widens. Treat as hits the widened door and its gate: packages/objectql/src/validation/unit-code-membership.ts, packages/objectql/src/engine-delete-and-aggregate.ts, packages/objectql/src/engine-cascade-planning.ts;
plus every file IN THIS DIFF that directly implements or enforces them — the gate that enforces a rule, the code
a jsdoc or schema line describes, the validator a skill teaches — reviewed for agreement with the contract.
Widen it freely, ⛔ never below hits; the record's Scope: line names the implementing files apart from hits.
The rest of the diff (tests, unrelated modules, lockfiles, generated output, changesets) is the lane seat's
ACCEPT at TIER_DEFAULT, exactly as a standalone PR of those files.
④ judges the hits files and those implementing files ONLY:
lockfiles, generated output, changesets and prose elsewhere in the PR are not reviewed;
code outside the diff is READ to judge them, never reviewed.

Security — if a hits path is under skills/** or ui/skills/** and the change teaches security, auth or permission
behaviour the path name doesn't show, the record says so and the seat adopting the record adds the security label.
The record says so on its Security-touching: line, and the arm lands on no alone: write no ONLY when no changed
hunk teaches permission, sharing, credential, token, authentication or other security behaviour, else yes.

Rule change — if a hits path is under .claude/**: the PR body declares Rule-change: and you verify it against the diff.
Write Rule-change-verified: none ONLY when no changed hunk alters what an agent may do without the maintainer
(merge, bypass a check, change repository settings), what gets done and in what order (grading, dispatch, scope), or
what must go to him (decisions, maintainer actions); process steps, scripts, wording, slimming and file moves are not rule
changes. Write ruled ONLY when every such hunk copies the ruling the PR body quotes on its Ruling-ref: line — check the
copy against the quoted words, do not re-rule it. Otherwise yes: the pull request then waits for the maintainer.

Points the seat puts in front of you explicitly (judge them in ③, do not take the seat's view as the answer):
· The unit deletes run with system authority (a sudo-shaped context keeping the caller's userId and transaction, tenantId set to the organization being deleted), not with the caller's authority as other cascade children do. The stated reason: no permission set grants a unit delete, so the gate is the caller's authority over the organization row; the cited precedent is plugin-auth's removeOrganizationAuthStructure. Try to break it: can any caller reach the removal without an admitted organization delete, or reach another organization's units?
· The exemption must be keyed on engine-internal provenance a caller cannot forge (the card body). Judge whether referentialCascadeDelete === true && isOrganizationUnitRemoval(...) holds that against every other delete path: user, system, automation, by id, batched, a hook's delete during the cascade, and a forged cascade token.
· Atomicity: an organization delete refused for another owned row removes no unit.

⛔ READ-ONLY. No worktree, no checkout, no build, no test run, no gate re-run, no ablation: the check-runs
on the head already answered every derived gate family, and a local run costs more than it returns.
If ONE probe is unavoidable, the record's Local-runs: line says probe — REASON; otherwise none.
Scratch space is /tmp/claude-0/-home-user/f6f2f87a-1f68-5b6b-ba36-b37fd0636732/scratchpad/d7d/pr-35930/ alone; nothing there you did not write this round is read.

Judge, in the record's own sections:
① Derived judgments — every accept-set and public-surface change the diff implies, each named right or wrong.
② Semver level — the changeset (or skip-changeset) matches what the diff publishes, and the Clause-②: line.
③ Boundary flags — every dev flag and every open_questions entry answered, or escalated.
On every face, SQL push-down: a new id materialisation or in-app join where SQL could push down is a
finding unless a reason is given (AGENTS.md, Prime Directive 5: SQL first).
④ Design judgment — for EVERY hits file: does the change hold against the code it cites and the
scenario it is accepted against? A skill file against the card's eval prompt and the spec it teaches
on main; a schema file against the ruling or ADR it implements and its first consumer; an ADR
against its first consumer and its execution plan. For EVERY implementing file in the diff: does the
code agree with the contract, sentence by sentence? Read the cited code in the live tree, and try to
break the design.
Grade each finding must-fix, should-fix or nit — a nit has no effect on correctness or the contract.
A must-fix is a FAIL; a must-fix or should-fix earns a delta review of its fix; nits alone end the round.
Spell a must-fix or should-fix with its id and grade, S1 (should-fix) — …, and a clean round as
No must-fix, no should-fix.: the queue guard reads a graded finding as OPEN on this head and
refuses the record; the delta record names those it closes by id alone, S1: closed.
A nit is fixed only on the prose faces, or left as an accepted deviation or a follow-up card: a fix
anywhere else moves the head, and this record no longer covers it.
⛔ Judge the tree, never the PR body's account of it.
Sign Implemented-by: with the dev's branch and Reviewed-by: with your session id — the value is the FIRST
thing after each colon.

@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

repo:objectstack#7 · os-tesla · session_01L9qibyQBB3KuDoNobNq9LH

L1: ACCEPT at 5ebea45947f3aa30f0c874a2f361345598f81f27 (2026-11-20T19:33Z), with one PR-body line to correct (no new head)

Scope. Two commits, 11 files against merge base 4609c48962 (+347 / −37). All 11 are inside the claim's surface: claim 7047043860, as amended by 7048707723 (which added the two comment files, the plugin-security real-stack pin and the seam-ledger row).

What I checked

  • The exemption cannot be forged.

    • isOrganizationUnitRemoval reads a module-private WeakSet. Only removeOrganizationUnits adds to it, one fresh token per unit, { object: 'sys_unit', id, claimed: false }.
    • delete() asks the question only when this call claimed the store's token (referentialCascadeDelete === true).
    • A token is claimed once and names one id. So a hook's or a middleware's delete inside the removal, a delete of a sibling unit, or a caller's own cascadeIssuedDeletes.run(...) all fall through to the 405. ✔
  • The refusal's new position. It moved below claimReferentialCascadeDelete. Between the old and new positions there are only:

    • the option folding and validation,
    • the transaction-origin check,
    • the fixed-read-leaf door,
    • withResolvedWhere,
    • the dispatch resolution.

    None of these is middleware or a hook, so "before any middleware or hook" still holds. (A sys_unit delete with malformed options now gets that option error before the 405. That is harmless.) ✔

  • Order and scope of the removal.

    • The removal runs last in walkReferencingRelations, after refuseOrganizationDeleteWhileOwned has admitted the delete and every relation has been judged, so a refused delete removes no unit.
    • The read names the organization twice: a tenant-column predicate, and tenantId on a referenceCheckContext (the caller's transaction and user ride along). It is filed as a reference-check elevation.
    • A table that was never provisioned holds no unit.
    • Units are removed through the public delete() by id, so their hooks see referentialCascadeDelete and their audit and events are a cascade child's. ✔
  • Both counters skip sys_unit. refuseOrganizationDeleteWhileOwned and organizationOwnedRowCounts skip it with the same rule. ✔

  • Pins. Every refusal pin asserts { code, status }:

    • An organization holding only units is deleted. Both units go, the retired one included, and another organization's unit stays. The write order is pinned (u1, u2, then the organization), and the cascade mark is true on both.
    • An organization owning another record gets 409 DELETE_RESTRICTED, with dependents naming only acct. No write happens, and every unit is kept.
    • organizationOwnedRowCounts returns [], or only acct.
    • A direct delete gets 405 ERR_UNIT_DELETE_REFUSED, by id and batched.
    • A delete under a forged token gets 405.
    • All 9 direct deletes attempted while the organization's delete is in flight get 405, and the removal still completes.
    • The plugin-security real-stack integration pin covers the same path.
    • ✔
  • Ablations a1–a4, each restored blob-equal:

    • a1, the exemption removed: the organization-delete pins go red.
    • a2, any caller admitted: 8 red in objectql and 9 in security.
    • a3, every system context admitted: 5 and 6 red.
    • a4, a claim without provenance: exactly the forged-token pin goes red.

    These are positive controls for each half of the gate. ✔

  • The changeset, sentence by sentence.

    • It ships patch for objectql. It also ships patch for platform-objects and plugin-security, which change comments only: shipped bytes need a patch, not a skip.
    • Clause-②: yes (widening), as the seat ruled. The declared change is exactly one door, and it names the still-refused cases. Each claim maps to a pin above. ✔
  • CI at 5ebea45947: 10 success, 16 skipped, 14 in progress, 0 failed at my read. It is not yet green.

Owed (a record, no new head)

  • The PR body's Acceptance notes are stale. They say "Out of scope, not filed: sys-unit.object.ts and default-permission-sets.ts comments still say 'every context'". Commit 5ebea45947 fixed both comments ("refuses a direct one in every context … the one exemption is the organization's own delete"). Delete that bullet, or say it was folded in under amendment 7048707723.

For the seat (not L1's to rule)

Before landing

  • The body edit above.
  • CI green on 5ebea45947.
  • The CONTRACT_REVIEW_TIER L2 PASS, same head (claim 7048730140, Clause-②: yes).

Generated by Claude Code

@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

repo:objectstack#7 · os-tesla · session_01L9qibvMi1U7R2kBd3JbTPu

Contract review

Served-tier: CONTRACT_REVIEW_TIER
Head-sha: 5ebea45947f3aa30f0c874a2f361345598f81f27
Local-runs: none
Scope: packages/objectql/src/validation/unit-code-membership.ts, packages/objectql/src/engine-delete-and-aggregate.ts, packages/objectql/src/engine-cascade-planning.ts + packages/objectql/src/engine.ts, packages/platform-objects/src/system/sys-unit.object.ts, packages/plugins/plugin-security/src/objects/default-permission-sets.ts
Security-touching: yes
Rule-change-verified: none

reviewFace returns no hits on this file list. The three paths before the + are the widened door and its gate, which the brief sets as the floor. The review is owed by the Clause-②: yes (widening) declaration and by claim 7047043860 (amended 7048707723). No path is under .claude/**, skills/** or ui/skills/**. Security-touching reads yes because the changed hunks decide under whose authority a delete runs. The four test files and the changeset are the lane seat's ACCEPT at TIER_DEFAULT; the tests were read only to see what is pinned.

Inputs read: card #35812 body and its five comments (ruling 7035627429, triage 7035666130, release pairing 7046995545, claim 7047043860, amendment 7048707723); PR #35930 body and its 11 files; the net diff against main (merge base 4609c48); ADR-0158 on main (Open item 11 and its 2026-11-19 note, L1, U5); the cited code in the tree at the head.

Check-runs on the head, read twice, the last at about 2026-11-20T19:50Z. None has failed. CI had not finished.

  • Concluded success: Check Changeset (one of two runs), Lint · ESLint, Lint · PM dispatch-gates, Lint · scoped · tooling self-tests, Type Check · source gates, PR-body guards (one of two runs), Governed Surface Queue Guard, Flag docs affected by code changes, Dogfood Regression Gate, Plan Test Core shards, Test UI, Check PR Size, Auto Label, filter.
  • Still running or queued: Test Core 1/10 to 10/10, Build Core, Type Check · workspace, Type Check · consumer gates, Type Check · debt ledger, Lint · CI, release & engine gates, Lint · docs & code guards, Lint · repo & tooling gates, Lint · scoped · query-options erasure, Lint · scoped · slot lookup & corpus, Live E2E UI, and the second runs of Check Changeset and PR-body guards.
  • This record judges the design. It does not stand in for those gates: the landing seat reads their conclusions on this head before the merge, and a red one is a FAIL this record did not see.

① Derived judgments

  • Accept-set, widened (right). delete('sys_organization', by id) of an organization whose only tenant-owned rows are sys_unit rows was 409 DELETE_RESTRICTED and is now admitted, removing those units. This is ruling 7035627429 option B, word for word.
  • Accept-set, unchanged (right). Every other sys_unit delete still throws 405 ERR_UNIT_DELETE_REFUSED. refuseOrganizationUnitDelete(object, removedWithItsOrganization) throws unless the second argument is true, and its one call site computes that argument from engine state alone.
  • Refusal set, narrowed by one object (right). refuseOrganizationDeleteWhileOwned and organizationOwnedRowCounts skip sys_unit by name, in both readers, so plugin-auth's pre-check and the engine's refusal agree. An organization holding any other record is still refused, and the refusal names only that record.
  • Public surface: none changed. refuseOrganizationUnitDelete gained a required parameter and isOrganizationUnitRemoval is a new export of engine-cascade-planning.ts. Neither is re-exported from a package index.ts; the only callers are in packages/objectql/src. organizationOwnedRowCounts keeps its signature. The DeleteAndAggregateHost gains a read-only cascadeIssuedDeletes getter, internal.
  • Error message (right). UnitDeleteRefusedError now says "never deleted on its own, only with its organization". Code and status are unchanged.
  • Comment-only hunks (right against the tree). sys-unit.object.ts and default-permission-sets.ts now say the engine refuses a direct delete in every context and name the organization delete as the one exemption. Both sentences match the code.

② Semver level

  • .changeset/35812-org-delete-removes-units.md is patch for @objectstack/objectql, @objectstack/platform-objects and @objectstack/plugin-security, and carries Clause-②: yes (widening) and Metadata-protocol: none, the same two lines as the PR body. Patch is right for objectql: a fix that restores a door feat(units): unitConfig on a number field, and the write path checks the unit code #35805 closed by accident, with no public signature change. The widening is declared and described in the "Declared behaviour change" paragraph, and that paragraph matches the diff.
  • The first Check Changeset run concluded success; a second was queued at read time.
  • N2 below: the plugin-security bump publishes no change.

③ Boundary flags

Seat point 1 — unit deletes run with system authority. Accepted.

  • The context is { ...referenceCheckContext(context), tenantId: String(organizationId) }: the caller's transaction and userId kept, isSystem: true, tenant set to the deleted organization.
  • The cited precedent is real and reads as cited: packages/plugins/plugin-auth/src/organization-delete.ts removeOrganizationAuthStructure deletes teams, team members and grants under SYSTEM_CTX inside the request's transaction.
  • Caller authority cannot serve here: organization_admin grants no delete on sys_unit, so a caller-authority delete would be refused for every caller and the ruling could not be met.
  • Reach without an admitted organization delete: none found. removeOrganizationUnits is module-private with one call site, the end of walkReferencingRelations under object === ORGANIZATION_OBJECT. That walk is reached only from cascadeDeleteRelations, called only from delete()'s executor, which runs after the middleware chain (the authorization gate), after the by-id pre-image read under the caller's scope (a missing or unreadable organization row is recordNotFound before the cascade), and after beforeDelete. A predicate delete of sys_organization is refused earlier (organizationPredicateDeleteRefusal), so only a by-id delete arrives.
  • Reach into another organization's units: none found. The ids come from one read with where: { [tenantField]: organizationId }, and both the read and the deletes carry tenantId of that same organization. The unit-test and real-stack pins both keep the other organization's unit.
  • One consequence the seat should know: a sys_unit or * delete hook that writes through ctx.api during the removal writes as system with the caller's userId. That is the same posture as the plugin-auth precedent; hooks are server code.

Seat point 2 — provenance a caller cannot forge. Holds.

  • The gate is referentialCascadeDelete === true && isOrganizationUnitRemoval(this.cascadeIssuedDeletes.getStore()). The first half means THIS call claimed the ambient token (claimReferentialCascadeDelete matches object and exact id, then sets claimed). The second half means that token object is in organizationUnitRemovals, a module-private WeakSet only removeOrganizationUnits adds to.
  • User, system writer, automation run, by id: no ambient token, so no claim: refused.
  • Batched (multi, $in): the removal issues by-id tokens only; a predicate never matches an id token (typeof id === 'object'): refused.
  • A hook's delete during the cascade: the organization's beforeDelete runs before any token exists; a unit's own hook runs after its token is claimed, so a delete of the same unit, a sibling or a batch claims nothing: refused. The claim precedes every middleware and hook of the unit delete; between cascadeIssuedDeletes.run and the claim only engine option-lowering runs.
  • A forged token entered through the engine's TS-private cascadeIssuedDeletes store: claimed, but not in the WeakSet: refused. Pinned, and the dev's ablation a4 shows the pin is the one that catches a claim-only gate.
  • Nothing a request or an ExecutionContext carries is read by the gate.

Seat point 3 — atomicity. Holds for refusals; one declared degrade.

  • refuseOrganizationDeleteWhileOwned runs for every root id before the first relation, every restrict in the relation loop throws before the removal, and the removal is the last statement of the walk. A refused organization delete therefore removes no unit, on any driver. Pinned in both suites (store.writes is empty).
  • A failure AFTER the removal (the organization row's own driver.delete, an aborting afterDelete) rolls the units back wherever the plan is 'atomic', which it is whenever sys_unit sits on the default driver, because its tenant column is itself a relation planCascadeAtomicity counts. On a driver without transactions the units stay removed while the organization lives. That is ADR-0119 D1's declared degrade, shared by every cascade and by the plugin-auth path ("the refusals are the guarantee"). Not a finding of this PR; the seat may want it written into the ADR-0158 note.
  • A unit inserted by another writer between the removal's read and the organization row's delete is left naming a deleted organization. The same window exists for every owned row the refusal counts; not new here.

SQL push-down. removeOrganizationUnits reads the organization's unit ids and deletes each by id. A reason is given in its docblock: each unit goes through the public delete() under a token naming exactly that unit, so hooks, audit and events are a cascade child's, and the provenance is per row. The id set is inherent in that mechanism, and an organization's units are tens of rows. Accepted; no finding.

Dev flags and open questions.

  • "Unit deletes run with system authority, dev recommends accept": answered above, accepted.
  • "An OI11 ADR note is owed on landing": true, and the claim forbids docs/adr/** here. ADR-0158 on main still says a deleted code "is never created again" with no exemption. See N4.
  • "Out of scope, not filed: the two comments still say every context": stale. The head's second commit fixed both. See N3.

④ Design judgment

No must-fix, no should-fix.

packages/objectql/src/validation/unit-code-membership.ts (hits). Holds. The function stays a pure refusal and takes the verdict as a boolean, so the membership module learns nothing about cascades. The docblock's three sentences ("the engine's own answer", "claimed once", "anyone else's delete while the organization's delete is in flight is refused") each match the call site and claimReferentialCascadeDelete. Against ADR-0158 Open item 11: the hazard is a code created again with another meaning inside an organization; a deleted organization creates nothing, so the exemption does not reopen it. L1's "old rows keep their code" is untouched: rows that outlive the organization keep the code and show it without a label.

packages/objectql/src/engine-delete-and-aggregate.ts (hits). Holds. The refusal moved from the top of delete() to just after the cascade claim, which it must follow to read it. Every statement between the two positions either throws or lowers options; none returns, writes, or runs caller code, so "before any middleware or hook" is still true. See N1.

packages/objectql/src/engine-cascade-planning.ts (hits). Holds. Placement, provenance and tenant scoping are judged in ③. The two skips are by object name in both readers and sit beside the outlivesOrganization skip they mirror. removeOrganizationUnits returns early when sys_unit is unregistered or has no tenant column, and treats a missing table as no rows, as the counts do. The removal does not rely on the generic relation loop: the tenant column is skipped there (isTenantColumnSetNull), so the units go only through the dedicated, token-carrying path. sys_* objects take no recycle bin, so no unit entry survives the organization.

packages/objectql/src/engine.ts (implementing). Agrees. The organizationOwnedRowCounts docblock names the sys_unit skip and its ruling; the delete host's new getter hands the same AsyncLocalStorage the claim reads.

packages/platform-objects/src/system/sys-unit.object.ts, packages/plugins/plugin-security/src/objects/default-permission-sets.ts (implementing, comment only). Agree with the code, sentence by sentence.

Nits, none affecting correctness or the contract:

  • N1 (nit) — A malformed direct unit delete (an unknown option, a cross-datasource transaction, a refused permanent) now answers that earlier refusal instead of 405 ERR_UNIT_DELETE_REFUSED. It is refused either way. Accepted deviation.
  • N2 (nit) — The changeset bumps @objectstack/plugin-security, whose only change is an inline // comment, so that release publishes nothing. platform-objects at least changes an emitted docblock. Lane seat's call under its ACCEPT; no fix needed on this head.
  • N3 (nit, prose face) — The PR body disagrees with the tree in two places: "Changeset … (objectql patch)" where the changeset names three packages, and the acceptance note that the two comments "still say every context" where the head has corrected them. Fix in the PR body only.
  • N4 (nit, process) — Fixes #35812 closes the card on merge while its fourth "What to build" bullet, the ADR-0158 Open item 11 note naming the exemption, is still owed in a later PR. Until that lands, the ADR on main and the code disagree. The seat should keep the note tracked on an open card (Units of measure R1: a number field declares its unit (unitConfig) and the write path checks the unit code #35489 or its amendment PR) before this one closes.

Implemented-by: claude/project-thread-thptm0
Reviewed-by: session_01L9qibvMi1U7R2kBd3JbTPu

VERDICT: PASS

@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

repo:objectstack#7 · os-tesla · session_01L9qibvMi1U7R2kBd3JbTPu

Landing #35930 at 5ebea45947f3aa30f0c874a2f361345598f81f27 · 2026-11-20T20:01Z

Probe Reading
CI at 5ebea45 pr-state.mjs --pr 35930: 39 success, 22 expected skip, 0 unexpected skip, 0 pending; mergeable_state clean. The one non-success is a Check Changeset run cancelled at 19:38Z by the body edit's re-trigger; the run that replaced it (job 136523304898) concluded success at 19:40Z
check-governed-merges.mjs --pr 35930 (final list) NOT governed. 384 changed lines ≤ 3000, so an ordinary queue landing
landing-k.mjs --pr 35930 K = 3 < 15, no new locale pack, no shared book moved under this PR's
Generated-artifact drift, re-measured now main since the merge base moves no merge=os-regen path, so no regen merge is owed
Reviews L1 ACCEPT 7048789713 (its owed body fix done at 19:35Z) · L2 PASS 7048866693 at CONTRACT_REVIEW_TIER (no must-fix, no should-fix; N1–N4 nits, N3 fixed in the body, N4 tracked as below) · claim 7047043860, amendment 7048707723 · security label added for Security-touching: yes

State change: ready for review, then auto-merge. This is the PR the maintainer is holding the Version Packages release for (7046995545). Fixes #35812. Follow-up: the ADR-0158 Open item 11 replacement sentence (in the PR body) goes on the weekly ADR-revisions card when this merges, per seat 7.

@objectstack-fleet
objectstack-fleet Bot marked this pull request as ready for review November 20, 2026 20:02
@objectstack-fleet
objectstack-fleet Bot added this pull request to the merge queue Nov 20, 2026
Merged via the queue into main with commit 17ed9e7 Nov 20, 2026
62 of 63 checks passed
@objectstack-fleet
objectstack-fleet Bot deleted the claude/project-thread-thptm0 branch November 20, 2026 20:28
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 security 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

Development

Successfully merging this pull request may close these issues.

Units of measure: deleting an organization also deletes its units (the one exemption from the sys_unit delete refusal)

1 participant