Skip to content

Commit a274e36

Browse files
committed
fix(cloud-connection): an orphaned install is compared against the body the registry serves
Claude-Session: https://claude.ai/code/session_017ihL2dvnT51fbSebUyE3zW Co-Authored-By: Claude <noreply@anthropic.com>
1 parent ffe4e23 commit a274e36

3 files changed

Lines changed: 65 additions & 18 deletions

File tree

‎.changeset/30884-schema-upgrade-confirmation.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ Metadata-protocol: none
1616
Before any write, after the access upgrade check, the door compares the installed version (its ledger entry) with the incoming one through `comparePackageVersions` (`@objectstack/metadata-core`), the comparison the dry run and `os diff` read:
1717

1818
- **A suspected rename** (in one object, a stored field removed while a stored field is added, with no `renamedFrom` linking them) or **a type change** the drift categories call `needs_confirm` (both columns stored) or `destructive` (the new type stores no column) answers `409 SCHEMA_UPGRADE_CONFIRMATION_REQUIRED`. `error.details.findings` names each with a one-line `describe` (and, when the runtime's `manifest` service answers `planUpgrade`, the rows the installed column holds); `error.details.findingSet` is the token. The same request with `"confirmSchemaUpgrade": "<findingSet>"` installs, as the additive schema sync leaves the fields, and the ledger entry records `schemaUpgradeConfirmation` (the token, who, when). A token from another finding set is refused again with the fresh one. A type change riding on a declared rename is judged on its own.
19+
- **The installed side** is the ledger entry's body; an orphaned install (the registry still serves the package, the ledger holds no record) is compared against the body the registry serves. When there is no installed body to compare — the ledger file will not parse, or the orphan's registry row carries no body — the same `409` names that as its one finding (`installed_record_unreadable` with the file and the cause, or `installed_record_missing`), and its token admits the re-install, which rewrites the record.
1920
- **A declared rename** (`renamedFrom` on a field of the new version) answers `501 NOT_IMPLEMENTED`, naming each rename: this runtime cannot yet move a renamed field's values to its new key, and no token answers it.
2021
- A `safe` type change (the installed field had no stored column), a removed field or object and a seed dataset change are refused by nothing; `dryRun: true` reports them.
2122

‎packages/cloud-connection/src/marketplace-install-local-plugin.ts‎

Lines changed: 42 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -114,9 +114,11 @@
114114
* `destructive`, answers `409 SCHEMA_UPGRADE_CONFIRMATION_REQUIRED`
115115
* with `details.findings` and the finding set's token; the same
116116
* request with `confirmSchemaUpgrade: <token>` installs and records
117-
* the confirmation in the ledger entry. A record of the installed
118-
* version that will not parse, or an install the registry serves with
119-
* no record, answers the same 409 with one finding naming it
117+
* the confirmation in the ledger entry. An orphaned install (the
118+
* registry serves it, the ledger holds no record) is compared against
119+
* the body the registry serves. A record of the installed version
120+
* that will not parse, or an orphan whose registry row carries no
121+
* body, answers the same 409 with one finding naming it
120122
* (`installed_record_unreadable` / `installed_record_missing`): no
121123
* comparison ran, and its token admits the re-install. Removed fields,
122124
* `safe` type changes and seed changes are refused by nothing.
@@ -672,8 +674,8 @@ function schemaUpgradeFindingSet(manifestId: string, findings: readonly SchemaUp
672674

673675
/**
674676
* [epic cloud#3652 Q3, #30884] The verdict when there is no installed side to
675-
* compare: the ledger file would not parse, or the registry serves the
676-
* package with no ledger record at all (an orphaned install). The upgrade's
677+
* compare: the ledger file would not parse, or neither the ledger nor the
678+
* registry (an orphaned install's row) holds the installed body. The upgrade's
677679
* renames and type changes cannot be known, and a comparison that did not
678680
* run is never taken for "no finding" (2a, 2b and 2c answer the same way): the
679681
* one finding names what is missing, and its token admits the re-install —
@@ -696,7 +698,8 @@ function installedRecordUnavailableVerdict(
696698
}
697699
: {
698700
kind: 'installed_record_missing',
699-
describe: `This runtime serves "${manifestId}" but holds no record of the installed version, ${consequence}`,
701+
describe: `This runtime serves "${manifestId}" but holds no record of the installed version's package body, `
702+
+ consequence,
700703
};
701704
return { declaredRenames: [], findings: [finding], findingSet: schemaUpgradeFindingSet(manifestId, [finding]) };
702705
}
@@ -3817,12 +3820,15 @@ export class MarketplaceInstallLocalPlugin implements Plugin {
38173820
* version — its ledger entry, converted forward as the registry reads it —
38183821
* against `converted`, and what it decides.
38193822
*
3820-
* - **No installed body** (the ledger file would not parse, or the
3821-
* registry serves the package with no ledger record): no comparison can
3822-
* run, and one that did not run is never taken for "no finding" — the
3823-
* 409 below with one finding, `installed_record_unreadable` (its `file`
3824-
* and `cause`) or `installed_record_missing`. Its token admits the
3825-
* re-install, which rewrites the record, confirmed and recorded.
3823+
* - **The installed side** is the ledger entry's body; for an orphaned
3824+
* install (no ledger file, the registry still serves the package) it is
3825+
* the body the registry serves ({@link registeredPackageBody}).
3826+
* - **No installed body** (the ledger file would not parse, or neither the
3827+
* ledger nor the registry holds one): no comparison can run, and one
3828+
* that did not run is never taken for "no finding" — the 409 below with
3829+
* one finding, `installed_record_unreadable` (its `file` and `cause`) or
3830+
* `installed_record_missing`. Its token admits the re-install, which
3831+
* rewrites the record, confirmed and recorded.
38263832
* - **A declared rename**: `501 NOT_IMPLEMENTED`, naming each — no token
38273833
* answers it while this runtime cannot carry a renamed field's column to
38283834
* its new key (ruling record 6709061297, C2). Card 01b (#30885), which
@@ -3849,10 +3855,15 @@ export class MarketplaceInstallLocalPlugin implements Plugin {
38493855
refusal?: { body: Record<string, unknown>; status: 409 | 501 };
38503856
confirmation?: InstalledEntry['schemaUpgradeConfirmation'];
38513857
}> => {
3852-
// No installed body to compare (a ledger file that will not parse, or an
3853-
// orphaned install the registry still serves): the verdict is the one
3854-
// finding that says so, confirmable like any other — never "no finding".
3855-
const installed = previous.entry?.manifest ? this.convertPackageBodyForward(ctx, previous.entry.manifest) : undefined;
3858+
// The installed side: the ledger entry's body; for an orphaned install
3859+
// (no ledger file, the registry still serves the package — findConflict
3860+
// step 3) the body the registry serves. With neither — a ledger file
3861+
// that will not parse, or a registry row carrying no body — the verdict
3862+
// is the one finding that says so, confirmable like any other, never
3863+
// "no finding".
3864+
const installedBody = previous.entry?.manifest
3865+
?? (previous.entry === null && previous.failure === undefined ? this.registeredPackageBody(ctx, manifestId) : undefined);
3866+
const installed = installedBody ? this.convertPackageBodyForward(ctx, installedBody) : undefined;
38563867
const verdict = installed === undefined
38573868
? installedRecordUnavailableVerdict(manifestId, previous.failure)
38583869
: schemaUpgradeVerdict(manifestId, comparePackageVersions(packageUpgradeSideOf(installed), packageUpgradeSideOf(converted)));
@@ -4929,6 +4940,21 @@ export class MarketplaceInstallLocalPlugin implements Plugin {
49294940
return 'none';
49304941
};
49314942

4943+
/**
4944+
* [epic cloud#3652 Q3, #30884] The package body the engine registry serves
4945+
* under `manifestId` — the row {@link findConflict} step 3 finds for an
4946+
* orphaned install — or `undefined` when there is none, or it carries no
4947+
* body. Step 2c′ compares against it when the ledger holds no record.
4948+
*/
4949+
private registeredPackageBody = (ctx: PluginContext, manifestId: string): unknown => {
4950+
try {
4951+
const ql: any = ctx.getService('objectql');
4952+
const packages: any[] = ql?.registry?.getAllPackages?.() ?? [];
4953+
const row = packages.find((p: any) => manifestIdOf(p) === manifestId);
4954+
return row?.manifest && typeof row.manifest === 'object' ? row.manifest : undefined;
4955+
} catch { return undefined; }
4956+
};
4957+
49324958
/**
49334959
* Record the manifest ids the engine registry already holds, called once at
49344960
* `kernel:ready` before rehydrate. Best-effort: a missing/empty registry

‎packages/cloud-connection/src/marketplace-install-local-upgrade-plan.test.ts‎

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -308,10 +308,30 @@ describe('step 2c′: the schema upgrade verdict on a managed re-install', () =>
308308
expect(door.register).not.toHaveBeenCalled();
309309
});
310310

311-
it('an orphaned install (served by the registry, no ledger record) is refused 409 with one finding; its token installs', async () => {
311+
it('an orphaned install (served by the registry, no ledger record) is compared against the body the registry serves', async () => {
312312
const registryPackages: Row[] = [];
313313
const door = await mount({ registryPackages });
314-
registryPackages.push({ manifest: { id: VENDOR } }); // registered after boot: an orphan, not user code
314+
registryPackages.push({ manifest: V1 }); // registered after boot: an orphan, not user code
315+
316+
// A retype against the registry's body is refused like any other.
317+
const res = await door.install(makeC({ manifest: vendorBody('2.0.0', { company: { type: 'number' } }) }));
318+
expect(res.status).toBe(409);
319+
expect(res.payload.error.details.findings).toEqual([expect.objectContaining({
320+
kind: 'type_change', field: 'company', from: 'text', to: 'number', category: 'needs_confirm',
321+
})]);
322+
expect(door.register).not.toHaveBeenCalled();
323+
expect(ledgerFiles()).toEqual({});
324+
325+
// CONTROL: the same orphan upgraded with no field change installs, unasked.
326+
const clean = await door.install(makeC({ manifest: vendorBody('2.0.0', { company: { type: 'text' }, region: { type: 'text' } }) }));
327+
expect(clean.status).toBe(200);
328+
expect(entry()?.schemaUpgradeConfirmation).toBeUndefined();
329+
});
330+
331+
it('an orphan whose registry row carries no body is refused 409 installed_record_missing; its token installs', async () => {
332+
const registryPackages: Row[] = [];
333+
const door = await mount({ registryPackages });
334+
registryPackages.push({ id: VENDOR }); // served, but no body to compare against
315335

316336
const res = await door.install(makeC({ manifest: V2 }));
317337
expect(res.status).toBe(409);

0 commit comments

Comments
 (0)