diff --git a/docs/adr/0063-ssr-composition-pin.md b/docs/adr/0063-ssr-composition-pin.md index 95b4abd9d..c7b0d8fed 100644 --- a/docs/adr/0063-ssr-composition-pin.md +++ b/docs/adr/0063-ssr-composition-pin.md @@ -88,7 +88,11 @@ dev, prod, base, tenant. redeploys. The authored config schema is unchanged (the pins already exist in it). - "Why did this page SSR?" has one answer at every plane: a verified pin was present and (for tenants) policy allowed. Everything else is the CSR shell, a loud refusal, or a - loud 500 — there is no silent path left. + loud 500 — there is no silent path left. Amendment (#1259, 2026-12-02): the loud-500 + is the CORE scope only — a plugin ui slot whose compose fails (manifest, SSR entry, + container, or route config) degrades that slot's routes with a loud warning while the + rest of the tree keeps rendering, extending ADR 0024 §5's per-source isolation to + local plugin sources and mirroring the backend plane's per-plugin degrade contract. - The dev loop gains a node-env build on every keystroke for ui-local sessions; the measured tax is recorded above and plan 078 phase 0 owns the re-baseline numbers. `--no-ssr` restores the web-only build for operators who want it. diff --git a/host/src/services/ui-compose.ts b/host/src/services/ui-compose.ts index 9b70bec60..0775c4eb7 100644 --- a/host/src/services/ui-compose.ts +++ b/host/src/services/ui-compose.ts @@ -362,12 +362,12 @@ export function sharedSingletonSkew( } /** - * Per-source isolation (ADR 0024 §5): a plugin source that cannot produce a - * usable manifest — fetch failure with no last-good snapshot, unparsable - * content, or an identity mismatch with its config key — drops itself with a - * warning instead of failing the whole composition. The core source failing - * stays loud. composeUi and composeClientPayload digest the same healthy set, - * so their payloads stay in parity by construction. + * Per-source isolation (ADR 0024 §5, extended to local plugin sources by + * #1259): a plugin source that cannot produce a usable manifest — fetch + * failure, unparsable content, or an identity mismatch with its config key — + * drops itself with a loud warning instead of failing the whole composition. + * Only the core source failing stays loud; composeUi and + * composeClientPayload digest the same healthy set, keeping parity. */ const resolveComposableSources = Effect.fn("resolveComposableSources")(function* ( sources: UiSource[], @@ -385,30 +385,21 @@ const resolveComposableSources = Effect.fn("resolveComposableSources")(function* cause: new Error("identity mismatch (ADR 0008 §2)"), }); } - // A local ui source is authored into this runtime — a manifest that - // names another plugin is a configuration bug, not a transient remote - // failure: fail loud instead of silently dropping the remote. - if (source.localRoot) { - return yield* new UiComposeError({ - operation: `[Compose] local ui source "${source.key}" manifest names itself "${manifest.name}" — expected "${source.key}"`, - cause: new Error("identity mismatch (ADR 0008 §2)"), - }); - } yield* Effect.logWarning( - `[Compose] dropping ui source "${source.key}" — its manifest names itself "${manifest.name}" (identity mismatch, ADR 0008 §2)`, + `[Compose] dropping ui source "${source.key}" — its manifest names itself "${manifest.name}" (identity mismatch, ADR 0008 §2); its routes leave the composed tree`, ); return null; }).pipe( Effect.catch((error) => - source.localRoot || source.key === CORE_UI_KEY + source.key === CORE_UI_KEY ? Effect.fail( new UiComposeError({ - operation: `Failed to load UI manifest for ${source.localRoot ? "local" : "core"} ui source "${source.key}"`, + operation: `Failed to load UI manifest for the core ui source "${source.key}"`, cause: error, }), ) : Effect.logWarning( - `[Compose] dropping ui source "${source.key}" — no usable manifest (${error.message})`, + `[Compose] dropping ui source "${source.key}" — no usable manifest; its routes leave the composed tree (${error.message})`, ).pipe(Effect.as(null)), ), ), @@ -565,28 +556,60 @@ export const composeUi = Effect.fn("composeUi")(function* ( // invariant 4). const loader = yield* FederationLoader; const nonCore = composable.filter(({ source }) => source.key !== CORE_UI_KEY); - const pluginEntries = yield* Effect.forEach( + // Per-source container isolation (#1259): a plugin whose SSR entry or + // container cannot load drops itself; a last-good generation still serves + // the whole plane (#940 floor). + const pluginEntries: Array<{ source: UiSource; manifest: PluginManifest; entry: RemoteEntry }> = + []; + const recoveredVariants: ComposedUi[] = []; + yield* Effect.forEach( nonCore, - ({ source }) => - source.localRoot - ? containers.localUiRemoteEntry({ name: source.mfName, localRoot: source.localRoot! }) - : Effect.succeed(source.remote!), + ({ source, manifest }) => + Effect.gen(function* () { + const resolved = yield* ( + source.localRoot + ? containers.localUiRemoteEntry({ name: source.mfName, localRoot: source.localRoot! }) + : Effect.succeed(source.remote!) + ).pipe( + Effect.catch((error) => + Effect.logWarning( + `[Compose] dropping ui source "${source.key}" — no usable SSR entry; its routes leave the composed tree (${error.message})`, + ).pipe(Effect.as(null)), + ), + ); + if (!resolved) return; + if (source.localRoot) { + const outcome = yield* Effect.result(waitOrLastGood(resolved, config.env, cache)); + const failure = Result.match(outcome, { + onSuccess: () => null, + onFailure: (error) => error as { detail?: string; message: string }, + }); + if (failure) { + yield* Effect.logWarning( + `[Compose] dropping ui source "${source.key}" — SSR container unavailable with no last-good generation; its routes leave the composed tree (${failure.detail ?? failure.message})`, + ); + return; + } + const recovered = Result.match(outcome, { + onSuccess: (variant) => variant, + onFailure: () => null, + }); + if (recovered) { + recoveredVariants.push(recovered); + return; + } + } + pluginEntries.push({ source, manifest, entry: resolved }); + }), { concurrency: "unbounded" }, ); - const recoveredVariant = yield* Effect.forEach( - nonCore, - ({ source }, i) => - source.localRoot - ? waitOrLastGood(pluginEntries[i]!, config.env, cache) - : Effect.succeed(null), - { concurrency: "unbounded" }, - ).pipe(Effect.map((results) => results.find((result): result is ComposedUi => result !== null))); - if (recoveredVariant) return recoveredVariant; + if (recoveredVariants.length > 0) return recoveredVariants[0]!; + pluginEntries.sort((a, b) => a.source.key.localeCompare(b.source.key)); const session: CompositionSession = loader.ensureSession([ { name: core.mfName, entry: requireSsrEntryUrl(coreEntry, config.env) }, - ...nonCore.map(({ source }, i) => ({ + ...pluginEntries.map(({ source, entry }) => ({ name: source.mfName, - entry: requireSsrEntryUrl(pluginEntries[i]!, config.env), + entry: requireSsrEntryUrl(entry, config.env), })), ]); @@ -597,33 +620,31 @@ export const composeUi = Effect.fn("composeUi")(function* ( ]); const coreRouteConfig: RouteConfigModule = routeConfig; - // Per-source route-config isolation: a plugin whose container/config - // cannot load drops itself (warn); the core stays loud. The digest is - // computed over the final healthy set — after drops — so the engine's - // parity check and the client payload agree by construction. Plugin - // route-configs load in parallel through the pinned session. + // Per-source route-config isolation: a plugin whose route config cannot + // load drops itself with a loud warning — its routes leave the composed + // tree while core and siblings keep rendering. The digest runs over the + // final healthy set, so parity and the client payload agree by + // construction. Plugin route-configs load in parallel through the session. const healthy: ComposableSource[] = [{ source: core, manifest: corePair.manifest }]; const routeConfigByName = new Map([ [corePair.manifest.name, coreRouteConfig], ]); const loaded = yield* Effect.forEach( pluginEntries, - (entry, i) => + ({ source, entry }) => loadUiRouteConfig(entry, config.env, session).pipe( Effect.catch((error) => - nonCore[i]!.source.localRoot - ? Effect.fail(error) - : Effect.logWarning( - `[Compose] dropping ui source "${nonCore[i]!.source.key}" — route config unavailable (${error.message})`, - ).pipe(Effect.as(null)), + Effect.logWarning( + `[Compose] dropping ui source "${source.key}" — route config unavailable; its routes leave the composed tree (${error.message})`, + ).pipe(Effect.as(null)), ), ), { concurrency: "unbounded" }, ); for (let i = 0; i < loaded.length; i++) { if (loaded[i]) { - healthy.push(nonCore[i]!); - routeConfigByName.set(nonCore[i]!.manifest.name, loaded[i]!); + healthy.push(pluginEntries[i]!); + routeConfigByName.set(pluginEntries[i]!.manifest.name, loaded[i]!); } } const healthySources = healthy.map(({ source }) => source); diff --git a/host/tests/integration/ui-compose.test.ts b/host/tests/integration/ui-compose.test.ts index d586e7bab..bdb1904b4 100644 --- a/host/tests/integration/ui-compose.test.ts +++ b/host/tests/integration/ui-compose.test.ts @@ -16,6 +16,7 @@ const federationMocks = vi.hoisted(() => ({ loadUiRouteConfig: vi.fn(), loadRouterModule: vi.fn(), localUiRemoteEntry: vi.fn(), + waitForLocalContainer: vi.fn(), })); vi.mock("../../src/services/federation/loader", async (importOriginal) => { @@ -41,12 +42,14 @@ vi.mock("../../src/services/federation/containers", async (importOriginal) => { const actual = await importOriginal(); const containersService = { localUiRemoteEntry: (...args: unknown[]) => federationMocks.localUiRemoteEntry(...args), + waitForLocalContainer: (...args: unknown[]) => federationMocks.waitForLocalContainer(...args), }; const mutable = actual.FederationContainers as unknown as { layer: Layer.Layer }; mutable.layer = Layer.succeed(actual.FederationContainers, containersService as never); return { ...actual, - waitForLocalContainer: () => Effect.void, + waitForLocalContainer: (...args: unknown[]) => federationMocks.waitForLocalContainer(...args), + localUiRemoteEntry: (...args: unknown[]) => federationMocks.localUiRemoteEntry(...args), }; }); @@ -239,6 +242,7 @@ beforeEach(async () => { catch: (cause) => new Error(`localUiRemoteEntry stub failed: ${String(cause)}`), }), ); + federationMocks.waitForLocalContainer.mockImplementation(() => Effect.void); }); afterEach(async () => { @@ -431,6 +435,20 @@ describe("composeUi", () => { expect(construct.mock.calls[0]![0].plugins).toEqual([{ key: "ui", mfName: "ui" }]); }); + it("drops a plugin whose route config cannot load and composes the core (#1259)", async () => { + const config = configWithPlugin(); + federationMocks.loadUiRouteConfig.mockImplementation(() => + Effect.fail(new Error("route config broken")), + ); + + const variant = await compose(config); + + expect(construct).toHaveBeenCalledTimes(1); + expect(construct.mock.calls[0]![0].plugins).toEqual([{ key: "ui", mfName: "ui" }]); + expect(variant.clientPayload.remotes).toEqual([CORE_REMOTE]); + expect(variant.routeTree).toEqual({ id: "composed-tree" }); + }); + it("drops a plugin whose manifest names itself something else (identity mismatch)", async () => { const config = configWithPlugin(); fetchMock.mockImplementation(async (url: unknown) => { @@ -452,7 +470,7 @@ describe("composeUi", () => { expect(variant.clientPayload.manifests).toEqual([CORE_MANIFEST]); }); - it("fails loudly when a local plugin ui source has no usable manifest", async () => { + it("drops a local plugin ui source with no usable manifest and composes the core (#1259)", async () => { const localRoot = await mkdtemp(path.join(tmpdir(), "ui-compose-local-missing-manifest-")); await mkdir(path.join(localRoot, "src"), { recursive: true }); @@ -466,14 +484,18 @@ describe("composeUi", () => { localPath: localRoot, } as never; - const result = await composeExit(config); - expect(Exit.isFailure(result)).toBe(true); - expect(construct).not.toHaveBeenCalled(); + const variant = await compose(config); + expect(construct).toHaveBeenCalledTimes(1); + const constructInput = construct.mock.calls[0]![0] as { + plugins: Array<{ key: string }>; + }; + expect(constructInput.plugins).toEqual([{ key: "ui", mfName: "ui" }]); + expect(variant.clientPayload.remotes).toEqual([CORE_REMOTE]); await rm(localRoot, { recursive: true, force: true }); }); - it("fails loudly when a local plugin ui manifest names itself something else", async () => { + it("drops a local plugin ui source whose manifest names itself something else (#1259)", async () => { const localRoot = await mkdtemp(path.join(tmpdir(), "ui-compose-local-mismatch-")); await mkdir(path.join(localRoot, "src"), { recursive: true }); await writeFile( @@ -491,21 +513,45 @@ describe("composeUi", () => { localPath: localRoot, } as never; - const result = await composeExit(config); - expect(Exit.isFailure(result)).toBe(true); - if (result._tag !== "Failure") throw new Error("unreachable"); - const reasons = result.cause.reasons; - expect(reasons).toHaveLength(1); - const reason = reasons[0]!; - expect(reason._tag).toBe("Fail"); - if (reason._tag === "Fail") { - expect(reason.error).toMatchObject({ - operation: expect.stringMatching(/Failed to load UI manifest for local ui source "auth"/), - cause: expect.objectContaining({ - operation: expect.stringMatching(/manifest names itself "not-auth" — expected "auth"/), - }), - }); - } + const variant = await compose(config); + expect(construct).toHaveBeenCalledTimes(1); + const constructInput = construct.mock.calls[0]![0] as { + plugins: Array<{ key: string }>; + }; + expect(constructInput.plugins).toEqual([{ key: "ui", mfName: "ui" }]); + expect(variant.clientPayload.remotes).toEqual([CORE_REMOTE]); + + await rm(localRoot, { recursive: true, force: true }); + }); + + it("drops a local plugin ui source whose SSR container never becomes ready (#1259)", async () => { + const localRoot = await mkdtemp(path.join(tmpdir(), "ui-compose-local-container-down-")); + await mkdir(path.join(localRoot, "src"), { recursive: true }); + await mkdir(path.join(localRoot, "dist", "ssr"), { recursive: true }); + await writeFile( + path.join(localRoot, "src", "manifest.gen.json"), + JSON.stringify({ ...AUTH_MANIFEST, name: "auth" }), + ); + + const config = { + ...configWithPlugin(), + env: "development", + } as RuntimeConfig; + config.plugins!.auth!.ui = { + name: "auth-ui", + source: "local", + localPath: localRoot, + } as never; + federationMocks.waitForLocalContainer.mockImplementation(() => + Effect.fail(new Error("container never ready")), + ); + + await compose(config); + expect(construct).toHaveBeenCalledTimes(1); + const constructInput = construct.mock.calls[0]![0] as { + plugins: Array<{ key: string }>; + }; + expect(constructInput.plugins).toEqual([{ key: "ui", mfName: "ui" }]); await rm(localRoot, { recursive: true, force: true }); });