Repository navigation
Commit 7dd1a2f
fix(objectql): a system-door delete of a record with no organization keeps it in the recycle bin (#36097)
repo:objectstack#7 · os-tesla · session_01L9qibwJEh7hMPPvagWM1g7
Fixes #35667
Clause-②: no
Metadata-protocol: none
Clause-② basis: no (the seat's reading, from L1 O1 7063276615). Under a
walled posture, a system-door delete of an org-less record is now
refused with `ERR_SYSTEM_WRITE_ORGANIZATION_REQUIRED`. That is not a
narrowed accept set. Every SQL store already refused that delete on the
bin's NOT NULL. The memory store accepted it only by writing a bin entry
no organization owns, which breaks the bin's own invariant (ADR-0148 D1,
ADR-0131 D1): no organization's listing or cascade reaches it. The fix
makes every store answer as D9 states, so it is a bug fix, not a
`(narrowing)`.
## 维护者速读
-
用户能看到什么变化:流程、钩子或管理工具以系统身份删除一条不归属任何组织的记录时,记录会进入回收站并可恢复,不再报数据库错误;多组织隔离模式下则明确拒绝并说明原因。
- 为什么做:回收站功能的修复,替以系统身份删除全局记录的流程和管理工具解决删除失败的问题。
- 出错会怎样:最坏情况是系统身份删除被拒绝而记录原样保留,不会丢数据;撤回本次改动即恢复原状。
- 要你做什么:无。
## What changes
A delete under `{ isSystem: true }` of a record that names no
organization (a record of a `tenancy: { enabled: false }` object) wrote
its recycle-bin entry with no organization. On SQL the delete failed
with `NOT NULL constraint failed: sys_recycle_bin.organization_id` and
the record stayed. On a store that enforces no NOT NULL, the delete
succeeded and left an entry that no organization owned.
The entry is a row of a tenant-column object (ADR-0148 D1). It now takes
the organization any system insert takes (ADR-0131 D9): the record's
own, else the context's, else the engine's one system-insert resolver.
Under `single` that resolver answers the Default Organization. Under a
wall it refuses with `ERR_SYSTEM_WRITE_ORGANIZATION_REQUIRED` before the
root row is removed.
Route B of the seat's routing call (claim amendment 7062354282, analysis
7062338699): `packages/objectql/src/engine.ts` gains no line and
`scripts/facade-delegation-registry.json` is untouched.
- `packages/objectql/src/engine-delete-and-aggregate.ts`: the delete
module already holds the engine and already reads a sibling facet's host
through it (`securityResolversHost.of(this.facade)`). It hands the
capture's `write()` a call to
`MiddlewareAndContextFacet.resolveSystemInsertOrganization` through
`middlewareAndContextHost.of(this.facade)`. That is the same body the
engine's insert calls, not a second spelling of it.
- `packages/objectql/src/recycle-bin/capture.ts`:
`write(resolveSystemInsertOrganization)` stamps the resolver's answer
when neither the record nor the context names an organization. A new
exported type `RecycleBinSystemInsertOrganization` states the contract
and why it arrives as an argument and not as a `RecycleBinCaptureHost`
member.
- Pins:
- `packages/runtime/src/recycle-bin-orgless-system-delete.test.ts`: a
real `ObjectQL` on a real `SqlDriver` (better-sqlite3), the bin as
platform-objects declares it, and the Default Organization.
- A top-level describe in
`packages/objectql/src/recycle-bin/capture.test.ts`, the shared capture
harness, for the store that enforces no NOT NULL.
- A `patch` changeset for `@objectstack/objectql`.
### Files to read first
1. `packages/objectql/src/recycle-bin/capture.ts`, the `write()` hunk:
the order is record, then context, then resolver, and a refusal throws
before `driver.create`.
2. `packages/objectql/src/engine-delete-and-aggregate.ts`, the
`bin?.write(...)` call: the cross-facet host read.
3. `packages/objectql/src/recycle-bin/capture.test.ts`, the `makeEngine`
Default Organization seed: fixture triage, see Acceptance notes.
### Two-minute check
Run `pnpm --filter @objectstack/runtime exec vitest run --project local
src/recycle-bin-orgless-system-delete.test.ts` after building objectql.
Expect 3 passed: under `single` the entry's `organization_id` is
`org_default` and restore brings the record back; a context-named
organization is kept; under `isolated` the delete is refused with
`ERR_SYSTEM_WRITE_ORGANIZATION_REQUIRED` and the record stays.
## Tests
All readings are on head 4bd70f0 unless noted.
<details><summary>Measurement before the fix (main 8145424, scratch
test, not committed)</summary>
- sqlite: the system-door delete threw `SQLITE_CONSTRAINT_NOTNULL`, `NOT
NULL constraint failed: sys_recycle_bin.organization_id`, and no entry
was written. A beforeDelete hook saw session `{ isSystem: true }` and no
`tenantId`.
- memory store: the delete answered `true`, and the bin held `{
object_name: mz_global, organization_id: null }`.
- Control on sqlite: a tenant-column record written by a system insert
was stamped `org_default` (D9), and its delete kept the entry under
`org_default`.
</details>
<details><summary>Gate before building (route B premises)</summary>
- `pnpm check:facade-delegation-only` exited 0 and printed
`packages/objectql/src/engine.ts: 6857 lines, ceiling 6857 (0 left;
ruling 7051956587)`. `wc -l packages/objectql/src/engine.ts` reads 6857.
- `pnpm --filter @objectstack/objectql typecheck` (`tsc --noEmit && pnpm
check:test-typecheck`) passed under lock VERDICT command-exit 0 with the
cross-facet call in place.
</details>
<details><summary>Pins, ablation and package suites</summary>
- Runtime pin (sqlite): Tests 3 passed (3).
- Capture harness: Tests 30 passed (30). The `src/recycle-bin/`
directory: Test Files 5 passed, Tests 178 passed.
- Ablation on head 4bd70f0:
- The mutation went through `scripts/ablation-replace.mjs`, replacing
the resolver call with `const derived: string | undefined = undefined;`.
Anchor count went 1 to 0, and the blob went d124655 to
79309b11f005.
- objectql was rebuilt, and `ablation-dist-preflight --absent` confirmed
the marker was absent from all 14 built files.
- Results with the mutation: the runtime pin had 2 failed and 1 passed
(the context control). The capture harness had 2 failed and 28 passed.
- Restore: `git checkout HEAD --`, then `git diff HEAD` was 0 bytes and
the hash matched d124655. objectql was rebuilt, the preflight found
the marker present in 2 built files, and the tree was clean.
- After the restore the runtime pin had 3 passed and the capture harness
30 passed.
- `pnpm --filter @objectstack/objectql test`: Test Files 624 passed
(624), Tests 14217 passed (14217). `pnpm --filter @objectstack/objectql
typecheck` passed. Lock VERDICT command-exit 0.
- Consumers that compose the bin and delete without a booted auth (`mcp`
stdio-data-bridge.recycle-bin, `cloud-connection`
connection-credential-ledger, `metadata-protocol` seed-tenancy-backfill,
`runtime` sandbox body-runner): 5, 11, 58 and 42 tests passed. Lock
VERDICT command-exit 0.
- Not run locally, left to CI: `pnpm --filter @objectstack/runtime
typecheck`, which needs the runtime dependency closure built, and
`test:repo`.
</details>
## Verification
<details><summary>Gate families</summary>
`node scripts/pm/dispatch-gates.mjs --commands` derived 66 families on
4bd70f0, and all 66 exited 0. `--ran` reconciliation: 66 derived, 66
run, 0 NOT-MEASURED, 0 UNRUN.
On the earlier head e95ae7d, `check:driver-memory-census` was red
because the first runtime pin imported `@objectstack/driver-memory`.
Head 4bd70f0 moved that leg into the capture harness, and the census
is green there.
`overlap-check` returned a clean verdict before each push: origin/main
merges cleanly, and so does #36060, which shares
`engine-delete-and-aggregate.ts`.
</details>
## Acceptance notes
- **Deviation from the dispatch: the memory leg is not on
`@objectstack/driver-memory`.** A new test consumer of that driver is a
ruled disposition. `check:driver-memory-census` printed: "LEDGERED: …
binds @objectstack/driver-memory (import) and the ledger does not cover
it … Rule it, migrate it, or file it". So the store that enforces no NOT
NULL is pinned in the capture harness, which keeps rows the way
`driver-memory` does. That harness is the shared harness file for this
component.
- **Fixture triage (adds a missing declaration).** The capture harness
registered `sys_organization` but held no organization. Under `single`
that is the broken boot invariant D9 refuses. Ten existing capture tests
deleted org-less records with org-less contexts there and went red on
`ERR_SYSTEM_WRITE_ORGANIZATION_REQUIRED`. The harness now seeds the
Default Organization. The one test whose deletes all name their
organization (the organization-delete cascade) opts out, so it still
counts only its own two organizations.
- **Walled posture.** A system-door delete with no `tenantId` of a
tenancy-disabled record is refused with
`ERR_SYSTEM_WRITE_ORGANIZATION_REQUIRED` (500) and the record stays. The
seat accepted this as D9 as written. A caller that needs it threads
`tenantId` on the context.
- **MongoDB.** `MongoDBDriver` does not stamp the tenant column on
insert, by its own docblock
(`packages/drivers/driver-mongodb/src/mongodb-driver.ts`, the
single-tenant note). A tenant-column row it writes therefore carries no
`organization_id`. No test here reproduces that; this is a code read
only, and on the seat's word it is noted here and not filed. The capture
change covers the system-door delete of such a row under `single`.
---
_Generated by [Claude
Code](https://claude.ai/code/session_01L9qibwJEh7hMPPvagWM1g7)_
<!-- signed: repo:objectstack#7 · os-tesla ·
session_01L9qibwJEh7hMPPvagWM1g7 -->
---------
Co-authored-by: Claude <noreply@anthropic.com>1 parent 3ae62ac commit 7dd1a2f
5 files changed
Lines changed: 241 additions & 7 deletions
File tree
- .changeset
- packages
- objectql/src
- recycle-bin
- runtime/src
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
41 | 41 | | |
42 | 42 | | |
43 | 43 | | |
44 | | - | |
| 44 | + | |
| 45 | + | |
45 | 46 | | |
46 | 47 | | |
47 | 48 | | |
| |||
687 | 688 | | |
688 | 689 | | |
689 | 690 | | |
690 | | - | |
| 691 | + | |
| 692 | + | |
| 693 | + | |
| 694 | + | |
| 695 | + | |
| 696 | + | |
| 697 | + | |
691 | 698 | | |
692 | 699 | | |
693 | 700 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
217 | 217 | | |
218 | 218 | | |
219 | 219 | | |
| 220 | + | |
| 221 | + | |
220 | 222 | | |
221 | | - | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
222 | 233 | | |
223 | 234 | | |
224 | 235 | | |
225 | 236 | | |
226 | 237 | | |
227 | | - | |
| 238 | + | |
228 | 239 | | |
229 | 240 | | |
| 241 | + | |
230 | 242 | | |
231 | 243 | | |
232 | 244 | | |
| |||
532 | 544 | | |
533 | 545 | | |
534 | 546 | | |
535 | | - | |
| 547 | + | |
| 548 | + | |
536 | 549 | | |
537 | 550 | | |
538 | 551 | | |
| |||
599 | 612 | | |
600 | 613 | | |
601 | 614 | | |
| 615 | + | |
| 616 | + | |
| 617 | + | |
| 618 | + | |
| 619 | + | |
| 620 | + | |
| 621 | + | |
| 622 | + | |
| 623 | + | |
| 624 | + | |
| 625 | + | |
| 626 | + | |
| 627 | + | |
| 628 | + | |
| 629 | + | |
| 630 | + | |
| 631 | + | |
| 632 | + | |
| 633 | + | |
| 634 | + | |
| 635 | + | |
| 636 | + | |
| 637 | + | |
| 638 | + | |
| 639 | + | |
| 640 | + | |
| 641 | + | |
| 642 | + | |
| 643 | + | |
| 644 | + | |
| 645 | + | |
| 646 | + | |
| 647 | + | |
| 648 | + | |
| 649 | + | |
| 650 | + | |
| 651 | + | |
| 652 | + | |
| 653 | + | |
| 654 | + | |
| 655 | + | |
| 656 | + | |
| 657 | + | |
| 658 | + | |
| 659 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
92 | 92 | | |
93 | 93 | | |
94 | 94 | | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
95 | 118 | | |
96 | 119 | | |
97 | 120 | | |
| |||
238 | 261 | | |
239 | 262 | | |
240 | 263 | | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
241 | 271 | | |
242 | | - | |
| 272 | + | |
243 | 273 | | |
244 | 274 | | |
245 | 275 | | |
| |||
267 | 297 | | |
268 | 298 | | |
269 | 299 | | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
270 | 315 | | |
271 | 316 | | |
272 | 317 | | |
| |||
324 | 369 | | |
325 | 370 | | |
326 | 371 | | |
327 | | - | |
| 372 | + | |
| 373 | + | |
328 | 374 | | |
329 | 375 | | |
330 | 376 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
0 commit comments