Commit 71f6b9d
fix(agentex): snapshot stream cursor before reading task status at connect
Close a connect-time race that could leave a zombie stream. A terminal
transition writes the DB before it XADDs its task_updated event, and get_task
reads the DB while get_stream_tail_id sets the cursor the live loop reads after.
Previously status was read before the tail snapshot: if the task went terminal
in that gap, the status read said RUNNING (stale) so the connect-time terminal
branch didn't fire, and the tail snapshot then landed on the just-published
terminal event, which the live loop reads past — blocking forever.
Snapshot the tail first, then read status. A non-terminal status read now
guarantees any racing terminal event lands after the cursor, so the live loop is
guaranteed to surface it. Pure reorder of two reads; no behavior change beyond
eliminating the race.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>1 parent 65a0af3 commit 71f6b9d
1 file changed
Lines changed: 12 additions & 6 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
103 | 103 | | |
104 | 104 | | |
105 | 105 | | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
106 | 118 | | |
107 | 119 | | |
108 | 120 | | |
109 | 121 | | |
110 | 122 | | |
111 | 123 | | |
112 | | - | |
113 | | - | |
114 | | - | |
115 | | - | |
116 | | - | |
117 | | - | |
118 | 124 | | |
119 | 125 | | |
120 | 126 | | |
| |||
0 commit comments