Repository navigation
Commit 153869d
fix(runtime,service-automation): a write in an action, hook or job body, or a flow record node, that landed under a failing roll-up answers its own success (#29283)
<!-- claude-projects-attribution: {"github_login":"os-steve"} -->
_Requested by **Steve** · [project
thread](https://claude.ai/code/project/chan_01FdL1XeUyvVNxLreh3F4Qi9?thread=cmsg_01FdL1XeUyvVNxLreh3F4Qi98nf8o68Xa2qqqX5Z9XoQ7N)_
Fixes #28861
Clause-②: yes (widening)
Metadata-protocol: none
Skills-docs: none — no file under `skills/**` or the docs teaches what a
body's or a flow node's write answers when a parent roll-up cannot be
recomputed after it, and this changes no authorable shape
## 维护者速读
- 改了什么:动作处理器的 `ctx.engine` / `ctx.api`、沙箱里 hook / 动作 / 任务正文的
`ctx.api.object(x)`、以及流程的 `create_record` / `update_record` /
`delete_record`
节点,在写入已落库、只是父记录汇总重算失败(`ERR_SUMMARY_RECOMPUTE`)时,返回这次写入本来的成功结果,正文和流程继续往下跑;过期汇总列按字段每进程以
error 记一次日志。REST 动作入口和 MCP `run_action` 只在声明式 update 动作上把拒绝里挂的结果当作成功。
-
为什么改:以前这个拒绝直接抛进作者代码:写入其实已经生效,但正文下一行不再执行,动作、hook、任务或流程都报失败,调用方重试就会再写一遍。数据入口和
MCP 工具早已按成功答复,作者代码这一侧没有跟上(席位裁定 6570987196)。
- 风险与回滚:写入前的拒绝(校验、权限、约束)完全照旧;没有新错误码、字段或形状,也没加事务。回滚就是整体 revert 本
PR,没有数据或元数据迁移。
- 先看:`packages/runtime/src/action-execution.ts`(`invokeBusinessAction` 的
catch 和 `withoutWriteAnswer`、`buildActionEngineFacade` 的多 id
删除);`packages/runtime/src/landed-write-answer.ts`;`packages/services/service-automation/src/builtin/crud-nodes.ts`。
- 两分钟验证:`pnpm --filter @objectstack/runtime exec vitest run
src/action-body-write-stale-summary.test.ts
src/sandbox/body-write-stale-summary.test.ts`,应看到 2 个文件、19 个测试全部通过。
- 需要你做的:无,席位落地。
## What changes
Seat ruling 6570987196 on #28861: a write the engine stored answers its
own success at every author-visible write surface when only the parent
roll-up recompute after it fails. The refusal is objectql's
`SummaryRecomputeError` (`ERR_SUMMARY_RECOMPUTE`), whose `written` is
exactly what the call returns on a healthy recompute. Each surface
returns that `written` value and logs the stale column through
`staleSummaryAnswerLines` (`@objectstack/types`), the same line the data
doors log. Every other throw, including a refusal raised before the
write is stored, is rethrown unchanged (`staleSummaryRefusalOrThrow`).
No new error code, member, shape or transaction.
- **Shared layer** (new `packages/runtime/src/landed-write-answer.ts`):
- `landedWriteAnswer(e, object, surface)` is the one `catch` body.
- `answerLandedWritesDespiteStaleSummary(api, surface)` wraps every
repository write verb of a scoped API, on the API and on every context
it derives (`object(name)`, `sudo()`, `withRunAs(...)`, a
`transaction(fn)` callback's context, `beginTransaction()`'s `ctx`). It
walks the API through the existing `deriveThroughSeam`, and the verb
list is the existing `WRITE_RETURN_VERBS`. Both are now exported from
`stored-metadata-reader-seam.ts`, so there is one definition of what a
write is and what an API derives. Idempotent.
- **`ctx.engine`** (`buildActionEngineFacade`, `action-execution.ts`):
`insert` answers `{ id }` read from the written record; `update`
resolves. A multi-id `delete` catches per id, so a stale roll-up after
one id no longer leaves the later ids undeleted.
- **`ctx.api`** (`buildActionApi`, objectql `createContext`): wrapped
beneath `serveStoredMetadataReadsThrough`, so the answer is served by
the reader seam like any write's return.
- **Sandbox `ctx.api.object(x)`** (`buildSandboxApi`,
`sandbox/body-runner.ts`): wrapped beneath both body refusal layers,
over whichever source the API is built from: the engine's hook API, the
host's action `api`, or a job's `executionContext` + `createContext`
fallback. Hook, action and job bodies all go through it.
- **Flow record nodes** (`builtin/crud-nodes.ts`,
`@objectstack/service-automation`): `create_record` / `update_record` /
`delete_record` wrap their one data call. The node answers the same
`output`, `outputVariable`, `droppedFields` and `acted` it answers on a
clean write, with the stale line on the node's logger at `error`. A
non-stale throw reaches the node's existing `catch` and is `success:
false` as before. `packages/runtime/src/domains/automation.ts` (#29097's
file) is not touched.
- **The action doors' generic `earnedAnswerOf` reading is pinned to the
declarative-update arm.** That arm composes and attaches the ACTION's
result (#28856). Any other arm's refusal could only carry a WRITE's data
answer, for example a handler that let out a refusal a data door had
attached its answer to.
- REST action door (`dispatchAdmittedRestAction`'s catch,
`domains/actions.ts`): reads it only when
`isDeclarativeUpdateAction(actionDef)`; any other arm answers the
failure as before #28856.
- `invokeBusinessAction` (MCP): the audit row is `succeeded` only on the
declarative arm. Any other arm's throw leaves with nothing attached
(`withoutWriteAnswer` rebuilds the same `SummaryRecomputeError`: class,
`failures`, `written`, message, stack). So `run_action`'s generic
`landedWriteResultOrError` in `packages/mcp/src/mcp-http-tools.ts` (not
edited) cannot relay a write's answer as the action's result either.
- **Changesets:** new
`.changeset/28861-body-write-stale-summary-answer.md` (runtime and
service-automation patch). The last sentence of the still-pending
`.changeset/28856-action-stale-summary-answer.md` is corrected: it said
a `flow` action's record nodes turn the refusal into a node failure and
that script/body was a follow-up, and both stop being true with this PR.
This deliberately reds `check-empty-changeset` (its DELIBERATE
CORRECTION class: "do NOT restore it -- say so on the PR and get it
confirmed"). Confirmation is asked of the seat here.
## Tests
No existing test was edited (no forced test edits). Three new files, red
first on the test-only commit `897a4c53` over `origin/main` `2af0ae2a`.
Each engine double opens its `update` / `delete` / `findOne` with the
producer's predicate (`assertEngineUpdateDispatch` /
`assertEngineDeleteDispatch` / `assertEngineFindOnePredicate`,
`@objectstack/metadata-core`), so it refuses what ObjectQL refuses;
`scripts/engine-double-contract.pinned.json` records the 7 new pinned
rows (`check-engine-double-contract --write`, 0 lost).
- `packages/runtime/src/action-body-write-stale-summary.test.ts` (14).
The real `HttpDispatcher` over objectql's real `ScopedContext`
(`createContext`), with an audit service and an engine double whose
writes apply and then throw objectql's own `SummaryRecomputeError`.
- `ctx.engine` insert, update and a multi-id delete (every id deleted).
- `ctx.api` `object(x).insert`, `update` + `delete`, and a derived
context (`sudo()`).
- NEGATIVE PIN: five pre-write refusals (`it.each`) reach the body as
before, nothing written.
- Door pin: a script action body that throws a stale refusal carrying an
attached answer. REST answers exactly what the same body answers when it
throws the bare refusal, and never the attached answer. The MCP bridge
throws the refusal with `earnedAnswerOf` undefined, code
`ERR_SUMMARY_RECOMPUTE`, and an audit row `failed`.
- One `error` line naming `"stv_account.visit_count"`.
- Red on base: 8 of 14. The 5 negatives and the log pin were green; on
base the log line came from the REST door's generic carrier reading of
the door pin, a reading this PR removes.
- `packages/runtime/src/sandbox/body-write-stale-summary.test.ts` (5),
on the QuickJS runner: a hook body (the engine's hook API, patch
merged), an action body (update + delete, own value returned), a job
body (`createContext` fallback, own outcome), a NEGATIVE PIN
(`VALIDATION_FAILED` / `400` caught in the body, nothing written), and
one `error` line naming `"stb_order.line_total"`. Red on base: 4 of 5,
the negative green.
-
`packages/services/service-automation/src/builtin/crud-stale-summary.test.ts`
(3): a `create_record` → `update_record` → `delete_record` run reaching
its end, with exactly one stale line; the `create_record` executor's
output (`record`, `droppedFields`, `acted: 1`, `outputVariable`); and a
NEGATIVE PIN where a `PERMISSION_DENIED` before the write still fails
the run with nothing written. Red on base: 2 of 3, the negative green.
<details><summary>Ablations: each mutation landed on disk with
<code>ablation-replace</code>, red, then restored to blob == HEAD (final
head <code>e591f329</code>)</summary>
| # | ablation | file | red |
|---|---|---|---|
| A1 | `ctx.engine.insert` rethrows | `action-execution.ts` | 1 of 14 |
| A2 | `ctx.engine.update` rethrows | `action-execution.ts` | 1 of 14 |
| A3 | `ctx.engine.delete` rethrows | `action-execution.ts` | 1 of 14 |
| A4 | `buildActionApi` without the layer | `action-execution.ts` | 3 of
14 |
| A5 | `buildSandboxApi` without the layer | `sandbox/body-runner.ts` |
4 of 5 |
| A6 | `create_record` rethrows | `crud-nodes.ts` | 2 of 3 |
| A7 | `update_record` rethrows | `crud-nodes.ts` | 1 of 3 |
| A8 | `delete_record` rethrows | `crud-nodes.ts` | 1 of 3 |
| N1 | a pre-write refusal answered as success (`landedWriteAnswer`
swallows every throw) | `landed-write-answer.ts` | 8 of 19 |
| N2 | the same in the flow nodes | `crud-nodes.ts` | 1 of 3 |
| N3 | REST door reads every arm's attached answer |
`domains/actions.ts` | 1 of 14 |
| N4 | `invokeBusinessAction` lets a write's answer out |
`action-execution.ts` | 1 of 14 |
| N5 | the audit row reads every arm's attached answer |
`action-execution.ts` | 1 of 14 |
All 13 were first measured on `13f35e09`, then rerun on `7c5f3e55`
(after the double pinning) and on the final head `e591f329` (after
merging `main` with #29036), with the same counts each time. On the
first round, the tries at A5, N3 and N5 were refused by
`ablation-replace` with nothing changed on disk ("the replacement count
moved 1 -> 1"), because the replacement sat inside its anchor. They were
rerun with a `/* ablated */`-prefixed replacement; the counts above are
those runs.
</details>
## Acceptance notes
- **Clause-② measured as widening.** Each changed call answers success
where it threw or failed before. The doors' narrowing to the declarative
arm narrows only #28856's generic reading (PR #28882, merged
2026-11-02). That reading is unreleased:
`.changeset/28856-action-stale-summary-answer.md` is still pending, and
`@objectstack/runtime` is at `18.2.0`. No published surface narrows.
- **Out of the ruling's reach on purpose:** objectql's `ScopedContext`
and the engine itself. Bulk callers (the seed loader, the import runner)
read the refusal as "written, with a stale summary" in their own
results. An in-process code hook's `HookContext.api` is platform or
deployer code, not an author's body. Both are unchanged.
- **Noted, not filed:** objectql's `ObjectRepository.execute()` hands a
nested handler a raw `ScopedContext`. Its own census lists zero callers,
so it reaches no author today.
- The engine's own `warn` per failed recompute is unchanged; the
surfaces add the doors' once-per-field `error` line.
- No `packages/spec/**` or `ui/**` edit, and no workflow file.
## Verification
<details><summary>Suites and typecheck</summary>
- `@objectstack/runtime` full local suite on `281d91ae` (after merging
`main` at `692a4e4a`): 516 of 516 files, 8337 passed and 19 skipped
(`os-verify-lock` VERDICT command-exit 0).
- `@objectstack/service-automation` typecheck exit 0 and full suite 258
of 258 files, 3312 of 3312 tests, on `281d91ae`.
- `@objectstack/mcp` stale-summary neighbours (`mcp-run-action-`,
`mcp-create-record-`, `mcp-update-delete-record-stale-summary.test.ts`):
13 of 13.
- `pnpm --filter @objectstack/runtime typecheck` (`tsc --noEmit` and
`check:test-typecheck`): exit 0. The first read was exit 1 on the
untouched
`organization-ownership-boot-guard.turso-remote.kernel.test.ts` (TS2307,
`@objectstack/driver-turso`). That was a missing `dist` of the optional
peer, not this diff; it was green after building
`@objectstack/driver-turso`.
- After merging `main` again at `c44c8ac4` (head `7365c82a`; `main`
touched objectql and service-automation, not `packages/runtime`):
service-automation typecheck exit 0 and full suite 259 of 259 files,
3317 of 3317 tests; runtime `tsc --noEmit` exit 0; runtime vitest over
the new files, `src/domains` and `src/sandbox`: 219 of 219 files, 4192
of 4192 tests.
- `7c5f3e55` (the doubles opened with the producer predicates): the
three new files 19 of 19 and 3 of 3.
- Final head `e591f329`, after merging `main` at `0c0d3b68` (#29036
landed there as `af8448fe`, editing `action-execution.ts`; merged clean,
both intents kept). Every `packages/**` package built (78 of 78). `pnpm
--filter @objectstack/runtime typecheck` and `pnpm --filter
@objectstack/service-automation typecheck`: exit 0. service-automation
full suite: 260 of 260 files, 3338 of 3338 tests. runtime vitest over
`src/action-*`, `src/domains` and `src/sandbox` (#29036's
`api-action-forward.test.ts` among them): 248 of 248 files, 4665 of 4665
tests.
</details>
<details><summary>Gates</summary>
On the final head `e591f329`, after building every `packages/**` package
(`turbo run build --filter='./packages/**'`, 78 of 78 tasks). The same
71 commands also ran on `7c5f3e55` with the same result:
- `node scripts/pm/dispatch-gates.mjs --commands --repo
objectstack-ai/objectstack` derived 71 commands; each was run with `<
/dev/null`, and `--ran` reconciles **71 derived, 71 run, 0 NOT-MEASURED,
0 UNRUN** (exit 0).
- 70 of 71 exit 0. The one red is `node
scripts/check-empty-changeset.mjs --base origin/main` (exit 1), by
design: it names `.changeset/28856-action-stale-summary-answer.md` as
"present on the merge base and CHANGED by this PR". This is its
DELIBERATE CORRECTION class (see What changes), declared here for the
seat to confirm. `Check Changeset` is not a required check.
- First pass on this branch (`7365c82a`): `check:engine-double-contract`
exit 1, because the three new doubles did not open with the producer
predicates. This was fixed in `7c5f3e55` (doubles pinned, ledger
written), not by a baseline entry. `check-plugin-teardown-shape
--self-test` exit 3 (prerequisite: the pinned fixture commit `621a4876`
was missing from the shallow clone); green after `git fetch --depth=1
origin 621a487…`.
- `pnpm lint`: exit 0.
- PR body offline: `node scripts/check-changeset-no-major.mjs --base
origin/main --event <this body>`: exit 0 (LEVEL AXIS: `yes (widening)`
and `none` at `patch`). `check-closing-keyword-parity --body`: only
`Fixes #28861` binds.
</details>
No live probe: storing a stale roll-up needs the lint roll-up gate
turned off at the runtime door (the #28782 recipe). The producer half,
the engine raising `SummaryRecomputeError` with `written` after the
write, is objectql's and pinned there (`engine-summary-retry.test.ts`,
`summary-recompute-code-constant.test.ts`); this change is the
author-facing surfaces, pinned above through the real `HttpDispatcher`,
`ScopedContext`, QuickJS runner and `AutomationEngine`. Full dogfood is
not owed (no `!`, no narrowing arm).
---
_Generated by [Claude
Code](https://claude.ai/code/session_01ADHkmQEc6KnPaxi9d3soLZ)_
---------
Co-authored-by: Claude <noreply@anthropic.com>1 parent affba40 commit 153869d
12 files changed
Lines changed: 889 additions & 32 deletions
File tree
- .changeset
- packages
- runtime/src
- domains
- sandbox
- services/service-automation/src/builtin
- scripts
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
15 | 15 | | |
16 | 16 | | |
17 | 17 | | |
18 | | - | |
| 18 | + | |
| 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 | + | |
| 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 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
0 commit comments