Skip to content

Commit 0bebbcd

Browse files
committed
fix(runtime,service-automation)!: the flow doors judge the served holders of a name two packages hold (WIP)
A bare flow name an enabled and a disabled package hold reaches the enabled holder's slot; two served holders are refused naming them only; none is no flow. Durable coordinates (slot keys, run keys, dispatch key, guards) stay judged over every holder. Co-authored-by: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_016WV4cx5ZPCyTk8ckTsx4ut
1 parent 4c32b96 commit 0bebbcd

5 files changed

Lines changed: 268 additions & 71 deletions

File tree

‎packages/runtime/src/domains/automation-address.ts‎

Lines changed: 59 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,27 @@
7373
* {@link bareNameRefusal} is the same resolution for a bare address: a bare
7474
* name the resolver refuses is answered `409` naming every candidate (D5), on
7575
* the doors whose own answer was no such `409`.
76+
*
77+
* [ADR-0150 D3, #33386; seat ruling 6884403301] A name two or more packages
78+
* hold, one of them disabled, is judged over the SERVED holders at the doors
79+
* (a disabled package holds no name), the shape the email send took
80+
* (plugin-email `template-loader.ts`):
81+
*
82+
* - a bare name ({@link bareNameAdmission}): one served holder is that
83+
* holder's slot, two or more are refused naming the served holders only,
84+
* and none is no item (the door's own `404`). A slot is `(package, name)`
85+
* and is never re-pointed: a disable only moves which slot the bare name
86+
* reaches;
87+
* - an address naming the disabled holder's namespace is never another
88+
* package's item: `not-held-by-qualifier` naming the served holders, or
89+
* `404` when none remains; `_env` and any other namespace name the served
90+
* holders only.
91+
*
92+
* The durable coordinates stay judged over EVERY holder (amendment 7): the
93+
* engine's slot keys, a run's key, and {@link bareNameRefusal}, which the MCP
94+
* resume door reads to tell a run row's slot. So does the refusal a slot
95+
* carries for the doors that cannot serve from the slot (the definition
96+
* writes): a write targets the name every holder holds.
7697
*/
7798

7899
import {
@@ -259,6 +280,33 @@ export function bareNameRefusal(
259280
return resolution.status === 'refused' ? resolution : undefined;
260281
}
261282

283+
/**
284+
* [ADR-0150 D3, #33386] A BARE by-name door's admission (see the module note):
285+
* the bare name's `409` naming the served holders when two or more serve it,
286+
* the slot of its one served holder when the name is held by two or more
287+
* packages over every holder (each holder's item is then its own slot), and
288+
* `undefined` otherwise — the bare path, as before, which answers its own
289+
* `404` when no served holder remains. A name held by one package or none is
290+
* judged as {@link bareNameRefusal} judges it, unchanged. Read-only.
291+
*/
292+
export function bareNameAdmission(
293+
registry: AutomationAddressRegistry | undefined,
294+
type: 'flow' | 'connector',
295+
name: string,
296+
): AutomationAddressRefusal | AutomationAddressSlot | undefined {
297+
if (!registry || !canResolve(registry)) return undefined;
298+
const every = resolvePackageScopedName(registry, { type, name, callerPackageId: null, includeDisabledPackages: true });
299+
if (every.status !== 'refused' || holdersOf(registry, type, name, { includeDisabledPackages: true }).length < 2) {
300+
return every.status === 'refused' ? { status: 409, refusal: every } : undefined;
301+
}
302+
const served = resolvePackageScopedName(registry, { type, name, callerPackageId: null });
303+
if (served.status === 'refused') return { status: 409, refusal: served };
304+
if (served.status === 'resolved' && served.holder.kind === 'package') {
305+
return { status: 'slot', packageId: served.holder.packageId, refusal: every };
306+
}
307+
return undefined;
308+
}
309+
262310
/**
263311
* Judge an addressed path's qualifier (see the module note). `undefined`
264312
* admits it: the path is then served as its bare path, whose item is the
@@ -279,14 +327,16 @@ export function admitAutomationAddress(
279327
? undefined
280328
: { status: 404, message: `${noun} '${name}' not found in namespace '${qualifier.namespace}'` };
281329
}
282-
// [#32183, R4-G] A name two or more packages hold over every holder (the
283-
// state #31696 opened for a flow, each holder's flow in its own engine
284-
// slot) is judged over every holder, a disabled package's included, so a
285-
// disable moves no address of it (`main`'s answer). A one-holder name is
286-
// judged over the served holders, as every by-name door is.
330+
// [ADR-0150 D3, #33386] Judged over the served holders, as every by-name
331+
// door is: a disabled package holds no name, so an address naming it is
332+
// never another package's item, and a refusal names the served holders
333+
// only (seat ruling 6884403301, amendments 2 and 6). A name two or more
334+
// packages hold over EVERY holder (the state #31696 opened, each holder's
335+
// item in its own engine slot) is still served from the addressed
336+
// holder's slot: the slots are keyed over every holder (amendment 7).
287337
const everyHolder = holdersOf(registry, type, name, { includeDisabledPackages: true });
288338
const shared = everyHolder.length > 1;
289-
const holders = shared ? everyHolder : holdersOf(registry, type, name);
339+
const holders = holdersOf(registry, type, name);
290340
let holder: PackageScopedHolder;
291341
if (qualifier.kind === 'environment') {
292342
if (registry.getEnvironmentScopedItem(type, name) !== undefined || holders.length === 0) return undefined;
@@ -313,7 +363,9 @@ export function admitAutomationAddress(
313363
// [#31696] A flow name two packages hold: each holder's flow is its own
314364
// slot, and the address names one holder of it. [ADR-0150 D9, #31699]
315365
// So is a connector name: each holder's instance is its own, and the
316-
// connection door connects the addressed one.
366+
// connection door connects the addressed one. [#33386] The addressed
367+
// holder is a served one (above); the slot's refusal, for the doors
368+
// that cannot serve from it, stays the name's over every holder.
317369
return (type === 'flow' || type === 'connector') && holder.kind === 'package'
318370
? { status: 'slot', packageId: holder.packageId, refusal: bare }
319371
: { status: 409, refusal: bare };

‎packages/runtime/src/domains/automation.ts‎

Lines changed: 30 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,13 @@ import { buildApiError } from '../error-envelope.js';
2020
import {
2121
admitAutomationAddress,
2222
automationAddressRegistryOf,
23-
bareNameRefusal,
23+
bareNameAdmission,
2424
readAutomationAddress,
2525
automationRouteAllow,
2626
AUTOMATION_DOOR_LITERALS,
2727
type AutomationAddressRefusal,
2828
type AutomationAddressRegistry,
29+
type AutomationAddressSlot,
2930
} from './automation-address.js';
3031
// [#31696] One holder's flow of a shared name, served from its own slot; a
3132
// start's admission walks callees from the calling flow's package.
@@ -1255,7 +1256,7 @@ async function automationRegistryOf(deps: DomainHandlerDeps, context: HttpProtoc
12551256

12561257
/**
12571258
* [ADR-0150 D5, child G1] The item a BARE by-name run or read names, for the
1258-
* bare name's `409` (`bareNameRefusal`): the flow of the trigger, toggle, read
1259+
* bare name's `409` (`bareNameAdmission`): the flow of the trigger, toggle, read
12591260
* and run doors, and the connector instance of the connection door. The
12601261
* definition writes (`PUT` / `DELETE /:name`, the clone) are absent: they
12611262
* answer their own `409` with its remedy (`flowWriteRefusal`).
@@ -1279,15 +1280,19 @@ function bareByNameItem(parts: readonly string[], method: string): { type: 'flow
12791280
return undefined;
12801281
}
12811282

1282-
/** [ADR-0150 D5, child G1] A bare by-name door's `409`, when the resolver refuses its name. */
1283-
function bareByNameRefusal(
1283+
/**
1284+
* [ADR-0150 D5, child G1] A bare by-name door's `409`, when the resolver
1285+
* refuses its name. [ADR-0150 D3, #33386] Judged over the served holders
1286+
* (`bareNameAdmission`): a name two packages hold whose one served holder
1287+
* remains is that holder's slot, never a `409` naming a disabled package.
1288+
*/
1289+
function bareByNameAdmission(
12841290
registry: AutomationAddressRegistry | undefined,
12851291
parts: readonly string[],
12861292
method: string,
1287-
): AutomationAddressRefusal | undefined {
1293+
): AutomationAddressRefusal | AutomationAddressSlot | undefined {
12881294
const item = bareByNameItem(parts, method);
1289-
const refusal = item ? bareNameRefusal(registry, item.type, item.name) : undefined;
1290-
return refusal ? { status: 409, refusal } : undefined;
1295+
return item ? bareNameAdmission(registry, item.type, item.name) : undefined;
12911296
}
12921297

12931298
/**
@@ -3861,19 +3866,31 @@ export async function handleAutomationRequest(deps: DomainHandlerDeps, path: str
38613866
// [ADR-0150 D9, #31699] A connector name two packages hold, addressed by
38623867
// the namespace of one of them: the connection door connects, reads and
38633868
// revokes that holder's instance (`ConnectorConnectionRequest.package`).
3869+
//
3870+
// [ADR-0150 D3, #33386] Every admission here is judged over the served
3871+
// holders: a bare name two packages hold whose one served holder remains
3872+
// is served from that holder's slot, as its address is (seat ruling
3873+
// 6884403301). `item` is the address's item, else the bare door's own.
38643874
let connectorPackage: string | undefined;
38653875
{
3876+
const door = bareByNameItem(parts, m);
3877+
const item = address.qualifier ? address.item : door;
38663878
const admission = address.qualifier && address.item
38673879
? admitAutomationAddress(addressRegistry, address.qualifier, address.item)
3868-
: bareByNameRefusal(addressRegistry, parts, m);
3869-
if (admission?.status === 'slot' && address.item?.type === 'connector' && bareByNameItem(parts, m)?.type === 'connector') {
3880+
: bareByNameAdmission(addressRegistry, parts, m);
3881+
if (admission?.status === 'slot' && item?.type === 'connector' && door?.type === 'connector') {
38703882
connectorPackage = admission.packageId;
38713883
} else if (admission?.status === 'slot') {
3872-
const slotted = bareByNameItem(parts, m)?.type === 'flow' && address.item
3873-
? flowSlotView(automationService, admission.packageId, address.item.name)
3884+
const slotted = door?.type === 'flow' && item
3885+
? flowSlotView(automationService, admission.packageId, item.name)
38743886
: undefined;
3875-
if (!slotted) return { handled: true, response: automationAddressRefusalResponse(deps, { status: 409, refusal: admission.refusal }) };
3876-
automationService = slotted;
3887+
if (slotted) {
3888+
automationService = slotted;
3889+
} else if (address.qualifier || door?.type !== 'flow') {
3890+
return { handled: true, response: automationAddressRefusalResponse(deps, { status: 409, refusal: admission.refusal }) };
3891+
}
3892+
// [#33386] Else a bare flow name and no slot entries: the bare
3893+
// service, whose bare entries judge the served holders themselves.
38773894
} else if (admission) {
38783895
const byRun = !address.qualifier && admission.status === 409 && parts[1] === 'runs' && parts[2]
38793896
? await runSlotView(automationService, parts[0], parts[2], admission.refusal.candidates.flatMap((c) => (c.kind === 'package' ? [c.packageId] : [])))

0 commit comments

Comments
 (0)