You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 5704d13
Browse filesBrowse the repository at this point in the historyBrowse files
fix(plugin-approvals): a terminal run is read by the steps it logged by its end, not a fan-out branch's late steps (#38978)
<!-- claude-projects-attribution: {"github_login":"os-support-ai"} -->
_Requested by **Yibo Wang** · [project
thread](https://claude.ai/code/project/chan_01BVUyyPie8gHwoPM18iABwB?thread=cmsg_01BVUyyPie8gHwoPM18iABwB12LHqjnJsWFhAJNYDzW4BQ)_Fixes#38691
Clause-②: no
Metadata-protocol: none
## 维护者速读
-
问题:流程在顶层同时分出两条分支时,一条分支失败后另一条还会继续跑,并在运行已经结束后往日志里追加步骤。审批插件把"日志最后一步"当成运行停下的位置,于是对账时把失败位置认错,还会把一个没有历史行的子运行当成"已通过"。
- 已复现(真实引擎):修复前新测试 2 个失败、2 个通过;修复后 4 个全部通过。
- 做法:审批插件只按运行 `completedAt` 之前完成的步骤来判断停在哪里、哪些步骤已过。没有 `completedAt`
的运行、同一毫秒完成的步骤,读法不变。
- 顺手修正:卡片第 2 到 5 项(一处注释、一次重复序列化、两个缺失的测试、spec 文件里一段注释,没有改 schema)。
- 另外发现一个越界问题(失败的运行上仍会打开新的审批请求),已立为 #38985,不在本 PR 里修。
- 审查指出的三种未覆盖情况(挂起状态只在内存里、被拒绝的运行、`routedFailure` 仍读晚到的步骤)已立为后续卡 #38988。
- 要你做什么:无。
## What changes
**Item 1 (N23 + `stopOf`), `@objectstack/plugin-approvals`,
`approval-service.ts`.**
- New helper `loggedAfterEnd(step, ended)`: a step whose `completedAt`
is strictly later than the run's `completedAt`.
- `stopOf(log, status, endedAt?)` skips those steps when it picks the
last top-level step of a terminal run.
- `childRunsOf(…, endedAt?)` computes the last in-run step without them,
so `passed` (a step before the last one) no longer counts a step another
branch completed after the run ended.
- The three call sites pass `run.completedAt`; the run read type gains
`completedAt?`. The docblocks now say log order is a convention, and
why.
- Unchanged: a run with no `completedAt`, a step completed in the same
millisecond as the run, a paused run (the parked-visit guard still
applies), and a run cancelled from its pause (pinned as a control).
**Item 2 (N14), `@objectstack/service-automation`,
`engine-run-log.ts`.** The `MAX_STEP_CHILD_RUN_IDS` docblock (the
constant moved here from `engine.ts`) names `MAX_RUNS_READ_PER_APPROVAL`
in `@objectstack/plugin-approvals`. Both are 200 on the base. The
real-engine reconciler suite already ties them
(`approval-reconciler-37767.integration.test.ts`, the case near line
1533), so no new tie is added.
**Item 3 (N15), `suspended-run-store.ts`.** `serializeStepsBounded`
stringifies the log once. Under the cap it returns that string; over it,
it sheds and halves as before. An empty log still returns `null`.
**Item 4 (N16), `step-child-runs.test.ts`.** Two cases: a log still over
the cap after the shed is halved, with the newest steps kept and marked;
and the 28-byte band, where a log that fits only without its marks is
halved while the same log with no links is kept whole.
**Item 5 (N17), `@objectstack/spec`, `execution.zod.ts`.** Comment only,
over `childRunIds`: the list is bounded and can be shed (seat ruling
7258590209, ruling 7268216330), so a reader cannot count on reaching
every run of its tree from the log alone. No schema byte and no
`.describe()` text changes.
## Reproduction (item 1, real kernel)
New test
`packages/plugins/plugin-approvals/src/approval-fanout-stop-38691.test.ts`,
on the real-kernel harness of
`approval-reconciler-37767.integration.test.ts`. Flow `fork_fail`: an
approval, then a top-level fork to a slow subflow branch (`mid`) and a
branch (`note`) that fails first.
- The stored log of the failed run reads `… note(failure),
mid(success)`, and `mid.completedAt` is later than the run's
`completedAt`. This is the card's premise, measured.
- The reconciler and the decision door give the same sentence: "ended
failed at node 'note', between two steps".
- A child run with no history row under a step completed after the run's
end is not taken as passed: the result is undetermined and the record
stays pending.
- Control: a parked run that is cancelled is still read as abandoned at
`mid`.
Red first on the base (origin/main `d38006b9`, test only): 2 failed, 2
passed. The two failures: the door said "its node 'note' failed between
two steps, and the flow went on…", and the reconciler counted `finished:
1` for the child with no row. On this head: 4 of 4 pass.
`step-child-runs.test.ts`: 12 of 12 pass.
## Out of scope, measured: #38985
After `note` fails, the other branch keeps running and can reach a later
approval step. In a probe (`mid` → `second`, an approval), approving
`first` answers `RESUME_FAILED`, the run is `failed`, `second` is opened
and stays `pending` on the failed run, the record stays `pending`, and
the record carries no reconciliation mark, so the reconciler never
judges it. That is a different defect: which branch runs, not how the
log is read. This PR does not change it. It is in the #38838 family and
is filed as #38985.
## Acceptance notes
- File surface is the claim's: `approval-service.ts` (`stopOf`,
`childRunsOf`, the new helper, three call sites and their run type),
`engine-run-log.ts` (docblock), `suspended-run-store.ts`
(`serializeStepsBounded`), `step-child-runs.test.ts`, `execution.zod.ts`
(comment), the new test, the changeset. `run-history.ts` (#38674, PR
#38969) is not touched; #38969 carries the `engine.ts` `getRun` docblock
line, as agreed with the seat.
- Semver: `patch` on the three packages. `Clause-②: no`: no accept set,
export or schema moves; one read (where a terminal fan-out run stopped,
and whether a step passed) changes in the cell above.
- L2 at the contract-review tier: PASS, comment 7318891630 (no must-fix,
no should-fix). Its escalation (a suspension held in memory, a refused
fan-out run, `routedFailure` reading late steps, with nits N2 to N5) is
the follow-up #38988; this PR keeps `Fixes#38691` on the seat's ruling.
L1 owed.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
https://claude.ai/code/session_01WGufzhiGvpFMQX4XptMEtQ
<!-- signed: repo:objectstack@os-support-ai · os-support-ai ·
session_01WGufzhiGvpFMQX4XptMEtQ -->
---------
Co-authored-by: Claude <noreply@anthropic.com>
fix(plugin-approvals): an approval's run is read by the steps it logged by its end, not a fan-out branch that went on after it
8
+
9
+
Clause-②: no
10
+
Metadata-protocol: none
11
+
12
+
When a flow's node fans out to branches that run together and one branch fails, the automation engine does not stop the others: they go on appending steps to the run's log after the run has ended. The approvals plugin read the last top-level step of a terminal run as where it stopped, and any later step as the run going on past a step, so a step another branch completed after the run's end moved both readings: the reconciler placed a failed run at the other branch's node (and told a failure the flow never routed as one it went on from), and took a child run with no history row as passed. Both readings now use only the steps the run completed by its `completedAt`; a run that names no `completedAt`, and a step completed in the same millisecond, read as before.
13
+
14
+
Also: the terminal history row serializes a log under its size cap once, not twice (`@objectstack/service-automation`); the source comment over the step log's `childRunIds` no longer says a reader reaches every run of its tree from the log alone, since the list is bounded and can be shed (`@objectstack/spec`, comment only, no schema change).
it('a log that fits the cap without its links by less than its marks cost is halved, where the same log that named no child run is kept whole',async()=>{
.describe('The data engine\'s own drop events behind those warnings: which caller-supplied fields of which object the write did not store, and why. Absent when the step dropped nothing'),
219
219
// [ADR-0162 Execution item 8] The child runs a delegating step started, so a
220
-
// reader of one run can reach every run of its tree from the step log alone:
221
-
// a child's own log is a row of its own, and nothing else on the parent's
222
-
// log names it once the parent has moved past the step.
220
+
// reader of one run can follow its log to the runs of its tree: a child's
221
+
// own log is a row of its own, and nothing else on the parent's log names it
222
+
// once the parent has moved past the step. Not to every run of it: the list
223
+
// is bounded and can be shed (`childRunIdsTruncated` below, seat ruling
224
+
// 7258590209 and ruling 7268216330), so a reader takes a marked step for
225
+
// one that named only some of its runs, or none.
223
226
childRunIds: z.array(z.string()).optional()
224
227
.describe('Run ids of the child runs this step started: the one run of a `subflow`, and for a `map` the item runs this execution of the step started, at most 200, the first ones started. Absent for a step that started none, and where `childRunIdsTruncated` says the links were shed'),
225
228
// [ADR-0162 Execution item 8] Seat ruling 7258590209 on #37767: the list is
0 commit comments