Skip to content

Commit b96dd30

Browse files
fix(approvals)!: a request whose stamped flow package was uninstalled never reads another package's flow of that name (#33297)
<!-- claude-projects-attribution: {"github_login":"os-elon-musk"} --> _Requested by **Elon** · [project thread](https://claude.ai/code/project/chan_01WedDzV26nniwxv7jC88B9D?thread=cmsg_01WedDzV26nniwxv7jC88B9DDZYUbJbnXUTqZoZ56k4czR)_ Fixes #32647 Clause-②: yes (narrowing) Metadata-protocol: none Skills-docs: none — no skill or docs page teaches how an approval request reads its flow once its package is uninstalled; the moved answers are runtime refusals at approval doors, nothing an author writes. ## 维护者速读 - **改了什么**:审批单记着打开它的包(`process_package`)。这个包卸载后,如果另一个包还发同名 flow,审批单不再去读那个包的 flow:退回(send-back)和停滞的重新提交改为 409 拒绝并列出所有持有者,详情读取不再给出 `flow_route` / `flow_steps`,队列包按"没有 flow"处理。 - **为什么改**:ADR-0150 D8 R7 规定审批单属于打开它的那个包的 flow;之前卸载后会按裸名或按运行的 key 读到别的包的同名 flow,审批人看到并操作的是一张从没跑过这单的流程图。 - **风险与回滚**:只影响"打开它的包已卸载、而别的包持有同名 flow"的审批单(第一方调用方 0 个);记下的包仍持有该名、单子没记包、或已无任何持有者时答案不变。回滚即 revert 本 PR。 - **先看**:`packages/plugins/plugin-approvals/src/approval-service.ts` 的 `requestFlowSlot`(新增已卸载分支)、`requestFlow`(拒绝)、`requestFlowKey`;再看 `approval-revise.test.ts` 新增的 `[#32647]` describe。 - **两分钟验证**:`pnpm --filter @objectstack/plugin-approvals exec vitest run --maxWorkers=2 src/approval-revise.test.ts`,预期 29 个用例全绿,其中 3 个是 `[#32647]`。 - **需要你做的**:无,席位落地。 ## What changes `ApprovalService.requestFlowSlot` (`packages/plugins/plugin-approvals/src/approval-service.ts`) now answers a request stamped with a package (`process_package`) by that package's slot ONLY. When the stamped package holds no slot of the request's flow name (uninstalled, or no longer shipping the flow), it answers a withdrawn marker naming the slots that do hold the name, and never falls through to the run's key or the bare read: both served another package's flow (the bare read once a second holder was left alone; the run's key once another package installed the name after the stamped package left, because the key is the bare name again). - `requestFlow` (send-back's edge check, the stranded-resubmit continuation's revise window, the request read's `flow_route` / `flow_steps`): a withdrawn stamp with holders throws `PackageScopedNameRefusedError` (`409 RESOURCE_CONFLICT`), reason `not-held-by-qualifier` with the stamped package as the qualifier and every holder as a candidate, and a sentence of the request's own (the qualifier read's "address it by its holder" is no move an approver has). With no holder left it answers `null`, the deleted-flow answer the bare read gave, unchanged. - `requestFlowKey` (the queue package a re-resolved slate reads a `queue` name from): a withdrawn stamp answers `null`, the no-flow answer. - The request-open path (`input.flowName`, no package asked) is unchanged; it narrows the new union type away. Declared FROM → TO per door, for a request whose stamped package withdrew while another package holds the name: | Door | FROM (measured, ablation) | TO | |:--|:--|:--| | send-back (`POST /approvals/requests/ID/revise`) | the other package's revise edge checked; unit harness, run carrying the bare name: request `returned` on the other graph; booted stack, record-triggered run: passes the edge check, then `409 RESUME_TARGET_LOST` | `409 RESOURCE_CONFLICT` naming every holder, nothing written | | request read `flow_route` / `flow_steps` | the other package's route and steps (`Iota gate`) | neither served | | stranded resubmit's revise window | the other package's window (`wait_revision`) | `409 RESOURCE_CONFLICT` | | queue package | the other package (`com.acme.beta`) | none (environment-wide read) | ## Tests - `packages/plugins/plugin-approvals/src/approval-revise.test.ts`, new `[#32647]` describe beside the `[#31696]` one (real `AutomationEngine`, loader set attached so the queue door's package is readable): (1) withdrawn beside a second holder, (2) install / open / uninstall / another package installs the name (with a CONTROL leg: no holder left answers as a deleted flow, as on `main`), (3) CONTROL: stamped package still holds the name, alone and beside a second holder, every door reads its own flow. - `packages/qa/dogfood/test/approval-flow-name-per-namespace.dogfood.test.ts`, new top-level describe on a booted stack: host stack + install-local alpha, open a request through alpha's record-triggered flow, `DELETE /marketplace/install-local/ALPHA`, CONTROL (no holder: send-back `VALIDATION_FAILED`, no route or steps), install iota's same-named flow (filed under the bare key the run carries), then send-back `409 RESOURCE_CONFLICT` naming alpha and iota, read with no route or steps, row still `pending`. ## Acceptance notes - One-holder answers are unchanged and pinned (CONTROL test 3, and the `[#31696]` describe stays green). - In the unit harness, a run started by bare name while its package was the name's one holder resumed on the other package's graph once that package held the name (the send-back FROM `returned` above): the engine's run-key lookup, not this service's. On the booted stack the record-triggered run carried its package-qualified key and the engine refused the resume (`RESUME_TARGET_LOST`). Not measured through a public door for a by-name run; carrier: none. - Local gates were targeted per the dispatch (affected package tests and typecheck, the new pins, one ablation per moved answer); CI runs the farm. ## Verification All readings at head `bb3fbd644` (branch merged with `origin/main` at `199e36244`), each under `scripts/pm/os-verify-lock.sh`. <details><summary>plugin-approvals typecheck + tests: exit 0</summary> ``` pnpm --filter @objectstack/plugin-approvals typecheck && pnpm --filter @objectstack/plugin-approvals test check:test-typecheck: OK (8 file(s) / 321 error(s) / 27 pinned signature(s) held in test-typecheck-debt.json, unchanged) Test Files 119 passed (119) Tests 1635 passed (1635) os-verify-lock: VERDICT command-exit 0 ``` </details> <details><summary>Full dogfood battery (narrowing arm): typecheck exit 0, tests green</summary> ``` pnpm --filter @objectstack/dogfood typecheck -> DOGFOOD_TYPECHECK_EXIT=0 pnpm --filter @objectstack/dogfood test (no OS_TEST_SHARD, no path) Test Files 464 passed | 3 skipped (467) Tests 3928 passed | 42 skipped (3970) os-verify-lock: VERDICT batch-last-exit 0 ``` </details> <details><summary>Ablation, one per moved answer: the stamped branch mutated to `if (false as boolean)` through scripts/ablation-replace.mjs, restored to HEAD by blob</summary> Unit suite `src/approval-revise.test.ts` under the mutation: 2 failed, 27 passed. The two withdrawn cases go red with the FROM answers: steps `Beta Review`, route present, queue package `com.acme.beta`, resubmit window `wait_revision`, send-back `returned` (run carrying the bare name); CONTROL stays green. Restore: blob after restore equals HEAD (`3a6234935de2`), diff against HEAD empty. Booted pin (dogfood aliases `@objectstack/plugin-approvals` to source) under the same mutation: 1 failed, 1 passed; FROM read `[200, "route", ["Iota gate"]]`, send-back `[409, "RESUME_TARGET_LOST"]`. Restored the same way. </details> <details><summary>Targeted gates: each exit 0</summary> `check-adr-0087-registration --base origin/main` (disposition `not-required (no-migration-prescription)` read), `check-changeset-no-major`, `check-empty-changeset`, `check:doc-authoring`, `check:nul-bytes`, `check:issue-citations` (and the script run), `check:cross-package-test-inputs`, `check:engine-double-contract`, `check:closed-ceremony-text`. `dispatch-gates --ran`: 74 derived, 10 run, 64 left to CI (declared narrowing per the dispatch). </details> --- _Generated by [Claude Code](https://claude.ai/code/session_016WV4cyrFFk86Jqf7Mp5Rzw)_ --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent 1bbeb94 commit b96dd30

4 files changed

Lines changed: 327 additions & 5 deletions

File tree

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
---
2+
'@objectstack/plugin-approvals': patch
3+
---
4+
5+
fix(approvals)!: an approval request whose flow package was uninstalled never reads another package's flow of the same name (ADR-0150 D8 row R7)
6+
7+
Clause-②: yes (narrowing) — an approval request stamped with the package it was opened on (`process_package`), whose package no longer holds a flow of the request's name while another package does, moves FROM reading that other package's flow TO reading none, at four doors: (1) send-back (`POST /approvals/requests/ID/revise`) FROM checking the other package's revise edge (then returning the request on that graph where the run carries the bare name, or refused `409 RESUME_TARGET_LOST` by the run pre-flight where it carries its package's key) TO `409 RESOURCE_CONFLICT` (reason `not-held-by-qualifier`, the stamped package as the qualifier, every holder named) with nothing written; (2) the request read (`GET /approvals/requests/ID`) FROM serving the other package's `flow_route` and `flow_steps` TO serving neither; (3) the stranded-resubmit continuation's revise window FROM the other package's window TO the same `409`; (4) the queue package a re-resolved slate reads a `queue` approver's name from FROM the other package TO none (the environment-wide read a request with no flow takes). The other package is read today through the bare name (the stamped package withdrew from a name two packages held) or through the run's key (the stamped package was the name's one holder, and the other package installed the name after it left). First-party callers in that position: 0 (no first-party package uninstalls a flow that another first-party package ships under the same name). Unchanged: a request whose stamped package still holds the name, beside a second holder or alone, and a request naming no package; with no holder of the name left, every door answers as for a deleted flow, as before.
8+
Metadata-protocol: none
9+
10+
<!-- adr-0087: not-required (no-migration-prescription) No key of any schema is added, removed, renamed or re-shaped, and no stored row changes shape: what moves is which flow body four approval doors read for a request whose package was uninstalled, so there is nothing for a migration to rewrite and no tombstone. -->
11+
12+
**BREAKING** for an approval request opened on a package's flow after that package is uninstalled while another package ships a flow of the same name. FROM the request answered from the other package's flow TO refused `409 RESOURCE_CONFLICT`, naming every package that holds the name. The fix: install the request's package again (the refusal names it) to act on the request; nothing else answers it from a flow it was not opened on.

‎packages/plugins/plugin-approvals/src/approval-revise.test.ts‎

Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -840,4 +840,125 @@ describe('Send back for revision (ADR-0044)', () => {
840840
expect((await fake.find('sys_approval_request', { where: { id: control.id } }))[0].status).toBe('pending');
841841
});
842842
});
843+
844+
describe('[#32647] a request whose stamped package withdrew never reads another package\'s flow of that name (ADR-0150 D8 row R7)', () => {
845+
const P1 = 'com.acme.alpha';
846+
const P2 = 'com.acme.beta';
847+
const FLOW = 'expense_approval';
848+
// The loader's set (ADR-0126 §7.2), as the automation plugin attaches it:
849+
// a slot's package ships its flow, so the queue door's package is readable.
850+
beforeEach(() => automation.setPackagedFlowSource((name: string, packageId?: string) => {
851+
const slots = automation.getFlowSlots(name);
852+
return packageId ?? (slots.length === 1 ? slots[0].packageId ?? undefined : undefined);
853+
}));
854+
/**
855+
* P2's flow of the name: a full revise flow under its own labels, so every
856+
* door that read it in place of P1's would ANSWER (the moved answers are
857+
* then visible as answers, not as refusals that happen to match).
858+
*/
859+
const shipP2 = () => automation.registerFlow(FLOW, {
860+
name: FLOW, label: 'Beta Expense', type: 'autolaunched',
861+
nodes: [
862+
{ id: 'start', type: 'start', label: 'Start' },
863+
{ id: 'review', type: 'approval', label: 'Beta Review', config: { approvers: [{ type: 'user', value: 'u2' }] } },
864+
{ id: 'wait_revision', type: APPROVAL_REVISE_NODE_TYPE, label: 'Beta Revision' },
865+
{ id: 'end', type: 'end', label: 'End' },
866+
],
867+
edges: [
868+
{ id: 'e1', source: 'start', target: 'review' },
869+
{ id: 'e2', source: 'review', target: 'end', label: 'approve' },
870+
{ id: 'e3', source: 'review', target: 'end', label: 'reject' },
871+
{ id: 'e4', source: 'review', target: 'wait_revision', label: 'revise' },
872+
{ id: 'e5', source: 'wait_revision', target: 'review', label: 'resubmit', type: 'back' },
873+
],
874+
}, { source: 'package', packageId: P2, holder: P2 });
875+
const open = async (recordId: string, slotted: boolean) => {
876+
const ctx = { object: 'fin_expense', record: { id: recordId }, userId: 'submitter' };
877+
const paused = slotted ? await automation.executeSlot(P1, FLOW, ctx) : await automation.execute(FLOW, ctx);
878+
expect(paused.status).toBe('paused');
879+
return (await fake.find('sys_approval_request', { where: { record_id: recordId } }))[0];
880+
};
881+
const stored = async (id: string) => (await fake.find('sys_approval_request', { where: { id } }))[0];
882+
/** The four doors that read the request's flow, each answered as data (a refusal is its error's code and message). */
883+
const doors = async (req: any) => {
884+
const raw = await stored(req.id);
885+
const settle = async (p: Promise<any>) => p.then((v) => ({ ok: v }), (e: any) => ({
886+
code: e?.code, status: e?.status, message: String(e?.message),
887+
refusal: e?.refusal && { reason: e.refusal.reason, qualifier: e.refusal.callerPackageId, candidates: e.refusal.candidates },
888+
}));
889+
const read: any = await service.getRequest(req.id, SYSTEM_CTX);
890+
return {
891+
steps: read.flow_steps?.map((s: any) => s.label),
892+
route: read.flow_route === undefined ? undefined : 'present',
893+
// The resubmit door: which revise window a stranded resubmit continues (ADR-0044).
894+
resubmitWindow: await settle((service as any).expectedPauseNode(raw, { decision: 'resubmit', what: 'the resubmit' }, req.id, raw.flow_run_id)
895+
.then((n: any) => n.nodeId)),
896+
// The queue door: the package a step's queue name is read from (ADR-0150 D3).
897+
queuePackage: (service as any).flowPackageOf(await (service as any).requestFlowKey(raw)),
898+
sendBack: await settle(service.sendBack(req.id, { actorId: 'u1' }, asUser('u1')).then((out) => out.request.status)),
899+
status: (await stored(req.id)).status,
900+
};
901+
};
902+
903+
it('withdrawn beside a second holder: every door refuses or reads no flow, naming every holder, and nothing is written (FROM: P2\'s flow)', async () => {
904+
registerReviseFlow({ packageId: P1 });
905+
shipP2();
906+
const req = await open('x1', true);
907+
expect(req.process_package).toBe(P1);
908+
automation.withdrawFlowSlot(P1, FLOW);
909+
// P2 now holds the name alone, under the bare key the bare read serves.
910+
expect((await automation.getFlow(FLOW))?.label).toBe('Beta Expense');
911+
912+
const answered = await doors(req);
913+
expect(answered).toMatchObject({
914+
steps: undefined, route: undefined, queuePackage: null, status: 'pending',
915+
resubmitWindow: { code: 'RESOURCE_CONFLICT', status: 409 },
916+
sendBack: { code: 'RESOURCE_CONFLICT', status: 409 },
917+
});
918+
for (const refused of [answered.sendBack, answered.resubmitWindow] as any[]) {
919+
expect(refused.refusal).toEqual({ reason: 'not-held-by-qualifier', qualifier: P1, candidates: [{ kind: 'package', packageId: P2 }] });
920+
expect([refused.message.includes(P1), refused.message.includes(P2)]).toEqual([true, true]);
921+
}
922+
expect(await actionsOf(req.id)).toEqual(['submit']);
923+
});
924+
925+
it('install, open, uninstall, another package installs the name: the run\'s key is the bare name again and still reads no other package\'s flow', async () => {
926+
registerReviseFlow({ packageId: P1 });
927+
const req = await open('x1', false);
928+
expect(req.process_package).toBe(P1);
929+
automation.withdrawFlowSlot(P1, FLOW);
930+
931+
// CONTROL: no package holds the name: the doors answer as for a deleted flow, as on `main`.
932+
const gone = await doors(req);
933+
expect(gone).toMatchObject({ steps: undefined, route: undefined, queuePackage: null, status: 'pending' });
934+
expect([(gone.sendBack as any).refusal, (gone.sendBack as any).message]).toEqual([undefined, expect.stringMatching(/^VALIDATION_FAILED:/)]);
935+
expect([(gone.resubmitWindow as any).refusal, (gone.resubmitWindow as any).message]).toEqual([undefined, expect.stringMatching(/^INVALID_STATE:/)]);
936+
937+
shipP2();
938+
expect(automation.flowSlotKey(P2, FLOW)).toBe(FLOW);
939+
const answered = await doors(req);
940+
expect(answered).toMatchObject({
941+
steps: undefined, route: undefined, queuePackage: null, status: 'pending',
942+
resubmitWindow: { code: 'RESOURCE_CONFLICT', status: 409 },
943+
sendBack: { code: 'RESOURCE_CONFLICT', status: 409 },
944+
});
945+
expect((answered.sendBack as any).refusal).toEqual({ reason: 'not-held-by-qualifier', qualifier: P1, candidates: [{ kind: 'package', packageId: P2 }] });
946+
expect(await actionsOf(req.id)).toEqual(['submit']);
947+
});
948+
949+
it('CONTROL: a request whose stamped package still holds the name reads its own flow at every door, beside a second holder and alone', async () => {
950+
registerReviseFlow({ packageId: P1 });
951+
const lone = await open('x1', false);
952+
const loneAnswer = await doors(lone);
953+
shipP2();
954+
const shared = await open('x2', true);
955+
const sharedAnswer = await doors(shared);
956+
for (const answer of [loneAnswer, sharedAnswer]) {
957+
expect(answer).toMatchObject({
958+
steps: ['Manager Review'], route: 'present', queuePackage: P1,
959+
resubmitWindow: { ok: 'wait_revision' }, sendBack: { ok: 'returned' }, status: 'returned',
960+
});
961+
}
962+
});
963+
});
843964
});

‎packages/plugins/plugin-approvals/src/approval-service.ts‎

Lines changed: 73 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -74,15 +74,17 @@ import type { EnableLike, ObjectCapabilitiesParsed } from '@objectstack/spec/dat
7474
// (`approval_recall_not_submitter`) into it ahead of this consumer half.
7575
import { renderOperationMessage, type ValidationMessageTranslator } from '@objectstack/spec/system';
7676
import {
77+
describePackageScopedHolder,
7778
holdsPlatformPermissionSet,
7879
isGrantActive,
7980
omitInternalFieldsFromWriteResponse,
81+
PackageScopedNameRefusedError,
8082
resolveReadableParentIds,
8183
resolveUserAuthzGrants,
8284
vetOrganizationClaim,
8385
withoutOperationPrivateKeys,
8486
} from '@objectstack/core';
85-
import type { HeldPermissionSets, PackageScopedRefusal } from '@objectstack/core';
87+
import type { HeldPermissionSets, PackageScopedHolder, PackageScopedRefusal } from '@objectstack/core';
8688
import type { TenancyPosture } from '@objectstack/spec/security';
8789
import { normalizeTenancyPosture, postureEnforcesWall } from '@objectstack/spec/security';
8890
import {
@@ -1320,6 +1322,43 @@ function packageScopedRefusalOf(err: unknown): PackageScopedRefusal | undefined
13201322
: undefined;
13211323
}
13221324

1325+
/**
1326+
* [ADR-0150 D8 row R7, #32647] A request stamped with package
1327+
* `withdrawnPackageId` whose package the engine holds no slot of the flow
1328+
* for: uninstalled, or no longer shipping the flow. `holders` are the
1329+
* packages whose slots DO hold the name (`null`: the package-less slot) —
1330+
* each another package's flow, so none is the request's.
1331+
*/
1332+
interface WithdrawnRequestFlow {
1333+
readonly withdrawnPackageId: string;
1334+
readonly holders: ReadonlyArray<string | null>;
1335+
}
1336+
1337+
function isWithdrawnRequestFlow(slot: unknown): slot is WithdrawnRequestFlow {
1338+
return typeof (slot as Partial<WithdrawnRequestFlow> | undefined)?.withdrawnPackageId === 'string';
1339+
}
1340+
1341+
/**
1342+
* [ADR-0150 D5, D8 row R7, #32647] The refusal a read of a withdrawn request
1343+
* flow answers: the stamp is the request's exact qualifier and its package
1344+
* holds no item of the name (`not-held-by-qualifier`), and every holder is
1345+
* named. The sentence is the request's own — "address it by its holder", the
1346+
* qualifier read's remedy, is no move an approver has: the request was
1347+
* opened on the stamped package's flow, and only that package can answer it.
1348+
*/
1349+
function withdrawnRequestFlowRefusal(name: string, withdrawn: WithdrawnRequestFlow): PackageScopedRefusal {
1350+
const candidates: PackageScopedHolder[] = withdrawn.holders.map((packageId) =>
1351+
packageId === null ? { kind: 'environment' } : { kind: 'package', packageId });
1352+
const stamped = withdrawn.withdrawnPackageId;
1353+
const message = `The flow "${name}" this approval request was opened on is package "${stamped}"'s, and package `
1354+
+ `"${stamped}" no longer holds it: it is held by ${candidates.map(describePackageScopedHolder).join('; ')}. `
1355+
+ 'A request is answered only from the flow of the package it was opened on (ADR-0150 D8 row R7), never '
1356+
+ `from another package's flow of the same name: install package "${stamped}" again to act on this request.`;
1357+
return {
1358+
status: 'refused', reason: 'not-held-by-qualifier', type: 'flow', name, callerPackageId: stamped, candidates, message,
1359+
};
1360+
}
1361+
13231362
/**
13241363
* [ADR-0150 D3] What makes a refused queue name resolve, for the package the
13251364
* step was read from — the refusal's own remedy, said for a step.
@@ -3749,17 +3788,28 @@ export class ApprovalService implements IApprovalService, ObjectSchemaReadDelega
37493788
* or nothing names exactly one slot: the bare name is all a reader has,
37503789
* and the bare read refuses a name two packages hold, naming every holder.
37513790
* ⛔ Never a pick between holders.
3791+
*
3792+
* [ADR-0150 D8 row R7, #32647] A request stamped with a package belongs to
3793+
* that package's flow and to no other: when the stamped package holds no
3794+
* slot of `name` (it was uninstalled, or stopped shipping the flow), the
3795+
* answer is {@link WithdrawnRequestFlow}, naming the slots that DO hold the
3796+
* name — never the run's key and never the bare name, both of which would
3797+
* read another package's flow (the run's key is the bare name again once a
3798+
* second package holds it alone).
37523799
*/
37533800
private async requestFlowSlot(
37543801
name: string,
37553802
request: { packageId?: unknown; runId?: unknown; runKey?: string },
3756-
): Promise<{ packageId: string | null; key: string } | undefined> {
3803+
): Promise<{ packageId: string | null; key: string } | WithdrawnRequestFlow | undefined> {
37573804
const automation = this.automation;
37583805
if (typeof automation?.getFlowSlots !== 'function' || typeof automation.flowSlotKey !== 'function') return undefined;
37593806
const slots = automation.getFlowSlots(name)
37603807
.map(({ packageId }) => ({ packageId, key: automation.flowSlotKey!(packageId, name) ?? '' }));
37613808
const own = slots.find((slot) => slot.packageId !== null && slot.packageId === request.packageId);
37623809
if (own) return own;
3810+
if (typeof request.packageId === 'string' && request.packageId !== '') {
3811+
return { withdrawnPackageId: request.packageId, holders: slots.map((slot) => slot.packageId) };
3812+
}
37633813
let key = request.runKey;
37643814
if (key === undefined && typeof request.runId === 'string' && request.runId !== '') {
37653815
try {
@@ -3775,18 +3825,34 @@ export class ApprovalService implements IApprovalService, ObjectSchemaReadDelega
37753825
* to: its own slot's ({@link requestFlowSlot}), else the bare read of
37763826
* `name`, which answers a one-holder name as before and refuses a name two
37773827
* packages hold, naming every holder. The caller has checked `getFlow`.
3828+
*
3829+
* [ADR-0150 D8 row R7, #32647] A request whose stamped package holds no
3830+
* slot of `name` ({@link WithdrawnRequestFlow}): `null` while no slot holds
3831+
* the name either, the answer the bare read gives a deleted flow; else
3832+
* refused, `409 RESOURCE_CONFLICT` naming every holder, and nothing read.
37783833
*/
37793834
private async requestFlow(raw: any, name: string): Promise<any | null> {
37803835
const slot = await this.requestFlowSlot(name, { packageId: raw?.process_package, runId: raw?.flow_run_id });
3836+
if (isWithdrawnRequestFlow(slot)) {
3837+
if (slot.holders.length === 0) return null;
3838+
throw new PackageScopedNameRefusedError(withdrawnRequestFlowRefusal(name, slot));
3839+
}
37813840
if (slot && typeof this.automation?.getFlowSlot === 'function') return this.automation.getFlowSlot(slot.packageId, name);
37823841
return this.automation!.getFlow!(name);
37833842
}
37843843

3785-
/** [#31696] The key the request `raw`'s flow is filed under ({@link requestFlowSlot}), else its name; `null` for none. */
3844+
/**
3845+
* [#31696] The key the request `raw`'s flow is filed under ({@link requestFlowSlot}), else its name; `null` for none.
3846+
* [#32647] `null` too for a request whose stamped package holds no slot of
3847+
* the name ({@link WithdrawnRequestFlow}): its flow is gone, and the key
3848+
* another package's slot is filed under is not its key.
3849+
*/
37863850
private async requestFlowKey(raw: any): Promise<string | null> {
37873851
const name = typeof raw?.process_name === 'string' && raw.process_name.startsWith('flow:') ? raw.process_name.slice('flow:'.length) : '';
37883852
if (!name) return null;
3789-
return (await this.requestFlowSlot(name, { packageId: raw.process_package, runId: raw.flow_run_id }))?.key ?? name;
3853+
const slot = await this.requestFlowSlot(name, { packageId: raw.process_package, runId: raw.flow_run_id });
3854+
if (isWithdrawnRequestFlow(slot)) return null;
3855+
return slot?.key ?? name;
37903856
}
37913857

37923858
/**
@@ -4602,7 +4668,9 @@ export class ApprovalService implements IApprovalService, ObjectSchemaReadDelega
46024668
// [ADR-0150 D3] The package this step is declared in — its flow's — which
46034669
// every slate below reads a `queue` approver's name from. [#31696] Read
46044670
// from the run's own slot, whose package the request records (D8 R7).
4605-
const flowSlot = input.flowName ? await this.requestFlowSlot(input.flowName, { runKey: input.flowKey, runId: input.runId }) : undefined;
4671+
const runSlot = input.flowName ? await this.requestFlowSlot(input.flowName, { runKey: input.flowKey, runId: input.runId }) : undefined;
4672+
// No package is asked here, so no stamp can have withdrawn.
4673+
const flowSlot = isWithdrawnRequestFlow(runSlot) ? undefined : runSlot;
46064674
const callerPackageId = this.flowPackageOf(flowSlot?.key ?? input.flowName);
46074675
const submitterId = input.submitterId !== undefined ? input.submitterId : (context.userId ?? null);
46084676
// [#25573] `excludeSubmitter: true` (ruling 6377888641, letter B): the

0 commit comments

Comments
 (0)