Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions .changeset/33893-served-holder-keeps-slot-key.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
---
'@objectstack/service-automation': patch
---

fix(service-automation): the served holder of a flow name a disabled package also ships keeps its slot key and its trigger

Clause-②: no
Metadata-protocol: none

When two packages ship a flow of the same name and one of them is disabled, the engine holds the served package's flow in its own slot, filed under `PACKAGE/NAME`. Two paths lost that slot's trigger:

- At boot, with one holder disabled, only the served holder's flow is pulled. Its slot was filed under the bare name and declined as if the other package's body had been refused, so its trigger never ran, behind a warning that named a refused body.
- At runtime, the re-sync that follows a disable withdraws the disabled holder's slot. The served slot was moved to the bare name and its trigger binding was stopped, and not armed again.

Now a disable moves no key: in both cases the served holder's slot stays under `PACKAGE/NAME`, armed, and runs on its trigger; the bare name reaches it as the name's one served holder. When the other package is enabled again, its re-sync registers both packages' flows, in either order, and both slots end armed on their triggers. The warning about a refused body is said only once another package's body of the name is recorded as refused. When the other package is uninstalled, the name goes back to its bare key, as before. Before its slot is withdrawn, that happens at the withdrawal. After the withdrawal, it happens the first time the engine registers the served holder's flow again, fires its trigger or is asked for the name. Every bare entry (`execute`, `getFlow`, removal, version history, rollback, the bare inbound hook, credentials) then serves the name as one package's, and a re-sync that fails leaves no flow unreachable.
31 changes: 31 additions & 0 deletions .changeset/33905-disabled-sole-holder-flow.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
---
'@objectstack/service-automation': patch
---

fix(service-automation)!: a flow whose only holder's package is disabled is not run by its trigger, and the engine's bare entries answer as for no flow (ADR-0150 D3)

Clause-②: no (narrowing)
Metadata-protocol: none

<!-- adr-0087: not-required (no-migration-prescription) No key of any schema is added, removed, renamed or re-shaped, and no export changes shape. The moved answers are a trigger-fired run and the bare execute, getFlow and toggleFlow entries under a reversible package state: no stored row, slot key, run key, trigger binding or dispatch key changes, so there is nothing for a migration to rewrite and no tombstone. -->

**BREAKING** for a deployment where a package that alone ships a flow name is disabled while the automation engine still holds that flow (the re-sync that follows a disable failed or did not run): the flow no longer runs, and the bare entries no longer serve it. Before this release it kept running and was served.

What moves, for such a flow, while its package is disabled:

- Its trigger binding (record-change, schedule, time-relative, or an api inbound hook's queued post) ran the flow. Now nothing runs and no run-history row is written; the skip is logged once at `info` per slot.
- `execute(name, …)`, by any caller, a `subflow` or `map` node's call included, ran the flow. It now answers `{ success: false, error: "Flow 'NAME' not found" }`, the answer for a flow the engine does not hold.
- `getFlow(name)` answered the flow. It now answers `null`, so the bare HTTP doors that ask it first (`GET /automation/NAME`, `POST /automation/NAME/trigger`, `POST /automation/trigger/NAME`, `POST /automation/NAME/toggle`, `POST /automation/NAME/clone`, `GET /automation/NAME/runs`) answer `404`, which is what the namespaced address `/automation/NAMESPACE/NAME…` already answered.
- `toggleFlow(name, …)` switched the flow. It now rejects with `Flow 'NAME' not found`.

Three HTTP write doors ask `getFlow` whether the name is held, and move with it for such a flow. These answers were read from the runtime source; the engine's half of the clone answer was measured. Each holds only where the door's earlier checks, such as the packaged-base and authoring rules, let the request through.

- `POST /automation/SOURCE/clone`, with the flow's name as the new name: the taken-name probe refused the copy with `409`. It now finds no flow and lets the copy through. The engine files the copy's body in the disabled package's slot of the name, and once the package is enabled again its trigger runs the copy's body until the next re-sync. That is the answer the door already gives once the disable's re-sync has withdrawn the flow, so the door accepts nothing the normal path refuses.
- A definition write (`POST /automation`, `PUT /automation/NAME`) or a clone that the engine accepts and that is then refused (an unknown `notify` channel, a refused landing, a refused save) put back the definition the engine held. It now has nothing to put back, so it removes the name's registration. A `PUT` body that leaves out a stored credential no longer keeps the one the engine held.
- `DELETE /automation/NAME` answered a deletion. It still removes the engine's registration, but now answers `404` unless a stored row was removed.

Remedy: enable the package. Its flow runs on its trigger again with no re-arm, and the bare entries serve it again.

An event that fires while the package is disabled is dropped, not replayed when the package is enabled again.

Nothing durable moves: the slot key, run keys, the trigger binding, the dispatch holder, credentials and the version history stay judged over every holder. Resuming a run parked before the disable is not decided here. A flow no package ships (the environment's own, or one registered straight into the engine) answers as before.
83 changes: 83 additions & 0 deletions packages/runtime/src/domains/automation-addressed-route.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -636,3 +636,86 @@ describe('[#33386] the by-name doors judge the served holders of a name two pack
});
});
});

/**
* [ADR-0150 D3, #33905] A flow name one package holds, that package disabled,
* over a real `SchemaRegistry`: its namespaced address is refused `404` at
* admission, before the service is asked. The bare path reaches the engine,
* whose bare entries now answer as for a flow it does not hold (`getFlow`
* `null`, pinned in service-automation's `flow-slots-per-package.test.ts`),
* so each bare door answers what the address answers. The service here
* answers as the engine does for such a flow.
*/
describe('[#33905] a flow whose only holder\'s package is disabled: the bare door answers as its namespaced address (404)', () => {
function registryHolding(disabled: boolean) {
const registry = new SchemaRegistry();
registry.logLevel = 'silent';
registry.installPackage({ id: CRM, name: CRM, version: '1.0.0', type: 'app', namespace: 'crm' } as never, 'code');
registry.registerItem('flow', { name: 'solo', _packageId: CRM }, 'name' as never, CRM);
if (disabled) registry.disablePackage(CRM);
return registry;
}

function dispatcherOver(registry: SchemaRegistry, held: boolean) {
const automation = {
handlerReady: true,
getFlow: vi.fn(async (name: string) => (held && name === 'solo' ? { name } : null)),
execute: vi.fn(async (name: string) => (held ? { success: true, output: {} } : { success: false, error: `Flow '${name}' not found` })),
toggleFlow: vi.fn(async (name: string) => { if (!held) throw new Error(`Flow '${name}' not found`); }),
listRunsPage: vi.fn(async () => ({ runs: [] as unknown[], hasMore: false })),
getActionDescriptors: vi.fn(() => []),
getFlowRuntimeStates: vi.fn(() => []),
};
const services: Record<string, unknown> = { automation, objectql: { registry } };
const resolve = (name: string) => services[name];
const kernel: any = { getService: resolve, getServiceAsync: async (name: string) => resolve(name), context: { getService: resolve } };
const dispatcher = new HttpDispatcher(kernel);
const call = async (path: string, method: string, body: unknown = {}) => {
const answered = await dispatcher.handleAutomation(path, method, body, { request: {}, executionContext: ADMIN } as any, {});
return { status: answered.response?.status ?? 200, body: answered.response?.body as any };
};
return { call, automation };
}

const DOORS: ReadonlyArray<readonly [string, string, string, unknown]> = [
['/solo', '/crm/solo', 'GET', {}],
['/solo/trigger', '/crm/solo/trigger', 'POST', {}],
['/trigger/solo', '/trigger/crm/solo', 'POST', {}],
['/solo/toggle', '/crm/solo/toggle', 'POST', { enabled: false }],
['/solo/runs', '/crm/solo/runs', 'GET', {}],
];

it('each bare door answers 404 as its namespaced address does; nothing runs or switches (FROM: the bare door served the flow)', async () => {
const { call, automation } = dispatcherOver(registryHolding(true), false);
for (const [bare, addressed, method, body] of DOORS) {
const viaAddress = await call(addressed, method, body);
const viaBare = await call(bare, method, body);
expect([bare, viaBare.status, codeOf(viaBare)]).toEqual([bare, 404, codeOf(viaAddress)]);
expect([addressed, viaAddress.status]).toEqual([addressed, 404]);
}
expect(automation.execute).not.toHaveBeenCalled();
expect(automation.toggleFlow).not.toHaveBeenCalled();
expect(automation.listRunsPage).not.toHaveBeenCalled();
});

it('the clone door with the flow as its source answers 404 as its namespaced address does; nothing is registered (FROM: the source was copied)', async () => {
const { call, automation } = dispatcherOver(registryHolding(true), false);
const registerFlow = vi.fn();
(automation as Record<string, unknown>).registerFlow = registerFlow;
const viaAddress = await call('/crm/solo/clone', 'POST', { name: 'solo_copy', label: 'Solo copy' });
const viaBare = await call('/solo/clone', 'POST', { name: 'solo_copy', label: 'Solo copy' });
expect([viaBare.status, codeOf(viaBare)]).toEqual([404, codeOf(viaAddress)]);
expect(viaAddress.status).toBe(404);
expect(registerFlow).not.toHaveBeenCalled();
});

it('CONTROL — the package enabled: the address is its bare path, and both serve the flow', async () => {
const { call } = dispatcherOver(registryHolding(false), true);
for (const [bare, addressed, method, body] of DOORS) {
const viaAddress = await call(addressed, method, body);
const viaBare = await call(bare, method, body);
expect([bare, viaBare.status]).toEqual([bare, 200]);
expect([addressed, viaAddress.status]).toEqual([addressed, 200]);
}
});
});
Loading
Loading