Repository navigation
Commit f28091a
fix(approvals): a record delete cancels the flow run its voided approval gated (#38293)
<!-- claude-projects-attribution: {"github_login":"os-sales"} -->
_Requested by **Sales** · [project
thread](https://claude.ai/code/project/chan_01D5bWFY3rFzgJcytD5gD4Uu?thread=cmsg_01D5bWFY3rFzgJcytD5gD4Uu39QwNEMYYq9N1C1xLDGdAJ)_
Refs #37763
Clause-②: yes (widening)
Metadata-protocol: none
## 维护者速读
-
用户能看到什么变化:单据在等审批时被删掉,等这条审批的流程运行现在当场结束,状态为「已取消」并写明原因是单据被删;批准、驳回两条后续都不走。审批套在子流程里时上层一并取消;批量审批里的一条被删,批量接着走下一条。
- 为什么做:维护者在这张卡上选了「自动取消」;此前这类运行永远停在「暂停」,和真在等人批的运行分不出来。
- 出错会怎样:取消失败不会让删除失败,那条运行照旧停着并在告警里点名,和今天一样;本 PR 之前留下的旧运行不自动清理。可直接撤回。
- 要你做什么:无。审批技能与审批指南各补的一句另开 PR(受治理路径,需你合并)。
## What changes
- `packages/plugins/plugin-approvals/src/approval-service.ts`
- `cancelForDeletedRecord`: after voiding every pending request of the
deleted record (unchanged), it ends the run each request gated through
the new private `cancelRunsOfVoidedRequest`. It answers a new
`cancelledRuns` list (a new member of a public method's answer on the
exported `ApprovalService`, hence `Clause-②: yes (widening)`);
`suspendedRuns` keeps its meaning, the runs left behind, which are now
only the runs that could not be cancelled, and the warning fires only
for those. With no `cancelRun` on the engine it logs at `error` in the
delete's own words (not the decision door's `missingRunCapability` line)
and the run is left.
- `cancelRunsOfVoidedRequest`: cancels the request's run with the reason
`approval request ID was cancelled because the record it is about was
deleted`, then every `subflow` parent above it on the same record,
deepest first, through the engine's existing `cancelRun`. If the top of
that chain is a `map` item, the batch above it is read first
(`batchAboveItem`, as the revise-window recall does) and woken
afterwards through the existing `resumeBatchOfRecalledItem`, which now
takes a `cause` so its log and message say which of the two cancelled
the item. ⛔ No resume is ever sent to a `subflow` parent; neither the
`approve` nor the `reject` branch runs.
- `voidedRunChain`: finds the chain with existing reads only. The
request row's `record_run_id` (ADR-0162 Execution item 7) is the highest
run over the same record; the walk goes down from it along each parent's
correlation (`subflow:CHILD`, `map:CHILD`) through `suspensionOf`, one
keyed read per hop, until it reaches the request's `flow_run_id`, and
cuts the chain below its lowest `map:` link (a batch is woken, never
ended). Bounded at 32 hops.
- Docblocks of `cancelForDeletedRecord`, `REQUEST_STATUS_STRANDABILITY`
and `ApprovalResumeSurface.suspensionOf` updated to the ruling.
- Tests: the existing "must not cancel" pin in
`record-delete-cancel.integration.test.ts` is rewritten to the ruling,
plus a failed-cancel case; the real-engine cases are a new top-level
`describe` in `batch-item-recall-resumes-batch.test.ts` (the shared
harness for a cancelled batch item).
- Changeset: `.changeset/approval-delete-cancels-parked-run.md`,
`@objectstack/plugin-approvals` patch, which also says how an
administrator finds the runs left paused by earlier deletes.
⛔ Not changed: `service-automation` (no engine member added,
`run-resume.ts` untouched), `packages/spec`, the delete hook in
`lifecycle-hooks.ts` (it already calls `cancelForDeletedRecord` and
swallows its failures).
## Why
Maintainer ruling on #37763, option A (card comment 7237973760): the run
parked on a request its record's delete voided is cancelled in the same
step, end state `cancelled`, reason the delete; neither branch runs; the
delete is never refused and a failed cancel never fails it; a batch item
wakes its batch (as PR #28228 does for a revise-window recall); inside a
subflow the parent chain is cancelled too, never resumed; runs parked by
earlier deletes are not cleaned up.
### The ruling's three premises, measured before writing
Probe: real `AutomationEngine` + real `ApprovalService` over the fake
engine of `batch-item-recall-resumes-batch.test.ts`, in-memory
suspended-run store, on `main` `f19350b4`. Probe file and its output are
kept outside the repo (the project's shared folder,
`37763/probe-37763.test.ts` and `probe-37763-readings.txt`); 5/5 passed.
| premise | reading |
|:-|:-|
| ① `cancelRun` on a run parked at an approval node succeeds and leaves
no other state | `true`; history `cancelled` with the reason as `error`;
nothing parked; `hasSuspendedRun` false; `inspectConsumedSuspension`
answers `NO_CONSUMED_SUSPENSION`; a second call answers `false`; the
request row untouched (`cancelled` / `record_deleted`). On `main` the
run stays parked after the delete. |
| ② the existing wake-the-parent path moves a batch on |
`batchAboveItem` before, `cancelRun` on the item,
`resumeBatchOfRecalledItem` after: no error, item 2's request opens;
after approving it the batch completes, its reader ran once. |
| ③ inside a subflow the parent stays parked, and the existing cancel
suffices | Measured: after cancelling the child the parent stays parked
at the `subflow` node on `subflow:CHILD`. The parent is reachable with
existing surfaces: `record_run_id` names the top of the chain and
`suspensionOf` names each child; a three-level chain was cancelled
deepest first with all three `cancelled` and nothing run after the
subflow; a batch item that runs its sign-off in a subflow was cancelled
as a chain and the batch moved on. No new contract surface. |
Small decisions taken in the thread (listed for review):
- The chain is cut below its lowest `map:` link, so a batch whose items
carry no record of their own is woken, not cancelled (the ruling's batch
rule, read literally).
- A request with no `record_run_id` (opened before requests recorded it,
or on an engine that hands no record run) cancels only its own run and
logs nothing: that is also every flat run on such an engine, where a
warning would be noise (seat ruling on review finding S1). An engine
without `suspensionOf`, or a walk that does not reach the request's run,
cancels the request's own run alone and warns that a run above it may
stay parked.
- A `cancelRun` that throws stops the chain there: that run and the runs
above it are logged at `error` (as the revise-window recall's failed
cancel is) and named in the summary `warn`. A `false` answer (no
suspension under that id, or a store the engine could not read, which
the engine names at `error` itself) does not stop the chain.
- The runs are cancelled after every request of the record is voided, so
a failing cancel never leaves a later request in the inbox.
## Verification
- `batch-item-recall-resumes-batch.test.ts`, new `describe('a record
delete cancels the run its voided request gated (#37763)')`, 7 cases: a
flat run (cancelled with the reason, neither branch's node ran, nothing
parked, no log); a batch item (cancelled marker in its slot, outside
`count`, next item opens, batch completes); a three-level subflow chain
(cancelled deepest first, every reason the delete, `resume` never
called, nothing after the subflow ran); a batch item whose sign-off is
in a subflow; a request with no `record_run_id` (own run cancelled, no
log); a `suspensionOf` that throws; a `cancelRun` that throws.
- `record-delete-cancel.integration.test.ts` (real ObjectQL + SQLite,
the real delete hook): the "runs no flow node" pin now asserts one
`cancelRun('run_1', reason)`, no `resume`, no left-behind warning; two
new cases: `cancelRun` rejects, the delete lands, the request is
`cancelled`, the run is named in the warning; and an engine with no
`cancelRun`, where the delete lands and the run is named in the delete's
own `error` line and in the warning.
- Reverse check: with `approval-service.ts` restored to `main`, 8 of the
new or rewritten cases fail (all 7 above, and the rewritten pin);
restored to the head (`git hash-object` equal to `HEAD`), all pass.
<details><summary>Local runs</summary>
Head `e103c2e0` (base `main` `f19350b4`; `e103c2e0` is the review fix on
top of `948f4494`; the 9 commits `main` gained since touch none of
`plugin-approvals`, `service-automation` or `objectql`).
- `pnpm --filter @objectstack/plugin-approvals test` (whole package,
under the verify lock): 131 files, 1988 tests passed, 0 failed (at the
head; 1987 at `948f4494`). `pnpm --filter @objectstack/plugin-approvals
typecheck`: exit 0.
- `npx eslint` on the four changed source and test files: exit 0.
- Reverse check above: 8 failed / 21 passed in the two touched test
files with `approval-service.ts` at `main`; 29/29 at `948f4494`; the two
touched files 30/30 at the head.
- `node scripts/pm/dispatch-gates.mjs --repo objectstack-ai/objectstack
--ran FILE` (exit codes recorded before any pipe): **72 derived, 69 run,
3 NOT-MEASURED, 0 UNRUN**, every run family exit 0 (at `948f4494`; the
review fix touches the same four files and re-ran the package suite,
typecheck and eslint). NOT MEASURED (exit 3, prerequisite not met):
`check-plugin-teardown-shape.mjs --self-test` (its fixture commit is
outside this shallow clone), `check:dual-build-cjs-loads` and
`check:i18n` (they read dists of packages not built in this container;
only the `plugin-approvals` closure is).
</details>
## Acceptance notes
- A record deleted while its request is `returned` (in a revision
window) is outside the ruling: only `pending` requests are voided by a
delete, so that run is untouched, as before.
- The approvals skill and the approvals guide gain one sentence each in
a separate PR, #38295 (`skills/**` is Tier H); that one is the PR that
finishes the card, so this one only refers to it.
## Human Minimum
- [x] 1. Schemas start as Zod; `packages/spec` holds no runtime logic.
(not touched)
- [x] 2. Every name I added uses the casing for its kind.
- [x] 3. No formatter ran; eslint on the changed files passes (the full
`pnpm lint` was not run locally; CI runs it).
- [x] 4. One issue, one branch off an up-to-date `main`, one pull
request. (branch `claude/project-thread-sz9xxz` is the harness-assigned
name)
- [x] 5. A change that publishes carries a changeset, and both
declaration lines are filled in here and in the changeset.
- [x] 6. `packages/spec` touched: no.
- [x] 7. No hand edits to `content/docs/references/`,
`packages/*/CHANGELOG.md` or `content/docs/releases/`.
- [x] 8. Title, body and comments are in English (the 维护者速读 block is the
maintainer summary).
- [x] The *Before Submitting* list in CONTRIBUTING.md is done.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
https://claude.ai/code/session_01L6bhgUpmvWke9Z2P4VKvaD
<!-- signed: repo:objectstack#2 · os-sales ·
session_01L6bhgUpmvWke9Z2P4VKvaD -->
---------
Co-authored-by: Claude <noreply@anthropic.com>1 parent c2a3e61 commit f28091a
5 files changed
Lines changed: 510 additions & 39 deletions
File tree
- .changeset
- packages/plugins/plugin-approvals/src
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
0 commit comments