Skip to content

Commit 6455104

Browse files
fix(service-automation): an install-local package keeps its flows registered after a restart, whatever the plugin order (#33095)
<!-- claude-projects-attribution: {"github_login":"os-elon-musk"} --> _Requested by **Elon** · [project thread](https://claude.ai/code/project/chan_01WedDzV26nniwxv7jC88B9D?thread=cmsg_01WedDzV26nniwxv7jC88B9DPZVafoyPJiw5GSH3KRXGJh)_ Fixes #33049 Clause-②: no Metadata-protocol: none ## 维护者速读 1. 问题:通过 install-local 安装的包,重启后对象还在,但它的流程没注册到自动化引擎,触发返回 404,要等下一次随便装个包才恢复。 2. 原因:引擎只在自己的 `kernel:ready` 里做一次开机流程绑定;install-local 在它自己的 `kernel:ready` 里才恢复已装包。谁先跑取决于插件启动顺序。 3. 为什么只有 showcase 中招:连接器插件都声明依赖自动化插件,showcase 又把 install-local 排在连接器之后,于是自动化插件先启动、先绑定,恢复的包就漏了。空白应用和 app-todo 的 install-local 由 CLI 先挂载,所以不受影响。 4. 修复:引擎在 `kernel:bootstrapped`(所有 `kernel:ready` 跑完之后、封存流程归属之前)再读一次流程视图,视图有变化才补绑一次;没变化什么都不做。与 #28591 对连接器的做法一致。 5. 不是 18.3.0 回归:18.3.0 版本提交上四个条件全都已经存在(卡片评论 6850890576),因此按冻结规则本 PR 不进合并队列,除非 triage 改判为阻塞。 6. 验证:真实 `objectstack dev` 在文件库上重启 showcase,修复前触发 404、修复后 200 且 `registered`;新增 dogfood 重启 pin 和单元 pin,把修复拿掉两者都变红。 ## What changes - `packages/services/service-automation/src/plugin.ts`: a `kernel:bootstrapped` pass (`bindFlowsRegisteredDuringBoot`) on the flow sync queue. The `kernel:ready` bind (`syncFlowsFromProtocol`) now records a fingerprint of the flow view it read (`flowViewFingerprint`: every flow's whole definition, order-free). At `kernel:bootstrapped`, which fires once every `kernel:ready` handler has settled whatever the plugin order, the view is read again; when it differs, the same additive bind runs over it (logged `Bound N flow(s) from the protocol at kernel:bootstrapped`). An unchanged view binds nothing; a boot whose `kernel:ready` bind read no view does nothing. The hook is registered before the plugin's own seal/audit `kernel:bootstrapped` hook, so the rebound flows are in place before `sealFlowHolders`, the node-type audit and the trigger-binding audit. The #28591 comment that claimed "Its flows already bind" is corrected. - Changeset: `@objectstack/service-automation` patch. Why there and not in the install-local rehydrate: the defect is the engine's assumption that every package registered in a `kernel:ready` handler is registered before its own; any plugin registering flows there meets it. Announcing `metadata:reloaded` from the rehydrate would run every reload consumer during the boot, which the install-local plugin explicitly does not do at `kernel:ready`. ## Mechanism (measured on main c419609) - Real restart: scratch copy of `examples/app-showcase`, `objectstack dev --seed-admin --no-compile --no-watch` over a file DB with an isolated `OS_HOME`, the card's manifest. Before the fix: install 200, trigger 200, restart, trigger **404** `RESOURCE_NOT_FOUND`, `registration.state: unregistered`, banner `33 flow(s)`. With the fix: trigger 200, `registered`, banner `34 flow(s)`. - Debug log of the failing boot: plugin start order `service-automation` #17, the four connector plugins #18 to #21, `marketplace-install-local` #23; `[Automation] Bound 33 flow(s) from the protocol at kernel:ready` at 10:55:17.997Z, `[MarketplaceInstallLocal] rehydrated com.qa.solo@1.0.0` at 10:55:18.372Z. - The kernel's dependency sort starts a plugin's declared dependencies first; all four connector plugins declare `dependencies = ['com.objectstack.service-automation']`. ## Tests - `packages/qa/dogfood/test/install-local-restart-connectors.dogfood.test.ts`: a second top-level `describe` in the shared harness file. It mounts `MarketplaceInstallLocalPlugin` inside the showcase's own `plugins`, after the plugins that depend on the automation plugin, where the showcase lists it. The existing describe passes it through `extraPlugins`, which `bootStack` mounts before the app's plugins, so it never met the CLI's order. Pins: the composition precondition, the pre-restart install and trigger, the listing after the restart, the trigger by name after the restart (200), and `registration.state: registered` after the restart. - `packages/services/service-automation/src/flow-cold-boot-bind.test.ts`: a new top-level `describe` on a `LiteKernel`: a plugin registered after the automation plugin adds a packaged flow to the protocol's view in its own `kernel:ready` handler; after `bootstrap()` the flow is registered, beside the one the `kernel:ready` bind registered. Ablation (both negative pins, fix reverted to origin/main in the tree and `service-automation` rebuilt, then restored from HEAD): - dogfood: `Tests 2 failed | 8 passed (10)`; `after the restart, the package's flow triggers by name`: `expected 404 to be 200` (`RESOURCE_NOT_FOUND`); `after the restart, the package's flow reads registered`: `expected 'unregistered' to be 'registered'`. Restored: `Tests 10 passed (10)`. - unit: `Tests 1 failed | 5 passed (6)`, `registered after a later kernel:ready handler added it: expected null not to be null`. Restored: `Tests 6 passed (6)`. ## Acceptance notes - Release check: not a regression vs 18.3.0 (card comment 6850890576). 18.4.0 merge freeze: this PR stays out of the merge queue unless triage grades the card a blocker. - Reach beyond the showcase: any host that wires its own `MarketplaceInstallLocalPlugin` after a plugin that depends on the automation plugin met the same loss. A host relying on the CLI-mounted install-local did not. - The dogfood pins boot in memory, not over a file DB: the loss is decided by plugin order and the ledger directory (kept across the two boots), not by the database. The file-DB restart was measured by hand on the real CLI (above). ## Verification Head `348024bd50` (origin/main `c4196099` merged before the PR opened; main had not moved). The gates ran on `3093fdb91f`, whose tree is byte-identical to the head's (the amend only removed a card trailer from the commit message). Every exit captured before any pipe. <details><summary>Package tests, typecheck and pins</summary> - `pnpm --filter @objectstack/service-automation exec vitest run --maxWorkers=2`: `Test Files 279 passed (279)`, `Tests 3830 passed (3830)`. - `pnpm --filter @objectstack/service-automation typecheck` (`tsc --noEmit` + `check:test-typecheck`): exit 0, `0 file(s) / 0 error(s)`. - `pnpm --filter @objectstack/dogfood exec vitest run --maxWorkers=2 test/install-local-restart-connectors.dogfood.test.ts`: `Tests 10 passed (10)`. - `src/flow-cold-boot-bind.test.ts`: `Tests 6 passed (6)`. - Prerequisite: whole-tree `pnpm exec turbo run build --concurrency=2` under the verify lock, exit 0 (`120 successful`). </details> <details><summary>Derived gates (`dispatch-gates.mjs --commands`, 74) and lint</summary> `node scripts/pm/dispatch-gates.mjs --ran gates-ran-348024bd50.txt`: `✓ dispatch-gates --ran: 74 derived famil(ies) accounted for — 74 run, 0 NOT-MEASURED (a DERIVED zero — all 74 recorded an exit code and none of them is 3)`. `check:dual-build-cjs-loads` first answered exit 3 (11 packages without `dist/`) and was re-run after the whole-tree build: exit 0. `pnpm lint` (`eslint . --no-inline-config`): exit 0, recorded outside the derivation. ```text node scripts/check-adr-0087-registration.mjs --base origin/main :: exit 0 node scripts/check-adr-0087-registration.mjs --self-test :: exit 0 node scripts/check-changeset-no-major.mjs --base origin/main :: exit 0 node scripts/check-closing-keyword-parity.mjs :: exit 0 node scripts/check-closing-keyword-parity.mjs --self-test :: exit 0 node scripts/check-comment-mask-adoption.mjs :: exit 0 node scripts/check-comment-mask-adoption.mjs --self-test :: exit 0 node scripts/check-comment-mask-corpus.mjs :: exit 0 node scripts/check-dts-emitted.mjs --self-test :: exit 0 node scripts/check-empty-changeset.mjs --base origin/main :: exit 0 node scripts/check-empty-changeset.mjs --self-test :: exit 0 node scripts/check-issue-citations.mjs :: exit 0 node scripts/check-plugin-teardown-shape.mjs :: exit 0 node scripts/check-plugin-teardown-shape.mjs --self-test :: exit 0 node scripts/check-tenant-audit-census.mjs :: exit 0 node scripts/check-tenant-audit-census.mjs --self-test :: exit 0 node scripts/ci/assert-turbo-remote-cache.mjs --self-test :: exit 0 node scripts/ci/plan-test-core-shards.mjs --self-test :: exit 0 node scripts/ci/prune-turbo-cache.mjs --self-test :: exit 0 node scripts/ci/snapshot-next.mjs --self-test :: exit 0 node scripts/docs-audit/check-affected-docs.mjs :: exit 0 node scripts/docs-audit/check-drift-comment.mjs :: exit 0 node scripts/pm/release-rehearsal-clone.mjs --self-test :: exit 0 node scripts/release-pending-publish.mjs --self-test :: exit 0 pnpm --filter @objectstack/spec run check:duration-unit-keys :: exit 0 pnpm --filter @objectstack/spec run check:empty-state :: exit 0 pnpm --filter @objectstack/spec run check:liveness :: exit 0 pnpm --filter @objectstack/spec run check:strictness-ledger :: exit 0 pnpm --filter @objectstack/spec run check:variant-docs :: exit 0 pnpm check:adr-symbol-anchors :: exit 0 pnpm check:changeset-gate-self-tests :: exit 0 pnpm check:ci-filter-parity :: exit 0 pnpm check:cli-command-ids :: exit 0 pnpm check:closed-ceremony-text :: exit 0 pnpm check:cross-package-test-inputs :: exit 0 pnpm check:doc-authoring :: exit 0 pnpm check:driver-memory-census :: exit 0 pnpm check:dts-closure :: exit 0 pnpm check:dual-build-cjs-loads :: exit 0 pnpm check:durability-log-level :: exit 0 pnpm check:engine-double-contract :: exit 0 pnpm check:error-status-conformance :: exit 0 pnpm check:gitlink-declared :: exit 0 pnpm check:init-service-contract :: exit 0 pnpm check:issue-citations :: exit 0 pnpm check:keyed-text-bounds :: exit 0 pnpm check:lean-entry-closure :: exit 0 pnpm check:logger-receiver-detach :: exit 0 pnpm check:nul-bytes :: exit 0 pnpm check:object-def-param-keys :: exit 0 pnpm check:objectql-double-limit :: exit 0 pnpm check:optional-error-sink :: exit 0 pnpm check:org-identifier :: exit 0 pnpm check:package-naming :: exit 0 pnpm check:page-declaration-shape :: exit 0 pnpm check:platform-object-tenancy-census :: exit 0 pnpm check:published-files :: exit 0 pnpm check:query-options-erasure :: exit 0 pnpm check:refd-timer-probe :: exit 0 pnpm check:registry-log-declared :: exit 0 pnpm check:rest-log-spy-declared :: exit 0 pnpm check:settings-bind-window :: exit 0 pnpm check:slot-lookup :: exit 0 pnpm check:sourcemap-no-sources-content :: exit 0 pnpm check:startup-registry-verdict :: exit 0 pnpm check:system-context-census :: exit 0 pnpm check:test-source-alias :: exit 0 pnpm check:tier-file-adoption :: exit 0 pnpm check:type-check-coverage :: exit 0 pnpm check:type-check-debt :: exit 0 pnpm check:undeclared-dep-imports :: exit 0 pnpm check:vouch-for-reference-callers :: exit 0 pnpm check:watch-hint-literal :: exit 0 pnpm check:where-matcher :: exit 0 pnpm lint :: exit 0 ``` </details> <!-- signed: domain:server#6 · os-elon-musk · session_016WV4cwZuSHmXjzxcfEXUGA --> --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent 4aceae5 commit 6455104

4 files changed

Lines changed: 270 additions & 8 deletions

File tree

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
'@objectstack/service-automation': patch
3+
---
4+
5+
fix(service-automation): a package installed through install-local keeps its flows registered after a restart, whatever the plugin order
6+
7+
Clause-②: no
8+
Metadata-protocol: none
9+
10+
The engine bound a cold boot's flows once, in its own `kernel:ready` handler. The install-local rehydrate re-registers every installed package in its own `kernel:ready` handler, so the bind saw those packages only when the install-local plugin started first. A host that lists a plugin depending on the automation plugin (any connector plugin) before `MarketplaceInstallLocalPlugin` starts the automation plugin first: after a restart the package was listed and its objects served, but its flows answered 404 on the trigger door and read `registration.state: unregistered` until some later hot install re-synced the engine. The engine now reads the flow view again at `kernel:bootstrapped`, once every `kernel:ready` handler has settled and before the flow holders seal, and binds again when the view changed since the `kernel:ready` bind. A boot whose view did not change binds nothing more.

‎packages/qa/dogfood/test/install-local-restart-connectors.dogfood.test.ts‎

Lines changed: 149 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,30 @@
3333
//
3434
// Boots fixture stacks of its own (the install-local plugin mounted), so it
3535
// stays out of `SHARED_SHOWCASE`.
36+
//
37+
// ## Second describe: the flows, with the plugin order `objectstack dev` boots
38+
//
39+
// Measured on a real `objectstack dev` restart of the showcase over a file DB
40+
// before the fix: the package was listed and its objects served, but its flow
41+
// answered 404 on the trigger door and `registration.state: unregistered`.
42+
// The engine's `kernel:ready` bind sees a rehydrated package only when the
43+
// install-local plugin starts before the automation plugin, and the showcase
44+
// lists `MarketplaceInstallLocalPlugin` in its own `plugins` AFTER the
45+
// connector plugins, each of which declares a dependency on the automation
46+
// plugin, so the kernel starts the automation plugin first and the rehydrate
47+
// runs after the bind. The first describe mounts install-local through
48+
// `extraPlugins`, which `bootStack` mounts before the app's plugins, so it
49+
// never met that order. The second describe mounts it where the showcase
50+
// lists it, and pins:
51+
//
52+
// 1. (precondition) the boot's composition lists install-local after a
53+
// plugin that depends on the automation plugin;
54+
// 2. (precondition) the install answers 200, hot-loaded, and the flow
55+
// triggers by name before the restart;
56+
// 3. after the restart: the package is listed;
57+
// 4. after the restart: the flow triggers by name (200);
58+
// 5. after the restart: the flow's metadata reads `registration.state:
59+
// registered`.
3660

3761
import { mkdtempSync, rmSync } from 'node:fs';
3862
import { tmpdir } from 'node:os';
@@ -41,6 +65,7 @@ import { join } from 'node:path';
4165
import { describe, it, expect, beforeAll, afterAll } from 'vitest';
4266
import { type VerifyStack } from '@objectstack/verify';
4367
import { MarketplaceInstallLocalPlugin } from '@objectstack/cloud-connection';
68+
import showcaseStack from '@objectstack/example-showcase';
4469
import { bootShowcase } from './showcase-boot.js';
4570

4671
const ROUTE = '/marketplace/install-local';
@@ -183,3 +208,127 @@ describe('dogfood: an install-local package\'s connector is live again after a r
183208
expect(listed(after, HOST_CONNECTOR), JSON.stringify(names(after))).toBeDefined();
184209
});
185210
});
211+
212+
const FLOW_PACKAGE_ID = 'com.dogfood.restartflow';
213+
const ORDER_FLOW = 'rstflow_manual_probe';
214+
const AUTOMATION_PLUGIN = 'com.objectstack.service-automation';
215+
216+
const FLOW_INSTALL_BODY = {
217+
manifest: {
218+
id: FLOW_PACKAGE_ID,
219+
namespace: 'rstflow',
220+
name: 'Restart flow probe',
221+
version: '0.1.0',
222+
type: 'app',
223+
flows: [
224+
{
225+
name: ORDER_FLOW,
226+
label: 'Restart flow probe (run by name)',
227+
type: 'autolaunched',
228+
status: 'active',
229+
nodes: [
230+
{ id: 'start', type: 'start', label: 'Start' },
231+
{ id: 'end', type: 'end', label: 'End' },
232+
],
233+
edges: [{ id: 'e1', source: 'start', target: 'end' }],
234+
},
235+
],
236+
},
237+
};
238+
239+
const dependsOnAutomation = (plugin: unknown): boolean =>
240+
Array.isArray((plugin as { dependencies?: unknown })?.dependencies)
241+
&& ((plugin as { dependencies: unknown[] }).dependencies).includes(AUTOMATION_PLUGIN);
242+
243+
/**
244+
* The showcase with `MarketplaceInstallLocalPlugin` in its own `plugins`, after
245+
* the plugins that depend on the automation plugin, where the showcase's
246+
* configuration lists it whenever a control plane is configured (this suite
247+
* runs with `OS_CLOUD_URL=off`, which leaves it out).
248+
*/
249+
function showcaseWithInstallLocal(storageDir: string): { plugins: unknown[] } {
250+
const own = ((showcaseStack as { plugins?: unknown[] }).plugins ?? []);
251+
let at = 0;
252+
own.forEach((plugin, index) => {
253+
if (dependsOnAutomation(plugin)) at = index + 1;
254+
});
255+
return {
256+
...(showcaseStack as object),
257+
plugins: [...own.slice(0, at), new MarketplaceInstallLocalPlugin({ controlPlaneUrl: 'off', storageDir }), ...own.slice(at)],
258+
};
259+
}
260+
261+
describe('dogfood: an install-local package\'s flow is registered again after a restart, in the plugin order the showcase boots', () => {
262+
let storageDir: string;
263+
let composition: { plugins: unknown[] };
264+
let install: Answer;
265+
let triggerBefore: Answer;
266+
let packages: Answer;
267+
let triggerAfter: Answer;
268+
let metaAfter: Answer;
269+
let bootError: unknown;
270+
271+
beforeAll(async () => {
272+
storageDir = mkdtempSync(join(tmpdir(), 'dogfood-install-local-restart-flow-'));
273+
composition = showcaseWithInstallLocal(storageDir);
274+
const first = await bootShowcase({}, composition);
275+
try {
276+
const token = await first.signIn();
277+
install = await json(await first.apiAs(token, 'POST', ROUTE, FLOW_INSTALL_BODY));
278+
triggerBefore = await json(await first.apiAs(token, 'POST', `/automation/${ORDER_FLOW}/trigger`, {}));
279+
} finally {
280+
await first.stop();
281+
}
282+
283+
let second: VerifyStack | undefined;
284+
try {
285+
second = await bootShowcase({}, showcaseWithInstallLocal(storageDir));
286+
} catch (err) {
287+
bootError = err;
288+
return;
289+
}
290+
try {
291+
const token = await second.signIn();
292+
packages = await json(await second.apiAs(token, 'GET', ROUTE));
293+
triggerAfter = await json(await second.apiAs(token, 'POST', `/automation/${ORDER_FLOW}/trigger`, {}));
294+
metaAfter = await json(await second.apiAs(token, 'GET', `/meta/flow/${ORDER_FLOW}`));
295+
} finally {
296+
await second.stop();
297+
}
298+
}, 300_000);
299+
300+
afterAll(() => {
301+
if (storageDir) rmSync(storageDir, { recursive: true, force: true });
302+
});
303+
304+
it('the composition lists install-local after a plugin that depends on the automation plugin (precondition)', () => {
305+
const installLocalAt = composition.plugins.findIndex((p) => p instanceof MarketplaceInstallLocalPlugin);
306+
const lastDependentAt = composition.plugins.reduce<number>((last, p, i) => (dependsOnAutomation(p) ? i : last), -1);
307+
expect(lastDependentAt).toBeGreaterThanOrEqual(0);
308+
expect(installLocalAt).toBeGreaterThan(lastDependentAt);
309+
});
310+
311+
it('before the restart, the install is hot-loaded and the flow triggers by name (precondition)', () => {
312+
expect(install.status, JSON.stringify(install.body)).toBe(200);
313+
expect(install.body?.data?.hotLoaded).toBe(true);
314+
expect(triggerBefore.status, JSON.stringify(triggerBefore.body)).toBe(200);
315+
});
316+
317+
it('the second boot over the same ledger succeeds and lists the package', () => {
318+
expect(bootError).toBeUndefined();
319+
expect(packages.status, JSON.stringify(packages.body)).toBe(200);
320+
const item = (packages.body?.data?.items ?? []).find((i: any) => i?.manifestId === FLOW_PACKAGE_ID);
321+
expect(item, JSON.stringify(packages.body)).toBeDefined();
322+
expect(item.notLoaded).toBeUndefined();
323+
});
324+
325+
it('after the restart, the package\'s flow triggers by name', () => {
326+
expect(triggerAfter.status, JSON.stringify(triggerAfter.body)).toBe(200);
327+
});
328+
329+
it('after the restart, the package\'s flow reads registered', () => {
330+
expect(metaAfter.status, JSON.stringify(metaAfter.body)).toBe(200);
331+
const doc = metaAfter.body?.data ?? metaAfter.body;
332+
expect(doc?.registration?.state, JSON.stringify(metaAfter.body)).toBe('registered');
333+
});
334+
});

‎packages/services/service-automation/src/flow-cold-boot-bind.test.ts‎

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,3 +218,48 @@ describe('cold-boot bind survives the read path annotations (cloud#971)', () =>
218218
await kernel.shutdown();
219219
});
220220
});
221+
222+
/**
223+
* A package registered in ANOTHER plugin's own `kernel:ready` handler, after
224+
* this plugin's bind ran — the order a host gets when a plugin that depends on
225+
* the automation plugin (every connector plugin does) is listed before the
226+
* install-local plugin, whose rehydrate re-registers every installed package in
227+
* `kernel:ready` and announces no reload. Its flow is in the protocol's view
228+
* from then on, and must be registered once the boot settles.
229+
*/
230+
describe('a flow registered by a later plugin\'s kernel:ready handler is registered after the boot', () => {
231+
async function bootWithLateRegistrar(early: unknown[], late: unknown[]) {
232+
const served = [...early];
233+
const kernel = new LiteKernel({ logger: { level: 'silent' } } as never);
234+
kernel.use(new AutomationServicePlugin());
235+
kernel.use({
236+
name: 'test.late-registrar',
237+
type: 'standard' as const,
238+
version: '1.0.0',
239+
dependencies: [] as string[],
240+
async init(ctx: any) {
241+
ctx.registerService('protocol', fakeProtocolService(served));
242+
},
243+
async start(ctx: any) {
244+
// Registered after the automation plugin's: runs after its bind.
245+
ctx.hook('kernel:ready', async () => {
246+
served.push(...late);
247+
});
248+
},
249+
} as never);
250+
await kernel.bootstrap();
251+
return kernel;
252+
}
253+
254+
it('registers the late flow, and keeps the one the kernel:ready bind registered', async () => {
255+
const kernel = await bootWithLateRegistrar(
256+
[recordTriggeredFlow('host_flow', 'task')],
257+
[{ ...recordTriggeredFlow('installed_flow', 'task'), _packageId: 'com.example.installed' }],
258+
);
259+
await flush();
260+
const engine = kernel.getService<AutomationEngine>('automation');
261+
expect(await engine.getFlow('host_flow')).not.toBeNull();
262+
expect(await engine.getFlow('installed_flow'), 'registered after a later kernel:ready handler added it').not.toBeNull();
263+
await kernel.shutdown();
264+
});
265+
});

‎packages/services/service-automation/src/plugin.ts‎

Lines changed: 66 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1121,6 +1121,16 @@ function connectorInstanceSignature(entry: {
11211121
});
11221122
}
11231123

1124+
/**
1125+
* [#33049] The protocol's flow view as one comparable string: each flow's
1126+
* whole definition, order-free. Two reads of an unchanged view give the same
1127+
* string, so the `kernel:bootstrapped` pass binds again only when a plugin
1128+
* registered or changed a flow after the `kernel:ready` bind read the view.
1129+
*/
1130+
function flowViewFingerprint(defs: readonly unknown[]): string {
1131+
return stableStringify(defs.map((def) => stableStringify(def)).sort());
1132+
}
1133+
11241134
/**
11251135
* [#28591] The provider-bound instances a declaration asks the reconcile for,
11261136
* as one comparable string: the name and {@link connectorInstanceSignature} of
@@ -1507,6 +1517,12 @@ export class AutomationServicePlugin implements Plugin {
15071517
* unregisters them.
15081518
*/
15091519
private syncedFlowNames = new Set<string>();
1520+
/**
1521+
* [#33049] The flow view the boot's last protocol bind read
1522+
* ({@link flowViewFingerprint}); `undefined` until a bind has read one.
1523+
* The `kernel:bootstrapped` pass compares against it.
1524+
*/
1525+
private bootFlowViewFingerprint: string | undefined;
15101526
/**
15111527
* Provider-bound declarative connectors this plugin has materialized
15121528
* (ADR-0097), keyed by connector name. `signature` is a stable hash of the
@@ -2623,11 +2639,12 @@ export class AutomationServicePlugin implements Plugin {
26232639
// package a plugin registers in its own `kernel:ready` handler arrives
26242640
// after it — the install-local rehydrate re-registers every installed
26252641
// package there — and announces no reload, so its connectors were never
2626-
// materialized until some unrelated reload. Its flows already bind: the
2627-
// `kernel:ready` flow sync below reads the protocol's view after the
2628-
// rehydrate. Connectors are read again at `kernel:bootstrapped`, which
2629-
// fires once every `kernel:ready` handler has settled, whatever the
2630-
// plugin order. See {@link reconcileConnectorsRegisteredDuringBoot}.
2642+
// materialized until some unrelated reload. Connectors are read again at
2643+
// `kernel:bootstrapped`, which fires once every `kernel:ready` handler
2644+
// has settled, whatever the plugin order. See
2645+
// {@link reconcileConnectorsRegisteredDuringBoot}. [#33049] Its flows
2646+
// need the same second read: see the `kernel:bootstrapped` flow pass
2647+
// below the `kernel:ready` bind.
26312648
ctx.hook('kernel:bootstrapped', async () => {
26322649
await this.reconcileConnectorsRegisteredDuringBoot(ctx);
26332650
});
@@ -2725,6 +2742,22 @@ export class AutomationServicePlugin implements Plugin {
27252742
}
27262743
});
27272744

2745+
// ── [#33049] Flows a plugin registered after the bind above ──────────
2746+
// The bind above sees a package registered in another plugin's own
2747+
// `kernel:ready` handler only when that handler ran first, and handlers
2748+
// run in plugin start order: a plugin that declares a dependency on
2749+
// this one (every connector plugin does) starts this one earlier, so
2750+
// the install-local rehydrate, which re-registers every installed
2751+
// package there and announces no reload, then runs after the bind. Its
2752+
// flows were served and never registered, until some unrelated hot
2753+
// install re-synced. `kernel:bootstrapped` fires once every
2754+
// `kernel:ready` handler has settled, whatever the plugin order, and
2755+
// before this plugin seals its flow holders below: the view is read
2756+
// again there, and bound again only when it changed.
2757+
ctx.hook('kernel:bootstrapped', async () => {
2758+
await this.enqueueFlowSync(() => this.bindFlowsRegisteredDuringBoot(ctx));
2759+
});
2760+
27282761
// [#27238] Setup → Integrations → Connector Credentials — the door's
27292762
// nav entry ships with the door (cloud ADR-0009 shape). After the
27302763
// inert-mode return above: a one-shot tool serves no console.
@@ -5775,10 +5808,16 @@ export class AutomationServicePlugin implements Plugin {
57755808
* flow in the view at `kernel:ready` — a record made there could be
57765809
* contradicted by this same boot (AGENTS.md "Startup registry reads").
57775810
*/
5778-
private async syncFlowsFromProtocol(ctx: PluginContext): Promise<void> {
5811+
private async syncFlowsFromProtocol(
5812+
ctx: PluginContext,
5813+
phase: 'kernel:ready' | 'kernel:bootstrapped' = 'kernel:ready',
5814+
read?: Array<{ name?: string }>,
5815+
): Promise<void> {
57795816
if (!this.engine) return;
5780-
const defs = await this.readFlowDefsFromProtocol(ctx);
5817+
const defs = read ?? await this.readFlowDefsFromProtocol(ctx);
57815818
if (!defs) return;
5819+
// [#33049] What this bind read, for the `kernel:bootstrapped` pass.
5820+
this.bootFlowViewFingerprint = flowViewFingerprint(defs);
57825821
let bound = 0;
57835822
// [#20913] Through the boot pull's own precedence decision — see
57845823
// {@link resolveFlowContenders}. registerFlow is idempotent, so
@@ -5811,10 +5850,29 @@ export class AutomationServicePlugin implements Plugin {
58115850
}
58125851
}
58135852
if (bound > 0) {
5814-
ctx.logger.info(`[Automation] Bound ${bound} flow(s) from the protocol at kernel:ready`);
5853+
ctx.logger.info(`[Automation] Bound ${bound} flow(s) from the protocol at ${phase}`);
58155854
}
58165855
}
58175856

5857+
/**
5858+
* [#33049] The `kernel:bootstrapped` pass: bind again, through the same
5859+
* additive {@link syncFlowsFromProtocol}, when the protocol's flow view
5860+
* differs from the one the `kernel:ready` bind read, so a package a plugin
5861+
* registered after that bind (the install-local rehydrate) has its flows
5862+
* registered whatever the plugin order. An unchanged view binds nothing;
5863+
* a bind that never read a view (no protocol) leaves this pass nothing to
5864+
* compare, and it does nothing. Runs on the flow sync queue, before the
5865+
* flow holders seal.
5866+
*/
5867+
private async bindFlowsRegisteredDuringBoot(ctx: PluginContext): Promise<void> {
5868+
if (!this.engine || this.destroyed) return;
5869+
if (this.bootFlowViewFingerprint === undefined) return;
5870+
const defs = await this.readFlowDefsFromProtocol(ctx);
5871+
if (!defs) return;
5872+
if (flowViewFingerprint(defs) === this.bootFlowViewFingerprint) return;
5873+
await this.syncFlowsFromProtocol(ctx, 'kernel:bootstrapped', defs);
5874+
}
5875+
58185876
/**
58195877
* [#21725] Run `job` on the flow sync queue: after every flow sync queued
58205878
* before it, before every one queued after. The returned promise settles

0 commit comments

Comments
 (0)