Skip to content

Commit e343ab7

Browse files
fix(runtime): an artifact boot names every code plugin of the app that it does not run (#36708)
<!-- claude-projects-attribution: {"github_login":"os-warren"} --> _Requested by **Warren** · [project thread](https://claude.ai/code/project/chan_01U5RdnAAmkSQmZbqh6FtqZ8?thread=cmsg_01U5RdnAAmkSQmZbqh6FtqZ83ouv8C9ThpkfsQ5SAfyzjU)_ Fixes #36647 Clause-②: no Metadata-protocol: none ## 维护者速读 - 用户能看到什么变化:应用用编译产物上线时,如果它带的代码插件没有跑起来,启动日志会逐个点名这些插件并说清怎么补上;以前一声不吭。 - 为什么做:BrightRule 评估里知识库、向量检索和条款索引三个插件全部没装上,后面检索为空、钩子找不到服务,没有任何提示,排查很难。 - 出错会怎样:只多一条警告,不加载、不拒绝、不改变任何插件,启动照常;改动可以直接撤回。 - 要你做什么:无(走的是已有裁决「产物只带元数据,插件由宿主装配」这条路,没有替你选「把插件塞进产物」)。 ## What changes - **`packages/runtime/src/artifact-declared-plugins.ts`** (new): `warnUnmountedDeclaredPlugins` judges each entry of the app's `plugins` by name against the kernel's own plugin table and warns **once**, naming every listed plugin the kernel does not run, with the remedy: boot from `objectstack.config.ts`, or from a host config that loads the artifact and lists the plugins in its own `plugins`, or package them (`os plugin build` → `os plugin install`). Structured fields `{ appId, plugins }`. A host that assembles the app's plugins itself hears nothing about the ones it runs. A bundle entry (no `init`) also counts as running under the `plugin.app.ID` name a host wraps it into. A package-specifier string is never judged: the name its plugin registers under is not in the specifier, so nothing is said that the table could contradict. - **`AppPlugin.start()`**: makes that call when the plugin was composed with `securityMetadataRegistrar: 'artifact-door'`, the existing declaration that its bundle IS the artifact the artifact door reads. Only `createStandaloneStack` (the door every artifact boot goes through: `createDefaultHostConfig` for `OS_ARTIFACT_URL` and for cloud's composed boot, `os start` on a built app) and the `os dev` host-config artifact door make it. A config boot (the CLI's `new AppPlugin(config)` wrap, default registrar) is never judged, because its host materializes the stack's `plugins` under names a descriptor cannot predict. Read in `start()`: the kernel refuses `use()` once bootstrap has begun, so the table is final. No option, export or artifact field is added. - **`content/docs/deployment/self-hosting.mdx`**: one row in the artifact-pinned boot table saying an artifact boot runs without the app's code plugins, that the boot names them, and what to do. - Changeset: `@objectstack/runtime` patch. Level is `warn`: a capability is absent and its next caller finds out, which AGENTS.md "Degradation log levels" grades functional, not durability. ## Why: the route, and why it is not a fork The card offers "carry them" or "refuse them, loudly" and leaves the pick to the maintainer. Two existing rulings already make it: - **#15219, maintainer ruling A (2026-09-04, 「同意」)**: `plugins` / `devPlugins` are artifact **envelope** keys, "runtime ASSEMBLY instructions, not metadata … An artifact carries metadata; a host assembles plugins" (`packages/spec/src/stack.zod.ts`, the envelope-key docblock). - **ADR-0025 (Accepted)** §3.10: an L2 code plugin (real npm deps + host APIs) ships as a signed `.osplugin` with permission consent; the environment artifact is the L0/L1 declarative channel. `cwdConfigJoinsBoot` (`packages/cli/src/utils/artifact-precedence.ts`) already says it: a host config's "own compiled output cannot carry that code". "Carry them" would put app code and its dependencies into the environment artifact, against both. So this PR takes the other half of the card's own Expected: the drop stays, the silence goes. Making `os build` fail on a stack with `plugins` was not done: the same build feeds config boots that do mount them (`os start` / `os dev` over the config's own output), so a refusal there would break working apps; that would be a narrowing and is not this card's call. ## Tests `packages/cli/test/build-artifact-code-plugins-boot.test.ts` (new, 2 tests): a real `os build` (the `Compile` command in process) of a config listing two live plugin instances, then a real boot of the artifact it wrote through `createStandaloneStack` (reached through `@objectstack/runtime`'s `exports`, so `dist/`). - PREMISE: `objectstack.json` holds both plugins as descriptors with no `init`; - the boot runs neither (`kernel.hasPlugin` false for both) and warns exactly once with `{ appId, plugins: [vector, indexer] }`. `packages/runtime/src/artifact-declared-plugins.test.ts` (new, 9 tests): real kernel boots of `createStandaloneStack` over an artifact file on disk carrying two plugin descriptors exactly as `os build` writes them. - neither mounted → exactly one warning, `{ appId, plugins: [vector, indexer] }`, both names and the remedy in the line (CONTROL: `kernel.hasPlugin` is false for both); - CONTROL: host mounts one → the warning names only the other; - CONTROL: host mounts both → silent; - CONTROL: artifact lists no plugins → silent; - CONTROL: config door (`new AppPlugin(config)`, default registrar) with an unmounted descriptor → silent; - four unit cases of `findUnmountedDeclaredPlugins` (order and dedupe, wrapped bundle alias, live instance, strings / unnamed / non-array never named). **Ablation**: with the door's call switched off (the pre-fix behaviour), the runtime file goes red (2 failed | 7 passed) and, with the runtime rebuilt, the cli pin goes red on the boot test (1 failed | 1 passed, the premise test stays green). Restored and rebuilt: 9/9 and 2/2. ## Acceptance notes - `objectstack-ai/cloud` `apps/objectos-ee/deploy/artifact-pinned-boot.md`, "What this mode does and does not mount", says "The app's own plugins, flows and triggers come from the artifact". For plugins that has not been true on this tree; the doc fix is the cloud repo's (carrier: cloud). - Not touched: the build summary's `Runtime: N plugins` count. It counts what the stack lists, which is true; a build-time note that the artifact does not carry them would print on every build of every app with plugins, including the ones served from their config. Left as a possible follow-up for the maintainer. ## Verification At head `a5af61eea5` (heavy runs under `scripts/pm/os-verify-lock.sh`): - `pnpm --filter @objectstack/runtime exec vitest run --maxWorkers=2 src/artifact-declared-plugins.test.ts` → 9/9 passed. - `pnpm --filter @objectstack/cli exec vitest run --maxWorkers=2 test/build-artifact-code-plugins-boot.test.ts` → 2/2 passed (runtime rebuilt first). - Neighbours: runtime `src/app-plugin*.test.ts src/standalone-stack*.test.ts src/default-host*.test.ts` → 41 files, 564 tests passed. - `pnpm --filter @objectstack/runtime typecheck`, `pnpm --filter @objectstack/cli typecheck` → exit 0; eslint `--no-inline-config` on every touched source → exit 0; cli `test/vitest-tiers-partition.test.ts` → 22/22. - `node scripts/pm/overlap-check.mjs` → clean (shares `self-hosting.mdx` with #36311 and #35129, both merge cleanly). - Derived gate families (`node scripts/pm/dispatch-gates.mjs --commands`, 100 commands) at `3676b4f987`: 97 exit 0; `pnpm check:test-source-alias` exit 1 (the new cli pin reached two lazy loads inside a clocked window), fixed at `a5af61eea5` by two module-top side-effect imports and re-run there: exit 0; `pnpm --filter @objectstack/spec run check:skill-examples` and `pnpm check:dual-build-cjs-loads` exit 3, PREREQUISITE NOT MET (they read built output of packages this change does not build): NOT MEASURED locally, CI runs them. CI at `3676b4f987` was red on the same test-source-alias gate only. ## Two-minute check `OS_ARTIFACT_URL=file://$PWD/dist/objectstack.json os start` on an app whose config lists `plugins: [new SomePlugin()]`: the boot log carries one `[AppPlugin] app '…' lists 1 plugin(s) that are not running on this kernel: '…'` line. `os start` from the same app's config prints no such line. --- _Generated by [Claude Code](https://claude.ai/code/session_01JQwxba17kw1B3myaWtd4wP)_ 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01JQwxba17kw1B3myaWtd4wP <!-- signed: repo:objectstack#1 · os-warren · session_01JQwxba17kw1B3myaWtd4wP --> --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent ac43336 commit e343ab7

6 files changed

Lines changed: 475 additions & 1 deletion

File tree

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
---
2+
'@objectstack/runtime': patch
3+
---
4+
5+
fix(runtime): an artifact boot names every code plugin of the app that it does not run
6+
7+
Clause-②: no
8+
Metadata-protocol: none
9+
10+
A compiled artifact carries an app's metadata and hook handlers, not its code plugins: `os build` writes each entry of the stack's `plugins` as a plain descriptor (`{ name, version, dependencies, options }`), and the runtime module beside the JSON exports `functions` only. So a boot from the artifact (`OS_ARTIFACT_URL`, the composed hosted boot, `os start` on a built app) runs none of them. That is the envelope-key rule: an artifact carries metadata, a host assembles plugins. It used to happen in silence, and every service those plugins register was simply absent, so whatever depended on them failed later and somewhere else.
11+
12+
The artifact boot now says so once, at `warn`, when the app's `AppPlugin` starts: `[AppPlugin] app 'APP_ID' lists N plugin(s) that are not running on this kernel: 'PLUGIN_NAME', …`, with the remedy (boot the app from its `objectstack.config.ts`, or from a host config that loads the artifact and lists the plugins in its own `plugins`, or package them with `os plugin build` and `os plugin install`). The structured fields are `{ appId, plugins }`. Each listed plugin is judged by name against the kernel's own plugin table, so a host that assembles the app's plugins itself hears nothing about the ones it runs. A package-specifier string entry is not judged: the name its plugin registers under is not in the specifier.
13+
14+
Only the artifact door judges: the `AppPlugin` that `createStandaloneStack` builds over the artifact it loaded (the one composed with `securityMetadataRegistrar: 'artifact-door'`). A config boot's `AppPlugin` does not, because its host materializes the stack's `plugins` itself. No option, export or artifact field is added, and nothing else changes: no plugin is mounted, refused or reordered, and the boot does not fail.

‎content/docs/deployment/self-hosting.mdx‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@ rotate. Two variables would make "URL updated, hash not" a state you can reach.
150150
| `#sha256=` present, artifact host unreachable | Falls back to the cached copy **only** if it still hashes to the pin, with a loud warning that the instance is running on cached content. |
151151
| Artifact's `engines.protocol` excludes this runtime | **Refuses to boot** — the safety belt of the two-axis split. Repoint the reference, or run a matching image version. |
152152
| The artifact needs a destructive schema change | Safe migrations run at boot; a destructive one **refuses to boot** and names each change. Run `os migrate apply --allow-destructive` deliberately, then restart. Never skipped in silence. |
153+
| The app's stack lists code plugins (`plugins: [new XPlugin()]`) | Boots **without them**: an artifact carries the app's metadata and hook handlers, not its code plugins, so nothing those plugins register exists. The boot warns once, naming each listed plugin the kernel does not run. To run them, boot a host config that loads the artifact and lists the plugins in its own `plugins`, or package them as a plugin (`os plugin build`, then `os plugin install`). |
153154

154155
**Recommended production discipline** (convention, not enforced by the runtime):
155156
publish immutable, version-named objects; give only CI write access to the
Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license.
2+
3+
/**
4+
* #36647, end to end: a real `os build` of a stack that lists a code plugin,
5+
* then a real boot of the artifact it wrote. The boot runs none of the app's
6+
* code plugins, and says so, naming each one, once.
7+
*
8+
* The build half is the measured premise. `os build` writes the stack's
9+
* `plugins` into `objectstack.json` as plain JSON (the instance's own data, no
10+
* `init`), and nothing on the artifact path turns that back into a plugin:
11+
* `plugins` are artifact ENVELOPE keys, runtime assembly instructions a host
12+
* hands to `kernel.use()`, never metadata the artifact carries. The boot half
13+
* is the fix: the artifact door's `AppPlugin` names every listed plugin the
14+
* kernel's own table does not hold (`@objectstack/runtime`,
15+
* `artifact-declared-plugins.ts`), so the drop is no longer silent.
16+
*
17+
* The boot reaches `@objectstack/runtime` through its `exports` map, so it
18+
* measures `dist/`: rebuild the runtime before reading a result here.
19+
*/
20+
21+
import { afterAll, beforeAll, describe, expect, it, vi } from 'vitest';
22+
import { mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from 'node:fs';
23+
import { tmpdir } from 'node:os';
24+
import { join, resolve } from 'node:path';
25+
import { fileURLToPath } from 'node:url';
26+
import { createStandaloneStack, Runtime } from '@objectstack/runtime';
27+
import Compile from '../src/commands/compile';
28+
import { defineStackSourceFromLiteral, linkSpec } from './helpers/define-stack-fixture.js';
29+
30+
// Pay the first transform of these dist-resolved workspace deps at MODULE LOAD:
31+
// the build and the boot below import them lazily, inside a clocked hook
32+
// (`scripts/check-test-source-alias.mjs`, the clocked-window rule).
33+
import '@objectstack/objectql/core';
34+
import '@objectstack/plugin-security';
35+
36+
const CLI_ROOT = resolve(fileURLToPath(import.meta.url), '..', '..');
37+
const APP_ID = 'com.test.issue-36647-build';
38+
const VECTOR = 'com.test.issue-36647-build.vector';
39+
const INDEXER = 'com.test.issue-36647-build.indexer';
40+
const BOOT_TIMEOUT = 120_000;
41+
42+
/**
43+
* The stack as an author writes it: two code plugins, live instances with an
44+
* `init`, the shape `plugins: [new XPlugin()]` evaluates to.
45+
*/
46+
const CONFIG_LITERAL = `{
47+
manifest: { id: '${APP_ID}', name: 'Plugin Build Probe', version: '1.0.0', type: 'app', namespace: 'probeb' },
48+
objects: [{ name: 'probeb_clause', label: 'Clause', sharingModel: 'private', fields: { title: { type: 'text', label: 'Title' } } }],
49+
plugins: [
50+
{ name: '${VECTOR}', version: '1.0.0', dependencies: [], options: { dimensions: 1536 }, init: async () => {} },
51+
{ name: '${INDEXER}', version: '1.0.0', dependencies: ['${VECTOR}'], init: async () => {} },
52+
],
53+
}`;
54+
55+
let root = '';
56+
let artifactPath = '';
57+
58+
/** Runs `os build` in-process; answers the exit code (0 when the command returned) and what it printed. */
59+
async function build(configPath: string, output: string): Promise<{ code: number; stdout: string }> {
60+
const chunks: string[] = [];
61+
const spy = vi.spyOn(process.stdout, 'write').mockImplementation(((chunk: unknown, ...rest: unknown[]) => {
62+
chunks.push(String(chunk));
63+
const done = rest.find((a) => typeof a === 'function') as ((e?: Error | null) => void) | undefined;
64+
done?.(null);
65+
return true;
66+
}) as never);
67+
const exitCodeBefore = process.exitCode;
68+
try {
69+
await Compile.run([configPath, '--output', output], { root: CLI_ROOT });
70+
return { code: 0, stdout: chunks.join('') };
71+
} catch (error) {
72+
const exit = (error as { oclif?: { exit?: unknown } }).oclif?.exit;
73+
if (typeof exit !== 'number') throw error;
74+
return { code: exit, stdout: chunks.join('') };
75+
} finally {
76+
spy.mockRestore();
77+
process.exitCode = exitCodeBefore;
78+
}
79+
}
80+
81+
beforeAll(async () => {
82+
root = mkdtempSync(join(tmpdir(), 'os-36647-build-'));
83+
const dir = join(root, 'app');
84+
mkdirSync(dir, { recursive: true });
85+
const configPath = join(dir, 'objectstack.config.ts');
86+
writeFileSync(configPath, defineStackSourceFromLiteral(CONFIG_LITERAL));
87+
linkSpec(dir);
88+
mkdirSync(join(root, 'host'), { recursive: true });
89+
artifactPath = join(dir, 'dist', 'objectstack.json');
90+
const built = await build(configPath, artifactPath);
91+
expect(built.code, built.stdout).toBe(0);
92+
}, 60_000);
93+
94+
afterAll(() => {
95+
if (root) rmSync(root, { recursive: true, force: true });
96+
});
97+
98+
describe('#36647 — os build, then an artifact boot of what it wrote', () => {
99+
it('PREMISE: the artifact holds the plugins as inert descriptors, nothing that can start', () => {
100+
const artifact = JSON.parse(readFileSync(artifactPath, 'utf8')) as { plugins?: Array<Record<string, unknown>> };
101+
expect(artifact.plugins?.map((p) => p.name)).toEqual([VECTOR, INDEXER]);
102+
for (const p of artifact.plugins ?? []) expect(p).not.toHaveProperty('init');
103+
});
104+
105+
it('the boot runs neither plugin, and warns once naming both', async () => {
106+
let kernel: any;
107+
try {
108+
const standalone = await createStandaloneStack({
109+
artifactPath,
110+
// A directory of its own: the boot's root, apart from the source tree the build read.
111+
projectRoot: join(root, 'host'),
112+
databaseUrl: ':memory:',
113+
skipSeedData: true,
114+
runPlatformMigrations: false,
115+
});
116+
kernel = new Runtime({ cluster: false }).getKernel();
117+
const warn = vi.spyOn(kernel.logger, 'warn');
118+
for (const p of standalone.plugins) await kernel.use(p as never);
119+
await kernel.bootstrap();
120+
// CONTROL: the drop is real.
121+
expect(kernel.hasPlugin(VECTOR)).toBe(false);
122+
expect(kernel.hasPlugin(INDEXER)).toBe(false);
123+
const named = warn.mock.calls
124+
.map(([message, meta]) => ({ message: String(message), meta: meta as any }))
125+
.filter(({ meta }) => meta?.appId === APP_ID && Array.isArray(meta?.plugins));
126+
expect(named).toHaveLength(1);
127+
expect(named[0]!.meta).toEqual({ appId: APP_ID, plugins: [VECTOR, INDEXER] });
128+
expect(named[0]!.message).toContain(VECTOR);
129+
expect(named[0]!.message).toContain(INDEXER);
130+
} finally {
131+
try { await kernel?.shutdown(); } catch { /* noop */ }
132+
}
133+
}, BOOT_TIMEOUT);
134+
});

‎packages/runtime/src/app-plugin.ts‎

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ import { QuickJSScriptRunner } from './sandbox/quickjs-runner.js';
4242
import { hookBodyRunnerFactory, actionBodyRunnerFactory } from './sandbox/body-runner.js';
4343
import { hookRefusalI18nReader } from './sandbox/hook-refusal-catalogue.js';
4444
import { bindAppArtifactHandlers, scheduleAppArtifactJobs } from './app-artifact-handlers.js';
45+
import { warnUnmountedDeclaredPlugins } from './artifact-declared-plugins.js';
4546
import { countServerTiming } from '@objectstack/observability';
4647

4748
/**
@@ -1439,7 +1440,21 @@ export class AppPlugin implements Plugin {
14391440
}
14401441
const sys = this.bundle.manifest || this.bundle;
14411442
const appId = sys.id || sys.name;
1442-
1443+
1444+
// The artifact's `plugins` (an envelope key: top level only) that this
1445+
// kernel does not run, named once. An artifact carries descriptors for
1446+
// them and nothing that can start, so a boot from the artifact alone
1447+
// mounts none of them; before this it said nothing. Keyed on the
1448+
// `'artifact-door'` registrar: it is the declaration, made by
1449+
// `createStandaloneStack` alone, that this bundle IS the artifact that
1450+
// door reads. A config bundle's `plugins` are materialized by its host
1451+
// under names a descriptor cannot predict, so they are not judged here.
1452+
// Read in `start()`: the kernel's plugin table is closed once bootstrap
1453+
// begins. See `./artifact-declared-plugins.ts`.
1454+
if (this.securityMetadataRegistrar === 'artifact-door') {
1455+
warnUnmountedDeclaredPlugins(ctx, (this.bundle as { plugins?: unknown }).plugins, String(appId));
1456+
}
1457+
14431458
// Execute Runtime Step
14441459
// Retrieve ObjectQL engine from services
14451460
// ctx.getService throws when a service is not registered, so we

0 commit comments

Comments
 (0)