Commit d461f70
authored
fix(animation): spinner now driven by server status, not job_count (#423)
Problem:
1. Spinner flashed on every UI open. The gate was jobs.is_running(),
which every HTTP request bumps (including pure queries), so
toggle on issued 3-4 queries and the spinner blinked.
2. Spinner never appeared after attach or toggle off-then-on. SSE
cannot replay past events, and toggle off wiped the only local
copy of status_data.
3. Spinner could stay on forever after the model finished:
a. sync's GET response, stale by the time it landed, overwrote
the cache with a busy snapshot and started the spinner
against an already-idle server (which emits no follow-up).
b. SSE idle before set_active was skipped (active_session
guard), so replay read the stale busy.
Solution:
- Gate the spinner on a new `_should_animate()`: status_data is
non-idle AND tagged with the active session's sessionID.
- Per-session `last_status_map` (always a table) holds the cache.
SSE writes unconditionally; sync merges only missing entries
(SSE wins).
- New `OpencodeApiClient:list_session_status` + `M.sync_from_server()`
hydrate on setup and replay to status_data.
- `M.refresh()` is the single entry point that reconciles the
running state with status_data and active_session.
Tests:
- `does not regress to busy when sync returns a stale snapshot
after SSE idle` covers race 3a.
- `replays the active session from the cache (handles
sync-before_set_active)` covers race 3b.
- `merges the response into the cache (only fills missing
entries)` asserts SSE-preserved entries survive sync.
- `does not leave a stale spinner running when the model finishes
during a hide` covers the toggle off / model finishes / toggle
on scenario.1 parent 69aa869 commit d461f70
4 files changed
Lines changed: 472 additions & 60 deletions
File tree
- lua/opencode
- ui
- tests/unit
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
195 | 195 | | |
196 | 196 | | |
197 | 197 | | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
198 | 205 | | |
199 | 206 | | |
200 | 207 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
775 | 775 | | |
776 | 776 | | |
777 | 777 | | |
| 778 | + | |
| 779 | + | |
| 780 | + | |
| 781 | + | |
| 782 | + | |
| 783 | + | |
| 784 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
| 11 | + | |
11 | 12 | | |
12 | 13 | | |
13 | 14 | | |
14 | 15 | | |
15 | 16 | | |
16 | 17 | | |
| 18 | + | |
17 | 19 | | |
18 | 20 | | |
19 | 21 | | |
| |||
90 | 92 | | |
91 | 93 | | |
92 | 94 | | |
93 | | - | |
94 | | - | |
| 95 | + | |
95 | 96 | | |
96 | 97 | | |
97 | 98 | | |
98 | | - | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
99 | 107 | | |
100 | 108 | | |
101 | 109 | | |
102 | | - | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
103 | 126 | | |
104 | 127 | | |
105 | | - | |
| 128 | + | |
106 | 129 | | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
107 | 134 | | |
108 | 135 | | |
109 | 136 | | |
| |||
138 | 165 | | |
139 | 166 | | |
140 | 167 | | |
141 | | - | |
142 | | - | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
143 | 171 | | |
144 | 172 | | |
145 | 173 | | |
| |||
167 | 195 | | |
168 | 196 | | |
169 | 197 | | |
170 | | - | |
171 | | - | |
| 198 | + | |
| 199 | + | |
172 | 200 | | |
173 | 201 | | |
174 | 202 | | |
| |||
199 | 227 | | |
200 | 228 | | |
201 | 229 | | |
202 | | - | |
203 | 230 | | |
204 | 231 | | |
205 | 232 | | |
206 | 233 | | |
207 | 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 | + | |
208 | 274 | | |
209 | 275 | | |
210 | 276 | | |
211 | 277 | | |
212 | | - | |
| 278 | + | |
213 | 279 | | |
214 | 280 | | |
215 | 281 | | |
216 | | - | |
217 | | - | |
218 | | - | |
219 | | - | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
220 | 287 | | |
221 | 288 | | |
222 | 289 | | |
223 | 290 | | |
224 | 291 | | |
225 | | - | |
226 | | - | |
| 292 | + | |
| 293 | + | |
227 | 294 | | |
228 | 295 | | |
| 296 | + | |
229 | 297 | | |
230 | 298 | | |
231 | 299 | | |
232 | | - | |
233 | | - | |
| 300 | + | |
| 301 | + | |
234 | 302 | | |
235 | 303 | | |
| 304 | + | |
236 | 305 | | |
| 306 | + | |
| 307 | + | |
237 | 308 | | |
238 | 309 | | |
239 | 310 | | |
0 commit comments