Repository navigation
Commit 57657df
fix(plugin-approvals): a refused fan-out run and a run held in memory are read by the steps logged by the run's end (#39000)
Part of #38988
Clause-②: no
Metadata-protocol: none
## 维护者速读
-
用户能看到什么变化:审批流程在中途分成多条同时运行的分支时,若运行停在审批处后被取消(仅内存保存挂起状态的部署),或因某条分支走到"拒绝"结束而停止,对账结果不再被其他分支事后补写的步骤带偏。
- 为什么做:这是上一轮"按运行结束时刻读日志"修复(审批分支停止位置问题)留下的未覆盖情形,由合约审查的升级记录点名。
- 出错会怎样:只影响分支并行的审批流;读法只会更保守(从"已通过"变为"待定"),不会把原本判定正确的审批改判;本改动可直接撤回。
- 要你做什么:卡片第 3 项(运行结束后另一分支补写的失败是否算"流程继续")留待你裁决:是否引入"按分支判断"的规则;本 PR
不含该项,并用测试记录了它现在的读法。
## What changes
Item 3 of the card (the routed-failure reading ignoring steps logged
after the run ended, N5's routed-failure half) is **held out of this
PR** for the maintainer's ruling on a fan-out-aware judge; see
Acceptance notes. This PR carries items 1 and 2 and the docblocks N2–N4,
plus N5's `reachedAnEnd` half.
**Item 1 — a suspension held in memory,
`@objectstack/service-automation`, `run-resume.ts`.**
- New module-private `heldStepLog(steps)`: a copy of the step-log array.
- `persistSuspendedRun` writes the held map entry with its own step log,
at the pause. The two durable stores already copy the run as they save
it (`InMemorySuspendedRunStore.save`,
`ObjectStoreSuspendedRunStore.save`); the map did not, so the held entry
was the live array that the other branches of a fan-out kept appending
to.
- `heldSuspensionCopy` hands out its own step log on each read (both
returns, the cycle fallback included), as a store hands a row.
- Shallow, measured: an entry is never written in place once logged; its
one rewrite (`creditChildRun`) replaces the entry at its index, which a
copied array does not see. A deep copy would walk every entry's arrays
for no write.
**Item 2 — a run that reached an end, `@objectstack/plugin-approvals`,
`approval-service.ts`.**
- `childRunsOf`: a step completed after the run's `completedAt` is not
`passed`, on a run that reached an end (`completed`, `refused`)
included. A refusing `end` unwinds the fan-out's `Promise.all` as a
failure does (measured on the real engine below), and the other branches
go on logging.
- `passed` only narrows (true to false), and only where a step's
`completedAt` is strictly later than the run's.
**Docblocks.** N2 (`loggedAfterEnd`: the one-clock premise and what skew
does), N3 (`stopOf`: the cancelled/failed/unresumable sentence rests on
the run being written from its suspension as at the pause, now true of a
held suspension too), N4 (`stopOf`: a late step is left out wherever it
sits, the whole-log fallback; `childRunsOf` leaves them out the same way
with no fallback), N5's `reachedAnEnd` half (`childRunsOf`).
`routedFailure` is byte-identical to the base. `dag-traversal.ts` is
untouched. In `approval-service.ts` (15k lines) the edits are one
condition and docblocks; no new logic was big enough for a sibling
module.
## Tests
Two new files, named for this card. Red first on the base, green after;
one ablation per fix.
<details><summary>Red first on base 20f47c9</summary>
- `held-suspension-steps-38988.test.ts` (engine, no store / failed save
/ control with a store / hand-out): `Tests 3 failed | 1 passed (4)`; the
control (a durable store) passed on the base, as it should.
- `approval-fanout-late-steps-38988.test.ts` (real kernel, ObjectQL,
automation engine, approval node, sqlite): the memory-store cancel cell
`expected 'note' to be 'mid'`; the refused-run cell `expected {
finished: 1 } to deeply equal { undetermined: 1 }`.
</details>
<details><summary>Green at ff6b5f1</summary>
- `pnpm --filter @objectstack/service-automation test`: `Test Files 303
passed (303)`, `Tests 4488 passed (4488)` (run at 4a3c8e1; the later
commits touch only plugin-approvals files).
- `pnpm --filter @objectstack/plugin-approvals test`: `Test Files 145
passed (145)`, `Tests 2279 passed (2279)` (at 4a3c8e1); the two card
files plus the #38691 control file re-run at ff6b5f1: `Tests 8 passed
(8)`.
- `pnpm --filter @objectstack/service-automation typecheck`, `pnpm
--filter @objectstack/plugin-approvals typecheck`: exit 0 (includes
`check:test-typecheck`).
</details>
<details><summary>Ablations (on-disk mutation, restored byte-identical
by hash)</summary>
- Drop the copy at the pause: `Tests 3 failed | 1 passed (4)` (both
held-cancel cells and the hand-out cell).
- Drop the copy at hand-out only: `Tests 1 failed | 3 passed (4)` (the
hand-out cell).
- Drop the `childRunsOf` late-step condition: `Tests 1 failed | 7 passed
(8)` (the refused-run cell, `{ finished: 1 }`).
</details>
## Acceptance notes
- **Item 3 held — measured before/after for `fork_fail_both`** (first
approval, then a fork: `note` fails at 30 ms on its way to the end;
`late` fails at 120 ms on its way to the second approval). At this head
(routed-failure reading unchanged, as on the base): the door writes
`approved`, the reconciler writes `recalled` (`{ abandoned: 1 }`, naming
node `late`). With item 3 applied (measured at 4a3c8e1 plus the
rewritten pin): the door and the reconciler both write `approved`, and
the second approval is never asked. The pins in the last `describe` of
`approval-fanout-late-steps-38988.test.ts` record the reading as it
stands (`fork_fail_both`, and a refused run with a late failure) and are
expected to change with the ruling.
- The new approvals file repeats the harness of the #38691 suite (no
shared harness file exists in the package; the claim names new files for
this card).
- Not measured, observed only: the pause snapshot's `variables` is
`Object.fromEntries(variables)`, so a nested value a late branch writes
into in place would still reach a held suspension before its first read;
the step log was the only aliasing this card measured.
## Verification
Read first: `run-resume.ts` `persistSuspendedRun` (the reassignment
before the map write); `approval-service.ts` `childRunsOf` (the one
added condition); the last `describe` of the approvals test file (the
held reading).
Two minutes: `pnpm --filter @objectstack/service-automation exec vitest
run src/held-suspension-steps-38988.test.ts` shows 4 passed; a run
cancelled where it waited ends at `park`.
Local gates: `dispatch-gates.mjs --ran`: `76 derived famil(ies)
accounted for — 74 run, 2 NOT-MEASURED` (`check:dual-build-cjs-loads`,
`check:i18n`: PREREQUISITE NOT MET, a full build; CI runs them).
`check-plugin-teardown-shape --self-test` first refused on the shallow
clone (pinned fixture commit), passed after fetching that one commit.
---
_Generated by [Claude
Code](https://claude.ai/code/session_01WGufzhKEbEnW8pwZRgK2gJ)_
---------
Co-authored-by: Claude <noreply@anthropic.com>1 parent 5064289 commit 57657df
5 files changed
Lines changed: 528 additions & 11 deletions
File tree
- .changeset
- packages
- plugins/plugin-approvals/src
- services/service-automation/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 | + | |
0 commit comments