Skip to content

Commit e814dd1

Browse files
committed
Merge remote-tracking branch 'origin/main' into claude/issue-27464-interfaces-rename-held-guard
2 parents 9e41e3b + aef631b commit e814dd1

7 files changed

Lines changed: 623 additions & 6 deletions
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
---
2+
'@objectstack/cloud-connection': patch
3+
---
4+
5+
fix(cloud-connection): an install-local uninstall withdraws the package's flows from the automation engine at once, and unbinds their triggers
6+
7+
Clause-②: no
8+
Metadata-protocol: none
9+
10+
`DELETE /api/v1/marketplace/install-local/:manifestId` withdrew the package from the registry and ran its uninstall cleanups, but never told the running kernel. The automation engine withdraws a flow only when it re-syncs on `metadata:reloaded`, so the uninstalled package's flows stayed registered: `GET /api/v1/meta/flow/NAME` answered 404 while `GET /api/v1/automation/NAME` still answered `active`, `POST /api/v1/automation/NAME/trigger` still ran the flow and wrote a run row, and its record and schedule triggers stayed armed. That lasted until some unrelated reload, such as a view publish or another package's install. The door's note said the package was withdrawn from the running kernel.
11+
12+
- **Now.** After the registry withdrawal and the cleanups, the door announces `metadata:reloaded` with `{ changed: ['app/MANIFEST_ID'] }`, the same signal the install door's hot load announces. The engine's re-sync withdraws every flow it had armed that the package no longer provides and unbinds each one's trigger. Right after the `DELETE` returns, `GET /api/v1/automation/NAME` and its trigger door answer 404, and a write to a watched object runs nothing.
13+
- **When the re-sync does not run.** If a subscriber throws, or the kernel context cannot announce, the uninstall still answers 200, and `cleanups` carries one failed outcome named `metadata:reloaded`. The note then says the engine can still hold the package's flows until the next restart. The cause goes to the operator log at `warn`, with the restart as the remedy.
14+
- **Unchanged.** Nothing is announced when the uninstall did not happen (a refused caller, an id this door never installed, a ledger write that failed), or when the registry refused the withdrawal, because the package is still registered.

‎packages/cloud-connection/src/marketplace-install-local-plugin.ts‎

Lines changed: 99 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,10 @@
111111
* serving them at once too (#24070), then runs the uninstall
112112
* cleanups domain plugins registered with the protocol (#21490) —
113113
* the package's permission sets and their grants go with it — and
114-
* reports each outcome as `cleanups`, a refused withdrawal included.
114+
* last announces the withdrawal as `metadata:reloaded`, so the
115+
* automation engine withdraws the package's flows and unbinds their
116+
* triggers at once (#27395); it reports each outcome as `cleanups`,
117+
* a refused withdrawal or a re-sync that did not run included.
115118
*
116119
* Persistence layout:
117120
* <cwd>/.objectstack/installed-packages/<safe-manifest-id>.json
@@ -303,6 +306,13 @@ const REGISTRY_WITHDRAWAL = 'registry.uninstallPackage';
303306
*/
304307
const OBJECT_COPY_WITHDRAWAL = 'metadata.unregister';
305308

309+
/**
310+
* [#27395] The outcome name this door reports when the running kernel was not
311+
* told of the withdrawal — named for the event it announces, the re-sync the
312+
* automation engine withdraws an uninstalled package's flows on.
313+
*/
314+
const KERNEL_RESYNC = 'metadata:reloaded';
315+
306316
/**
307317
* [#8976] The capability every MUTATING install-local route demands.
308318
*
@@ -2291,13 +2301,28 @@ export class MarketplaceInstallLocalPlugin implements Plugin {
22912301
...(copies ? [copies] : []),
22922302
...await this.runUninstallCleanups(ctx, manifestId, admission.userId, declared),
22932303
];
2294-
const withdrawals = (withdrawal ? 1 : 0) + (copies ? 1 : 0);
2304+
// [#27395] LAST — after the registry withdrawal and the cleanups, never
2305+
// before, for the window described above — announce the withdrawal as
2306+
// `metadata:reloaded`, the re-sync the install's hot load announces, so
2307+
// the consumers that hold what they read from a package re-read it now
2308+
// that it is gone. ⛔ Nothing here withdraws a flow or unbinds a trigger
2309+
// itself: the uninstall drives the one teardown a reload drives. Not
2310+
// when the registry refused: the package is still registered, so a
2311+
// re-sync would only read it back.
2312+
const resync = withdrawal ? undefined : await this.announceUninstall(ctx, manifestId);
2313+
if (resync) cleanups.push(resync);
2314+
const withdrawals = (withdrawal ? 1 : 0) + (copies ? 1 : 0) + (resync ? 1 : 0);
22952315
ctx.logger?.info?.(
22962316
`[MarketplaceInstallLocal] uninstalled ${manifestId} (cached manifest removed; `
22972317
+ (withdrawal
22982318
? 'the running kernel did NOT withdraw it, so it stays loaded until the next restart; '
2299-
: copies
2300-
? 'withdrawn from the running kernel\'s registry, but the metadata service kept copies of its objects until the next restart; '
2319+
: copies || resync
2320+
? 'withdrawn from the running kernel\'s registry, but '
2321+
+ [
2322+
...(copies ? ['the metadata service kept copies of its objects'] : []),
2323+
...(resync ? ['the automation engine can still hold its flows'] : []),
2324+
].join(' and ')
2325+
+ ' until the next restart; '
23012326
: 'withdrawn from the running kernel; ')
23022327
+ `${cleanups.length - withdrawals} uninstall cleanup(s) ran)`,
23032328
);
@@ -2308,13 +2333,81 @@ export class MarketplaceInstallLocalPlugin implements Plugin {
23082333
cleanups,
23092334
note: withdrawal
23102335
? 'Cached manifest removed, and the uninstall cleanups this runtime\'s plugins registered ran — each one\'s outcome is in `cleanups`. The running kernel did not withdraw the package, so it stays loaded until the next restart; that is the `registry.uninstallPackage` entry in `cleanups`.'
2311-
: copies
2312-
? 'Cached manifest removed, the package withdrawn from the running kernel\'s registry, and the uninstall cleanups this runtime\'s plugins registered ran — each one\'s outcome is in `cleanups`. The metadata service kept copies of the package\'s objects, so the object listing and reads keep serving them until the next restart; that is the `metadata.unregister` entry in `cleanups`.'
2336+
: copies || resync
2337+
? 'Cached manifest removed, the package withdrawn from the running kernel\'s registry, and the uninstall cleanups this runtime\'s plugins registered ran — each one\'s outcome is in `cleanups`.'
2338+
+ (copies
2339+
? ' The metadata service kept copies of the package\'s objects, so the object listing and reads keep serving them until the next restart; that is the `metadata.unregister` entry in `cleanups`.'
2340+
: '')
2341+
+ (resync
2342+
? ' The running kernel\'s re-sync did not run, so the automation engine can still hold the package\'s flows — triggerable by name, their triggers armed — until the next restart; that is the `metadata:reloaded` entry in `cleanups`.'
2343+
: '')
23132344
: 'Cached manifest removed, the package withdrawn from the running kernel, and the uninstall cleanups this runtime\'s plugins registered ran — each one\'s outcome is in `cleanups`.',
23142345
},
23152346
}, 200);
23162347
};
23172348

2349+
/**
2350+
* [#27395] Announce an uninstall this door just completed to the running
2351+
* kernel as `metadata:reloaded` — the re-sync signal
2352+
* {@link announceHotInstall} announces for an install, with the same
2353+
* payload — so every consumer that holds what it read from a package
2354+
* re-reads a kernel that no longer has it:
2355+
*
2356+
* - `service-automation` re-syncs its flows from the protocol
2357+
* (`resyncFlowsFromProtocol`) and withdraws each flow it armed that the
2358+
* protocol's view no longer lists — the uninstalled package's, which
2359+
* the registry withdrawal took out of that view — and `withdrawFlow`
2360+
* unbinds each one's record or schedule trigger in the same step.
2361+
*
2362+
* Before this, the door withdrew the package from the registry and the
2363+
* engine never heard of it: `GET /meta/flow/NAME` answered 404 while
2364+
* `GET /automation/NAME` still answered `active`, and the trigger door, a
2365+
* record write or a schedule still ran the uninstalled package's flow
2366+
* until an unrelated reload — a view publish, another package's install —
2367+
* cleared it. ⛔ No engine-side list of the package's flows is kept or
2368+
* withdrawn here: a second teardown is how the two would drift.
2369+
*
2370+
* Never throws: the uninstall has already happened. Two answers:
2371+
* - `undefined` — announced, and every subscriber returned;
2372+
* - one failed outcome named {@link KERNEL_RESYNC}, when the context
2373+
* cannot announce or a subscriber threw. It rides on `cleanups`, the
2374+
* way a refused registry withdrawal does, and the operator log says
2375+
* what it costs and the remedy; the cause is logged, never put on the
2376+
* wire. A FUNCTIONAL degradation, so `warn` — the level the install's
2377+
* announce failure uses.
2378+
*/
2379+
private announceUninstall = async (
2380+
ctx: PluginContext,
2381+
manifestId: string,
2382+
): Promise<UninstallCleanupOutcome | undefined> => {
2383+
const failed: UninstallCleanupOutcome = {
2384+
name: KERNEL_RESYNC,
2385+
success: false,
2386+
removed: 0,
2387+
error: 'the running kernel did not re-sync — the automation engine can still hold the package\'s flows until the next restart',
2388+
};
2389+
const cost = 'its flows can stay registered in the automation engine — triggerable by name, their record and '
2390+
+ 'schedule triggers still armed — until the runtime restarts. The outcome is on the response (`cleanups`). '
2391+
+ 'Remedy: restart the runtime — the ledger entry is already gone, so the restart does not bring the package back.';
2392+
if (typeof ctx.trigger !== 'function') {
2393+
ctx.logger?.warn?.(
2394+
`[MarketplaceInstallLocal] uninstalled ${manifestId}, but this kernel context cannot announce `
2395+
+ `metadata:reloaded — ${cost}`,
2396+
);
2397+
return failed;
2398+
}
2399+
try {
2400+
await ctx.trigger('metadata:reloaded', { changed: [`app/${manifestId}`] });
2401+
return undefined;
2402+
} catch (err: any) {
2403+
ctx.logger?.warn?.(
2404+
`[MarketplaceInstallLocal] uninstalled ${manifestId}, but the metadata:reloaded re-sync FAILED `
2405+
+ `(${err?.message ?? err}) — ${cost}`,
2406+
);
2407+
return failed;
2408+
}
2409+
};
2410+
23182411
/**
23192412
* [#21576] Withdraw a package this door just removed from its ledger from
23202413
* the running kernel — through `SchemaRegistry.uninstallPackage`, the ONE

‎packages/cloud-connection/src/marketplace-install-local-uninstall-cleanups.test.ts‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,9 @@ async function bootPlugin(protocolMode: ProtocolMode = { kind: 'runner' }, opts:
136136
return svc;
137137
},
138138
logger,
139+
// Every kernel context can announce; the uninstall's `metadata:reloaded`
140+
// (#27395) is pinned in the resync file, so here it reaches no subscriber.
141+
trigger: async () => undefined,
139142
};
140143
const plugin = new MarketplaceInstallLocalPlugin({ controlPlaneUrl: 'off', storageDir: dir });
141144
await plugin.start(ctx);

‎packages/cloud-connection/src/marketplace-install-local-uninstall-meta-reads.test.ts‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,9 @@ async function bootPlugin(opts: { refuseUnregister?: string; before?: (metadata:
187187
return services[name];
188188
},
189189
logger,
190+
// Every kernel context can announce; the uninstall's `metadata:reloaded`
191+
// (#27395) is pinned in the resync file, so here it reaches no subscriber.
192+
trigger: async () => undefined,
190193
};
191194
const plugin = new MarketplaceInstallLocalPlugin({ controlPlaneUrl: 'off', storageDir: dir });
192195
await plugin.start(ctx as never);

0 commit comments

Comments
 (0)