Repository navigation
Commit 86c6955
fix(service-automation): a currency hole refused after a failed tenant-settings read is a runtime failure, not a guard refusal (#28110)
<!-- claude-projects-attribution: {"github_login":"os-elon-musk"} -->
_Requested by **Elon** · [project
thread](https://claude.ai/code/project/chan_01WedDzV26nniwxv7jC88B9D?thread=cmsg_01WedDzV26nniwxv7jC88B9DF8zq975FQQqJfYxnH4mVgp)_
domain:server#4 · os-elon-musk · session_016WV4czcfiRnuFCuLdmegYt
Fixes #28056
Clause-②: no (a refusal that followed a failed read of the
organization's default currency is now an ordinary runtime failure,
which a `fault` edge routes; every run that succeeded still succeeds,
and a refusal after a read that succeeded stays the guard refusal it
was)
Metadata-protocol: none
## 维护者速读
- 改了什么:flow 文本里 `{{ amount | currency }}` 缺租户默认币种时,若是因为读 `sys_setting`
失败(而不是组织真没设),现在判为普通运行时失败:fault 边能接住,`errorHandling: retry`
读恢复后就成功;报错说“设置读不出来”,不再叫人去设币种。
- 为什么改:自动化插件的币种解析器忽略 `readFailed`,运行准备又把拒绝和“没有”一样吞掉,于是一次瞬时读故障被当成 guard
拒绝(不可路由),原因还写错。messaging 通道在 #27257 已按同样规则分级。
- 风险与回滚:只在“本次读失败 + 用占位币种重渲染能成功”时改判;真没设币种、或模板别处本身有错,仍是原 guard 拒绝。无新错误码,不动
`packages/spec` 与 `AutomationContext`,读失败标记放在本包 WeakMap,不持久化。回滚即 revert。
-
先看:`packages/services/service-automation/src/builtin/template.ts`(`gradeAfterTenantCurrencyReadFault`)、`src/dag-traversal.ts`(executeNode
的 throw 分支)、`src/run-resume.ts`(两处 catch)、`src/plugin.ts`(`readFailed`
时拒绝)。
- 两分钟验证:`pnpm --filter @objectstack/service-automation exec vitest run
--maxWorkers=2 src/builtin/notify-currency-read-fault.test.ts
src/builtin/notify-currency-tenant-default.test.ts`,预期全绿:读失败被 fault
边接住、retry 后发出 CN¥ 标题;真没设币种仍不路由。
- 需要你做的:无,席位落地。
## What changes
`FlowTenantCurrencyResolver` gives a rejection its own meaning: the read
FAILED. `undefined` still means the read succeeded and found no default.
- **`plugin.ts`.** The automation plugin's tenant-currency resolver
rejects when `resolveLocalizationContext` answers `readFailed` (#27257),
as the messaging channels' `getTenantCurrency` does. It used to return
`localization.currency` and drop `readFailed`.
- **`run-resume.ts`.** Run setup (`resolveRunContext`) and a resumed
segment's re-read (`withTenantCurrency`) still leave
`AutomationContext.currency` unset on a rejection, and now note the
failed read beside that context (`noteTenantCurrencyReadFault`). The
resumed segment notes a copy, so the persisted context never carries one
segment's fault into a later resume. Nothing is added to
`AutomationContext` (`packages/spec`) or the persisted run.
- **`builtin/template.ts`.** `gradeAfterTenantCurrencyReadFault(err,
variables, context)`: a `FlowTextTemplateError` thrown for a context
whose read failed is rendered once more with the placeholder currency
`XXX` (ISO 4217's "no currency"). If that renders, the only refusal was
the missing default, and a plain `Error` without the guard brand is
returned, saying the `localization.currency` setting could not be read.
If it still refuses, the guard refusal is returned as it stands. Any
other failure, and every refusal after a successful read, is returned
unchanged. Same probe as service-messaging's
`templateRefusalAfterCurrencyReadFault` (#27257).
- **`dag-traversal.ts`.** `executeNode`'s throw arm grades the thrown
failure first, so the failure step, `$error` and the `isGuardRefusal`
routing decision all read the graded failure. This is the engine's
existing classification (#3863): a non-guard failure is routable by a
`fault` edge; `errorHandling.strategy: 'retry'` re-runs a failed run
either way. No new code.
- **`engine.ts`.** The `FlowTenantCurrencyResolver` docblock states the
rejection meaning.
The seam is shared by every text slot a node renders, so `http` and
`screen` slots are graded the same way as `notify`.
## Why
A transient `sys_setting` read failure failed a `notify` run as a
permanent guard refusal: a declared `fault` edge could not route it, and
the error told the operator to set a default currency the organization
may already have.
## Verification
Measured on `main` `5448585d` before the change (a scratch test, not
committed): a `notify` flow with a `fault` edge, the resolver throwing:
| Case | Before | After |
|:--|:--|:--|
| read fails, `fault` edge declared | run `failed`; the edge is not
taken; error "...the organization has none set... Set the default
currency in Setup → Localization" | run completes through the `fault`
edge; `$error.message` says the `localization.currency` setting could
not be read |
| read fails, `errorHandling: retry` (`maxRetries: 2`) | re-run (3
reads), every attempt refused | unchanged retry; the run succeeds on the
attempt whose read succeeds |
| read succeeds, no default | guard refusal, not routed | unchanged |
| read succeeds, `CNY` | `Won CN¥1,234.50` | unchanged |
Pins, `src/builtin/notify-currency-read-fault.test.ts` (3 red on `main`,
10/10 green on this head):
- engine: a failed read is routed by the `fault` edge and `$error` names
the failed read; retry succeeds once the read does; a successful read
with no default keeps the guard refusal (not routed); a successful read
with a default is unchanged.
- resume: a resumed segment whose read fails is routed by its `fault`
edge, and the persisted context stays as it parked.
- unit: the probe regrades only a refusal a default would cure; with no
failed read noted, every refusal is returned as it stands.
- plugin: booted over an ObjectQL whose `sys_setting` read throws, the
refusal is routed; over one that finds no default, the guard refusal
stands.
The existing `notify-currency-tenant-default.test.ts` row "refuses the
node by name when the read fails" still holds (no `fault` edge there, so
the run still fails, naming the hole and `localization.currency`).
Ablations (each restored through `scripts/ablation-replace.mjs`, blob ==
HEAD after):
- A1 the throw arm does not grade → 3 red (engine, resume, plugin).
- A2 the plugin resolver ignores `readFailed` → 1 red (plugin).
- A3 the resumed segment does not note the failure → 1 red (resume).
- A4 no probe (always regrade) → 1 red (a refusal a default would not
cure).
- A5 run setup does not note the failure → 2 red (engine, plugin).
Suites: `@objectstack/service-automation` full vitest 228 files / 2886
tests pass; `pnpm --filter @objectstack/service-automation typecheck`
(incl. `check:test-typecheck`) passes. `dispatch-gates --commands`
derived 62 families at head `e62036b8`: all exit 0
(`check:dual-build-cjs-loads` after the `dogfood^...` + `runtime^...`
dist build), `--ran` reconcile 62/62, 0 NOT MEASURED; `pnpm lint` exit
0. `main` merged at `549203d0`; nothing on `main` since touches
`service-automation`.
## Human Minimum
- [x] 1. Schemas start as Zod; `packages/spec` holds no runtime logic.
- [x] 2. Every name I added uses the casing for its kind.
- [x] 3. No formatter ran; `pnpm lint` passes.
- [x] 4. One issue, one branch off an up-to-date `main`, one pull
request.
- [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: not touched.
- [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.
- [x] The *Before Submitting* list in CONTRIBUTING.md is done.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
https://claude.ai/code/session_016WV4czcfiRnuFCuLdmegYt
Co-authored-by: Claude <noreply@anthropic.com>1 parent 11a7f96 commit 86c6955
7 files changed
Lines changed: 397 additions & 10 deletions
File tree
- .changeset
- packages/services/service-automation/src
- builtin
| 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 | + | |
| 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 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
141 | 141 | | |
142 | 142 | | |
143 | 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 | + | |
0 commit comments