Skip to content

Commit 5c706cd

Browse files
committed
fix(service-automation): a stored connector entry refused its package ref never fails the boot
A stored row at rest is hydrated into the registry before the automation service's boot reconcile, whose configuration faults are fatal, so a stored entry the #28594 refusal newly refuses would have stopped the next restart. That refusal now takes the soft path at boot too: logged, the entry skipped. An authored package's row that reaches the boot before its package row is judged stored, not unrecorded. Every other configuration fault keeps the fail-loud contract. Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01FEkQ5mBUwWJMnLUdKBYraT
1 parent 43953ed commit 5c706cd

5 files changed

Lines changed: 363 additions & 35 deletions

File tree

‎.changeset/28594-stored-connector-file-ref.md‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
"@objectstack/service-automation": patch
2+
"@objectstack/service-automation": minor
33
---
44

55
fix(service-automation)!: a connector stored in the environment never reads the host's files
@@ -12,10 +12,10 @@ Metadata-protocol: narrowed (a stored connector's `providerConfig` may no longer
1212

1313
<!-- adr-0087: not-required (no-migration-prescription) No key is added, removed or renamed and the stored shape is unchanged: the same `providerConfig` is accepted at the save door, and what is refused is the host's root being read on the stored entry's behalf. No conversion can carry a file the environment never held; the refusal names the entry, its package if it has one, the ref and the remedy. -->
1414

15-
**BREAKING** behaviour narrowing for stored connectors (`@objectstack/service-automation`), shipped as `patch`.
15+
**BREAKING** behaviour narrowing for stored connectors (`@objectstack/service-automation`), shipped as `minor`.
1616

1717
- **Before.** A stored entry's package-relative refs (an `openapi` spec path, a stdio `mcp` transport's working directory) resolved against the host's root.
18-
- **Now.** Every such ref is refused for a stored entry, naming the entry, its package if it has one, and the ref: a configuration fault, so the instance is not materialized and the reconcile logs the refusal. Only an entry the host's stack declares reads the host's root: one a package registration filed with the same provider binding, or one the host's own artifact carries. A stored row is never read as the host's, whatever `_packageId` its body carries.
18+
- **Now.** Every such ref is refused for a stored entry, naming the entry, its package if it has one, and the ref: a configuration fault, so the instance is not materialized and the reconcile logs the refusal. It never fails a boot: a stored row already at rest when the platform starts is logged and skipped like one saved while it runs, and the host's own entries beside it serve. Only an entry the host's stack declares reads the host's root: one a package registration filed with the same provider binding, or one the host's own artifact carries. A stored row is never read as the host's, whatever `_packageId` its body carries.
1919
- **Unchanged.** A stored entry carrying its document inline or as an `http(s)` URL, every entry of the host's own stack, and an installed package's entries (refused as before).
2020
- **Who sees it.** A connector saved in the environment whose `openapi` spec is a package-relative path, or whose `mcp` transport is stdio.
2121

‎content/docs/automation/connectors.mdx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -866,7 +866,7 @@ retry):
866866
| Instance `name` collides with a plugin-registered connector | **Hard boot error** — there is no silent precedence between the two worlds |
867867
| stdio transport without host opt-in | **Hard boot error** with the `declarativeStdio` fix inline — a security rejection is never retried |
868868
| An entry of an **installed** package (`os package install`, `POST /api/v1/marketplace/install-local`) names a package-relative file — an `openapi` `spec` path — or needs a location inside its package, as a stdio `mcp` transport's working directory does | Configuration fault, **never resolved against the host's directory**: an installed package has no directory on the runtime it was installed into, and the host's is not its own. The instance is not materialized, and the reconcile's error names the entry, its package and the ref. Rebuild the package with a current `os build`, which carries an `openapi` spec file into the artifact, or inline the document; reach an MCP server from an installed package over `http`. Whether an entry is the host's is read from what the install recorded, never from the package's own words: an entry carrying a `_packageId` other than its own package's is refused at the install, every member of a `packages[]` bundle is recorded as installed whatever its `source` says, and an entry naming a package no registration records is refused its ref too. The host's own entries keep reading their files |
869-
| A **stored** entry — one saved in this environment through the metadata door (`PUT /api/v1/meta/connector/:name`, Studio), environment-wide or in a package created here (`POST /api/v1/packages`) — names a package-relative file or needs a location inside a package | Configuration fault, **never resolved against the host's directory**: a stored definition is no package's declaration and has no directory on disk. The instance is not materialized, and the reconcile's error names the entry, its package if it has one, and the ref. Carry the document inline in the definition, or name it by an `http(s)` URL; reach an MCP server from a stored entry over `http`. Only what the host's own stack declares reads its files: a stored row is never read as the host's, whatever `_packageId` its body carries |
869+
| A **stored** entry — one saved in this environment through the metadata door (`PUT /api/v1/meta/connector/:name`, Studio), environment-wide or in a package created here (`POST /api/v1/packages`) — names a package-relative file or needs a location inside a package | Configuration fault, **never resolved against the host's directory**: a stored definition is no package's declaration and has no directory on disk. The instance is not materialized, and the reconcile's error names the entry, its package if it has one, and the ref. This one is never fatal, even at boot: a stored row at rest is logged and skipped, and the platform starts. Carry the document inline in the definition, or name it by an `http(s)` URL; reach an MCP server from a stored entry over `http`. Only what the host's own stack declares reads its files: a stored row is never read as the host's, whatever `_packageId` its body carries |
870870
| MCP server unreachable / `tools/list` fails; remote spec URL unreachable or transiently failing (408/429/5xx) | **Not fatal**: the instance registers **degraded** (visible on `GET /api/v1/automation/connectors` with the reason), dispatches fail with that reason, and the platform retries on a 5s→5min backoff — recovery is automatic |
871871
| An `mcp` instance's `toolsSnapshot` does not match what the server serves (a pinned tool's description or `inputSchema` changed; or a pinned tool is no longer listed, on an instance whose credential did not reach the server) | **Not fatal**: the instance registers **degraded** with no actions, its reason naming each tool and the digest it now serves, and the logs say "serves a tool definition that differs from its toolsSnapshot" (`CONNECTOR_UPSTREAM_CHANGED`); it is re-checked on the same backoff and recovers once the server serves the pinned definitions again — or set the pin to the reviewed digest. A pinned tool no longer listed on an instance whose credential **did** reach the server (its `auth` over http) takes the credential row above instead: a server may hide tools from a credential, so the reason names both causes (fix the credential and set it again, or update the pin), a stored credential is marked `rejected`, and no retry runs against the same value |
872872
| A retry of a degraded instance reaches the upstream and meets a configuration fault (an `include` naming a tool or operation the upstream does not offer; on an `mcp` instance that sends a static credential, the credential row above applies instead) | **Not fatal**: the instance stays **degraded**, now with the configuration reason, and is **not retried** — dispatches fail saying to edit its declaration; an edit of the entry (or a restart) re-attempts it |
Lines changed: 201 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,201 @@
1+
// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license.
2+
//
3+
// GOLDEN REGRESSION — a stored connector entry whose package-relative ref is
4+
// refused (#28594) never stops the platform from booting.
5+
//
6+
// ## Why a restart
7+
//
8+
// `stored-connector-package-ref.dogfood.test.ts` saves its entries into a
9+
// RUNNING kernel, where the reconcile that refuses them is the post-boot one.
10+
// A row already at rest takes the other road: ObjectQL's `start()` hydrates
11+
// `sys_metadata` into the registry, and the automation service's own
12+
// `start()` reconcile reads that registry. That reconcile treats a
13+
// configuration fault as fatal, so an entry the upgrade newly refuses (one
14+
// that worked the day before) would refuse the next boot of every
15+
// environment holding it.
16+
//
17+
// ## What this file pins
18+
//
19+
// Two showcase boots over one database file. The first saves, through the
20+
// metadata door, an environment-wide `openapi` entry naming a
21+
// package-relative file, the same entry in an `authored` package, an
22+
// environment-wide stdio `mcp` entry, and a control carrying its document
23+
// inline. The second boot:
24+
//
25+
// 1. starts (no throw);
26+
// 2. does not list either refused entry, and its boot record names each
27+
// entry and its ref;
28+
// 3. lists the stored inline control `ready` with its operation (the rows
29+
// were hydrated, so the refusal above was read at boot, not skipped);
30+
// 4. lists the showcase's own file-ref and stdio entries `ready` (control).
31+
//
32+
// Boots fixture stacks of its own (a database file), so it stays out of
33+
// `SHARED_SHOWCASE`.
34+
35+
import { mkdtempSync, rmSync } from 'node:fs';
36+
import { tmpdir } from 'node:os';
37+
import { join } from 'node:path';
38+
39+
import { describe, it, expect, beforeAll, afterAll } from 'vitest';
40+
import { type VerifyStack } from '@objectstack/verify';
41+
import { bootShowcase } from './showcase-boot.js';
42+
43+
const FILE_REF = './src/system/connectors/status-openapi.json';
44+
const ENV_FILE = 'srr_env_file';
45+
const ENV_CWD = 'srr_env_cwd';
46+
const AUTHORED_FILE = 'srr_authored_file';
47+
/** An `authored` package created through the package door. */
48+
const AUTHORED_PACKAGE_ID = 'com.dogfood.storedrestart';
49+
const INLINE = 'srr_inline';
50+
const HOST_FILE_ENTRY = 'showcase_status_openapi';
51+
const HOST_STDIO_ENTRY = 'showcase_mcp_tools';
52+
53+
/** A one-operation OpenAPI 3 document; nothing is dispatched, so its server answers nothing. */
54+
const DOCUMENT = {
55+
openapi: '3.0.3',
56+
info: { title: 'Stored inline document', version: '1.0.0' },
57+
servers: [{ url: 'http://127.0.0.1:9/' }],
58+
paths: { '/v1/things': { get: { operationId: 'GetThings', responses: { '200': { description: 'ok' } } } } },
59+
};
60+
61+
const openapi = (name: string, spec: unknown) => ({
62+
name,
63+
label: `Stored ${name}`,
64+
type: 'api',
65+
provider: 'openapi',
66+
providerConfig: { spec, baseUrl: 'http://127.0.0.1:9/' },
67+
});
68+
69+
type Answer = { status: number; body: any };
70+
71+
async function json(res: Response): Promise<Answer> {
72+
return { status: res.status, body: await res.json().catch(() => null) };
73+
}
74+
75+
/** Every line the process writes while `run` is in flight — the kernel logger writes to the streams. */
76+
async function captureOutput<T>(run: () => Promise<T>): Promise<{ value: T; lines: string[] }> {
77+
const lines: string[] = [];
78+
const stdout = process.stdout.write.bind(process.stdout);
79+
const stderr = process.stderr.write.bind(process.stderr);
80+
const warn = console.warn;
81+
const error = console.error;
82+
(process.stdout as any).write = (chunk: unknown, ...rest: any[]) => { lines.push(String(chunk)); return stdout(chunk as any, ...rest); };
83+
(process.stderr as any).write = (chunk: unknown, ...rest: any[]) => { lines.push(String(chunk)); return stderr(chunk as any, ...rest); };
84+
console.warn = (...args: unknown[]) => { lines.push(args.map(String).join(' ')); warn(...args); };
85+
console.error = (...args: unknown[]) => { lines.push(args.map(String).join(' ')); error(...args); };
86+
try {
87+
return { value: await run(), lines };
88+
} finally {
89+
(process.stdout as any).write = stdout;
90+
(process.stderr as any).write = stderr;
91+
console.warn = warn;
92+
console.error = error;
93+
}
94+
}
95+
96+
const listed = (answer: Answer): any[] => answer.body?.data?.connectors ?? [];
97+
const entryOf = (answer: Answer, name: string): any => listed(answer).find((c: any) => c?.name === name);
98+
const shown = (answer: Answer, name: string): string => {
99+
const c = entryOf(answer, name);
100+
return c === undefined
101+
? `'${name}' not listed`
102+
: JSON.stringify({ name: c.name, state: c.state, actions: c.actions?.map((a: any) => a.key) });
103+
};
104+
105+
/** Read the listing until every `names` entry lists `ready`, or the window closes. */
106+
async function settle(stack: VerifyStack, token: string, names: readonly string[]): Promise<Answer> {
107+
const deadline = Date.now() + 15_000;
108+
let answer: Answer;
109+
do {
110+
answer = await json(await stack.apiAs(token, 'GET', '/automation/connectors'));
111+
if (names.every((n) => entryOf(answer, n)?.state === 'ready')) break;
112+
await new Promise((r) => setTimeout(r, 100));
113+
} while (Date.now() < deadline);
114+
return answer;
115+
}
116+
117+
describe('dogfood: a stored connector entry refused its package-relative ref does not stop the next boot', () => {
118+
let dir: string;
119+
const saves: Record<string, Answer> = {};
120+
let before: Answer;
121+
let bootError: unknown;
122+
let after: Answer;
123+
let bootLines: string[] = [];
124+
let second: VerifyStack | undefined;
125+
126+
beforeAll(async () => {
127+
dir = mkdtempSync(join(tmpdir(), 'dogfood-stored-connector-restart-'));
128+
const databaseFile = join(dir, 'os.db');
129+
130+
const first = await bootShowcase({ databaseFile });
131+
try {
132+
const token = await first.signIn();
133+
saves[ENV_FILE] = await json(await first.apiAs(token, 'PUT', `/meta/connector/${ENV_FILE}`, openapi(ENV_FILE, FILE_REF)));
134+
saves[ENV_CWD] = await json(await first.apiAs(token, 'PUT', `/meta/connector/${ENV_CWD}`, {
135+
name: ENV_CWD,
136+
label: 'Stored stdio',
137+
type: 'api',
138+
provider: 'mcp',
139+
providerConfig: { transport: { kind: 'stdio', command: 'node', args: ['./scripts/mcp-fixture.mjs'] } },
140+
}));
141+
saves.package = await json(await first.apiAs(token, 'POST', '/packages', {
142+
id: AUTHORED_PACKAGE_ID, name: 'Stored connector restart', version: '1.0.0', type: 'app',
143+
}));
144+
saves[AUTHORED_FILE] = await json(await first.apiAs(
145+
token, 'PUT', `/meta/connector/${AUTHORED_FILE}?package=${AUTHORED_PACKAGE_ID}`, openapi(AUTHORED_FILE, FILE_REF),
146+
));
147+
saves[INLINE] = await json(await first.apiAs(token, 'PUT', `/meta/connector/${INLINE}`, openapi(INLINE, DOCUMENT)));
148+
before = await settle(first, token, [INLINE]);
149+
} finally {
150+
await first.stop();
151+
}
152+
153+
const captured = await captureOutput(async () => {
154+
try {
155+
second = await bootShowcase({ databaseFile });
156+
} catch (err) {
157+
bootError = err;
158+
return undefined;
159+
}
160+
const token = await second.signIn();
161+
return settle(second, token, [INLINE, HOST_FILE_ENTRY, HOST_STDIO_ENTRY]);
162+
});
163+
bootLines = captured.lines;
164+
if (captured.value) after = captured.value;
165+
}, 300_000);
166+
167+
afterAll(async () => {
168+
await second?.stop?.();
169+
if (dir) rmSync(dir, { recursive: true, force: true });
170+
});
171+
172+
it('precondition: the first boot accepts every save and lists the inline control', () => {
173+
for (const [name, answer] of Object.entries(saves)) {
174+
expect(answer.status, `${name}: ${JSON.stringify(answer.body).slice(0, 400)}`).toBeLessThan(300);
175+
}
176+
expect(entryOf(before, INLINE)?.state, shown(before, INLINE)).toBe('ready');
177+
expect(entryOf(before, ENV_FILE), shown(before, ENV_FILE)).toBeUndefined();
178+
});
179+
180+
it('the second boot over the same database starts', () => {
181+
expect(bootError, bootError instanceof Error ? bootError.message.slice(0, 600) : String(bootError)).toBeUndefined();
182+
});
183+
184+
it.each([
185+
[ENV_FILE, `file ref '${FILE_REF}'`],
186+
[ENV_CWD, 'path ref \'.\''],
187+
[AUTHORED_FILE, `file ref '${FILE_REF}'`],
188+
])('%s is not listed after the restart, and the boot record names it and its ref', (name, ref) => {
189+
expect(entryOf(after, name), shown(after, name)).toBeUndefined();
190+
const record = bootLines.find((l) => l.includes(`connector instance '${name}'`) && l.includes('is refused'));
191+
expect(record, `no boot record refuses '${name}'`).toBeDefined();
192+
expect(record).toContain(ref);
193+
});
194+
195+
it('controls: the stored inline entry, and the showcase\'s own file-ref and stdio entries, list ready after the restart', () => {
196+
expect(entryOf(after, INLINE)?.state, shown(after, INLINE)).toBe('ready');
197+
expect(entryOf(after, INLINE).actions.map((a: any) => a.key)).toEqual(['GetThings']);
198+
expect(entryOf(after, HOST_FILE_ENTRY)?.state, shown(after, HOST_FILE_ENTRY)).toBe('ready');
199+
expect(entryOf(after, HOST_STDIO_ENTRY)?.state, shown(after, HOST_STDIO_ENTRY)).toBe('ready');
200+
});
201+
});

0 commit comments

Comments
 (0)