Commit 5111e24
authored
🤖 fix: prevent init state persist race condition (#1056)
Fixed flaky test `should persist init state to disk for replay across
page reloads`.
## Root Cause
Race condition in `InitStateManager.endInit()`:
1. In-memory state was updated (`exitCode`) synchronously
2. Then `persist()` was awaited to write to disk
3. But `logComplete()` called `endInit()` with `void` (fire-and-forget)
If replay happened while `persist()` was still running, it would see
`exitCode !== null` but the file wouldn't exist yet.
## Fix
Persist state BEFORE updating in-memory `exitCode`, ensuring the
invariant: **if `init-end` is visible (live or replay), the file MUST
exist**.
## Validation
- Test passes consistently (5 consecutive runs)
- All init tests pass
- Full static-check passes
_Generated with `mux`_1 parent e9da918 commit 5111e24
2 files changed
+20
-4
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
114 | 114 | | |
115 | 115 | | |
116 | 116 | | |
| 117 | + | |
117 | 118 | | |
118 | 119 | | |
119 | 120 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
197 | 197 | | |
198 | 198 | | |
199 | 199 | | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
200 | 204 | | |
201 | 205 | | |
202 | 206 | | |
| |||
207 | 211 | | |
208 | 212 | | |
209 | 213 | | |
210 | | - | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
211 | 229 | | |
212 | 230 | | |
213 | 231 | | |
214 | | - | |
215 | | - | |
216 | | - | |
217 | 232 | | |
218 | 233 | | |
219 | 234 | | |
| |||
0 commit comments