Repository navigation
Commit a2205a8
fix(rest): the cached by-name meta read revalidates across a translation change (#38495)
Fixes #38288
Clause-②: no
Metadata-protocol: none
## 维护者速读
用户能看到什么变化:前台和接口客户端在翻译更新后,再次打开对象或报表时会立刻看到新的显示名称,翻译故障恢复后提示也会随之消失;以前要强制刷新才行。
为什么做:多语言显示的缓存漏洞,翻译变了而缓存校验没变,客户端一直沿用旧文字(来自翻译故障提示那张卡的复审发现)。
出错会怎样:最坏情况是客户端多拿一次完整内容、少一次缓存命中,不会出现错误数据;本改动可以直接撤回。
要你做什么:无
## What changes
The default by-name metadata read (`GET /meta/:type/:name`, the cached
door, `metadata.enableCache: true`) issued an `ETag` the protocol
computed from the stored document and the locale, and translated the
item only after `If-None-Match` was judged against it. A translation
edit, or a translation fault beginning or clearing, moved no byte of
that validator, so a revalidating client was answered `304` and kept the
old labels, or kept a `translationWarning` after the fault had cleared.
ADR-0156 D3 (verbatim: "The per-caller gate, the field mask, translation
into the caller's locale and the `ETag` are computed on every request,
over the cached part.") decides the shape: the door now translates on
every request BEFORE it judges the request, and folds what the
translation contributed into the validator.
- `packages/rest/src/meta-item-read-routes.ts` (the landing point; the
validator's input must come from the REST door because the translation
happens there and the protocol has no i18n): the cached arm never hands
the protocol `ifNoneMatch` any more and judges `If-None-Match` itself
for every type, after `translateMetaEnvelope`. A new
`cachedTranslationFingerprint` (the translated item and the fault
warning, hashed) is folded into the validator with the existing folds.
It is EMPTY when the translation changed nothing and reported no fault,
so such a read keeps the exact `ETag` it had before. The action arm's
early `304` moved into the common judgment for the same reason. The
nested fold chain became one ordered list; the fold order, and so every
existing `ETag` value, is unchanged.
- `packages/metadata-protocol/src/protocol-search-and-cache.ts`: comment
only, at the validator: the locale is all of the translation it holds,
so a door that translates must not hand it `ifNoneMatch`.
- Why a hash of the translated output and not a bundle version: none
exists. `II18nService` declares no version or change counter, and
ADR-0156 lists translation bundles among the sources "with no counter".
The translation also reads the packaged base, the pair's and the
patching packages' translations; only its output says what all of them
produced. Adding a counter would be a new contract surface.
- The translated answer is not cached; only the validator changes.
## Tests
New `packages/rest/src/meta-item-cached-translation-etag.test.ts`: the
real REST route over the real `ObjectStackProtocolImplementation` over a
real `SchemaRegistry`, with an i18n double whose bundles are replaced in
place and whose read can be made to fail. For `object` (the arm that
already judged its own validator, before translating) and `report` (an
arm the protocol judged):
1. The card's round trip: read, update the translation, revalidate with
the earlier `ETag` → `200` with the new label and a new `ETag`; the new
`ETag` then revalidates to `304`.
2. Control: an unchanged translation revalidates to `304`.
3. A read served during a translation fault, revalidated after the fault
clears → `200`, no `translationWarning`, translated label.
4. A fault that begins after a healthy read → `200` with the warning.
<details><summary>Reproduction on unfixed code, fix, ablation (head
02ae5c5)</summary>
- Before the fix (test file only, on base 7e1b222): `Tests 6 failed | 2
passed (8)`, each failure `expected 304 to be 200`; the two controls
passed.
- With the fix: `Tests 8 passed (8)`.
- Ablation via `scripts/ablation-replace.mjs` (fingerprint forced
empty): anchor 1 to 0, blob 003518b to 1a5a24f60025, `Tests 6
failed | 2 passed (8)`, the same six; restored, blob equals HEAD, `git
diff HEAD` empty.
- `@objectstack/rest` local project, whole package: `Test Files 438
passed (438)`, `Tests 9025 passed | 351 skipped (9376)` (lock VERDICT
command-exit 0; run at e626f84, the later commit removes one unused
binding and adds the changeset).
- `pnpm --filter @objectstack/rest typecheck` and `pnpm --filter
@objectstack/metadata-protocol typecheck`: VERDICT command-exit 0 at
02ae5c5.
</details>
<details><summary>Derived gates (dispatch-gates --commands, 68 families,
at 02ae5c5)</summary>
- 66 exit 0, including `check:nul-bytes`, `check:durability-log-level`,
`check:cross-package-test-inputs`, `check:test-source-alias`,
`check:adr-anchors`, `check:doc-authoring`, `check:issue-citations`,
`check-adr-0087-registration --base origin/main`,
`check-empty-changeset`, `check-changeset-no-major`.
- NOT MEASURED: `check:dual-build-cjs-loads`, reason: PREREQUISITE NOT
MET (reads every package's dist; this worktree built only the rest
closure). CI runs it.
- NOT MEASURED: `check-plugin-teardown-shape.mjs --self-test`, reason:
its pinned fixture commit is outside this shallow clone (checker health,
not a verdict on this diff).
- `--ran` reconciliation: 68 derived, 68 run, 0 UNRUN.
</details>
## Acceptance notes
- One-time revalidation miss: for a translated read (a locale whose
translation changes the item), the `ETag` gains a fold, so each client
gets one `200` after this deploys, then `304`s as before. A read the
translation does not change keeps its `ETag` byte for byte.
- Cost: a revalidation that the protocol used to answer `304` without
translating now translates first (the ADR-0156 D3 rule) plus up to two
`JSON.stringify` of the item. NOT MEASURED: per-request latency, reason:
no load harness in scope; the uncached doors already hash the full
served body per request.
- `GET /meta/:type/:name` wire behaviour moves (when a `304` is
answered); no spec schema, export or error code changes.
## Verification
Read first, by risk: `packages/rest/src/meta-item-read-routes.ts` (the
cached arm: `cacheRequest`, the translate-before-judge block, the fold
list and the `304` condition; then `cachedTranslationFingerprint` at the
bottom), then the new test file.
Two-minute check: `pnpm --filter @objectstack/rest exec vitest run
--maxWorkers=2 src/meta-item-cached-translation-etag.test.ts` → `Tests 8
passed (8)`.
Account: os-project-manager
---
_Generated by [Claude
Code](https://claude.ai/code/session_01FEkQ5pH8MaBBP5T2dVcTHL)_
---------
Co-authored-by: Claude <noreply@anthropic.com>1 parent dccf836 commit a2205a8
4 files changed
Lines changed: 314 additions & 61 deletions
File tree
- .changeset
- packages
- metadata-protocol/src
- rest/src
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
95 | 95 | | |
96 | 96 | | |
97 | 97 | | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
98 | 107 | | |
99 | 108 | | |
100 | 109 | | |
| |||
| 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 | + | |
0 commit comments