Skip to content

Commit 61d7ebc

Browse files
committed
fix(metadata-protocol,runtime): the move-in door judges each item's type, calls no door on a dry run, and puts the process back when a move stops (#38150)
- Each selected item's type is judged as a write of that type before anything is read or written (403 with its code), and a selected knowledge source is admitted for its new author as its save admits one. - A dry run answers the judgement made before any door runs and calls no door. - After a rollback or an undo, the registry, the mutation projector and the mutation signal run again at both addresses, so a refused move leaves every item served loose, as before. - An undo that fails answers a 500 naming the items that did not go back. A failure that is not a refusal, or a failed package commit, answers a 500 fault; a door's refusal keeps its code and sentence, filtered as the publish door filters them, and one with no code is MOVE_FAILED. - Each delete names the version the judgement read, so a save in between answers METADATA_CONFLICT. - client.packages.moveIn documents and tests that a refusal rejects with the code and the whole answer in details. Claude-Session: https://claude.ai/code/session_01L9qibyHmxFV4bTFZ5BKnUz Co-authored-by: Claude <noreply@anthropic.com>
1 parent 3777fbc commit 61d7ebc

11 files changed

Lines changed: 562 additions & 86 deletions

File tree

‎.changeset/38150-move-into-package-door.md‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,11 @@ What a move does:
1818
- The target is judged by the save door's own predicates: an uninstalled package is refused `422 WRITABLE_PACKAGE_REQUIRED`, and a package the deployment ships is refused as every package write door refuses it.
1919
- An object is judged against the target by the save door's object judges: the namespace prefix (`NAMESPACE_PREFIX`), the namespace clash (`NAMESPACE_CONFLICT`), the package that owns the name (`OBJECT_OVERLAY_PACKAGE_MISMATCH`) and the `__c` reservation.
2020
- The selection is judged as a set (ADR-0150 D3 (a)): a moved item that names a loose item of a package-scoped type the selection leaves behind is refused `REFERENCE_LEFT_BEHIND`, with the names in `references`.
21-
- Then every item goes through the delete door (storage kept) and the save door into the target, so every other save-door judge runs too, and each type writes through to the registry at once: a moved flow and dataset are read at the package's address with no restart. Items other than objects and the package commit (`operation: 'apply'`) run in one transaction. Objects move just before it, outside it, because an object's save syncs its storage, and that DDL waits forever on the lock a SQLite transaction holds. A later refusal undoes them.
22-
- Whole or nothing: any refusal answers `422` with the first item's code in `error.code` and the whole answer (`outcome: 'refused'`, every item's refusal) in `error.details`. Nothing is written.
23-
- `dryRun: true` answers `outcome: 'would_move'` with what each item's addresses become, and writes nothing.
21+
- Each selected item's type is judged as a write of that type: moving a `datasource` needs the platform-settings capability and moving a `knowledge_source` needs the knowledge-source capability and passes that source's own admission, as saving one does (`403`).
22+
- Then every item goes through the delete door (storage kept, naming the version the judgement read, so a save in between answers `409 METADATA_CONFLICT`) and the save door into the target, so every other save-door judge runs too, and each type writes through to the registry at once: a moved flow and dataset are read at the package's address with no restart. Items other than objects and the package commit (`operation: 'apply'`) run in one transaction. Objects move just before it, outside it, because an object's save syncs its storage, and that DDL waits forever on the lock a SQLite transaction holds. A later refusal undoes them.
23+
- Whole or nothing: any refusal answers `422` with the first item's code in `error.code` and the whole answer (`outcome: 'refused'`, every item's refusal) in `error.details`. What had moved is moved back, with the registry and the mutation signal replayed at both addresses, so every item is loose and resolves as before. A failure that is not a refusal answers `500`, every item loose as before; if moving an item back fails, the `500` names the items that did not go back.
24+
- `dryRun: true` answers `outcome: 'would_move'` with what each item's addresses become from the judgement made before any door runs (loose, target, the object judges, the set). It calls no door and writes nothing, so a save-door judge that runs only on the real move can still refuse an item a dry run passed.
25+
- `client.packages.moveIn` resolves the answer for `moved` and `would_move`. A refusal, a refused dry run included, rejects with the first item's code as `code` and the whole answer as `details`.
2426

2527
Measured on this door: after a move, `_env/NAME` answers `409 RESOURCE_CONFLICT` naming the package that now holds the item, and the bare name and `NAMESPACE/NAME` answer `200`.
2628

‎content/docs/references/api/package-lifecycle.mdx‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,7 @@ A navigation item another installed package contributes to an app the base owns,
342342
| **name** | `string` | ✅ | Name of the moved item; a move never renames. |
343343
| **member** | `string` | optional | The bundle member moved, for a bundled type. |
344344
| **states** | `Enum<'active' \| 'draft'>[]` | ✅ | Which of the item's rows moved: its published row, its pending draft, or both. |
345-
| **environmentAddress** | `string` | optional | The environment-qualified address the item answered at before the move (`_env/NAME`), present for a type addressed by package (ADR-0150 D5). After the move it no longer resolves: the item answers at `qualifiedAddress` and, while it is the only holder of its name, at its bare name. |
345+
| **environmentAddress** | `string` | optional | The environment-qualified address the item answered at before the move (`_env/NAME`), present for a type addressed by package (ADR-0150 D5) when the target package declares a namespace. After the move it no longer resolves: the item answers at `qualifiedAddress` and, while it is the only holder of its name, at its bare name. |
346346
| **qualifiedAddress** | `string` | optional | The package-qualified address the item answers at after the move (`NAMESPACE/NAME`), present beside `environmentAddress`. |
347347
| **aiFaceName** | `{ before: string; after: string }` | optional | The AI face name change (ADR-0150 D6), present for a tool, skill, agent or object-less action whose face the move changes. |
348348

@@ -388,7 +388,7 @@ Body of `POST /packages/:id/move-in`: the selection of loose items to move into
388388
| Property | Type | Required | Description |
389389
| :--- | :--- | :--- | :--- |
390390
| **items** | `{ type: string; name: string; member?: string }[]` | ✅ | The loose items to move: one, several, or every loose item of a type, across types. Each names an item bound to no package; an item a package holds, a customization pair item and an overlay of a shipped item are not loose and are refused. Listed once each. |
391-
| **dryRun** | `boolean` | optional | Judge the move and answer what it would do, writing nothing. Omitted or false, the move is made. |
391+
| **dryRun** | `boolean` | optional | Answer what the move would do from the judgement made before any door runs (loose, target, the object judges, the set), calling no door and writing nothing. A save-door judge runs only on the real move, so it can still refuse an item a dry run passed. Omitted or false, the move is made. |
392392

393393
### Nested Shape: `MoveIntoPackageRequest.items[number]`
394394

@@ -403,13 +403,13 @@ Body of `POST /packages/:id/move-in`: the selection of loose items to move into
403403

404404
## MoveIntoPackageResponse
405405

406-
Answer of the move door: what moved (or would move) and what each moved item's addresses become, or every refusal with nothing moved.
406+
Answer of the move door: what moved (or would move) and what each moved item's addresses become, or every refusal with every item left loose.
407407

408408
### Properties
409409

410410
| Property | Type | Required | Description |
411411
| :--- | :--- | :--- | :--- |
412-
| **outcome** | `Enum<'moved' \| 'would_move' \| 'refused'>` | ✅ | `moved`: every item moved. `would_move`: a dry run that would move every item; nothing was written. `refused`: at least one item is refused, so nothing moved. |
412+
| **outcome** | `Enum<'moved' \| 'would_move' \| 'refused'>` | ✅ | `moved`: every item moved. `would_move`: a dry run whose judgement passed every item; no door ran and nothing was written. `refused`: at least one item is refused, so what had moved was moved back and every item is loose, as before. |
413413
| **targetPackageId** | `string` | ✅ | The package the items move into. |
414414
| **moved** | `{ type: string; name: string; member?: string; states: Enum<'active' \| 'draft'>[]; … }[]` | ✅ | Every item, with what the move changes in its addresses. Empty on `refused`. |
415415
| **refused** | `{ type: string; name: string; member?: string; code: string; … }[]` | ✅ | Every refused item, each with its own code. Empty unless `outcome` is `refused`. |
@@ -423,7 +423,7 @@ Answer of the move door: what moved (or would move) and what each moved item's a
423423
| **name** | `string` | ✅ | Name of the moved item; a move never renames. |
424424
| **member** | `string` | optional | The bundle member moved, for a bundled type. |
425425
| **states** | `Enum<'active' \| 'draft'>[]` | ✅ | Which of the item's rows moved: its published row, its pending draft, or both. |
426-
| **environmentAddress** | `string` | optional | The environment-qualified address the item answered at before the move (`_env/NAME`), present for a type addressed by package (ADR-0150 D5). After the move it no longer resolves: the item answers at `qualifiedAddress` and, while it is the only holder of its name, at its bare name. |
426+
| **environmentAddress** | `string` | optional | The environment-qualified address the item answered at before the move (`_env/NAME`), present for a type addressed by package (ADR-0150 D5) when the target package declares a namespace. After the move it no longer resolves: the item answers at `qualifiedAddress` and, while it is the only holder of its name, at its bare name. |
427427
| **qualifiedAddress** | `string` | optional | The package-qualified address the item answers at after the move (`NAMESPACE/NAME`), present beside `environmentAddress`. |
428428
| **aiFaceName** | `{ before: string; after: string }` | optional | The AI face name change (ADR-0150 D6), present for a tool, skill, agent or object-less action whose face the move changes. |
429429

‎packages/client/src/index.ts‎

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3632,10 +3632,15 @@ export class ObjectStackClient {
36323632
/**
36333633
* Move a selection of loose (package-less) items into this package — one
36343634
* item, several, or every loose item of a type, across types. Whole or
3635-
* nothing: the answer's `outcome` is `moved`, or `refused` with every
3636-
* refused item's own code and nothing moved; `dryRun: true` answers
3637-
* `would_move` and writes nothing, so a confirm step can show what each
3638-
* item's addresses become.
3635+
* nothing. A move resolves with `outcome: 'moved'`; `dryRun: true`
3636+
* resolves with `outcome: 'would_move'` and calls no write, so a confirm
3637+
* step can show what each item's addresses become (the judgement is the
3638+
* door's own, so a save-door refusal can still meet the real move).
3639+
*
3640+
* A refusal is THROWN, never resolved: the server answers it 422, and the
3641+
* error carries the first refused item's code as its `code` and the whole
3642+
* answer (`outcome: 'refused'`, every item's refusal) in its `details`.
3643+
* A refused dry run throws the same way.
36393644
*/
36403645
moveIn: async (id: string, request: MoveIntoPackageRequest): Promise<MoveIntoPackageResponse> => {
36413646
const route = this.getRoute('packages');

‎packages/client/src/packages-lifecycle.test.ts‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,25 @@ describe('client.packages lifecycle (#3563 PR-4)', () => {
101101
});
102102
});
103103

104+
it('moveIn rejects a refused move with the first item\'s code and the whole answer in details', async () => {
105+
const answer = {
106+
outcome: 'refused',
107+
targetPackageId: 'p1',
108+
moved: [],
109+
refused: [{ type: 'flow', name: 'f', code: 'NOT_LOOSE', error: "flow 'f' is not loose." }],
110+
};
111+
const { client } = createMockClient({
112+
success: false,
113+
error: { code: 'NOT_LOOSE', message: "flow 'f' is not loose.", httpStatus: 422, details: answer },
114+
}, 422);
115+
const err: any = await client.packages
116+
.moveIn('p1', { items: [{ type: 'flow', name: 'f' }] })
117+
.then(() => { throw new Error('expected the refused move to reject'); }, (e) => e);
118+
expect(err.code).toBe('NOT_LOOSE');
119+
expect(err.httpStatus).toBe(422);
120+
expect(err.details).toEqual(answer);
121+
});
122+
104123
it('ensureCustomization POSTs to the ensure door with no body, URL-encoding the base id, and returns the answer', async () => {
105124
const answer = {
106125
basePackageId: 'com.acme.crm',

0 commit comments

Comments
 (0)