Skip to content

Commit c5e8a85

Browse files
committed
fix(cloud-connection): install-local's cloud branch refuses every register the engine refuses; only a fault stays lenient
A cloud-fetched install whose manifest.register throws a declared 4xx (the default record page, a misplaced default page, an owned object, an artifact or dependency object-name clash, an unresolved picklist, an unbound action target, the held names) now answers 422 PLUGIN_REGISTER_FAILED with nothing ledgered, as the inline branch does. A failure that declares no 4xx keeps the lenient answer and loads at the next restart. Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01FEkQ5ktJb5rQ5n2GUXSQMR
1 parent 7d7af56 commit c5e8a85

2 files changed

Lines changed: 451 additions & 87 deletions

File tree

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

Lines changed: 71 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -40,19 +40,19 @@
4040
* gives (ADR-0087 D1, #21762), and nothing is registered or written.
4141
* The answer's `hotLoaded` says whether the running kernel's
4242
* `manifest.register` resolved (#22695). An inline manifest whose
43-
* register throws is refused (`PLUGIN_REGISTER_FAILED`, 422); a
44-
* cloud-fetched one is still installed (the lenient path) and answers
45-
* `200` with `hotLoaded: false` and the register error's message as
46-
* `hotLoadError` — in the ledger, loaded at the next restart —
47-
* unless the registry refused it because another holder already
48-
* holds a name the package claims: its namespace (#31392), a
49-
* position, permission set or capability name (held by the
50-
* environment catalog, #25366, or by another package or a
51-
* built-in, #31392), or a bare name — a flow, a webhook, a
52-
* dataset, … (#31296; `bare-name-one-holder.ts` in
53-
* `@objectstack/objectql`). No restart clears any of these, so both
54-
* branches refuse them (`PLUGIN_REGISTER_FAILED`, 422) and nothing
55-
* is registered or written.
43+
* register throws is refused (`PLUGIN_REGISTER_FAILED`, 422), and
44+
* so is a cloud-fetched one whose register the engine REFUSED — a
45+
* throw declaring a 4xx status of its own (#31478): a name another
46+
* holder holds (its namespace, a position, permission set or
47+
* capability name, a bare name; #25366, #31296, #31392), a default
48+
* record page, an object another package owns, a picklist or a
49+
* bound action's object nobody declares, a body its schema refuses.
50+
* No restart heals a refusal, so nothing is registered or written.
51+
* A cloud-fetched register failure that declares no 4xx (the
52+
* runtime's own fault) takes the lenient path: still installed,
53+
* answering `200` with `hotLoaded: false` and the register error's
54+
* message as `hotLoadError` — in the ledger, loaded at the next
55+
* restart.
5656
*
5757
* `installMode: 'managed' | 'unmanaged'` (ADR-0131 D6; absent means
5858
* `managed`, the key parsed against `InstallModeSchema`) chooses
@@ -388,11 +388,6 @@ import {
388388
} from '@objectstack/metadata-protocol';
389389
import { resolveThrownHttpError } from '@objectstack/types';
390390
import { unknownQueryParamRefusalMessage } from '@objectstack/rest';
391-
// [#25366, #31296, #31392] The code the registry's namespace, security-catalog
392-
// and bare-name refusals share, compared with each class's `name` rather than
393-
// `instanceof`-tested: the engine keeps the classes unexported so a consumer
394-
// holding the other build realm's copy cannot misread them.
395-
import { NAMESPACE_CONFLICT_CODE } from '@objectstack/objectql';
396391

397392
/** What the auth service's in-process session read answers, as `AuthSessionApi` declares it. */
398393
type SessionRead = Awaited<ReturnType<NonNullable<AuthSessionApi['getSession']>>>;
@@ -434,57 +429,46 @@ interface UnmanagedImportAuditSurface {
434429
export const SAMPLE_DATA_COUNT_QUERY_PARAMS: readonly string[] = Object.freeze([]);
435430

436431
/**
437-
* [#25366, #31296, #31392] The registry's refusals of a name another holder
438-
* already holds in a deployment-wide namespace, by the `name` each class gives
439-
* itself (`registry.ts` in `@objectstack/objectql`). The three share
440-
* {@link NAMESPACE_CONFLICT_CODE}; the engine keeps the classes unexported, so
441-
* a consumer reads the code plus the name, never `instanceof`.
432+
* [#31478] Whether a `manifest.register` failure is the engine REFUSING this
433+
* package — a throw that declares a 4xx status of its own
434+
* (`resolveThrownHttpError(err).declaredStatus`), never one this door
435+
* supplies. Every refusal the registry's package door and the manifest
436+
* service's seals raise declares one (`422`, ADR-0112): the held names
437+
* (#25366, #31296, #31392), the default record page, a misplaced default page,
438+
* an object another package owns, an object name two packages of one
439+
* artifact or one shared namespace define, a picklist or a bound action's
440+
* object no loaded package declares, a body its schema refuses. Each is judged
441+
* before the refused package's own writes stand, and each is a verdict on the
442+
* body against this environment, so it is the inline branch's answer on this
443+
* branch too. (A multi-package artifact registers its packages one by one: a
444+
* member refused after another registered leaves that earlier member in the
445+
* running kernel, unledgered, exactly as on the inline branch.) Read by the
446+
* declaration, never by a list of classes or codes, so a refusal the engine
447+
* gains later is refused here without a change.
442448
*
443-
* - `NamespaceConflictError` — the package's `manifest.namespace` is owned by
444-
* another installed package that is not a co-owner of it (ADR-0048 Phase 1);
445-
* - `SecurityCatalogNameConflictError` — a position, permission set or
446-
* capability name it ships is held by another package, the environment
447-
* catalog or a built-in (`security-catalog-namespace.ts`);
448-
* - `BareNameConflictError` — an item of a bare-name type (a flow, a webhook,
449-
* a dataset, …) is held by another package or the platform
450-
* (`bare-name-one-holder.ts`).
451-
*/
452-
const NAME_HELD_ELSEWHERE_REFUSALS: ReadonlySet<string> = new Set([
453-
'NamespaceConflictError',
454-
'SecurityCatalogNameConflictError',
455-
'BareNameConflictError',
456-
]);
457-
458-
/**
459-
* [#25366, #31296, #31392] Whether a `manifest.register` failure is one of the
460-
* registry's refusals of a name another holder already holds
461-
* ({@link NAME_HELD_ELSEWHERE_REFUSALS}).
462-
*
463-
* Each is the ONE pre-write check for its rule: the registry's package door
464-
* raises it ahead of every mutation it makes, for every door that installs a
465-
* package, so this door asks it rather than keeping a second reading of who
466-
* holds a name. Recognised by the error's own brand, never by its types or
467-
* holders: which types a rule covers and who holds a name are the registry's
468-
* to decide, so a type a rule gains later is refused here without a change.
469-
*
470-
* No restart heals any of them, so the cloud branch's lenient answer ("loads
471-
* at the next restart") would be false for each:
472-
* - an environment-held catalog name is loaded from `sys_metadata` at every
473-
* boot, and the next load of the package meets it again;
474-
* - a namespace or a catalog name another package holds, and a built-in
475-
* catalog name, are judged again at every load, with no seal: the next
476-
* boot meets the same holder and refuses the registration again;
477-
* - a bare name is the other direction: the ledger entry is rehydrated
478-
* BEFORE the cold boot seals the holders, so the boot ADMITS the clash with
479-
* one warning (`BARE_NAME_COLD_BOOT_MODE`), and every consumer resolving
480-
* the name is served one of the two packages' items by registration order.
449+
* No restart heals any of them, so the lenient answer ("loads at the next
450+
* restart") would be false. Measured on a real rehydrate (the `kernel:ready`
451+
* seals run before it, so a ledger entry is judged as a late artifact):
452+
* - a refusal of the body itself (a misplaced default page, two objects of
453+
* one name in one artifact, a body its schema refuses) meets the same body
454+
* at every boot;
455+
* - a refusal naming a holder (an owned object, a default record page, a
456+
* held name) meets the same holder at every boot;
457+
* - a picklist or bound-action object nobody declares is healed only by
458+
* ANOTHER install that brings it — after which installing this package
459+
* again succeeds at once — and at a restart only when the ledger happens
460+
* to list the bringer first: the rehydrate sorts by declared
461+
* `dependencies`, and the reference this refusal names is one the package
462+
* did not declare. Declared, it is the pre-install dependency check's
463+
* `422` instead.
481464
*
482-
* Under `OS_METADATA_COLLISION=warn` the registry downgrades the namespace gate
483-
* to a warning and throws nothing, so there is nothing here to recognise.
465+
* What stays lenient is a failure that declares NO 4xx — an undeclared throw,
466+
* or a declared 5xx: the runtime's own fault, not a verdict on the package,
467+
* which the restart (of this build or a fixed one) can heal.
484468
*/
485-
function refusesNameHeldElsewhere(err: unknown): boolean {
486-
const e = err as { code?: unknown; name?: unknown } | null;
487-
return e?.code === NAMESPACE_CONFLICT_CODE && typeof e.name === 'string' && NAME_HELD_ELSEWHERE_REFUSALS.has(e.name);
469+
function isDeclaredRegisterRefusal(err: unknown): boolean {
470+
const declared = resolveThrownHttpError(err).declaredStatus;
471+
return declared !== undefined && declared >= 400 && declared < 500;
488472
}
489473

490474
/**
@@ -3114,8 +3098,8 @@ export class MarketplaceInstallLocalPlugin implements Plugin {
31143098
const registerError = String(err?.message ?? err);
31153099
// For offline file imports we treat a register failure as a hard
31163100
// failure (don't persist). Cloud installs historically tolerated
3117-
// this (the on-disk record survives a restart), so keep that path
3118-
// lenient for backwards compatibility.
3101+
// this (the on-disk record survives a restart), so that path stays
3102+
// lenient for a fault — never for a refusal (#31478, below).
31193103
// [#30885] Whatever the branch, the version that still serves is
31203104
// the installed one: the columns step 2f carried go back to it.
31213105
await reverseInstallDeclaredRenames(carried, reverseFailed);
@@ -3126,30 +3110,30 @@ export class MarketplaceInstallLocalPlugin implements Plugin {
31263110
error: { code: 'PLUGIN_REGISTER_FAILED', message: `Failed to register imported manifest: ${registerError}` },
31273111
}, 422);
31283112
}
3129-
// [#25366, #31296, #31392] …EXCEPT the registry's refusals of a
3130-
// name another holder already holds: the package's namespace, a
3131-
// position, permission set or capability name, or a bare name (a
3132-
// flow, a webhook, a dataset, …), held by another package, the
3133-
// environment catalog or the platform. No restart heals any of them
3134-
// (see {@link refusesNameHeldElsewhere}), so the lenient answer
3135-
// ("loads at the next restart") would be false. Measured for the
3136-
// environment-held catalog name on a real restart: the boot runs,
3137-
// the rehydrate logs the refusal, and the package is not loaded at
3138-
// all — its earlier version neither, since the ledger entry that
3139-
// named it was overwritten. The registry's package door refused
3140-
// before any of its own writes, and nothing of this door's is
3141-
// written yet, so the cloud branch refuses exactly as the inline
3142-
// branch does — `422 PLUGIN_REGISTER_FAILED`, the registry's
3143-
// sentence naming both holders — and the installer renames and
3144-
// retries.
3145-
if (refusesNameHeldElsewhere(err)) {
3113+
// [#25366, #31296, #31392, #31478] …EXCEPT a refusal: a register
3114+
// failure that declares a 4xx status of its own is the engine's
3115+
// verdict on this body against this environment (see
3116+
// {@link isDeclaredRegisterRefusal}), and no restart heals it, so
3117+
// the lenient answer ("loads at the next restart") would be false.
3118+
// Measured on a real restart (#25366, #31478): the rehydrate logs
3119+
// the same refusal and the package is not loaded at all — its
3120+
// earlier version neither, since the ledger entry that named it
3121+
// was overwritten.
3122+
// The engine refused before any of its own writes stood, and
3123+
// nothing of this door's is written yet, so the cloud branch
3124+
// refuses exactly as the inline branch does — `422
3125+
// PLUGIN_REGISTER_FAILED` with the engine's sentence — and the
3126+
// installer corrects the body or the environment and retries.
3127+
if (isDeclaredRegisterRefusal(err)) {
31463128
return c.json({
31473129
success: false,
31483130
error: { code: 'PLUGIN_REGISTER_FAILED', message: `Package '${manifestId}' cannot be installed: ${registerError}` },
31493131
}, 422);
31503132
}
3151-
// [#22695] The lenient path stays lenient — whether it should is a
3152-
// separate decision, ⛔ not made here. What changes is that the
3133+
// [#22695, #31478] The lenient path is what remains: a register
3134+
// failure that declares no 4xx — an undeclared throw or a declared
3135+
// 5xx, the runtime's own fault rather than a verdict on the
3136+
// package — is ledgered and loads at the next restart, and the
31533137
// caller is TOLD: the answer carries `hotLoaded: false` and this
31543138
// message, so a reader can say "installed, loads at the next
31553139
// restart" instead of a false success.

0 commit comments

Comments
 (0)