Repository navigation
Commit 9bb9370
fix(metadata-protocol): an orphan adoption rebinds a draft view in storage only, never registering it live (#23724)
Fixes #23690
Clause-②: no
Dev session `session_01SVE8bSorrxjRHx7edWAdKm`, dispatched by
`domain:engine` seat 1 (`session_01GP3comALHRcRBixS2TEnLF`), claim
6200629773.
## What this does
`reassignOrphanedMetadata` (the method `POST
/api/v1/packages/:id/adopt-orphans` calls, ADR-0070 D5) sends each
rebound view row through the registry write-through (#23198). The view
limb admitted a row by its type alone, so adopting a package-less
**draft** view registered its draft body as live, stamped `_packageId` =
the target package, until the next boot (which registers active rows
only, `loadMetaFromDb`). `applyRegistryWriteThrough`'s own header says
drafts "are a staging buffer and must never leak into the runtime"
(ADR-0048).
- **The fix, at the producer:** one `row.state !== 'active'` gate now
runs before both limbs (view and object). It replaces the object limb's
own copy of the same check (PR #23688), so the object limb's behaviour
is byte-for-byte the same (its pins green, below). An adopted draft view
is rebound in storage only.
- **Unchanged:** which rows are rebound, each row's stored `state`,
`reassignedCount` / `reassigned`, and an adopted ACTIVE view going live
at its new binding.
- **A second face of the same defect, now pinned:** a draft adopted
beside an active row of the same view name *replaced* the published body
the registry served (measured red on `main`, below).
- Accept sets: none moves. No door's accepted input changes; only what
the registry serves for an unpublished view, which is the implementation
brought back to its declared contract.
- ADRs: `docs/adr/` grepped for the surface (ADR-0070 D5 rules on the
storage rebind only; ADR-0048 on draft / active). No ADR is reversed.
## Verification (final head `f60a676d6`, a merge commit of `origin/main`
`9e0945cf4` that brought in PR #23706)
- **Negative control on `main` (`4c21e57169`), before the fix**, the new
pins on a real `ObjectKernel` + `ObjectQLPlugin`: `Tests 2 failed | 1
passed (3)`. The draft case: `registerItem` was called with `['view',
{…}, 'name']`. The draft-beside-active case: served `{ label: 'Draft
gadgets', … }` where `'Published gadgets'` was expected. The CONTROL
(active view adopted) passed.
- **Pins after the fix**
(`packages/objectql/src/protocol-adopt-orphans-draft-view-registry.test.ts`,
beside the object-registry pin):
- an adopted DRAFT view: the registry serves nothing before and after
the adoption, no `registerItem('view', …)` call, the stored row is Q's
draft, `reassignedCount: 1`, and a boot afterwards serves nothing;
- a draft adopted beside an active row of the same view:
`reassignedCount: 2`, the active body is served at Q, and a boot agrees;
- CONTROL: an adopted active view is served at Q at once, and a boot
agrees.
- With the object-registry pin and `protocol-package-lifecycle.test.ts`:
`Test Files 3 passed (3)`, `Tests 19 passed (19)` (before and after the
main merge).
- **Ablation** (`scripts/ablation-replace.mjs`, the gate narrowed to
objects only, `metadata-protocol` rebuilt, `ablation-dist-preflight`
marker present in `dist/index.cjs` and `dist/index.js`): `Tests 2 failed
| 7 passed (9)`, the two draft-view pins red; the CONTROL and all five
object pins green. Restored: blob == HEAD `07e2e03b650b`, `git diff
HEAD` empty; rebuilt, `--absent` clean across 24 built files, pins 3/3.
- **HTTP door, walked once** on `pnpm dev:crm -- --fresh -p 38690`
(better-sqlite3): package `com.qa.q` created (`201`), a package-less
draft view and a package-less active view seeded into `sys_metadata` (no
door writes package-less rows today). Before: `GET
/api/v1/meta/view/qa_draft_grid` `404`; the active one `200`. `POST
/api/v1/packages/com.qa.q/adopt-orphans` `200`, `reassignedCount: 2`.
After: draft `404 RESOURCE_NOT_FOUND`; active `200`, `label: 'Published
gadgets'`, `_packageId: 'com.qa.q'`; both stored rows bound to
`com.qa.q`, states unchanged.
- **HTTP negative control** (the same ablation, one-off, second server
on port 38691): the same sequence answered `GET
/api/v1/meta/view/qa_draft_grid` `200` with `"label":"Draft
gadgets","_packageId":"com.qa.q"` after the adoption. So the leak was
reachable at the public door, and the fix closes it there.
- **Suites:** `@objectstack/metadata-protocol` full suite `Test Files
236 passed | 3 skipped (239)`, `Tests 20566 passed | 19 skipped` on
`f60a676d6`. PR #23706's REST pin
`meta-draft-head-package-inheritance.test.ts` re-run after the merge:
21/21.
- **Typecheck:** `@objectstack/metadata-protocol` and
`@objectstack/objectql` exit 0 (`objectql`'s includes
`check:test-typecheck`: OK, debt held).
- **Derived gates** on `f60a676d6`: `node scripts/pm/dispatch-gates.mjs
--commands --repo objectstack-ai/objectstack` (3 paths, 67 commands),
all run; reconciled with `--ran`: `67 derived, 67 run, 0 NOT-MEASURED, 0
UNRUN` (a derived zero, every line carrying its exit code). Two families
first refused on the shallow clone (`check-engine-split-ratio.mjs --days
90` exit 2, `check-plugin-teardown-shape.mjs --self-test` exit 3); after
`git fetch --shallow-since=2026-07-10` both re-ran at exit 0.
## Neighbours
Open PRs touching `packages/metadata-protocol/src/protocol.ts`: PR
#23704 (#23514, the D9.9 / `saveMetaItem` region) only; `git merge-tree`
of this head with its branch is clean. PR #23418 touches a
`metadata-protocol` test file, not `protocol.ts`. PR #23706 (#23657)
landed on `main` while this was in flight and is merged in with a merge
commit (no conflict); its pins above.
## Acceptance notes
- #23646 and PR #23688 are referenced as context only.
- None found outside the card's scope.
---
_Generated by [Claude
Code](https://claude.ai/code/session_01SVE8bSorrxjRHx7edWAdKm)_
Co-authored-by: Claude <noreply@anthropic.com>1 parent fdbcec0 commit 9bb9370
3 files changed
Lines changed: 264 additions & 5 deletions
File tree
- .changeset
- packages
- metadata-protocol/src
- objectql/src
| 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 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
27627 | 27627 | | |
27628 | 27628 | | |
27629 | 27629 | | |
| 27630 | + | |
| 27631 | + | |
| 27632 | + | |
| 27633 | + | |
| 27634 | + | |
| 27635 | + | |
| 27636 | + | |
| 27637 | + | |
27630 | 27638 | | |
27631 | 27639 | | |
27632 | 27640 | | |
| |||
27702 | 27710 | | |
27703 | 27711 | | |
27704 | 27712 | | |
| 27713 | + | |
| 27714 | + | |
| 27715 | + | |
| 27716 | + | |
| 27717 | + | |
27705 | 27718 | | |
27706 | 27719 | | |
27707 | 27720 | | |
| |||
27712 | 27725 | | |
27713 | 27726 | | |
27714 | 27727 | | |
27715 | | - | |
27716 | | - | |
27717 | | - | |
| 27728 | + | |
27718 | 27729 | | |
27719 | 27730 | | |
27720 | | - | |
27721 | | - | |
| 27731 | + | |
27722 | 27732 | | |
27723 | 27733 | | |
27724 | 27734 | | |
| |||
| 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 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
0 commit comments