Commit 8898b0c
routes: wake parked consumers on generation bump (last-wins fix)
Advisor 2026-05-28 caught two bugs in the resume flow:
1. consumer_generation bump didn't wake parked consumers.
_stream_from_buffer's last-wins check is "while my_generation
== session.consumer_generation, sleep on cond". When a new
consumer increments the generation, the old consumer is parked
in cond.wait() — and stays parked until the next append_event
fires notify. If the generator is mid-pause awaiting a
user_question reply, no event ever appends so the old consumer
sleeps forever. Fix: both POST and resume handlers now
notify_all on the cond after bumping consumer_generation, so
parked old loops wake up + check the token + exit cleanly.
2. Redundant `session.consumer_generation = my_generation` write
inside the POST handler's sse_stream() coroutine. The value
was already captured immediately after the increment, and
echoing it back risked clobbering a newer consumer's bump if
a /resume call arrived between the route handler running and
the coroutine starting. Removed.
No new tests — both bugs only surface in narrow concurrent
scenarios (old consumer mid-pause when new arrives;
near-simultaneous POST + resume) that the TestClient's
single-coroutine pattern doesn't reliably reproduce. Manual
verification: lab device, kill SSE mid-user_question, foreground
auto-resume — old consumer log should show exit before the new
consumer starts streaming. 30 existing tests still pass.
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>1 parent 1a420fd commit 8898b0c
1 file changed
Lines changed: 16 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
235 | 235 | | |
236 | 236 | | |
237 | 237 | | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
238 | 245 | | |
239 | 246 | | |
240 | 247 | | |
| |||
244 | 251 | | |
245 | 252 | | |
246 | 253 | | |
247 | | - | |
248 | | - | |
249 | | - | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
250 | 258 | | |
251 | 259 | | |
252 | 260 | | |
| |||
294 | 302 | | |
295 | 303 | | |
296 | 304 | | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
297 | 308 | | |
| 309 | + | |
| 310 | + | |
298 | 311 | | |
299 | 312 | | |
300 | 313 | | |
| |||
0 commit comments