Repository navigation
Commit 828b6ec
fix(automation): reading one run answers its terminal store row over this process's stale paused entry (#38969)
Fixes #38674
Clause-②: no
Metadata-protocol: none
## 维护者速读
- 多进程部署下的审批使用者:一台进程已办完的审批,另一台进程读取这次流程运行时,以前可能显示为“暂停中”,现在正确显示为“已完成”。
- 属于审批流程的数据可靠性工作:防止审批插件把其实已经完成的审批误判为放弃。
- 出错的话,某次运行的状态会读错(误判已结束或仍暂停);改动只在读取顺序上,可直接撤回本 PR 恢复原行为。
- 无。
## What changes
`getRun` (`packages/services/service-automation/src/run-history.ts`)
answered from this process's in-memory ring first and returned the ring
entry before it asked the store. A run that paused here and was resumed
and finished by another process kept reading `paused` here although the
store held its terminal row.
Now:
- **Terminal ring entry**: answers alone, with no store read
(unchanged).
- **Non-terminal ring entry** (`paused`): `loadTerminal` is asked. A
terminal row answers, **unless** the store also holds a live pause for
the run (`store.load`), in which case the ring entry answers.
- **No terminal row**: the ring entry answers, and the suspension row is
not read for it (unchanged).
- **No ring entry**: unchanged (terminal row, then paused row).
**Default read and strict read change together.** Which source answers
is not what `strict` decides. Strict (ADR-0162 Execution item 8) decides
only what a store failure becomes. The default readers act on the same
stale `paused` answer: the run-detail route shows a finished run as
paused, and the approvals dead-run sweep skips a run that ended. One
precedence keeps the two reads telling one story. On either new read
failing, the default read answers the ring entry and logs a `warn`
naming that degradation. The strict read throws the store failure, as it
already does for its other two reads.
**Why the live-pause exception (a measured deviation from the card's
literal Ask 1).** The literal rule ("a terminal row wins over a
non-terminal ring entry") turned `consumed-suspension-restore.test.ts` >
"records the run as paused again, so the repair is not invisible" red
(`expected 'failed' to be 'paused'`). `restoreConsumedSuspension`
re-parks a run that failed mid-resume. It re-persists its pause and logs
a NEW `paused` ring entry, and it leaves the run's `failed` row in
place. Its own comment says that `getRun`'s ring-first order is what
makes the restored `paused` the answer. There the ring entry is the
later word, not the stale one. Under the literal rule the approvals
plugin's strict read would read a restored approval run as `failed`, the
same wrong-ending harm the card exists to stop. The discriminator: a run
another process finished has no live pause left (a resume claims the
pause before it continues). A restored run has one again. Every case the
card describes (a second engine finished the run, or a terminal row
written with no live pause) answers the terminal row.
**Cost.** One `loadTerminal` (a single-row read by id) only for a run
whose ring entry is non-terminal, plus one `store.load` only when a
terminal row is found. A process with no ring entry for the run already
pays `loadTerminal` and `load`. Hot paths that call `getRun` per row:
the approvals dead-run sweep and the stranded-request scan (one call per
pending request) now pay one indexed read for each request whose run is
paused in this ring. The Runs list does not call `getRun`
(`listRunsPage`), so it pays nothing.
### Consumers that act on a non-terminal answer (Ask 3)
None reads the ring directly: `git grep -n executionLogs` outside
`packages/services/service-automation` has 0 hits at `645e6b15`. Every
consumer goes through `getRun`:
- `plugin-approvals` `placeApprovalRun` (via `readApprovalRun`,
**strict**): this is the abandonment path. A `paused` answer with no
pause found (`suspensionOf`) reads `pause_gone`, and once a later
judgement reads the same, the run is read as stopped and the approval as
ended.
- `plugin-approvals` `runsReadAtOpening` (**strict**): child runs read
`paused` are not kept as ended.
- `plugin-approvals` dead-run sweep (default): releases a pending
request only on a terminal answer, so a stale `paused` delayed the
release.
- `plugin-approvals` `inspectStrandedRequests` (default, report only),
`runHasEnded` (display only), the flow-name lookup at the decision door.
- `runtime` run-detail routes (`domains/automation.ts`), the MCP run
read (`domains/mcp.ts`), `flow-slot-view.ts`.
- Engine-internal: `restoreConsumedSuspension`'s refusal reasons and
`continuePastCancelledMapItem` (`run-resume.ts`).
**Docblock.** The published `AutomationEngine.getRun` docblock in
`engine.ts` now states the new order: a terminal in-memory entry, else
the terminal history row unless the store holds a live pause, else a
non-terminal in-memory entry, else the suspension row. Claim amendment 1
added this one docblock to the file surface; nothing else in `engine.ts`
changes.
**Read first** (by risk):
1. `run-history.ts` `terminalRowUnlessParked`: the live-pause exception
and its failure arms.
2. `run-history.ts` `getRun`: the `terminal` handoff out of the
`loadTerminal` try, and the `inMem` return placed before the paused-row
probe.
3. `run-history-terminal-row-wins.test.ts`: the two-engine pin.
**Two-minute check:** `pnpm --filter @objectstack/service-automation
exec vitest run --maxWorkers=2 src/run-history-terminal-row-wins.test.ts
src/consumed-suspension-restore.test.ts`. Expect 38 passed.
## Tests
New
`packages/services/service-automation/src/run-history-terminal-row-wins.test.ts`
(14 tests). Each of the first 5 runs on both the default and the strict
read:
- engine B resumes and completes a run engine A parked: A answers
`completed` (the card's "second engine" pin);
- a terminal row written straight to the store, with no live pause left:
answers `cancelled`;
- a terminal row beside a live pause: the ring's `paused` answers (1
`loadTerminal`, 1 `load`);
- no terminal row: ring `paused`, 1 `loadTerminal`, 0 `load`;
- terminal ring entry: 0 store reads;
- `loadTerminal` or `load` throws: the default read answers `paused` and
logs one `warn`; the strict read rejects with the store's error.
<details><summary>Red first, and the ablation of the fix (HEAD 7ae8901,
by scripts/ablation-replace.mjs, restore verified blob ==
HEAD)</summary>
Ablation 1 put back origin/main's `if (inMem) return inMem;`. Result:
**12 failed / 26 passed** over the new file plus
`consumed-suspension-restore.test.ts`. All 12 new-file tests outside the
"terminal ring entry: 0 store reads" pair went red, for example
`expected 'paused' to be 'completed'` and `expected 'paused' to be
'cancelled'`. The two "0 store reads" tests stay green by design: that
behaviour is unchanged.
Ablation 2 replaced `return parked ? inMem :
this.runRecordToLogEntry(terminal);` with the literal rule. Result: **3
failed / 35 passed**: both "beside a live pause" tests, and
`consumed-suspension-restore.test.ts` > "records the run as paused
again, so the repair is not invisible".
</details>
<details><summary>Package suite and typecheck</summary>
- `pnpm --filter @objectstack/service-automation exec vitest run
--maxWorkers=2` at 6cddeb3 (literal rule): 1 failed / 4477 passed. The
failure was the restore test above, which led to the live-pause
exception. After 9300337, the new file plus
`consumed-suspension-restore`, `run-history`,
`engine-residual-log-cause` and `multi-replica-resume-staleness`: 5
files, 97 passed.
- `pnpm --filter @objectstack/service-automation build && … typecheck`:
exit 0. `check:test-typecheck: OK — 0 file(s) / 0 error(s)`.
- At head 730465d (the docblock commit): build and typecheck exit 0,
and the built `dist/index.d.ts` carries the new sentence (1 hit).
`run-history-terminal-row-wins.test.ts` + `run-history.test.ts`: 2
files, 36 passed.
</details>
## Acceptance notes
- Not changed, noted: a run parked here, resumed by another process and
parked again at a later node, still answers this ring's older `paused`
entry, whose steps stop at the earlier node. The status is right but the
step log is stale. The store's newer suspension row is not read when no
terminal row exists. Read from the code; not reproduced.
- Not changed, noted: a terminal row beside a suspension row whose
delete was lost answers the ring's `paused`. That is today's answer, so
nothing regresses.
- `test:repo` was not run locally (CI `Test Core`). Approvals plugin
tests were not run locally: the public types are byte-unchanged, and CI
runs them.
## Verification
Local gate subset: `node scripts/pm/dispatch-gates.mjs --commands`
derived 70 commands at 7ae8901, reconciled with `--ran`. See the report
comment on the card for each exit code. Two came back NOT MEASURED
(prerequisite not met, not a pass): `check-plugin-teardown-shape
--self-test` (a shallow clone cannot reach its pinned fixture commit)
and `check:dual-build-cjs-loads` (needs a full `pnpm build`). Both go to
CI.
At head 730465d: the derivation grew to 72 commands
(`check:facade-delegation-only` and `check:startup-registry-verdict`
joined for `engine.ts`). Both exit 0. `check:doc-authoring`,
`check:issue-citations`, `check:nul-bytes`, `check:adr-anchors`,
`check:adr-symbol-anchors`, `check:durability-log-level`,
`check:type-check-debt` and `check:type-check-coverage` were re-run: all
exit 0. `overlap-check`: `VERDICT clean exit 0`.
---
_Generated by [Claude
Code](https://claude.ai/code/session_01WGufzhKEbEnW8pwZRgK2gJ)_
<!-- signed: repo:objectstack@os-support-ai · os-support-ai ·
session_01WGufzhKEbEnW8pwZRgK2gJ -->
---------
Co-authored-by: Claude <noreply@anthropic.com>1 parent 5704d13 commit 828b6ec
4 files changed
Lines changed: 357 additions & 9 deletions
File tree
- .changeset
- packages/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 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4310 | 4310 | | |
4311 | 4311 | | |
4312 | 4312 | | |
4313 | | - | |
4314 | | - | |
| 4313 | + | |
| 4314 | + | |
| 4315 | + | |
4315 | 4316 | | |
4316 | 4317 | | |
4317 | 4318 | | |
| |||
| 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 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
0 commit comments