From d4fb78892011e123489d8771ba4c69288c1cea8a Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 16 Nov 2026 03:22:12 +0000 Subject: [PATCH 01/11] fix(runtime): the automation write doors read the flow a name holds over every holder The clone door's taken-name probe, the definition writes' put-back copy and carried-forward credentials, and the DELETE door's existence probe asked getFlow, the served read, a durable question. They now ask the engine's new engine-local getHeldFlow (bareFlowKey's read over every holder), so a flow whose one holder's package is disabled is still taken, put back, kept and found. Co-Authored-By: Claude Claude-Session: https://claude.ai/code/session_01QsR2jUZKdq3PK2Sab53cT3 --- packages/runtime/src/domains/automation.ts | 75 +++++++++++++++---- .../services/service-automation/src/engine.ts | 15 ++++ 2 files changed, 76 insertions(+), 14 deletions(-) diff --git a/packages/runtime/src/domains/automation.ts b/packages/runtime/src/domains/automation.ts index d39570fc212..8666f3388c0 100644 --- a/packages/runtime/src/domains/automation.ts +++ b/packages/runtime/src/domains/automation.ts @@ -2103,6 +2103,39 @@ function servedFlowDefinition(flow: T): T { return redactMetadataItem(FLOW_METADATA_TYPE, flow); } +/** The engine-local read over every holder (service-automation's `AutomationEngine.getHeldFlow`). */ +interface HeldFlowSource { + getHeldFlow?(name: string): unknown; +} + +/** + * [ADR-0150 D3, #34145; seat ruling 6884403301, amendment 7] The reader for a + * DURABLE question this domain's write doors ask of a flow name — is it taken + * (the clone's target), what did the engine hold before this write (the + * put-back copy), which credential does it keep (the carried-forward secret), + * does the engine hold it at all (`DELETE`'s existence probe). Judged over + * every holder: a flow whose one holder's package is disabled is still held, + * and a name two packages hold is refused `409` naming every holder, so none + * of these answers moves with a package's enable state. `getFlow` is the + * SERVED read (a disabled package holds no name), which the read and run + * doors keep. + * + * The engine's `getHeldFlow` is engine-local, not on the service contract; a + * service without it (a host composing another engine, which has no package + * to disable) is asked its `getFlow`. `undefined` when the service offers + * neither read. + */ +function heldFlowReader( + automationService: Pick, +): ((name: string) => Promise) | undefined { + const source = automationService as HeldFlowSource; + const getHeldFlow = source.getHeldFlow; + if (typeof getHeldFlow === 'function') return async (name) => getHeldFlow.call(source, name); + const getFlow = automationService.getFlow; + if (typeof getFlow === 'function') return (name) => getFlow.call(automationService, name); + return undefined; +} + /** * [#20552] The write-path inverse for the two doors that overwrite a flow by * name (`POST /` onto an existing name, `PUT /:name`): a body that carries the @@ -2112,19 +2145,20 @@ function servedFlowDefinition(flow: T): T { * same inverse (`carryForwardRedactedValues`), so both authoring surfaces keep * one rule. * - * The comparison runs against the definition the ENGINE holds (`getFlow`, the - * raw in-process read), not a served copy. A service without the optional - * `getFlow`, or a name it does not hold, carries nothing — the body is - * registered as written, and a missing secret is refused by the engine's own - * registration gate, loudly. + * The comparison runs against the definition the ENGINE holds (the raw + * in-process read, over every holder: {@link heldFlowReader} [#34145]), not a + * served copy. A service with no read, or a name it does not hold, carries + * nothing — the body is registered as written, and a missing secret is + * refused by the engine's own registration gate, loudly. */ async function keepStoredFlowCredentials( automationService: Pick, name: string, definition: unknown, ): Promise { - if (typeof automationService.getFlow !== 'function') return definition; - const stored = await automationService.getFlow(name); + const readHeld = heldFlowReader(automationService); + if (readHeld === undefined) return definition; + const stored = await readHeld(name); if (!stored) return definition; return carryForwardRedactedValues(FLOW_METADATA_TYPE, definition, stored); } @@ -2735,7 +2769,10 @@ async function registerAndSaveFlow( const store: (Partial> & Partial>) | undefined = await deps.resolveServiceOrLoud(context, 'protocol'); - const held = typeof automationService.getFlow === 'function' ? await automationService.getFlow(name) : null; + // [#34145] What the engine held, over every holder (`heldFlowReader`): the + // put-back copy does not move with the holder's package's enable state. + const readHeld = heldFlowReader(automationService); + const held = readHeld === undefined ? null : await readHeld(name); let registered: unknown; try { registered = automationService.registerFlow(name, definition); @@ -2990,9 +3027,13 @@ async function unregisterAndDeleteFlow( const store: (Partial> & Partial>) | undefined = await deps.resolveServiceOrLoud(context, 'protocol'); - // The trigger door's own probe: the engine holds no such flow. - const unknownToEngine = await flowIsUnknown(automationService, name); - const held = typeof automationService.getFlow === 'function' ? await automationService.getFlow(name) : null; + // [#34145] The engine holds no such flow, asked over every holder + // (`heldFlowReader`), as `unregisterFlow` removes it: a flow whose one + // holder's package is disabled is held, removed and answered as a + // deletion. A service with no read is never "unknown" here. + const readHeld = heldFlowReader(automationService); + const held = readHeld === undefined ? null : await readHeld(name); + const unknownToEngine = readHeld !== undefined && !held; automationService.unregisterFlow(name); let rowDeleted = false; if (typeof store?.deleteMetaItem === 'function') { @@ -4454,13 +4495,19 @@ export async function handleAutomationRequest(deps: DomainHandlerDeps, path: str if (credentialRefusal) return { handled: true, response: deps.errorFromThrown(credentialRefusal) }; // ⛔ SAME-NAME REFUSAL, loudly, naming the sanctioned path. - // Checked against the same probe, so "already exists" means the - // same thing here as everywhere else on this domain. This also + // Checked against the engine's read over every holder, as the + // definition writes' put-back and `DELETE` ask it. This also // catches `name === `, which is the case the ADR is // actually about — see `flowCloneNameTakenMessage` for why a // second definition under one bare name is a silent, // order-dependent shadow rather than a storage error. - const collision = await automationService.getFlow(targetName); + // [#34145] Taken is judged over every holder + // (`heldFlowReader`), not on the served read the source probe + // above uses: a name whose one holder's package is disabled is + // still taken, and a name two packages hold is refused naming + // every holder, whichever of them is served. + const readHeld = heldFlowReader(automationService); + const collision = readHeld === undefined ? null : await readHeld(targetName); if (collision) { return { handled: true, diff --git a/packages/services/service-automation/src/engine.ts b/packages/services/service-automation/src/engine.ts index cbf8da9fdc7..6ca008149dc 100644 --- a/packages/services/service-automation/src/engine.ts +++ b/packages/services/service-automation/src/engine.ts @@ -5951,6 +5951,21 @@ export class AutomationEngine implements IAutomationService { return key === undefined ? null : this.flows.get(key) ?? null; } + /** + * [ADR-0150 D3, #34145; seat ruling 6884403301, amendment 7] {@link getFlow}'s + * question judged over every holder ({@link bareFlowKey}): the flow the + * engine holds under the bare `name`, a disabled sole holder's included, + * `null` for a name it does not hold or a slot-key spelling, and a name two + * slots hold refused (409, every holder named), served or not. For a door + * that asks a durable question of a name (is it taken, what did the engine + * hold before this write, which credential does it keep), whose answer must + * not move with a package's enable state. Engine-local. + */ + getHeldFlow(name: string): FlowParsed | null { + const key = this.bareFlowKey(name); + return key === undefined ? null : this.flows.get(key) ?? null; + } + /** * Attach the durable activation ledger (ADR-0126 §4). Hosts call this at * start(), after ObjectQL is available; see the automation plugin. From cbef41639810b107b52f2ab138f2b68bac3976cc Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 16 Nov 2026 03:40:11 +0000 Subject: [PATCH 02/11] test(runtime): pin the automation write doors' read over every holder Co-Authored-By: Claude Claude-Session: https://claude.ai/code/session_01QsR2jUZKdq3PK2Sab53cT3 --- ...tomation-write-doors-durable-34145.test.ts | 293 ++++++++++++++++++ 1 file changed, 293 insertions(+) create mode 100644 packages/runtime/src/domains/automation-write-doors-durable-34145.test.ts diff --git a/packages/runtime/src/domains/automation-write-doors-durable-34145.test.ts b/packages/runtime/src/domains/automation-write-doors-durable-34145.test.ts new file mode 100644 index 00000000000..c61f04df533 --- /dev/null +++ b/packages/runtime/src/domains/automation-write-doors-durable-34145.test.ts @@ -0,0 +1,293 @@ +// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license. + +/** + * [ADR-0150 D3; seat ruling 6884403301, amendment 7] The `/automation` write + * doors ask a DURABLE question of a flow name, so they read it over every + * holder (the engine's engine-local `getHeldFlow`), never on the served read + * (`getFlow`), whose answer moves with a package's enable state: + * + * - the clone door's taken-name probe on the copy's new name; + * - the definition writes' put-back copy, after a write the engine accepted + * is refused (here: the store's save refuses); + * - the carried-forward credential of `PUT /:name` (`keepStoredFlowCredentials`); + * - the `DELETE /:name` existence probe. + * + * The flow under test is one a single package holds while that package is + * disabled and the engine still holds its slot (the disable's re-sync did not + * run, or failed). For it the engine's served read answers `null` (pinned in + * service-automation's `flow-slots-per-package.test.ts`, `[#33905]`), and its + * read over every holder answers the body. The automation service here + * answers both reads as the engine does for such a flow; a name two packages + * hold is refused by the read over every holder, `409` naming every holder. + * + * CONTROLs: an enabled holder answers as before at all four doors; a name the + * engine does not hold is still admitted by the clone door and answered `404` + * by `DELETE`; the bare served doors of such a flow still answer `404` + * (`automation-addressed-route.test.ts`, `[#33905]`); a service without the + * engine-local read is asked its `getFlow`. + * + * Driven through the real `HttpDispatcher`. The protocol double carries no + * locked-base or authoring verdict, so the doors' earlier guards admit each + * request (a composition whose metadata door leaves the `flow` type writable). + */ + +import { afterEach, beforeEach, describe, it, expect, vi } from 'vitest'; +// The dispatcher's reach loads this dependency in a function body; paid here, +// at collection, not inside the first case's clocked window. +import '@objectstack/metadata'; +import { PackageScopedNameRefusedError } from '@objectstack/core'; +import { registerMetadataTypeRedactor } from '@objectstack/spec/kernel'; + +import { HttpDispatcher } from '../http-dispatcher.js'; + +const SOLO = 'solo'; +const SHARED = 'shared_flow'; +const SOURCE = 'source_flow'; +const BASE_PACKAGE = 'crm'; +const PAIR_PACKAGE = 'crm.custom'; +const ADMIN = { userId: 'u_admin', systemPermissions: ['manage_metadata'] }; + +const withSecret = (name: string, secret: string) => ({ + name, + label: name, + type: 'api', + nodes: [ + { id: 'start', type: 'start', label: 'Start', config: { triggerType: 'api', secret } }, + { id: 'end', type: 'end', label: 'End' }, + ], + edges: [{ id: 'e1', source: 'start', target: 'end' }], +}); +/** The same definition as the read serves it: the hook secret withheld (the `flow` redactor's projection). */ +const projected = (name: string) => { + const definition = withSecret(name, 'x') as { nodes: Array<{ config?: Record }> }; + delete definition.nodes[0].config!.secret; + return definition; +}; + +/** + * The `flow` redactor the automation plugin registers, standing in: the start + * node's hook `secret` is withheld (`automation-flow-credential-projection.test.ts`'s). + */ +const flowRedactorStandIn = (item: Record) => { + const nodes = item.nodes; + if (!Array.isArray(nodes)) return { item, redactedKeys: [] as string[] }; + const redactedKeys: string[] = []; + const withheld = nodes.map((node: any, index: number) => { + if (node?.type !== 'start' || !node.config || !('secret' in node.config)) return node; + const { secret: _s, ...rest } = node.config; + void _s; + redactedKeys.push(`nodes.${index}.config.secret`); + return { ...node, config: rest }; + }); + return redactedKeys.length === 0 ? { item, redactedKeys } : { item: { ...item, nodes: withheld }, redactedKeys }; +}; + +beforeEach(() => registerMetadataTypeRedactor('flow', flowRedactorStandIn)); +// The registry is module-global; leave no identity overlay behind for a later block. +afterEach(() => registerMetadataTypeRedactor('flow', flowRedactorStandIn)); + +/** The refusal the engine's read over every holder raises for a name two packages hold. */ +const sharedRefusal = (name: string) => new PackageScopedNameRefusedError({ + status: 'refused', + reason: 'ambiguous-in-environment', + type: 'flow', + name, + callerPackageId: null, + candidates: [{ kind: 'package', packageId: 'com.a.pkg' }, { kind: 'package', packageId: 'com.b.pkg' }], + message: `Flow '${name}' is held by packages 'com.a.pkg' and 'com.b.pkg'.`, +} as never); + +interface Rig { + /** `disabled`: SOLO's one holder's package is disabled (served read `null`); `enabled`: served. */ + readonly holder: 'disabled' | 'enabled'; + /** Whether the service offers the engine-local read over every holder. */ + readonly heldRead?: boolean; + /** The store's save refuses (an ADR-0112 envelope the door relays). */ + readonly saveRefuses?: boolean; + /** The store holds a row for each of these names. */ + readonly stored?: readonly string[]; +} + +function rig({ holder, heldRead = true, saveRefuses = false, stored = [] }: Rig) { + const flows = new Map([ + [SOLO, withSecret(SOLO, 'stored-secret')], + [SOURCE, { name: SOURCE, label: 'Source', type: 'autolaunched', nodes: [], edges: [] }], + [SHARED, { name: SHARED, label: 'Shared, the served holder', type: 'autolaunched', nodes: [], edges: [] }], + ]); + const servedBy = (name: string) => !(holder === 'disabled' && name === SOLO); + const automation: Record = { + handlerReady: true, + // The served read: a disabled sole holder's flow is no flow; a name two + // packages hold, one of them disabled, is its served holder's. + getFlow: vi.fn(async (name: string) => (servedBy(name) ? flows.get(name) ?? null : null)), + registerFlow: vi.fn((name: string, definition: unknown) => { + if (name === SHARED) throw sharedRefusal(name); + flows.set(name, definition); + return definition; + }), + unregisterFlow: vi.fn((name: string) => { + if (name === SHARED) throw sharedRefusal(name); + flows.delete(name); + }), + execute: vi.fn(async () => ({ success: true, output: {} })), + }; + if (heldRead) { + // The read over every holder: the slot's body whatever its package's + // enable state; a name two packages hold refused, naming every holder. + automation.getHeldFlow = vi.fn((name: string) => { + if (name === SHARED) throw sharedRefusal(name); + return flows.get(name) ?? null; + }); + } + const rows = new Set(stored); + const protocol = { + packagedArtifactOwner: vi.fn(() => BASE_PACKAGE), + ensureCustomizationPackage: vi.fn(async ({ basePackageId }: { basePackageId: string }) => ({ + basePackageId, packageId: `${basePackageId}.custom`, namespace: 'crm_custom', dependencyRange: '^3', created: false, writable: true, + })), + saveMetaItem: vi.fn(async () => { + if (saveRefuses) throw Object.assign(new Error('flow failed spec validation'), { code: 'INVALID_METADATA', status: 422 }); + return { success: true }; + }), + deleteMetaItem: vi.fn(async ({ name }: { name: string }) => { + if (!rows.has(name)) return { success: true, reset: false }; + rows.delete(name); + return { success: true, reset: true }; + }), + getMetaItems: vi.fn(async () => ({ items: [] })), + }; + const manifests: Record }> = { + [BASE_PACKAGE]: { id: BASE_PACKAGE }, + [PAIR_PACKAGE]: { id: PAIR_PACKAGE, dependencies: { [BASE_PACKAGE]: '^3' } }, + }; + const objectql = { registry: { getPackage: (id: string) => (manifests[id] ? { manifest: manifests[id] } : undefined) } }; + const services: Record = { automation, protocol, objectql }; + 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: automation as Record>, flows, protocol }; +} + +const codeOf = (a: { body?: any }) => a.body?.error?.code; +const cloneOnto = (target: string) => ['/' + SOURCE + '/clone', 'POST', { name: target, label: 'Copy' }] as const; + +describe('[#34145] the clone door judges the new name taken over every holder', () => { + it('a name whose one holder\'s package is disabled is taken: 409, the door\'s name-taken answer, nothing registered (FROM: admitted)', async () => { + const disabled = rig({ holder: 'disabled' }); + const enabled = rig({ holder: 'enabled' }); + const viaDisabled = await disabled.call(...cloneOnto(SOLO)); + const viaEnabled = await enabled.call(...cloneOnto(SOLO)); + expect([viaDisabled.status, codeOf(viaDisabled), viaDisabled.body?.error?.message]) + .toEqual([409, codeOf(viaEnabled), viaEnabled.body?.error?.message]); + expect(viaEnabled.status).toBe(409); + expect(disabled.automation.registerFlow).not.toHaveBeenCalled(); + expect(disabled.protocol.saveMetaItem).not.toHaveBeenCalled(); + expect(disabled.automation.getHeldFlow).toHaveBeenCalledWith(SOLO); + }); + + it('a name two packages hold, one of them disabled, is refused 409 naming every holder, as when both are served (FROM: the served holder\'s name-taken answer)', async () => { + const { call, automation } = rig({ holder: 'enabled' }); + // The engine's refusal rides out of the dispatcher as thrown (the + // transport serves it), as the bare entries' refusal of a shared name does. + await expect(call(...cloneOnto(SHARED))).rejects.toMatchObject({ + code: 'RESOURCE_CONFLICT', + status: 409, + refusal: { candidates: [{ kind: 'package', packageId: 'com.a.pkg' }, { kind: 'package', packageId: 'com.b.pkg' }] }, + }); + expect(automation.registerFlow).not.toHaveBeenCalled(); + }); + + it('CONTROL — a name the engine does not hold is admitted as before: the copy is registered and saved', async () => { + const { call, automation, protocol } = rig({ holder: 'disabled' }); + const answer = await call(...cloneOnto('fresh_copy')); + expect(answer.status).toBe(200); + expect(automation.registerFlow).toHaveBeenCalledWith('fresh_copy', expect.objectContaining({ name: 'fresh_copy' })); + expect(protocol.saveMetaItem).toHaveBeenCalledWith(expect.objectContaining({ name: 'fresh_copy', packageId: PAIR_PACKAGE })); + }); +}); + +describe('[#34145] a refused definition write puts back what the engine held over every holder', () => { + for (const [door, method, path] of [['PUT /:name', 'PUT', '/' + SOLO], ['POST / onto the name', 'POST', '/']] as const) { + it(`${door}: the held body is registered again (FROM: the name was withdrawn)`, async () => { + const { call, automation, flows } = rig({ holder: 'disabled', saveRefuses: true }); + const held = flows.get(SOLO); + const answer = await call(path, method, withSecret(SOLO, 'new-secret')); + expect(answer.status).toBe(422); + expect(automation.registerFlow).toHaveBeenLastCalledWith(SOLO, held); + expect(automation.unregisterFlow).not.toHaveBeenCalled(); + expect(flows.get(SOLO)).toBe(held); + }); + } + + it('CONTROL — the holder enabled: the held body is put back, as before', async () => { + const { call, automation, flows } = rig({ holder: 'enabled', saveRefuses: true }); + const held = flows.get(SOLO); + const answer = await call('/' + SOLO, 'PUT', withSecret(SOLO, 'new-secret')); + expect(answer.status).toBe(422); + expect(automation.registerFlow).toHaveBeenLastCalledWith(SOLO, held); + expect(automation.unregisterFlow).not.toHaveBeenCalled(); + }); +}); + +describe('[#34145] PUT /:name keeps the credential the engine holds over every holder', () => { + it('a body in the served form keeps the stored secret (FROM: nothing carried forward)', async () => { + const { call, automation } = rig({ holder: 'disabled' }); + const answer = await call('/' + SOLO, 'PUT', projected(SOLO)); + expect(answer.status).toBe(200); + const [, registered] = automation.registerFlow.mock.calls[0] as [string, any]; + expect(registered.nodes[0].config.secret).toBe('stored-secret'); + }); + + it('CONTROL — the holder enabled: the stored secret is kept, as before; an explicit one replaces it', async () => { + const kept = rig({ holder: 'enabled' }); + await kept.call('/' + SOLO, 'PUT', projected(SOLO)); + expect((kept.automation.registerFlow.mock.calls[0] as [string, any])[1].nodes[0].config.secret).toBe('stored-secret'); + const replaced = rig({ holder: 'disabled' }); + await replaced.call('/' + SOLO, 'PUT', withSecret(SOLO, 'explicit')); + expect((replaced.automation.registerFlow.mock.calls[0] as [string, any])[1].nodes[0].config.secret).toBe('explicit'); + }); +}); + +describe('[#34145] DELETE /:name finds a flow the engine holds over every holder', () => { + it('a flow whose one holder\'s package is disabled, with no stored row, is removed and answered as a deletion (FROM: 404 after removing it)', async () => { + const { call, automation, flows } = rig({ holder: 'disabled' }); + const answer = await call('/' + SOLO, 'DELETE'); + expect([answer.status, answer.body?.data ?? answer.body]).toEqual([200, expect.objectContaining({ name: SOLO, deleted: true })]); + expect(automation.unregisterFlow).toHaveBeenCalledWith(SOLO); + expect(flows.has(SOLO)).toBe(false); + }); + + it('CONTROL — a name two packages hold is refused 409 naming every holder, the refusal the removal raised before; nothing is removed', async () => { + const { call, protocol } = rig({ holder: 'enabled' }); + await expect(call('/' + SHARED, 'DELETE')).rejects.toMatchObject({ code: 'RESOURCE_CONFLICT', status: 409 }); + expect(protocol.deleteMetaItem).not.toHaveBeenCalled(); + }); + + it('CONTROL — the holder enabled: removed, 200 deleted, as before', async () => { + const { call } = rig({ holder: 'enabled' }); + expect((await call('/' + SOLO, 'DELETE')).status).toBe(200); + }); + + it('CONTROL — a name the engine does not hold and the store has no row for is 404, as before; a stored row alone is still deleted', async () => { + const none = rig({ holder: 'disabled' }); + const unknown = await none.call('/no_such_flow', 'DELETE'); + expect([unknown.status, codeOf(unknown)]).toEqual([404, 'RESOURCE_NOT_FOUND']); + const rowOnly = rig({ holder: 'disabled', stored: ['row_only'] }); + expect((await rowOnly.call('/row_only', 'DELETE')).status).toBe(200); + }); +}); + +describe('[#34145] a service without the engine-local read is asked its getFlow', () => { + it('CONTROL — the four doors answer on getFlow, as before', async () => { + const { call, automation } = rig({ holder: 'enabled', heldRead: false }); + expect((await call(...cloneOnto(SOLO))).status).toBe(409); + expect((await call('/no_such_flow', 'DELETE')).status).toBe(404); + await call('/' + SOLO, 'PUT', projected(SOLO)); + expect((automation.registerFlow.mock.calls[0] as [string, any])[1].nodes[0].config.secret).toBe('stored-secret'); + expect(automation.getFlow).toHaveBeenCalledWith(SOLO); + }); +}); From fabbcfcf6e9f5980bc51e5cbeb6a67ae17052602 Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 16 Nov 2026 03:50:37 +0000 Subject: [PATCH 03/11] chore(changeset): the automation write doors' read over every holder Co-Authored-By: Claude Claude-Session: https://claude.ai/code/session_01QsR2jUZKdq3PK2Sab53cT3 --- .changeset/34145-write-doors-durable-read.md | 26 ++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 .changeset/34145-write-doors-durable-read.md diff --git a/.changeset/34145-write-doors-durable-read.md b/.changeset/34145-write-doors-durable-read.md new file mode 100644 index 00000000000..74e9652b106 --- /dev/null +++ b/.changeset/34145-write-doors-durable-read.md @@ -0,0 +1,26 @@ +--- +'@objectstack/runtime': patch +'@objectstack/service-automation': patch +--- + +fix(runtime): the automation write doors judge a flow name over every holder, whatever the holder's package's enable state + +Clause-②: no +Metadata-protocol: none + +Four `/automation` write doors ask a lasting question of a flow name: the clone door's taken-name check on the new name, the copy a refused definition write (`POST /`, `PUT /automation/NAME`) puts back, the credential `PUT /automation/NAME` keeps when the body leaves it out, and the `DELETE /automation/NAME` existence check. They read the engine's served view (`getFlow`), in which a flow whose one package is disabled is no flow. They now read the flow the engine holds over every holder, through the engine's new engine-local `AutomationEngine.getHeldFlow(name)`, so their answers no longer depend on whether that package is enabled. For a flow whose only package is disabled while the engine still holds it: + +- Clone with this flow's name as the new name: refused `409`, the door's name-taken answer, and nothing is registered. Before, the copy was admitted and filed in the disabled package's slot. +- A definition write the engine accepts and the store then refuses: the flow the engine held is registered again. Before, the name was withdrawn. +- `PUT` with a body that leaves out a stored credential: the stored credential is kept. Before, nothing was carried forward. +- `DELETE`: the flow is removed and the door answers a deletion. Before, the door removed it and answered `404`. + +These are the answers the last release gave: the served view changed after it. + +A name two packages hold, one of them disabled, is now refused at these doors `409` (`RESOURCE_CONFLICT`), naming every holder, before anything is registered. That is the answer the doors give while both packages are enabled. Before: + +- `DELETE` answered the same refusal: the engine's removal raises it. +- The clone's new name got the name-taken answer, also `409`. +- The definition writes got the same refusal while the engine still held the disabled package's slot, because the engine's registration raises it. Once the disable's re-sync had withdrawn that slot, the registration filed the body in the enabled package's slot. The store's save, which names no package, then refused it `409` naming the packages, and the engine was put back. A composition with no metadata store kept the write. + +A flow of an enabled package, and a name the engine does not hold, answer as before. The read and run doors (`GET`, trigger, toggle, runs, the clone's source) keep the served view. From f71a2dd339d8a062781f038c095308fc28674daf Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 16 Nov 2026 05:48:44 +0000 Subject: [PATCH 04/11] test(service-automation): pin the engine's read over every holder for a disabled sole holder Co-Authored-By: Claude Claude-Session: https://claude.ai/code/session_01QsR2jUZKdq3PK2Sab53cT3 --- .../service-automation/src/flow-slots-per-package.test.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/packages/services/service-automation/src/flow-slots-per-package.test.ts b/packages/services/service-automation/src/flow-slots-per-package.test.ts index d6691c41185..ea9e867ae39 100644 --- a/packages/services/service-automation/src/flow-slots-per-package.test.ts +++ b/packages/services/service-automation/src/flow-slots-per-package.test.ts @@ -1242,6 +1242,9 @@ describe('[#33905] the bare entries of a flow whose only holder\'s package is di expect(engine.flowSlotKey(P1, 'solo')).toBe('solo'); expect(engine.flowDispatchHolder('solo')).toEqual({ packageId: P1, claimBare: true }); expect(engine.getFlowVersionHistory('solo')).toHaveLength(1); + // [#34145] The write doors' read over every holder answers the slot's body. + expect(engine.getHeldFlow('solo')).toBe(engine.getFlowSlot(P1, 'solo')); + expect(engine.getHeldFlow('solo')).toMatchObject({ name: 'solo' }); registry.enablePackage(P1); expect((await engine.execute('solo')).success).toBe(true); From 156351f6376b700264dab623e87b580bc4135020 Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 16 Nov 2026 05:56:06 +0000 Subject: [PATCH 05/11] chore(changeset): declare the getHeldFlow widening and the no-store write narrowing Co-Authored-By: Claude Claude-Session: https://claude.ai/code/session_01QsR2jUZKdq3PK2Sab53cT3 --- .changeset/34145-write-doors-durable-read.md | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/.changeset/34145-write-doors-durable-read.md b/.changeset/34145-write-doors-durable-read.md index 74e9652b106..cec2c768f06 100644 --- a/.changeset/34145-write-doors-durable-read.md +++ b/.changeset/34145-write-doors-durable-read.md @@ -1,13 +1,19 @@ --- -'@objectstack/runtime': patch -'@objectstack/service-automation': patch +'@objectstack/runtime': minor +'@objectstack/service-automation': minor --- -fix(runtime): the automation write doors judge a flow name over every holder, whatever the holder's package's enable state +fix(runtime)!: the automation write doors judge a flow name over every holder, whatever the holder's package's enable state -Clause-②: no +Clause-②: yes (narrowing) Metadata-protocol: none + + +**BREAKING** only for a composition with no metadata store (no metadata protocol): a package-less `PUT /automation/NAME` or `POST /automation` onto a flow name two packages hold, one of them disabled, after the disable's re-sync withdrew the disabled package's slot, was accepted (`200`) and written into the enabled package's flow. It is now refused `409 RESOURCE_CONFLICT`, naming every holder, before anything is registered. Remedy: name the package. The bare write door names none, so save that package's flow through the metadata door with `?package=`, which needs a metadata store. + +**Added:** `AutomationEngine.getHeldFlow(name)` on `@objectstack/service-automation`: the flow the engine holds under a bare name, judged over every holder (a disabled package's included; a name two packages hold refused `409`). The write doors below read it. + Four `/automation` write doors ask a lasting question of a flow name: the clone door's taken-name check on the new name, the copy a refused definition write (`POST /`, `PUT /automation/NAME`) puts back, the credential `PUT /automation/NAME` keeps when the body leaves it out, and the `DELETE /automation/NAME` existence check. They read the engine's served view (`getFlow`), in which a flow whose one package is disabled is no flow. They now read the flow the engine holds over every holder, through the engine's new engine-local `AutomationEngine.getHeldFlow(name)`, so their answers no longer depend on whether that package is enabled. For a flow whose only package is disabled while the engine still holds it: - Clone with this flow's name as the new name: refused `409`, the door's name-taken answer, and nothing is registered. Before, the copy was admitted and filed in the disabled package's slot. From 62fe62378cc0b8367007587b3dfd6e7b173d5eed Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 16 Nov 2026 06:06:01 +0000 Subject: [PATCH 06/11] chore(changeset): grade the write doors' changeset patch under Metadata-protocol none Co-Authored-By: Claude Claude-Session: https://claude.ai/code/session_01QsR2jUZKdq3PK2Sab53cT3 --- .changeset/34145-write-doors-durable-read.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.changeset/34145-write-doors-durable-read.md b/.changeset/34145-write-doors-durable-read.md index cec2c768f06..c433e0dfcfc 100644 --- a/.changeset/34145-write-doors-durable-read.md +++ b/.changeset/34145-write-doors-durable-read.md @@ -1,6 +1,6 @@ --- -'@objectstack/runtime': minor -'@objectstack/service-automation': minor +'@objectstack/runtime': patch +'@objectstack/service-automation': patch --- fix(runtime)!: the automation write doors judge a flow name over every holder, whatever the holder's package's enable state From 7a4e4e18b4abada480c03417944f587737b3a16f Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 16 Nov 2026 08:11:27 +0000 Subject: [PATCH 07/11] fix(runtime): pin the no-store narrowing, answer the clone's shared name on its own path, correct the release prose The clone door's taken-name probe catches the engine's refusal of a name two packages hold into its own name-taken answer. A no-store rig drives the package-less PUT and POST onto a shared name after the co-holder's slot is withdrawn; the engine pins getHeldFlow in the withdrawn-slot case and in the uninstall stretch (the remedy). The BREAKING remedy names the uninstall door, and the pending 33905 changeset no longer reports the write-door moves this change reverses. Co-Authored-By: Claude Claude-Session: https://claude.ai/code/session_01QsR2jUZKdq3PK2Sab53cT3 --- .changeset/33905-disabled-sole-holder-flow.md | 6 +- .changeset/34145-write-doors-durable-read.md | 6 +- ...tomation-write-doors-durable-34145.test.ts | 88 +++++++++++++++---- packages/runtime/src/domains/automation.ts | 25 +++++- .../src/flow-slots-per-package.test.ts | 16 ++++ 5 files changed, 115 insertions(+), 26 deletions(-) diff --git a/.changeset/33905-disabled-sole-holder-flow.md b/.changeset/33905-disabled-sole-holder-flow.md index 6c1f5dde3ef..91eb7aacb43 100644 --- a/.changeset/33905-disabled-sole-holder-flow.md +++ b/.changeset/33905-disabled-sole-holder-flow.md @@ -18,11 +18,7 @@ What moves, for such a flow, while its package is disabled: - `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. +The HTTP write doors that ask a lasting question of the name do not move with it: the clone door's taken-name check on the new name, the definition a refused `POST /automation` or `PUT /automation/NAME` puts back, the stored credential a `PUT` body that leaves it out keeps, and the `DELETE /automation/NAME` existence check read the flow the engine holds over every holder. For such a flow the clone's new name is refused `409`, the held definition is put back, the credential is kept and `DELETE` answers a deletion, as before this release. Remedy: enable the package. Its flow runs on its trigger again with no re-arm, and the bare entries serve it again. diff --git a/.changeset/34145-write-doors-durable-read.md b/.changeset/34145-write-doors-durable-read.md index c433e0dfcfc..b4dc9c42e68 100644 --- a/.changeset/34145-write-doors-durable-read.md +++ b/.changeset/34145-write-doors-durable-read.md @@ -10,7 +10,7 @@ Metadata-protocol: none -**BREAKING** only for a composition with no metadata store (no metadata protocol): a package-less `PUT /automation/NAME` or `POST /automation` onto a flow name two packages hold, one of them disabled, after the disable's re-sync withdrew the disabled package's slot, was accepted (`200`) and written into the enabled package's flow. It is now refused `409 RESOURCE_CONFLICT`, naming every holder, before anything is registered. Remedy: name the package. The bare write door names none, so save that package's flow through the metadata door with `?package=`, which needs a metadata store. +**BREAKING** only for a composition with no metadata store (no metadata protocol): a package-less `PUT /automation/NAME` or `POST /automation` onto a flow name two packages hold, one of them disabled, after the disable's re-sync withdrew the disabled package's slot, was accepted (`200`) and written into the enabled package's flow. It is now refused `409 RESOURCE_CONFLICT`, naming every holder, before anything is registered. Remedy: uninstall the disabled co-holder (`DELETE /packages/PACKAGE`; with no metadata store it withdraws the package from the running registry). The name then has one holder and the bare write is admitted. A package that door refuses as read-only (one the deployment ships, or an installed app's module) is removed from the deployment instead. Re-enabling the co-holder does not help, and the addressed doors (`/automation/NAMESPACE/NAME`) write nothing: otherwise the write is refused there exactly as while both holders are enabled. **Added:** `AutomationEngine.getHeldFlow(name)` on `@objectstack/service-automation`: the flow the engine holds under a bare name, judged over every holder (a disabled package's included; a name two packages hold refused `409`). The write doors below read it. @@ -23,10 +23,10 @@ Four `/automation` write doors ask a lasting question of a flow name: the clone These are the answers the last release gave: the served view changed after it. -A name two packages hold, one of them disabled, is now refused at these doors `409` (`RESOURCE_CONFLICT`), naming every holder, before anything is registered. That is the answer the doors give while both packages are enabled. Before: +A name two packages hold, one of them disabled, is refused at these doors `409` (`RESOURCE_CONFLICT`) before anything is registered, whatever the state of the disabled package's slot, as while both packages are enabled. The definition writes and `DELETE` answer the engine's refusal, naming every holder. The clone's new name gets the door's own name-taken answer, as before. Before: - `DELETE` answered the same refusal: the engine's removal raises it. -- The clone's new name got the name-taken answer, also `409`. +- The clone's new name got the name-taken answer while one holder was disabled. While both were enabled it got the engine's refusal, thrown, naming every holder; it now gets the name-taken answer, same status and code, returned, whose remedy is a new name. - The definition writes got the same refusal while the engine still held the disabled package's slot, because the engine's registration raises it. Once the disable's re-sync had withdrawn that slot, the registration filed the body in the enabled package's slot. The store's save, which names no package, then refused it `409` naming the packages, and the engine was put back. A composition with no metadata store kept the write. A flow of an enabled package, and a name the engine does not hold, answer as before. The read and run doors (`GET`, trigger, toggle, runs, the clone's source) keep the served view. diff --git a/packages/runtime/src/domains/automation-write-doors-durable-34145.test.ts b/packages/runtime/src/domains/automation-write-doors-durable-34145.test.ts index c61f04df533..f2ae0f669c1 100644 --- a/packages/runtime/src/domains/automation-write-doors-durable-34145.test.ts +++ b/packages/runtime/src/domains/automation-write-doors-durable-34145.test.ts @@ -20,6 +20,16 @@ * answers both reads as the engine does for such a flow; a name two packages * hold is refused by the read over every holder, `409` naming every holder. * + * A name two packages hold is modelled in the engine's measured states + * (service-automation's `flow-slots-per-package.test.ts`, `[#33893]`, and the + * uninstall stretch): `kept`, the disabled co-holder's slot still held, where a + * package-less registration is refused; `withdrawn`, that slot withdrawn by + * the disable's re-sync, where the served read and a package-less + * registration both reach the served holder's slot while the read over every + * holder still refuses the name; `served`, both holders enabled, where every + * bare read refuses it; `uninstalled`, the co-holder uninstalled, where the + * name has one holder again. + * * CONTROLs: an enabled holder answers as before at all four doors; a name the * engine does not hold is still admitted by the clone door and answered `404` * by `DELETE`; the bare served doors of such a flow still answer `404` @@ -106,9 +116,13 @@ interface Rig { readonly saveRefuses?: boolean; /** The store holds a row for each of these names. */ readonly stored?: readonly string[]; + /** SHARED's state in the engine (see the file header). */ + readonly shared?: 'kept' | 'withdrawn' | 'served' | 'uninstalled'; + /** Whether the composition has a metadata store (the `protocol` service). */ + readonly store?: boolean; } -function rig({ holder, heldRead = true, saveRefuses = false, stored = [] }: Rig) { +function rig({ holder, heldRead = true, saveRefuses = false, stored = [], shared = 'kept', store = true }: Rig) { const flows = new Map([ [SOLO, withSecret(SOLO, 'stored-secret')], [SOURCE, { name: SOURCE, label: 'Source', type: 'autolaunched', nodes: [], edges: [] }], @@ -119,14 +133,17 @@ function rig({ holder, heldRead = true, saveRefuses = false, stored = [] }: Rig) handlerReady: true, // The served read: a disabled sole holder's flow is no flow; a name two // packages hold, one of them disabled, is its served holder's. - getFlow: vi.fn(async (name: string) => (servedBy(name) ? flows.get(name) ?? null : null)), + getFlow: vi.fn(async (name: string) => { + if (name === SHARED && shared === 'served') throw sharedRefusal(name); + return servedBy(name) ? flows.get(name) ?? null : null; + }), registerFlow: vi.fn((name: string, definition: unknown) => { - if (name === SHARED) throw sharedRefusal(name); + if (name === SHARED && (shared === 'kept' || shared === 'served')) throw sharedRefusal(name); flows.set(name, definition); return definition; }), unregisterFlow: vi.fn((name: string) => { - if (name === SHARED) throw sharedRefusal(name); + if (name === SHARED && shared !== 'uninstalled') throw sharedRefusal(name); flows.delete(name); }), execute: vi.fn(async () => ({ success: true, output: {} })), @@ -135,7 +152,7 @@ function rig({ holder, heldRead = true, saveRefuses = false, stored = [] }: Rig) // The read over every holder: the slot's body whatever its package's // enable state; a name two packages hold refused, naming every holder. automation.getHeldFlow = vi.fn((name: string) => { - if (name === SHARED) throw sharedRefusal(name); + if (name === SHARED && shared !== 'uninstalled') throw sharedRefusal(name); return flows.get(name) ?? null; }); } @@ -161,7 +178,7 @@ function rig({ holder, heldRead = true, saveRefuses = false, stored = [] }: Rig) [PAIR_PACKAGE]: { id: PAIR_PACKAGE, dependencies: { [BASE_PACKAGE]: '^3' } }, }; const objectql = { registry: { getPackage: (id: string) => (manifests[id] ? { manifest: manifests[id] } : undefined) } }; - const services: Record = { automation, protocol, objectql }; + const services: Record = store ? { automation, protocol, objectql } : { automation, objectql }; 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); @@ -189,15 +206,13 @@ describe('[#34145] the clone door judges the new name taken over every holder', expect(disabled.automation.getHeldFlow).toHaveBeenCalledWith(SOLO); }); - it('a name two packages hold, one of them disabled, is refused 409 naming every holder, as when both are served (FROM: the served holder\'s name-taken answer)', async () => { - const { call, automation } = rig({ holder: 'enabled' }); - // The engine's refusal rides out of the dispatcher as thrown (the - // transport serves it), as the bare entries' refusal of a shared name does. - await expect(call(...cloneOnto(SHARED))).rejects.toMatchObject({ - code: 'RESOURCE_CONFLICT', - status: 409, - refusal: { candidates: [{ kind: 'package', packageId: 'com.a.pkg' }, { kind: 'package', packageId: 'com.b.pkg' }] }, - }); + it.each(['kept', 'withdrawn', 'served'] as const)('a name two packages hold (co-holder %s) is taken: the door\'s own 409 name-taken answer, returned, nothing registered (FROM, both served: the engine\'s refusal thrown)', async (shared) => { + const { call, automation } = rig({ holder: 'enabled', shared }); + const taken = await rig({ holder: 'enabled' }).call(...cloneOnto(SOLO)); + const answer = await call(...cloneOnto(SHARED)); + expect([answer.status, codeOf(answer)]).toEqual([409, 'RESOURCE_CONFLICT']); + expect(codeOf(answer)).toBe(codeOf(taken)); + expect(answer.body?.error?.message).toMatch(new RegExp(`^Flow '${SHARED}' already exists`)); expect(automation.registerFlow).not.toHaveBeenCalled(); }); @@ -281,6 +296,49 @@ describe('[#34145] DELETE /:name finds a flow the engine holds over every holder }); }); +/** + * The declared narrowing (`Clause-②: yes (narrowing)`): a composition with no + * metadata store, a package-less write onto a name two packages hold after the + * disabled co-holder's slot was withdrawn. The served read reaches the served + * holder and a package-less registration lands in its slot, so the bare write + * was admitted; the read over every holder refuses the name, as when both + * holders are enabled. Once the co-holder is uninstalled the name has one + * holder and the write is admitted again (the remedy; the engine side is + * pinned in `flow-slots-per-package.test.ts`'s uninstall stretch). + */ +describe('[#34145] no metadata store: a package-less write onto a name two packages hold is refused over every holder', () => { + const doors = [['PUT /:name', 'PUT', '/' + SHARED], ['POST /', 'POST', '/']] as const; + + it.each(doors)('%s, the disabled co-holder\'s slot withdrawn: 409 RESOURCE_CONFLICT naming every holder, nothing registered (FROM: 200, registered into the served holder\'s slot)', async (_door, method, path) => { + const { call, automation, flows } = rig({ holder: 'enabled', shared: 'withdrawn', store: false }); + const before = flows.get(SHARED); + await expect(call(path, method, withSecret(SHARED, 'new-secret'))).rejects.toMatchObject({ + code: 'RESOURCE_CONFLICT', + status: 409, + refusal: { candidates: [{ kind: 'package', packageId: 'com.a.pkg' }, { kind: 'package', packageId: 'com.b.pkg' }] }, + }); + expect(automation.registerFlow).not.toHaveBeenCalled(); + expect(flows.get(SHARED)).toBe(before); + }); + + it.each(doors)('CONTROL — %s, both holders enabled: the same 409, as before', async (_door, method, path) => { + const { call, automation } = rig({ holder: 'enabled', shared: 'served', store: false }); + await expect(call(path, method, withSecret(SHARED, 'new-secret'))).rejects.toMatchObject({ + code: 'RESOURCE_CONFLICT', + status: 409, + refusal: { candidates: [{ kind: 'package', packageId: 'com.a.pkg' }, { kind: 'package', packageId: 'com.b.pkg' }] }, + }); + expect(automation.registerFlow).not.toHaveBeenCalled(); + }); + + it.each(doors)('the remedy — %s once the co-holder is uninstalled: one holder, the write admitted and registered', async (_door, method, path) => { + const { call, automation } = rig({ holder: 'enabled', shared: 'uninstalled', store: false }); + const answer = await call(path, method, withSecret(SHARED, 'new-secret')); + expect(answer.status).toBe(200); + expect(automation.registerFlow).toHaveBeenCalledWith(SHARED, expect.objectContaining({ name: SHARED })); + }); +}); + describe('[#34145] a service without the engine-local read is asked its getFlow', () => { it('CONTROL — the four doors answer on getFlow, as before', async () => { const { call, automation } = rig({ holder: 'enabled', heldRead: false }); diff --git a/packages/runtime/src/domains/automation.ts b/packages/runtime/src/domains/automation.ts index 8666f3388c0..402393b362a 100644 --- a/packages/runtime/src/domains/automation.ts +++ b/packages/runtime/src/domains/automation.ts @@ -12,7 +12,7 @@ import { shouldDenyAnonymous, ANONYMOUS_DENY_STATUS, ANONYMOUS_DENY_CODE, ANONYMOUS_DENY_MESSAGE, - matchInboundHookRoute, + matchInboundHookRoute, PackageScopedNameRefusedError, } from '@objectstack/core'; // [#22773] The inbound-hook door, handed the one route the floor admits. import { handleInboundHookRequest } from './automation-hooks.js'; @@ -2136,6 +2136,22 @@ function heldFlowReader( return undefined; } +/** + * [#34145] The clone door's taken-name probe over every holder + * ({@link heldFlowReader}): the held body, `null` when no holder has the name, + * and `true` when two or more packages hold it, whose read is refused + * (`PackageScopedNameRefusedError`): such a name is taken. Any other failure + * is thrown on. + */ +async function cloneTargetHeld(readHeld: (name: string) => Promise, name: string): Promise { + try { + return await readHeld(name); + } catch (e) { + if (e instanceof PackageScopedNameRefusedError) return true; + throw e; + } +} + /** * [#20552] The write-path inverse for the two doors that overwrite a flow by * name (`POST /` onto an existing name, `PUT /:name`): a body that carries the @@ -4505,9 +4521,12 @@ export async function handleAutomationRequest(deps: DomainHandlerDeps, path: str // (`heldFlowReader`), not on the served read the source probe // above uses: a name whose one holder's package is disabled is // still taken, and a name two packages hold is refused naming - // every holder, whichever of them is served. + // every holder, whichever of them is served. That refusal is + // caught into this door's own taken-name answer, as the store's + // is (`flowWriteRefusal`'s clone arm): a name two packages hold + // is taken, and the remedy is a NEW name, not a package. const readHeld = heldFlowReader(automationService); - const collision = readHeld === undefined ? null : await readHeld(targetName); + const collision = readHeld === undefined ? null : await cloneTargetHeld(readHeld, targetName); if (collision) { return { handled: true, diff --git a/packages/services/service-automation/src/flow-slots-per-package.test.ts b/packages/services/service-automation/src/flow-slots-per-package.test.ts index ea9e867ae39..1d32037562e 100644 --- a/packages/services/service-automation/src/flow-slots-per-package.test.ts +++ b/packages/services/service-automation/src/flow-slots-per-package.test.ts @@ -1401,6 +1401,14 @@ describe('[#33893] the served holder of a name a disabled package co-holds keeps expect(await fireAll()).toEqual([tagOf(on)]); expect(refusedBodyWarned()).toEqual([]); expect(engine.flowDispatchHolder(`${on}/t`)).toEqual({ packageId: on, claimBare: false, name: 't' }); + // [#34145] The write doors' read over every holder still refuses the + // name, naming both holders, while the served read reaches `on`'s flow. + let held: unknown; + try { engine.getHeldFlow('t'); } catch (e) { held = e; } + expect(held).toMatchObject({ code: 'RESOURCE_CONFLICT', status: 409 }); + expect((held as Error).message).toContain(P1); + expect((held as Error).message).toContain(P2); + expect(await engine.getFlow('t')).toMatchObject({ name: 't' }); registry.enablePackage(off); pull(off, triggered('t', tagOf(off))); @@ -1511,6 +1519,14 @@ describe('[#33893] the served holder of a name a disabled package co-holds keeps expect(await fireAll()).toEqual(['alpha']); }); + it('[#34145] the remedy for a write refused over every holder: the read over every holder answers the one holder\'s flow, so a package-less write is admitted', () => { + uninstalled(); + expect(engine.getHeldFlow('t')).toMatchObject({ name: 't' }); + expect(engine.flowSlotKey(P1, 't')).toBe('t'); + expect(() => engine.registerFlow('t', triggered('t', 'alpha'))).not.toThrow(); + expect(engine.getFlowSlots('t')).toHaveLength(1); + }); + it('first touched by a bare entry: each one serves the name (FROM: no flow under the bare name)', async () => { uninstalled(); expect(engine.inboundHookSlot('t')).toBeUndefined(); From 2b77c4fc1d982c56835a2b44c848cd2742dc656e Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 16 Nov 2026 08:28:27 +0000 Subject: [PATCH 08/11] docs(service-automation): getHeldFlow settles the name before it reads, and refuses a shared name on one slot too Co-Authored-By: Claude Claude-Session: https://claude.ai/code/session_01QsR2jUZKdq3PK2Sab53cT3 --- packages/services/service-automation/src/engine.ts | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/packages/services/service-automation/src/engine.ts b/packages/services/service-automation/src/engine.ts index 193454de44e..ffb47b4129f 100644 --- a/packages/services/service-automation/src/engine.ts +++ b/packages/services/service-automation/src/engine.ts @@ -5956,10 +5956,14 @@ export class AutomationEngine implements IAutomationService { * question judged over every holder ({@link bareFlowKey}): the flow the * engine holds under the bare `name`, a disabled sole holder's included, * `null` for a name it does not hold or a slot-key spelling, and a name two - * slots hold refused (409, every holder named), served or not. For a door - * that asks a durable question of a name (is it taken, what did the engine - * hold before this write, which credential does it keep), whose answer must - * not move with a package's enable state. Engine-local. + * packages hold refused (409, every holder named), served or not, whether + * the engine holds one slot of it or both. For a door that asks a durable + * question of a name (is it taken, what did the engine hold before this + * write, which credential does it keep), whose answer must not move with a + * package's enable state. Engine-local. Not a pure read: like + * {@link getFlow}, it first settles the name ({@link settleFlowName}), so a + * lone qualified slot of a name one package holds again is re-keyed to the + * bare name. */ getHeldFlow(name: string): FlowParsed | null { const key = this.bareFlowKey(name); From fa24e9f67c38582cbc8484a237faa972eccaa983 Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 16 Nov 2026 09:02:23 +0000 Subject: [PATCH 09/11] fix(runtime): read a name two packages hold on its served holder at the write doors The write doors keep the read over every holder for a name one package holds (a disabled sole holder). A name two packages hold falls back to the served read, as on main: the narrowing pins are replaced by pins showing the shared-name write admitted into the served holder, without a store and through the real metadata protocol's save on a booted kernel. The changesets declare the getHeldFlow widening only. Co-Authored-By: Claude Claude-Session: https://claude.ai/code/session_01QsR2jUZKdq3PK2Sab53cT3 --- .changeset/33905-disabled-sole-holder-flow.md | 2 +- .changeset/34145-write-doors-durable-read.md | 18 +- ...tomation-write-doors-durable-34145.test.ts | 185 +++++++++++++----- packages/runtime/src/domains/automation.ts | 84 ++++---- .../src/flow-slots-per-package.test.ts | 7 +- 5 files changed, 203 insertions(+), 93 deletions(-) diff --git a/.changeset/33905-disabled-sole-holder-flow.md b/.changeset/33905-disabled-sole-holder-flow.md index 91eb7aacb43..44cfd38778e 100644 --- a/.changeset/33905-disabled-sole-holder-flow.md +++ b/.changeset/33905-disabled-sole-holder-flow.md @@ -18,7 +18,7 @@ What moves, for such a flow, while its package is disabled: - `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`. -The HTTP write doors that ask a lasting question of the name do not move with it: the clone door's taken-name check on the new name, the definition a refused `POST /automation` or `PUT /automation/NAME` puts back, the stored credential a `PUT` body that leaves it out keeps, and the `DELETE /automation/NAME` existence check read the flow the engine holds over every holder. For such a flow the clone's new name is refused `409`, the held definition is put back, the credential is kept and `DELETE` answers a deletion, as before this release. +The HTTP write doors that ask a lasting question of the name do not move with it: the clone door's taken-name check on the new name, the definition a refused `POST /automation` or `PUT /automation/NAME` puts back, the stored credential a `PUT` body that leaves it out keeps, and the `DELETE /automation/NAME` existence check read the flow the engine holds whatever its package's enable state. For such a flow the clone's new name is refused `409`, the held definition is put back, the credential is kept and `DELETE` answers a deletion, as before this release. A name two packages hold is read at those doors on its served holder, as the bare entries read it. Remedy: enable the package. Its flow runs on its trigger again with no re-arm, and the bare entries serve it again. diff --git a/.changeset/34145-write-doors-durable-read.md b/.changeset/34145-write-doors-durable-read.md index b4dc9c42e68..58ae29a1968 100644 --- a/.changeset/34145-write-doors-durable-read.md +++ b/.changeset/34145-write-doors-durable-read.md @@ -3,18 +3,14 @@ '@objectstack/service-automation': patch --- -fix(runtime)!: the automation write doors judge a flow name over every holder, whatever the holder's package's enable state +fix(runtime): the automation write doors keep a flow whose only package is disabled, whatever that package's enable state -Clause-②: yes (narrowing) +Clause-②: yes (widening) Metadata-protocol: none - +**Added:** `AutomationEngine.getHeldFlow(name)` on `@objectstack/service-automation`: the flow the engine holds under a bare name, judged over every holder (a disabled package's included, `null` for a name it does not hold or a slot-key spelling); a name two packages hold is refused `409` naming every holder. Like `getFlow`, it settles the name first, so a lone qualified slot of a name one package holds again is re-keyed to the bare name. -**BREAKING** only for a composition with no metadata store (no metadata protocol): a package-less `PUT /automation/NAME` or `POST /automation` onto a flow name two packages hold, one of them disabled, after the disable's re-sync withdrew the disabled package's slot, was accepted (`200`) and written into the enabled package's flow. It is now refused `409 RESOURCE_CONFLICT`, naming every holder, before anything is registered. Remedy: uninstall the disabled co-holder (`DELETE /packages/PACKAGE`; with no metadata store it withdraws the package from the running registry). The name then has one holder and the bare write is admitted. A package that door refuses as read-only (one the deployment ships, or an installed app's module) is removed from the deployment instead. Re-enabling the co-holder does not help, and the addressed doors (`/automation/NAMESPACE/NAME`) write nothing: otherwise the write is refused there exactly as while both holders are enabled. - -**Added:** `AutomationEngine.getHeldFlow(name)` on `@objectstack/service-automation`: the flow the engine holds under a bare name, judged over every holder (a disabled package's included; a name two packages hold refused `409`). The write doors below read it. - -Four `/automation` write doors ask a lasting question of a flow name: the clone door's taken-name check on the new name, the copy a refused definition write (`POST /`, `PUT /automation/NAME`) puts back, the credential `PUT /automation/NAME` keeps when the body leaves it out, and the `DELETE /automation/NAME` existence check. They read the engine's served view (`getFlow`), in which a flow whose one package is disabled is no flow. They now read the flow the engine holds over every holder, through the engine's new engine-local `AutomationEngine.getHeldFlow(name)`, so their answers no longer depend on whether that package is enabled. For a flow whose only package is disabled while the engine still holds it: +Four `/automation` write doors ask a lasting question of a flow name: the clone door's taken-name check on the new name, the copy a refused definition write (`POST /`, `PUT /automation/NAME`) puts back, the credential `PUT /automation/NAME` keeps when the body leaves it out, and the `DELETE /automation/NAME` existence check. They read the engine's served view (`getFlow`), in which a flow whose one package is disabled is no flow. For a name one package holds they now read the flow the engine holds over every holder, through `getHeldFlow`, so their answers no longer depend on whether that package is enabled. For a flow whose only package is disabled while the engine still holds it: - Clone with this flow's name as the new name: refused `409`, the door's name-taken answer, and nothing is registered. Before, the copy was admitted and filed in the disabled package's slot. - A definition write the engine accepts and the store then refuses: the flow the engine held is registered again. Before, the name was withdrawn. @@ -23,10 +19,8 @@ Four `/automation` write doors ask a lasting question of a flow name: the clone These are the answers the last release gave: the served view changed after it. -A name two packages hold, one of them disabled, is refused at these doors `409` (`RESOURCE_CONFLICT`) before anything is registered, whatever the state of the disabled package's slot, as while both packages are enabled. The definition writes and `DELETE` answer the engine's refusal, naming every holder. The clone's new name gets the door's own name-taken answer, as before. Before: +A name two packages hold is read at these doors on its served holder, as before: a refused definition write puts back the served holder's body, and a `PUT` keeps the served holder's stored credential. With one holder disabled, a package-less `PUT /automation/NAME` or `POST /automation` onto such a name is admitted into the enabled holder, with or without a metadata store (the store's save, naming no package, writes the enabled holder's row), as before. While both holders are enabled, the definition writes and `DELETE` are refused `409` (`RESOURCE_CONFLICT`) naming every holder, as before. -- `DELETE` answered the same refusal: the engine's removal raises it. -- The clone's new name got the name-taken answer while one holder was disabled. While both were enabled it got the engine's refusal, thrown, naming every holder; it now gets the name-taken answer, same status and code, returned, whose remedy is a new name. -- The definition writes got the same refusal while the engine still held the disabled package's slot, because the engine's registration raises it. Once the disable's re-sync had withdrawn that slot, the registration filed the body in the enabled package's slot. The store's save, which names no package, then refused it `409` naming the packages, and the engine was put back. A composition with no metadata store kept the write. +The clone door's new name: a name two packages hold is taken. While one holder is disabled it gets the door's name-taken `409`, as before. While both are enabled, the engine's refusal used to leave the door thrown, naming every holder; the door now answers its own name-taken refusal, returned, with the same status and code (`409`, `RESOURCE_CONFLICT`), whose remedy is a new name. A flow of an enabled package, and a name the engine does not hold, answer as before. The read and run doors (`GET`, trigger, toggle, runs, the clone's source) keep the served view. diff --git a/packages/runtime/src/domains/automation-write-doors-durable-34145.test.ts b/packages/runtime/src/domains/automation-write-doors-durable-34145.test.ts index f2ae0f669c1..32916271db1 100644 --- a/packages/runtime/src/domains/automation-write-doors-durable-34145.test.ts +++ b/packages/runtime/src/domains/automation-write-doors-durable-34145.test.ts @@ -1,10 +1,12 @@ // Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license. /** - * [ADR-0150 D3; seat ruling 6884403301, amendment 7] The `/automation` write - * doors ask a DURABLE question of a flow name, so they read it over every - * holder (the engine's engine-local `getHeldFlow`), never on the served read - * (`getFlow`), whose answer moves with a package's enable state: + * [ADR-0150 D3; seat ruling 6884403301, amendment 7; seat ruling 6911640332, + * M1 = B] The `/automation` write doors ask a DURABLE question of a flow + * name. For a name ONE package holds they read it over every holder (the + * engine's engine-local `getHeldFlow`), not on the served read (`getFlow`), + * whose answer moves with that package's enable state. A name two packages + * hold is read on its served holder, as on `main`: * * - the clone door's taken-name probe on the copy's new name; * - the definition writes' put-back copy, after a write the engine accepted @@ -17,18 +19,16 @@ * run, or failed). For it the engine's served read answers `null` (pinned in * service-automation's `flow-slots-per-package.test.ts`, `[#33905]`), and its * read over every holder answers the body. The automation service here - * answers both reads as the engine does for such a flow; a name two packages - * hold is refused by the read over every holder, `409` naming every holder. + * answers both reads as the engine does for such a flow. * * A name two packages hold is modelled in the engine's measured states - * (service-automation's `flow-slots-per-package.test.ts`, `[#33893]`, and the - * uninstall stretch): `kept`, the disabled co-holder's slot still held, where a - * package-less registration is refused; `withdrawn`, that slot withdrawn by - * the disable's re-sync, where the served read and a package-less - * registration both reach the served holder's slot while the read over every - * holder still refuses the name; `served`, both holders enabled, where every - * bare read refuses it; `uninstalled`, the co-holder uninstalled, where the - * name has one holder again. + * (service-automation's `flow-slots-per-package.test.ts`, `[#33893]`): the + * read over every holder refuses it `409` in each. `kept`, the disabled + * co-holder's slot still held: the served read serves the enabled holder and + * a package-less registration is refused. `withdrawn`, that slot withdrawn by + * the disable's re-sync: the served read and a package-less registration both + * reach the enabled holder's slot. `served`, both holders enabled: every bare + * read refuses it. * * CONTROLs: an enabled holder answers as before at all four doors; a name the * engine does not hold is still admitted by the clone door and answered `404` @@ -41,11 +41,17 @@ * request (a composition whose metadata door leaves the `flow` type writable). */ -import { afterEach, beforeEach, describe, it, expect, vi } from 'vitest'; +import { afterAll, afterEach, beforeAll, beforeEach, describe, it, expect, vi } from 'vitest'; +import { mkdtempSync, rmSync } from 'node:fs'; +import { tmpdir } from 'node:os'; +import { join } from 'node:path'; // The dispatcher's reach loads this dependency in a function body; paid here, // at collection, not inside the first case's clocked window. import '@objectstack/metadata'; -import { PackageScopedNameRefusedError } from '@objectstack/core'; +import { ObjectKernel, PackageScopedNameRefusedError, type Plugin, type PluginContext } from '@objectstack/core'; +import { MetadataPlugin } from '@objectstack/metadata'; +import { ObjectQL, ObjectQLPlugin } from '@objectstack/objectql'; +import { SqlDriver } from '@objectstack/driver-sql'; import { registerMetadataTypeRedactor } from '@objectstack/spec/kernel'; import { HttpDispatcher } from '../http-dispatcher.js'; @@ -117,7 +123,7 @@ interface Rig { /** The store holds a row for each of these names. */ readonly stored?: readonly string[]; /** SHARED's state in the engine (see the file header). */ - readonly shared?: 'kept' | 'withdrawn' | 'served' | 'uninstalled'; + readonly shared?: 'kept' | 'withdrawn' | 'served'; /** Whether the composition has a metadata store (the `protocol` service). */ readonly store?: boolean; } @@ -126,7 +132,7 @@ function rig({ holder, heldRead = true, saveRefuses = false, stored = [], shared const flows = new Map([ [SOLO, withSecret(SOLO, 'stored-secret')], [SOURCE, { name: SOURCE, label: 'Source', type: 'autolaunched', nodes: [], edges: [] }], - [SHARED, { name: SHARED, label: 'Shared, the served holder', type: 'autolaunched', nodes: [], edges: [] }], + [SHARED, { ...withSecret(SHARED, 'served-secret'), label: 'Shared, the served holder' }], ]); const servedBy = (name: string) => !(holder === 'disabled' && name === SOLO); const automation: Record = { @@ -143,7 +149,7 @@ function rig({ holder, heldRead = true, saveRefuses = false, stored = [], shared return definition; }), unregisterFlow: vi.fn((name: string) => { - if (name === SHARED && shared !== 'uninstalled') throw sharedRefusal(name); + if (name === SHARED) throw sharedRefusal(name); flows.delete(name); }), execute: vi.fn(async () => ({ success: true, output: {} })), @@ -152,7 +158,7 @@ function rig({ holder, heldRead = true, saveRefuses = false, stored = [], shared // The read over every holder: the slot's body whatever its package's // enable state; a name two packages hold refused, naming every holder. automation.getHeldFlow = vi.fn((name: string) => { - if (name === SHARED && shared !== 'uninstalled') throw sharedRefusal(name); + if (name === SHARED) throw sharedRefusal(name); return flows.get(name) ?? null; }); } @@ -297,31 +303,34 @@ describe('[#34145] DELETE /:name finds a flow the engine holds over every holder }); /** - * The declared narrowing (`Clause-②: yes (narrowing)`): a composition with no - * metadata store, a package-less write onto a name two packages hold after the - * disabled co-holder's slot was withdrawn. The served read reaches the served - * holder and a package-less registration lands in its slot, so the bare write - * was admitted; the read over every holder refuses the name, as when both - * holders are enabled. Once the co-holder is uninstalled the name has one - * holder and the write is admitted again (the remedy; the engine side is - * pinned in `flow-slots-per-package.test.ts`'s uninstall stretch). + * [seat ruling 6911640332, M1 = B] A name two packages hold, one of them + * disabled, the disabled co-holder's slot withdrawn: the definition writes + * read it on the served holder, as on `main`. The engine's read over every + * holder refuses the name; the doors fall back to the served read, so the + * credential carried forward is the served holder's and a package-less write + * is admitted into the served holder, with or without a metadata store (the + * store's address: the booted-kernel describe below). */ -describe('[#34145] no metadata store: a package-less write onto a name two packages hold is refused over every holder', () => { +describe('[#34145] a name two packages hold is read on its served holder at the definition writes', () => { const doors = [['PUT /:name', 'PUT', '/' + SHARED], ['POST /', 'POST', '/']] as const; - it.each(doors)('%s, the disabled co-holder\'s slot withdrawn: 409 RESOURCE_CONFLICT naming every holder, nothing registered (FROM: 200, registered into the served holder\'s slot)', async (_door, method, path) => { + it.each(doors)('%s, no metadata store: admitted, 200, registered into the served holder (as on main)', async (_door, method, path) => { const { call, automation, flows } = rig({ holder: 'enabled', shared: 'withdrawn', store: false }); - const before = flows.get(SHARED); - await expect(call(path, method, withSecret(SHARED, 'new-secret'))).rejects.toMatchObject({ - code: 'RESOURCE_CONFLICT', - status: 409, - refusal: { candidates: [{ kind: 'package', packageId: 'com.a.pkg' }, { kind: 'package', packageId: 'com.b.pkg' }] }, - }); - expect(automation.registerFlow).not.toHaveBeenCalled(); - expect(flows.get(SHARED)).toBe(before); + const answer = await call(path, method, withSecret(SHARED, 'new-secret')); + expect(answer.status, JSON.stringify(answer.body)).toBe(200); + expect(automation.registerFlow).toHaveBeenCalledWith(SHARED, expect.objectContaining({ name: SHARED })); + expect(automation.getHeldFlow).toHaveBeenCalledWith(SHARED); + expect(automation.getFlow).toHaveBeenCalledWith(SHARED); + expect((flows.get(SHARED) as any).nodes[0].config.secret).toBe('new-secret'); + }); + + it('PUT /:name in the served form keeps the served holder\'s stored secret (as on main)', async () => { + const { call, automation } = rig({ holder: 'enabled', shared: 'withdrawn', store: false }); + expect((await call('/' + SHARED, 'PUT', projected(SHARED))).status).toBe(200); + expect((automation.registerFlow.mock.calls[0] as [string, any])[1].nodes[0].config.secret).toBe('served-secret'); }); - it.each(doors)('CONTROL — %s, both holders enabled: the same 409, as before', async (_door, method, path) => { + it.each(doors)('CONTROL — %s, both holders enabled: refused 409 RESOURCE_CONFLICT naming every holder, nothing registered, as before', async (_door, method, path) => { const { call, automation } = rig({ holder: 'enabled', shared: 'served', store: false }); await expect(call(path, method, withSecret(SHARED, 'new-secret'))).rejects.toMatchObject({ code: 'RESOURCE_CONFLICT', @@ -330,12 +339,100 @@ describe('[#34145] no metadata store: a package-less write onto a name two packa }); expect(automation.registerFlow).not.toHaveBeenCalled(); }); +}); - it.each(doors)('the remedy — %s once the co-holder is uninstalled: one holder, the write admitted and registered', async (_door, method, path) => { - const { call, automation } = rig({ holder: 'enabled', shared: 'uninstalled', store: false }); - const answer = await call(path, method, withSecret(SHARED, 'new-secret')); - expect(answer.status).toBe(200); - expect(automation.registerFlow).toHaveBeenCalledWith(SHARED, expect.objectContaining({ name: SHARED })); +/** + * [seat ruling 6911640332, M1 = B; contract review 6911286488 S1] The same + * write with a metadata store, through the REAL metadata protocol's save on a + * booted kernel (`MetadataPlugin`, `ObjectQLPlugin`, `sys_metadata` on + * SQLite): two authored packages hold the flow as stored rows, the second one + * disabled. The save naming no package is addressed to the enabled holder's + * row (`servedPackagelessSaveAddress`, #32605), so the write is admitted + * there and the disabled holder's row is byte-unchanged, as on `main`. The + * automation service is the double, answering as the engine does once the + * disabled co-holder's slot is withdrawn (`[#33893]`): the served read and a + * package-less registration reach the enabled holder; the read over every + * holder refuses the name. + */ +describe('[#34145] booted kernel: a package-less write onto a flow name an enabled and a disabled authored package hold is saved into the enabled holder\'s row', () => { + const ENABLED = 'com.qa.flow_alpha'; + const DISABLED = 'com.qa.flow_beta'; + const NAME = 'shared_t'; + const CALLER = { userId: 'u_34145', tenantId: 'org_qa', isSystem: true, positions: [], permissions: [], systemPermissions: ['manage_metadata'] }; + const body = (label: string) => ({ ...withSecret(NAME, 'x'), label }); + let kernel: ObjectKernel | undefined; + let engine: ObjectQL; + let root = ''; + const served = new Map(); + const automation = { + handlerReady: true, + getFlow: vi.fn(async (name: string) => served.get(name) ?? null), + getHeldFlow: vi.fn((name: string) => { + if (name === NAME) throw sharedRefusal(name); + return served.get(name) ?? null; + }), + registerFlow: vi.fn((name: string, definition: unknown) => { served.set(name, definition); return definition; }), + unregisterFlow: vi.fn((name: string) => { served.delete(name); }), + execute: vi.fn(async () => ({ success: true, output: {} })), + }; + const rows = async (): Promise> => { + const found = (await engine.find('sys_metadata', { where: { type: 'flow', name: NAME, state: 'active' }, context: { isSystem: true } } as any)) as any[]; + return Object.fromEntries(found.map((row) => [String(row.package_id ?? null), { + label: JSON.parse(String(row.metadata)).label, + bytes: JSON.stringify([row.metadata, row.version, row.checksum ?? null]), + }])); + }; + const write = async (method: 'PUT' | 'POST', label: string) => { + const dispatcher = new HttpDispatcher(kernel as any, undefined, { enforceProjectMembership: false }); + const path = method === 'PUT' ? '/' + NAME : '/'; + const answered = await dispatcher.handleAutomation(path, method, body(label), { request: {}, executionContext: { ...CALLER } } as any, {}); + return { status: answered.response?.status ?? 200, body: answered.response?.body as any }; + }; + + beforeAll(async () => { + kernel = new ObjectKernel({ logger: { level: 'silent' }, gracefulShutdown: false }); + root = mkdtempSync(join(tmpdir(), 'os-34145-served-flow-save-')); + engine = new ObjectQL(); + engine.registerDriver(new SqlDriver({ client: 'better-sqlite3', connection: { filename: ':memory:' }, useNullAsDefault: true }) as any, true); + await kernel.use(new MetadataPlugin({ watch: false, rootDir: root })); + await kernel.use(new ObjectQLPlugin({ ql: engine })); + const host: Plugin = { + name: 'qa.34145-automation-double', + dependencies: ['com.objectstack.engine.objectql'], + init: async (ctx: PluginContext) => { ctx.registerService('automation', automation); }, + }; + await kernel.use(host); + await kernel.bootstrap(); + await engine.syncSchemas(); + for (const id of [ENABLED, DISABLED]) { + engine.registry.installPackage({ id, name: id, version: '1.0.0', type: 'app' } as any, 'authored'); + await engine.insert('sys_metadata', { + type: 'flow', name: NAME, namespace: 'default', package_id: id, scope: 'platform', strategy: 'merge', state: 'active', version: 1, + metadata: JSON.stringify(body(`${id} row`)), + }, { context: { isSystem: true } } as any); + } + served.set(NAME, body(`${ENABLED} row`)); + }, 120_000); + + afterAll(async () => { + if (kernel?.getState() === 'running') await kernel.shutdown(); + if (root) rmSync(root, { recursive: true, force: true }); + }); + + it.each(['PUT', 'POST'] as const)('%s: 200, the enabled holder\'s row carries the edit, the disabled holder\'s row is byte-unchanged (as on main)', async (method) => { + const before = await rows(); + expect(Object.keys(before).sort()).toEqual([DISABLED, ENABLED].sort()); + engine.registry.disablePackage(DISABLED); + try { + const answer = await write(method, `edited by ${method}`); + expect(answer.status, JSON.stringify(answer.body)).toBe(200); + const after = await rows(); + expect(Object.keys(after).sort()).toEqual([DISABLED, ENABLED].sort()); + expect(after[ENABLED]?.label).toBe(`edited by ${method}`); + expect(after[DISABLED]?.bytes).toBe(before[DISABLED]?.bytes); + } finally { + engine.registry.enablePackage(DISABLED); + } }); }); diff --git a/packages/runtime/src/domains/automation.ts b/packages/runtime/src/domains/automation.ts index 402393b362a..17d55e44ce6 100644 --- a/packages/runtime/src/domains/automation.ts +++ b/packages/runtime/src/domains/automation.ts @@ -2109,16 +2109,19 @@ interface HeldFlowSource { } /** - * [ADR-0150 D3, #34145; seat ruling 6884403301, amendment 7] The reader for a - * DURABLE question this domain's write doors ask of a flow name — is it taken - * (the clone's target), what did the engine hold before this write (the - * put-back copy), which credential does it keep (the carried-forward secret), - * does the engine hold it at all (`DELETE`'s existence probe). Judged over - * every holder: a flow whose one holder's package is disabled is still held, - * and a name two packages hold is refused `409` naming every holder, so none - * of these answers moves with a package's enable state. `getFlow` is the - * SERVED read (a disabled package holds no name), which the read and run - * doors keep. + * [ADR-0150 D3, #34145; seat ruling 6884403301, amendment 7; seat ruling + * 6911640332, M1 = B] The reader for a DURABLE question this domain's write + * doors ask of a flow name — is it taken (the clone's target), what did the + * engine hold before this write (the put-back copy), which credential does it + * keep (the carried-forward secret), does the engine hold it at all + * (`DELETE`'s existence probe). A name ONE package holds is judged over every + * holder (`getHeldFlow`): a flow whose one holder's package is disabled is + * still held, so these answers do not move with that package's enable state. + * A name two packages hold is read on its served holder (`getFlow`), as the + * bare read, the bare metadata save (#32605) and amendment 9's doors read it: + * the engine's read over every holder refuses such a name, and that refusal + * is not the doors' answer. `getFlow` keeps its own refusal for a name two + * served holders hold. * * The engine's `getHeldFlow` is engine-local, not on the service contract; a * service without it (a host composing another engine, which has no package @@ -2130,18 +2133,31 @@ function heldFlowReader( ): ((name: string) => Promise) | undefined { const source = automationService as HeldFlowSource; const getHeldFlow = source.getHeldFlow; - if (typeof getHeldFlow === 'function') return async (name) => getHeldFlow.call(source, name); const getFlow = automationService.getFlow; - if (typeof getFlow === 'function') return (name) => getFlow.call(automationService, name); - return undefined; + const served = typeof getFlow === 'function' + ? (name: string): Promise => getFlow.call(automationService, name) + : undefined; + if (typeof getHeldFlow === 'function') { + return async (name) => { + try { + return await getHeldFlow.call(source, name); + } catch (e) { + if (e instanceof PackageScopedNameRefusedError && served !== undefined) return served(name); + throw e; + } + }; + } + return served; } /** - * [#34145] The clone door's taken-name probe over every holder - * ({@link heldFlowReader}): the held body, `null` when no holder has the name, - * and `true` when two or more packages hold it, whose read is refused - * (`PackageScopedNameRefusedError`): such a name is taken. Any other failure - * is thrown on. + * [#34145] The clone door's taken-name probe ({@link heldFlowReader}): the + * held body, `null` when no holder has the name, and `true` when the read + * refuses the name as one two or more packages hold + * (`PackageScopedNameRefusedError`, the served read's refusal of a name two + * served holders hold): such a name is taken, and the door answers its own + * name-taken refusal, whose remedy is a new name. Any other failure is thrown + * on. */ async function cloneTargetHeld(readHeld: (name: string) => Promise, name: string): Promise { try { @@ -2162,7 +2178,8 @@ async function cloneTargetHeld(readHeld: (name: string) => Promise, nam * one rule. * * The comparison runs against the definition the ENGINE holds (the raw - * in-process read, over every holder: {@link heldFlowReader} [#34145]), not a + * in-process read, {@link heldFlowReader} [#34145]: a disabled sole holder's + * included, a name two packages hold read on its served holder), not a * served copy. A service with no read, or a name it does not hold, carries * nothing — the body is registered as written, and a missing secret is * refused by the engine's own registration gate, loudly. @@ -2785,8 +2802,9 @@ async function registerAndSaveFlow( const store: (Partial> & Partial>) | undefined = await deps.resolveServiceOrLoud(context, 'protocol'); - // [#34145] What the engine held, over every holder (`heldFlowReader`): the - // put-back copy does not move with the holder's package's enable state. + // [#34145] What the engine held (`heldFlowReader`): the put-back copy of a + // name one package holds does not move with that package's enable state; + // a name two packages hold is its served holder's, as `registerFlow` files it. const readHeld = heldFlowReader(automationService); const held = readHeld === undefined ? null : await readHeld(name); let registered: unknown; @@ -3043,10 +3061,10 @@ async function unregisterAndDeleteFlow( const store: (Partial> & Partial>) | undefined = await deps.resolveServiceOrLoud(context, 'protocol'); - // [#34145] The engine holds no such flow, asked over every holder - // (`heldFlowReader`), as `unregisterFlow` removes it: a flow whose one - // holder's package is disabled is held, removed and answered as a - // deletion. A service with no read is never "unknown" here. + // [#34145] The engine holds no such flow, asked of `heldFlowReader`: a + // flow whose one holder's package is disabled is held, removed and + // answered as a deletion. A name two packages hold is refused by + // `unregisterFlow`, as before. A service with no read is never "unknown" here. const readHeld = heldFlowReader(automationService); const held = readHeld === undefined ? null : await readHeld(name); const unknownToEngine = readHeld !== undefined && !held; @@ -4517,14 +4535,14 @@ export async function handleAutomationRequest(deps: DomainHandlerDeps, path: str // actually about — see `flowCloneNameTakenMessage` for why a // second definition under one bare name is a silent, // order-dependent shadow rather than a storage error. - // [#34145] Taken is judged over every holder - // (`heldFlowReader`), not on the served read the source probe - // above uses: a name whose one holder's package is disabled is - // still taken, and a name two packages hold is refused naming - // every holder, whichever of them is served. That refusal is - // caught into this door's own taken-name answer, as the store's - // is (`flowWriteRefusal`'s clone arm): a name two packages hold - // is taken, and the remedy is a NEW name, not a package. + // [#34145] Taken is judged by `heldFlowReader`, not on the + // served read the source probe above uses: a name whose one + // holder's package is disabled is still taken. A name two + // packages hold is taken too: its served holder's body, or, + // when two holders are served, the read's refusal, caught into + // this door's own taken-name answer as the store's is + // (`flowWriteRefusal`'s clone arm). The remedy is a NEW name, + // not a package. const readHeld = heldFlowReader(automationService); const collision = readHeld === undefined ? null : await cloneTargetHeld(readHeld, targetName); if (collision) { diff --git a/packages/services/service-automation/src/flow-slots-per-package.test.ts b/packages/services/service-automation/src/flow-slots-per-package.test.ts index 1d32037562e..4b77cc0abf1 100644 --- a/packages/services/service-automation/src/flow-slots-per-package.test.ts +++ b/packages/services/service-automation/src/flow-slots-per-package.test.ts @@ -1401,8 +1401,9 @@ describe('[#33893] the served holder of a name a disabled package co-holds keeps expect(await fireAll()).toEqual([tagOf(on)]); expect(refusedBodyWarned()).toEqual([]); expect(engine.flowDispatchHolder(`${on}/t`)).toEqual({ packageId: on, claimBare: false, name: 't' }); - // [#34145] The write doors' read over every holder still refuses the - // name, naming both holders, while the served read reaches `on`'s flow. + // [#34145] The read over every holder still refuses the name, naming + // both holders, while the served read reaches `on`'s flow: the + // runtime's write doors read such a name on that served holder. let held: unknown; try { engine.getHeldFlow('t'); } catch (e) { held = e; } expect(held).toMatchObject({ code: 'RESOURCE_CONFLICT', status: 409 }); @@ -1519,7 +1520,7 @@ describe('[#33893] the served holder of a name a disabled package co-holds keeps expect(await fireAll()).toEqual(['alpha']); }); - it('[#34145] the remedy for a write refused over every holder: the read over every holder answers the one holder\'s flow, so a package-less write is admitted', () => { + it('[#34145] the read over every holder settles the name too: it answers the one holder\'s flow and folds the slot back, and a package-less registration is accepted', () => { uninstalled(); expect(engine.getHeldFlow('t')).toMatchObject({ name: 't' }); expect(engine.flowSlotKey(P1, 't')).toBe('t'); From e6f54de659a2fae098a24cd8ea176852c46abc79 Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 16 Nov 2026 09:59:48 +0000 Subject: [PATCH 10/11] test(runtime): read the booted-kernel flow rows through the typed trailing read options The rows probe in automation-write-doors-durable-34145.test.ts erased its engine query options to any, growing the query-options erasure test surface 236 to 237. The context now rides the read's trailing EngineReadOptions, and the where bag is typed by find's own signature. Claude-Session: https://claude.ai/code/session_01FEkQ5kgF3mo9f7LXuv5hac Co-Authored-By: Claude --- .../src/domains/automation-write-doors-durable-34145.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/runtime/src/domains/automation-write-doors-durable-34145.test.ts b/packages/runtime/src/domains/automation-write-doors-durable-34145.test.ts index 32916271db1..4f692138f07 100644 --- a/packages/runtime/src/domains/automation-write-doors-durable-34145.test.ts +++ b/packages/runtime/src/domains/automation-write-doors-durable-34145.test.ts @@ -376,7 +376,7 @@ describe('[#34145] booted kernel: a package-less write onto a flow name an enabl execute: vi.fn(async () => ({ success: true, output: {} })), }; const rows = async (): Promise> => { - const found = (await engine.find('sys_metadata', { where: { type: 'flow', name: NAME, state: 'active' }, context: { isSystem: true } } as any)) as any[]; + const found = await engine.find('sys_metadata', { where: { type: 'flow', name: NAME, state: 'active' } }, { context: { isSystem: true } }); return Object.fromEntries(found.map((row) => [String(row.package_id ?? null), { label: JSON.parse(String(row.metadata)).label, bytes: JSON.stringify([row.metadata, row.version, row.checksum ?? null]), From e5468471255dc453372de98294c1298ec00d0069 Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 16 Nov 2026 11:29:14 +0000 Subject: [PATCH 11/11] docs(runtime): name the both-disabled shared-name exception at the clone door, and the POST / credential carry Prose only, no code path moves (review#1 delta record 6915149305, S5 option 1, N2): the clone door's comment and the #34145 changeset state that a name two packages hold with both holders disabled is not taken at the clone door, as on main; both changesets name POST /automation onto a held name beside PUT as the doors that keep a stored credential. Claude-Session: https://claude.ai/code/session_01FEkQ5kgF3mo9f7LXuv5hac Co-Authored-By: Claude --- .changeset/33905-disabled-sole-holder-flow.md | 2 +- .changeset/34145-write-doors-durable-read.md | 8 ++++---- packages/runtime/src/domains/automation.ts | 6 +++++- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/.changeset/33905-disabled-sole-holder-flow.md b/.changeset/33905-disabled-sole-holder-flow.md index 44cfd38778e..41ae6724d37 100644 --- a/.changeset/33905-disabled-sole-holder-flow.md +++ b/.changeset/33905-disabled-sole-holder-flow.md @@ -18,7 +18,7 @@ What moves, for such a flow, while its package is disabled: - `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`. -The HTTP write doors that ask a lasting question of the name do not move with it: the clone door's taken-name check on the new name, the definition a refused `POST /automation` or `PUT /automation/NAME` puts back, the stored credential a `PUT` body that leaves it out keeps, and the `DELETE /automation/NAME` existence check read the flow the engine holds whatever its package's enable state. For such a flow the clone's new name is refused `409`, the held definition is put back, the credential is kept and `DELETE` answers a deletion, as before this release. A name two packages hold is read at those doors on its served holder, as the bare entries read it. +The HTTP write doors that ask a lasting question of the name do not move with it: the clone door's taken-name check on the new name, the definition a refused `POST /automation` or `PUT /automation/NAME` puts back, the stored credential a `PUT /automation/NAME` body, or a `POST /automation` body onto a name the engine holds, keeps when it leaves it out, and the `DELETE /automation/NAME` existence check read the flow the engine holds whatever its package's enable state. For such a flow the clone's new name is refused `409`, the held definition is put back, the credential is kept and `DELETE` answers a deletion, as before this release. A name two packages hold is read at those doors on its served holder, as the bare entries read it. Remedy: enable the package. Its flow runs on its trigger again with no re-arm, and the bare entries serve it again. diff --git a/.changeset/34145-write-doors-durable-read.md b/.changeset/34145-write-doors-durable-read.md index 58ae29a1968..8dfa2520fb2 100644 --- a/.changeset/34145-write-doors-durable-read.md +++ b/.changeset/34145-write-doors-durable-read.md @@ -10,17 +10,17 @@ Metadata-protocol: none **Added:** `AutomationEngine.getHeldFlow(name)` on `@objectstack/service-automation`: the flow the engine holds under a bare name, judged over every holder (a disabled package's included, `null` for a name it does not hold or a slot-key spelling); a name two packages hold is refused `409` naming every holder. Like `getFlow`, it settles the name first, so a lone qualified slot of a name one package holds again is re-keyed to the bare name. -Four `/automation` write doors ask a lasting question of a flow name: the clone door's taken-name check on the new name, the copy a refused definition write (`POST /`, `PUT /automation/NAME`) puts back, the credential `PUT /automation/NAME` keeps when the body leaves it out, and the `DELETE /automation/NAME` existence check. They read the engine's served view (`getFlow`), in which a flow whose one package is disabled is no flow. For a name one package holds they now read the flow the engine holds over every holder, through `getHeldFlow`, so their answers no longer depend on whether that package is enabled. For a flow whose only package is disabled while the engine still holds it: +Four `/automation` write doors ask a lasting question of a flow name: the clone door's taken-name check on the new name, the copy a refused definition write (`POST /`, `PUT /automation/NAME`) puts back, the credential `PUT /automation/NAME`, or `POST /automation` onto a name the engine already holds, keeps when the body leaves it out, and the `DELETE /automation/NAME` existence check. They read the engine's served view (`getFlow`), in which a flow whose one package is disabled is no flow. For a name one package holds they now read the flow the engine holds over every holder, through `getHeldFlow`, so their answers no longer depend on whether that package is enabled. For a flow whose only package is disabled while the engine still holds it: - Clone with this flow's name as the new name: refused `409`, the door's name-taken answer, and nothing is registered. Before, the copy was admitted and filed in the disabled package's slot. - A definition write the engine accepts and the store then refuses: the flow the engine held is registered again. Before, the name was withdrawn. -- `PUT` with a body that leaves out a stored credential: the stored credential is kept. Before, nothing was carried forward. +- `PUT`, or `POST /` onto the name, with a body that leaves out a stored credential: the stored credential is kept. Before, nothing was carried forward. - `DELETE`: the flow is removed and the door answers a deletion. Before, the door removed it and answered `404`. These are the answers the last release gave: the served view changed after it. -A name two packages hold is read at these doors on its served holder, as before: a refused definition write puts back the served holder's body, and a `PUT` keeps the served holder's stored credential. With one holder disabled, a package-less `PUT /automation/NAME` or `POST /automation` onto such a name is admitted into the enabled holder, with or without a metadata store (the store's save, naming no package, writes the enabled holder's row), as before. While both holders are enabled, the definition writes and `DELETE` are refused `409` (`RESOURCE_CONFLICT`) naming every holder, as before. +A name two packages hold is read at these doors on its served holder, as before: a refused definition write puts back the served holder's body, and a `PUT`, or a `POST /` onto the name, keeps the served holder's stored credential. With one holder disabled, a package-less `PUT /automation/NAME` or `POST /automation` onto such a name is admitted into the enabled holder, with or without a metadata store (the store's save, naming no package, writes the enabled holder's row), as before. While both holders are enabled, the definition writes and `DELETE` are refused `409` (`RESOURCE_CONFLICT`) naming every holder, as before. -The clone door's new name: a name two packages hold is taken. While one holder is disabled it gets the door's name-taken `409`, as before. While both are enabled, the engine's refusal used to leave the door thrown, naming every holder; the door now answers its own name-taken refusal, returned, with the same status and code (`409`, `RESOURCE_CONFLICT`), whose remedy is a new name. +The clone door's new name: a name two packages hold is taken. While one holder is disabled it gets the door's name-taken `409`, as before. While both are enabled, the engine's refusal used to leave the door thrown, naming every holder; the door now answers its own name-taken refusal, returned, with the same status and code (`409`, `RESOURCE_CONFLICT`), whose remedy is a new name. One exception, as before: a name two packages hold with both holders disabled is not taken at the clone door (no holder is served, so the door finds no flow there) and the copy is admitted. A flow of an enabled package, and a name the engine does not hold, answer as before. The read and run doors (`GET`, trigger, toggle, runs, the clone's source) keep the served view. diff --git a/packages/runtime/src/domains/automation.ts b/packages/runtime/src/domains/automation.ts index 17d55e44ce6..a4419bf105a 100644 --- a/packages/runtime/src/domains/automation.ts +++ b/packages/runtime/src/domains/automation.ts @@ -4542,7 +4542,11 @@ export async function handleAutomationRequest(deps: DomainHandlerDeps, path: str // when two holders are served, the read's refusal, caught into // this door's own taken-name answer as the store's is // (`flowWriteRefusal`'s clone arm). The remedy is a NEW name, - // not a package. + // not a package. The one exception, as on `main` (seat ruling + // 6911640332, M1 = B): a name two packages hold with BOTH + // holders disabled is NOT taken here. `getHeldFlow` refuses + // the shared name, the served fallback `getFlow` answers + // `null` (no holder is served), and the copy is admitted. const readHeld = heldFlowReader(automationService); const collision = readHeld === undefined ? null : await cloneTargetHeld(readHeld, targetName); if (collision) {