Skip to content

Commit 1855ffb

Browse files
committed
fix(service-automation): warn once when a flow runs on a never-sealed node-type vocabulary (#4792)
#4771 made sealNodeTypeVocabulary() the only moment the ADR-0018 node-type check runs. AutomationServicePlugin seals at kernel:bootstrapped, so plugin hosts are covered — but a host that constructs `new AutomationEngine()` and never seals lost the check entirely, in silence, discoverable only by reading a changeset. The first execute() on an unsealed engine now says so once. - Once per engine INSTANCE, not per process: a host with one engine per tenant/environment omitted the call on each of them. - The line reports the missing CALL, not the unknown-type audit: an unsealed engine's vocabulary can still grow by contract, so naming absent executors there would rebuild #4771's contradictable verdict inside the embedded path. getUnknownNodeTypeAudit() stays the read-only probe for hosts that want the findings without closing the vocabulary. - It deliberately does NOT auto-seal: authority over "closed" stays with the host, and after a seal registerFlow validates inline — auto-sealing would hand the false "will fail at execution time" warnings to any embedded host that registers executors after its first run (legal under ADR-0018). Tests: embedded host warns once; unknown/disabled flow names do not trigger it; the warn does not seal; plus two sentinels — an explicitly-sealed host and the AutomationServicePlugin boot gain no log line. decision-branch-routing's harnesses now seal (they are embedded hosts asserting zero warnings about #4414 routing), which the inversion check proves is load-bearing. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01BWS4heBoAitLmzCLhcYdbK
1 parent 8108787 commit 1855ffb

4 files changed

Lines changed: 330 additions & 0 deletions

File tree

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
---
2+
'@objectstack/service-automation': patch
3+
---
4+
5+
自动化引擎:嵌入式 host 从未调用 `sealNodeTypeVocabulary()` 时,首次执行 flow 会告警一次(#4792)
6+
7+
#4771 把 ADR-0018 的节点类型校验从 `registerFlow` 挪到了 `sealNodeTypeVocabulary()``AutomationServicePlugin``kernel:bootstrapped` 自动 seal,插件路径不受影响;但自己 `new AutomationEngine()` 且从不 seal 的嵌入式 host 就彻底拿不到这项校验,而且完全静默 —— 只有读过 changeset 的人才知道要补一行调用。现在这类 host 在第一次真正执行 flow 时会得到一条 `warn`,说明丢了什么、以及要调用哪个方法。
8+
9+
- 首次执行是最早既安全又必然到达的时点:正在跑 flow 的 host 显然已经装配完毕(否则这次执行本身就会 `NO_EXECUTOR` 失败)。
10+
- **每个引擎实例一次**,不是每进程一次 —— 一个 host 建了多个引擎(按租户/环境各一个是常见形态)就是在每个上都漏了这次调用。
11+
- 告警只报「缺了这次调用」这个关于 host 的事实,**不报**未知节点类型的审计结果:未 seal 的引擎其词汇表按契约仍可增长,在那里断言「某类型没有执行器」正是 #4771 删掉的那种会被本次启动反驳的判断。需要审计结果又不想封闭词汇表的 host 用只读的 `getUnknownNodeTypeAudit()`
12+
-**不会**顺带自动 seal:「谁决定词汇表封闭」只能有一个答案(host)。而且 seal 之后 `registerFlow` 会转为即时校验,自动 seal 会让「先执行、后注册插件执行器」(ADR-0018 允许)的嵌入式 host 开始收到 #4771 那种误报。
13+
14+
`AutomationServicePlugin` 的部署与已显式调用过 `sealNodeTypeVocabulary()` 的 host 都不会多打任何日志(两条哨兵测试守着)。

packages/services/service-automation/src/builtin/decision-branch-routing.test.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,15 @@ describe('decision branch routing (#4414)', () => {
5252
return { success: true };
5353
},
5454
});
55+
// This harness IS an embedded host, so it owes the host's half of the
56+
// ADR-0018 contract: every executor it will contribute is registered
57+
// above, so the vocabulary is closed (#4771). Without it the first
58+
// `execute()` below reports the omission (#4792) and the
59+
// zero-warning assertions in this file — which are about #4414 routing,
60+
// not about node types — would count that line. Declaring the seal is
61+
// the honest fix; filtering the warning out of the assertions would have
62+
// hidden a real signal in every future test that borrows this harness.
63+
engine.sealNodeTypeVocabulary();
5564
});
5665

5766
/** The guard from `examples/app-crm/src/flows/convert-lead.flow.ts`. */
@@ -353,6 +362,10 @@ describe('objectui-authored decision shape (FlowEdgeInspector.applyBranch)', ()
353362
{ id: 'e3', source: 'check', target: 'auto', label: 'Standard', isDefault: true },
354363
],
355364
});
365+
// Same reason as the harness above: an embedded host closes its own
366+
// vocabulary once every executor is in (#4771/#4792), and every node
367+
// type this flow uses is registered above, so the seal is silent.
368+
engine.sealNodeTypeVocabulary();
356369
});
357370

358371
it('takes only the guarded branch when it matches', async () => {

packages/services/service-automation/src/engine.ts

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1130,6 +1130,14 @@ export class AutomationEngine implements IAutomationService {
11301130
* started; only then is an unknown type a finding worth warning about.
11311131
*/
11321132
private nodeTypeVocabularySealed = false;
1133+
/**
1134+
* Whether this engine has already told its host that
1135+
* {@link sealNodeTypeVocabulary} was never called (#4792). Per **instance**,
1136+
* not per process: an embedded host that builds several engines (one per
1137+
* tenant/environment is the common shape) forgot the call on each of them,
1138+
* and a module-level flag would report only whichever engine ran first.
1139+
*/
1140+
private nodeTypeSealOmissionWarned = false;
11331141
private triggers = new Map<string, FlowTrigger>();
11341142
/**
11351143
* Flows currently wired to a trigger, keyed by flow name → the trigger
@@ -2379,6 +2387,13 @@ export class AutomationEngine implements IAutomationService {
23792387
return { success: false, error: `Flow '${flowName}' is disabled` };
23802388
}
23812389

2390+
// #4792 — a real run is about to start, so if the vocabulary was never
2391+
// sealed the ADR-0018 §M1 node-type check never ran on this engine at
2392+
// all. Say so once. Placed after the two guards above so the trigger is
2393+
// an execution and not a typo'd flow name (which is already loud) or a
2394+
// flow that cannot run. See the helper for why here and not earlier.
2395+
this.warnIfNodeTypeVocabularyNeverSealed();
2396+
23822397
// Re-entrancy loop guard (see `activeRecordFlows`). Break the SAME flow
23832398
// re-firing for the SAME record while a prior execution is still active —
23842399
// a self-trigger cascade whose start condition fails to suppress it would
@@ -3592,6 +3607,68 @@ export class AutomationEngine implements IAutomationService {
35923607
return audit;
35933608
}
35943609

3610+
/**
3611+
* Report — once per engine — that a flow ran on an engine whose node-type
3612+
* vocabulary was never sealed, so the ADR-0018 §M1 check never ran (#4792).
3613+
*
3614+
* #4771 made {@link sealNodeTypeVocabulary} the *only* moment node types are
3615+
* validated. `AutomationServicePlugin` calls it at `kernel:bootstrapped`, so
3616+
* every plugin-hosted deployment is covered — but a host that constructs
3617+
* `new AutomationEngine()` itself has no plugin doing it, and before #4771
3618+
* those hosts *did* get a verdict at `registerFlow` (an accurate one, since
3619+
* an embedded host controls its own ordering and typically registers
3620+
* executors first). For them the fix traded an unreliable warning for no
3621+
* warning at all, discoverable only by reading a changeset. "Documented" is
3622+
* not "enforced" (ADR-0049, #4632), so the omission has to say its own name.
3623+
*
3624+
* **Why the first `execute()` is the right moment.** It is the earliest point
3625+
* that is both safe and certain to be reached: the engine cannot know when a
3626+
* host has finished wiring, but a host that is *running flows* has finished —
3627+
* this very run resolves its executors from the same registry, and would fail
3628+
* `NO_EXECUTOR` otherwise. On the plugin path the seal already happened at
3629+
* `kernel:bootstrapped`, strictly before any `execute()`, so that path can
3630+
* never reach this line (pinned by test, so the warning cannot become noise).
3631+
*
3632+
* **Why it names the missing CALL and not the audit findings.** Running the
3633+
* unknown-type audit here and warning about what it finds would be the exact
3634+
* shape AGENTS.md "Startup registry reads" forbids: an unsealed engine is one
3635+
* whose host has *not* declared the vocabulary closed, so "no executor for
3636+
* `approval`" is still "not registered YET" — a verdict this process can
3637+
* contradict a line later, recorded in a log nobody can retract. That is
3638+
* #4771 rebuilt inside the embedded path. The missing call, by contrast, is a
3639+
* fact about the host that no later registration can change. A host that
3640+
* wants the findings without sealing has {@link getUnknownNodeTypeAudit},
3641+
* which is read-only by design.
3642+
*
3643+
* **Why it does not seal here.** Sealing would silently move the authority
3644+
* over "the vocabulary is closed" from the host to the first execution, and
3645+
* it would not be harmless: after the seal `registerFlow` validates inline,
3646+
* so an embedded host that registers a plugin's executors *after* running a
3647+
* flow — legal, ADR-0018 keeps the vocabulary open — would start getting the
3648+
* false "will fail at execution time" assertions #4771 exists to delete. The
3649+
* engine states the omission; the host still decides when the world is
3650+
* closed.
3651+
*
3652+
* Keep this text clear of {@link warnUnknownNodeTypes}'s "no registered
3653+
* executor or descriptor" phrase: tests and log filters use that substring
3654+
* to count *per-flow* findings, and a line that merely talks about them must
3655+
* not be counted as one.
3656+
*/
3657+
private warnIfNodeTypeVocabularyNeverSealed(): void {
3658+
if (this.nodeTypeVocabularySealed || this.nodeTypeSealOmissionWarned) return;
3659+
this.nodeTypeSealOmissionWarned = true;
3660+
this.logger.warn(
3661+
`[automation] flow executed on an engine whose node-type vocabulary was never sealed — ` +
3662+
`sealNodeTypeVocabulary() has not been called, so the ADR-0018 node-type check never ran and this ` +
3663+
`engine has never reported a flow whose node types nothing has registered; such nodes now fail ` +
3664+
`mid-run with NO_EXECUTOR instead of being named at startup. ` +
3665+
`A host that constructs AutomationEngine directly must call engine.sealNodeTypeVocabulary() once every ` +
3666+
`plugin has contributed its executors (AutomationServicePlugin does this at 'kernel:bootstrapped'); ` +
3667+
`engine.getUnknownNodeTypeAudit() returns the same finding without closing the vocabulary. ` +
3668+
`Reported once per engine instance.`,
3669+
);
3670+
}
3671+
35953672
/** One warning per flow, shared by the boot audit and the post-seal path. */
35963673
private warnUnknownNodeTypes(entry: UnknownNodeTypeAuditEntry): void {
35973674
this.logger.warn(
Lines changed: 226 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,226 @@
1+
// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license.
2+
3+
/**
4+
* #4792 — an embedded host that never seals the vocabulary must be TOLD, not
5+
* left silent.
6+
*
7+
* #4771 moved the ADR-0018 §M1 node-type check out of `registerFlow` and into
8+
* `sealNodeTypeVocabulary()`. `AutomationServicePlugin` calls it at
9+
* `kernel:bootstrapped`, so plugin-hosted deployments are covered — but a host
10+
* that builds `new AutomationEngine()` itself and never calls seal lost the
11+
* check entirely, with no signal. Those hosts control their own ordering, so
12+
* the pre-#4771 verdict was *accurate* for them: the fix swapped an unreliable
13+
* warning for no warning at all, recoverable only by reading a changeset.
14+
*
15+
* Two halves, and the second is as load-bearing as the first:
16+
*
17+
* 1. the omission is now loud, once per engine instance;
18+
* 2. the paths that did nothing wrong — the plugin boot, and a host that
19+
* calls seal itself — gain no log line at all, which is the only thing
20+
* keeping this warning from becoming the noise #4771 deleted.
21+
*
22+
* Reverse-verified while writing: temporarily inverting the guard in
23+
* `warnIfNodeTypeVocabularyNeverSealed()` (warn when the vocabulary IS sealed)
24+
* turns the two sentinels below red and the embedded-host cases green-for-the-
25+
* wrong-reason, so the sentinels really do guard the seal, not just the string.
26+
*/
27+
28+
import { describe, it, expect, vi } from 'vitest';
29+
import { LiteKernel } from '@objectstack/core';
30+
import type { Plugin, PluginContext } from '@objectstack/core';
31+
import { AutomationEngine } from './engine.js';
32+
import { AutomationServicePlugin } from './plugin.js';
33+
34+
/** Substring that identifies the #4792 line, wherever logs are captured. */
35+
const OMISSION_MARKER = 'node-type vocabulary was never sealed';
36+
37+
/** A flow that needs no plugin-contributed executor: structural nodes only. */
38+
const trivialFlow = (name: string) => ({
39+
name,
40+
label: name,
41+
type: 'autolaunched',
42+
nodes: [
43+
{ id: 'start', type: 'start', label: 'Start' },
44+
{ id: 'end', type: 'end', label: 'End' },
45+
],
46+
edges: [{ id: 'e1', source: 'start', target: 'end' }],
47+
});
48+
49+
/** A flow whose only real node type nothing registers (the #4771 subject). */
50+
const approvalFlow = (name: string) => ({
51+
name,
52+
label: name,
53+
type: 'autolaunched',
54+
nodes: [
55+
{ id: 'start', type: 'start', label: 'Start' },
56+
{ id: 'signoff', type: 'approval', label: 'Sign-off', config: { approvers: [{ type: 'user', value: 'u1' }] } },
57+
{ id: 'end', type: 'end', label: 'End' },
58+
],
59+
edges: [
60+
{ id: 'e1', source: 'start', target: 'signoff' },
61+
{ id: 'e2', source: 'signoff', target: 'end' },
62+
],
63+
});
64+
65+
function loggerCapturing(lines: string[]) {
66+
const l: any = {
67+
info: (m: string) => lines.push(`info ${m}`),
68+
debug: () => {},
69+
error: (m: string) => lines.push(`error ${m}`),
70+
warn: (m: string) => lines.push(`warn ${m}`),
71+
child: () => l,
72+
};
73+
return l;
74+
}
75+
76+
const omissionLines = (lines: string[]) => lines.filter((l) => l.includes(OMISSION_MARKER));
77+
78+
/**
79+
* Minimal `objectql` stand-in exposing the one seam the boot flow-pull reads,
80+
* mirroring `flow-node-type-audit.test.ts` — this is how a flow gets registered
81+
* during `AutomationServicePlugin.start()`, i.e. on the real plugin path.
82+
*/
83+
function fakeObjectqlPlugin(flows: unknown[]): Plugin {
84+
return {
85+
name: 'fake-objectql',
86+
version: '1.0.0',
87+
async init(ctx: PluginContext) {
88+
(ctx as unknown as { registerService(n: string, s: unknown): void }).registerService('objectql', {
89+
registry: {
90+
listItems: (type: string) => (type === 'flow' ? flows : []),
91+
getObject: () => undefined,
92+
},
93+
});
94+
},
95+
};
96+
}
97+
98+
const sealedState = (engine: AutomationEngine) =>
99+
(engine as unknown as { nodeTypeVocabularySealed: boolean }).nodeTypeVocabularySealed;
100+
101+
describe('#4792 — a never-sealed node-type vocabulary announces itself at the first execution', () => {
102+
it('warns on the first execute() of an embedded host that never sealed', async () => {
103+
const lines: string[] = [];
104+
const engine = new AutomationEngine(loggerCapturing(lines));
105+
// The embedded shape: register the executors, register the flows, run —
106+
// and never call sealNodeTypeVocabulary(), because no plugin does it here.
107+
engine.registerFlow('embedded_flow', trivialFlow('embedded_flow'));
108+
expect(omissionLines(lines), 'registration alone must stay quiet').toEqual([]);
109+
110+
const result = await engine.execute('embedded_flow');
111+
expect(result.success).toBe(true);
112+
113+
const warned = omissionLines(lines);
114+
expect(warned).toHaveLength(1);
115+
// The line owes both halves AGENTS.md asks a degradation for: what was
116+
// lost, and the call that restores it.
117+
expect(warned[0]).toMatch(/^warn /);
118+
expect(warned[0]).toContain('sealNodeTypeVocabulary()');
119+
expect(warned[0]).toContain('NO_EXECUTOR');
120+
expect(warned[0]).toContain('kernel:bootstrapped');
121+
});
122+
123+
it('says it ONCE per engine — and every engine instance speaks for itself', async () => {
124+
const lines: string[] = [];
125+
const engine = new AutomationEngine(loggerCapturing(lines));
126+
engine.registerFlow('a', trivialFlow('a'));
127+
engine.registerFlow('b', trivialFlow('b'));
128+
129+
await engine.execute('a');
130+
await engine.execute('a');
131+
await engine.execute('b');
132+
expect(omissionLines(lines), 'one line per engine, not one per run').toHaveLength(1);
133+
134+
// Dedupe is per instance, not per process/module: a host that builds one
135+
// engine per tenant forgot the call on each of them, and a module-level
136+
// flag would report only whichever engine happened to run first.
137+
const otherLines: string[] = [];
138+
const other = new AutomationEngine(loggerCapturing(otherLines));
139+
other.registerFlow('a', trivialFlow('a'));
140+
await other.execute('a');
141+
expect(omissionLines(otherLines)).toHaveLength(1);
142+
});
143+
144+
it('does not fire for an unknown or disabled flow name — the trigger is a real run', async () => {
145+
const lines: string[] = [];
146+
const engine = new AutomationEngine(loggerCapturing(lines));
147+
engine.registerFlow('off', trivialFlow('off'));
148+
await engine.toggleFlow('off', false);
149+
150+
expect((await engine.execute('never_registered')).success).toBe(false);
151+
expect((await engine.execute('off')).success).toBe(false);
152+
// Both already answer loudly on their own; the omission is reported when
153+
// an execution actually starts, which is the moment the issue argues is
154+
// both safe and certain to be reached.
155+
expect(omissionLines(lines)).toEqual([]);
156+
});
157+
158+
it('warns but does NOT seal — the host keeps authority over closing the vocabulary', async () => {
159+
const lines: string[] = [];
160+
const engine = new AutomationEngine(loggerCapturing(lines));
161+
engine.registerFlow('embedded_flow', trivialFlow('embedded_flow'));
162+
await engine.execute('embedded_flow');
163+
expect(omissionLines(lines)).toHaveLength(1);
164+
165+
// Auto-sealing here would put two answers behind "who decides the
166+
// vocabulary is closed", and the second one would not be harmless: after
167+
// a seal `registerFlow` validates inline, so a host that registers a
168+
// plugin's executors AFTER its first run — legal, ADR-0018 keeps the
169+
// vocabulary open — would start getting the false "will fail at
170+
// execution time" assertions #4771 exists to delete.
171+
expect(sealedState(engine)).toBe(false);
172+
engine.registerFlow('later', approvalFlow('later'));
173+
expect(lines.filter((l) => l.includes('no registered executor or descriptor'))).toEqual([]);
174+
175+
// …and the host's own seal still works, and still reports the finding.
176+
const audit = engine.sealNodeTypeVocabulary();
177+
expect(audit.map((e) => e.flowName)).toEqual(['later']);
178+
expect(lines.filter((l) => l.includes('no registered executor or descriptor'))).toHaveLength(1);
179+
});
180+
181+
it('SENTINEL — a host that called seal itself gets no extra line', async () => {
182+
const lines: string[] = [];
183+
const engine = new AutomationEngine(loggerCapturing(lines));
184+
engine.registerFlow('embedded_flow', trivialFlow('embedded_flow'));
185+
expect(engine.sealNodeTypeVocabulary()).toEqual([]);
186+
187+
const before = [...lines];
188+
expect((await engine.execute('embedded_flow')).success).toBe(true);
189+
190+
expect(omissionLines(lines)).toEqual([]);
191+
// Nothing at warn/error was added by the run at all — the new code is
192+
// reachable here (execute ran) and stayed silent because the host did
193+
// its part, not because the path was skipped.
194+
expect(sealedState(engine)).toBe(true);
195+
const added = lines.slice(before.length).filter((l) => l.startsWith('warn ') || l.startsWith('error '));
196+
expect(added).toEqual([]);
197+
});
198+
199+
it('SENTINEL — the AutomationServicePlugin path is untouched: sealed at boot, no new log', async () => {
200+
// `kernel:bootstrapped` fires strictly after every plugin's start() and
201+
// every kernel:ready handler, so any execute() is necessarily after the
202+
// seal and this warning can never reach the normal deployment.
203+
const stdout: string[] = [];
204+
const spy = vi.spyOn(process.stdout, 'write').mockImplementation(((chunk: unknown) => {
205+
stdout.push(String(chunk));
206+
return true;
207+
}) as never);
208+
const kernel = new LiteKernel();
209+
kernel.use(fakeObjectqlPlugin([trivialFlow('plugin_flow')]));
210+
kernel.use(new AutomationServicePlugin());
211+
try {
212+
await kernel.bootstrap();
213+
const engine = kernel.getService<AutomationEngine>('automation');
214+
expect(sealedState(engine), 'the plugin seals at kernel:bootstrapped').toBe(true);
215+
216+
const bootLines = stdout.length;
217+
expect((await engine.execute('plugin_flow')).success).toBe(true);
218+
219+
expect(omissionLines(stdout)).toEqual([]);
220+
expect(stdout.slice(bootLines).join('')).not.toContain('sealNodeTypeVocabulary');
221+
} finally {
222+
spy.mockRestore();
223+
await kernel.shutdown();
224+
}
225+
});
226+
});

0 commit comments

Comments
 (0)