Repository navigation
Commit 0ab9b15
fix(messaging): the one-time digest conversion rewrites only rows that held none before its claim (#36694)
<!-- claude-projects-attribution: {"github_login":"os-support-ai"} -->
_Requested by **Yibo Wang** · [project
thread](https://claude.ai/code/project/chan_01BVUyyPie8gHwoPM18iABwB?thread=cmsg_01BVUyyPie8gHwoPM18iABwBEaJzgBWzjWCNjBjkVoeRto)_
Fixes #36369
repo:objectstack#3 · os-support-ai · session_01WGufzi4PechTRCTBrfxV8W
Clause-②: no
Metadata-protocol: none
## 维护者速读
- 用户无感的升级修补:升级当天那次「把旧的不汇总清成未设置」只改开始前已存在的那批记录,运行期间成员新选的「不汇总」原样保留。
- 属于「成员不汇总与免打扰优先于组织默认」那项修复的收尾,替运行期间改了设置的成员解决选择被清掉的问题。
- 出错时,升级运行那几秒里选了「不汇总」的成员会被改回跟随组织;可直接撤回本改动,回到原先的做法。
- 无。
## What changes
`packages/services/service-messaging/src/preference-digest-conversion.ts`
(the one-time conversion of the legacy digest `none` to empty, ruling
7073270426 on #35123, item 4):
- **Snapshot before the claim.** The pass reads the ids (and
organization) of every row holding `digest = 'none'` first, in pages by
id cursor (`id > last`, `orderBy id asc`, page size 10000), then claims
its `sys_migration` row, then rewrites exactly that snapshot with the
same compare-and-set as before (`where: { id, digest: 'none' }`, the
row's own organization threaded).
- **No re-read.** The loop that re-read `where: { digest: 'none' }`
after each batch (and the `seen` set that ended it) is gone, and so is
its "re-reading failed after the claim" branch: a failure on any page of
the snapshot now happens before the claim and answers `read-failed`, so
the next boot retries with nothing recorded.
- An optional third parameter `{ pageSize }` (module-internal; the
function is not exported from the package entry) lets the pin exercise
more than one page.
Ruling text relied on (item 4):
> ⛔ The conversion must not run again after the fix is live: from then
on `none` is a member's real choice.
The deployment serves while the boot hook runs, so a `none` written
during the pass is written under the fixed release.
### Read first (by risk)
1. `preference-digest-conversion.ts` — `readSnapshot` (cursor paging;
the missing-table answer applies to the first page only) and the rewrite
loop that now iterates the snapshot once.
2. `preference-digest-three-states.integration.test.ts` —
`interceptOnce` and the "a none written during the pass" pin.
3. `.changeset/36369-digest-conversion-snapshot.md`.
## Tests
New pins in `preference-digest-three-states.integration.test.ts` (real
`ObjectQL` + `SqlDriver` better-sqlite3 file database that an earlier
release created):
- a `none` written during the pass (a new row with an explicit `none`,
and a `daily` row switched to `none`) survives it; only the pre-claim
row is rewritten (`converted: 1`);
- the snapshot is read in pages by id: five legacy rows across two
organizations with `pageSize: 2` are all converted;
- a claim that fails after the read (ledger insert refused) answers
`claim-failed`, logs one error, rewrites nothing and leaves no ledger
row;
- another node claiming between the read and the claim answers
`already-run` and this pass rewrites nothing.
All readings at head `6bd074ce`, after `pnpm --filter
'@objectstack/service-messaging^...' build` (lock VERDICT command-exit
0).
<details><summary>Package test and typecheck</summary>
- `pnpm --filter @objectstack/service-messaging test`: Test Files 80
passed (80), Tests 1088 passed (1088).
- `pnpm --filter @objectstack/service-messaging typecheck` (`tsc
--noEmit && tsc --noEmit -p tsconfig.scripts.json`): exit 0.
- Both under `os-verify-lock.sh`: VERDICT command-exit 0.
- `test:repo` not run locally (diff does not touch that project); CI
`Test Core` runs it.
</details>
<details><summary>Ablations (one-shot, through
scripts/ablation-replace.mjs; the test imports the module from source,
so no dist leg)</summary>
1. Re-read reintroduced: the snapshot loop replaced by a generator that
re-reads `digest = 'none'` after the snapshot and yields ids not yet
seen (the pre-fix shape). Mutation landed (anchor 1 to 0, blob
7ad5cf7 to cfc30aecaf87). Result: "a none written during the pass
is not rewritten" FAILED, `converted` expected 1, received 3; Tests 1
failed, 8 passed. Restored: blob == HEAD, `git diff HEAD` empty.
2. One page only: the short-page test before `return snapshot;` deleted,
so the read stops after the first page. Result: "reads the snapshot in
pages by id" FAILED, `converted` expected 5, received 2; Tests 1 failed,
8 passed. Restored: blob == HEAD, `git diff HEAD` empty.
</details>
## Acceptance notes
- **Split off — seat decides:** the Notification Settings page has no
"follow the organization again" action for digest or quiet hours
(optional item 1 of the card).
- **Split off — seat decides:** `QUIET_HOURS_OFF` is spelled in both
`preference-resolver.ts` and the UI `myPreferences.ts` with no pin tying
them together (optional item 2 of the card).
- **What the snapshot does not close (by construction).** When the claim
fails, nothing is rewritten and nothing can be recorded (the ledger is
the thing that failed), so the next boot takes a new snapshot and a
`none` written between those two boots is converted with the rest. The
card reads the snapshot as covering this case; it covers the
claim-fails-after-the-read case only within one boot (pinned above). The
failure is logged at `error` naming the fix. A row that held the legacy
`none` in the snapshot and is re-set to `none` by its member before its
own rewrite is indistinguishable from the legacy value and is converted;
that window is the time between the snapshot and that row's update.
## Verification
Two-minute check: `pnpm --filter @objectstack/service-messaging exec
vitest run src/preference-digest-three-states.integration.test.ts` —
expect 9 passed, including "a none written during the pass is not
rewritten: only the rows read before the claim are".
<details><summary>Local gates (dispatch-gates --commands, derived at
6bd074c)</summary>
- 67 derived commands: 63 exit 0; 4 exit 3 (PREREQUISITE NOT MET, read
as NOT MEASURED, CI's `Lint & Repo Gates` runs them on a full build):
- `node scripts/check-plugin-teardown-shape.mjs --self-test` (needs an
unshallow clone);
- `pnpm check:dual-build-cjs-loads` and `pnpm
check:published-readme-exports` (need every package's dist);
- `pnpm check:i18n` (needs the built CLI).
- `dispatch-gates --ran` with exit codes recorded: "67 derived
famil(ies) accounted for — 63 run, 4 NOT-MEASURED", exit 0.
- Branch is 2 commits behind `origin/main`; neither touches
`service-messaging` or `.changeset/36369*`, so no merge before opening.
</details>
---
_Generated by [Claude
Code](https://claude.ai/code/session_01WGufzi4PechTRCTBrfxV8W)_
<!-- signed: repo:objectstack#3 · os-support-ai ·
session_01WGufzi4PechTRCTBrfxV8W -->
---------
Co-authored-by: Claude <noreply@anthropic.com>1 parent b617675 commit 0ab9b15
3 files changed
Lines changed: 190 additions & 61 deletions
File tree
- .changeset
- packages/services/service-messaging/src
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
36 | 36 | | |
37 | 37 | | |
38 | 38 | | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
39 | 48 | | |
40 | 49 | | |
41 | 50 | | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
42 | 56 | | |
43 | 57 | | |
44 | 58 | | |
| |||
58 | 72 | | |
59 | 73 | | |
60 | 74 | | |
61 | | - | |
62 | | - | |
| 75 | + | |
| 76 | + | |
63 | 77 | | |
64 | 78 | | |
65 | 79 | | |
| |||
74 | 88 | | |
75 | 89 | | |
76 | 90 | | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
77 | 102 | | |
78 | 103 | | |
79 | | - | |
80 | | - | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
81 | 107 | | |
82 | 108 | | |
83 | 109 | | |
84 | | - | |
85 | | - | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
86 | 113 | | |
87 | 114 | | |
88 | 115 | | |
| |||
114 | 141 | | |
115 | 142 | | |
116 | 143 | | |
117 | | - | |
118 | | - | |
119 | | - | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
120 | 148 | | |
121 | 149 | | |
122 | 150 | | |
123 | 151 | | |
| 152 | + | |
124 | 153 | | |
125 | 154 | | |
126 | 155 | | |
| |||
151 | 180 | | |
152 | 181 | | |
153 | 182 | | |
154 | | - | |
155 | | - | |
156 | | - | |
157 | | - | |
158 | | - | |
159 | | - | |
160 | | - | |
161 | | - | |
162 | | - | |
163 | | - | |
164 | | - | |
| 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 | + | |
165 | 210 | | |
166 | 211 | | |
167 | 212 | | |
168 | | - | |
| 213 | + | |
169 | 214 | | |
170 | | - | |
| 215 | + | |
171 | 216 | | |
172 | 217 | | |
173 | 218 | | |
| |||
207 | 252 | | |
208 | 253 | | |
209 | 254 | | |
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 | | - | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
241 | 258 | | |
242 | | - | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
243 | 269 | | |
| 270 | + | |
244 | 271 | | |
245 | | - | |
246 | | - | |
247 | | - | |
248 | | - | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
249 | 275 | | |
250 | | - | |
| 276 | + | |
251 | 277 | | |
252 | | - | |
253 | 278 | | |
254 | 279 | | |
255 | 280 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
9 | 9 | | |
10 | 10 | | |
11 | 11 | | |
12 | | - | |
| 12 | + | |
| 13 | + | |
13 | 14 | | |
14 | 15 | | |
15 | 16 | | |
| |||
91 | 92 | | |
92 | 93 | | |
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 | + | |
94 | 118 | | |
95 | 119 | | |
96 | 120 | | |
| |||
152 | 176 | | |
153 | 177 | | |
154 | 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 | + | |
155 | 249 | | |
156 | 250 | | |
157 | 251 | | |
| |||
0 commit comments