Commit deab680
committed
fix(handler): single-flight on-demand probe per session
The boolean `claim_probe` rate-limiter let the first list request
enter the probe path, but **followers in the same burst skipped the
probe entirely** and resolved to PendingRoots immediately — returning
empty *before* the first probe's `peer.list_roots()` came back.
Trace from a Claude Code claude-vscode session opening a new
workspace:
02:17:19.950 resolver: roots-capable, roots pending (req 1)
02:17:19.950 resolver: roots-capable, roots pending (req 2 — skipped probe)
02:17:19.973 on-demand probe populated roots (req 1's probe finally landed)
Two of the three list responses (tools/list + prompts/list +
resources/list, fired within 1ms by Claude Code at init) returned
empty. The probe success at +23ms triggered a notifications/
tools/list_changed which the CLI variant honors but the VS Code
extension doesn't refetch on, so the empty initial list is what the
panel kept showing.
Replace the boolean with a per-session `tokio::sync::Mutex` for
single-flight semantics. First request acquires the lock, fires the
probe, populates `session_roots`. Followers await the same lock; on
acquire, they re-check `session_roots.get(sid)` and exit early since
the predecessor already populated. Net result: one upstream
`peer.list_roots()` call, three list responses with the correct
routing decision.
Kept the cool-down semantic too: `should_throttle_probe` +
`mark_probe_completed` rate-limit *sequential* probe attempts when
the previous one errored, so a peer that's failing list_roots
doesn't get hammered. Distinct from the lock — the lock is
concurrency, the throttle is failure recovery.
Doesn't help the upstream client bug (Claude Code claude-vscode
doesn't refetch on tools/list_changed) but means the *first*
response is correct, which is the only one some clients ever read.
cargo check + clippy (-D warnings) clean.
Signed-off-by: Mohammod Al Amin Ashik <maa.ashik00@gmail.com>1 parent a83e288 commit deab680
2 files changed
Lines changed: 87 additions & 37 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
206 | 206 | | |
207 | 207 | | |
208 | 208 | | |
209 | | - | |
| 209 | + | |
| 210 | + | |
210 | 211 | | |
211 | 212 | | |
212 | 213 | | |
| |||
220 | 221 | | |
221 | 222 | | |
222 | 223 | | |
223 | | - | |
224 | | - | |
225 | | - | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
226 | 229 | | |
227 | 230 | | |
228 | | - | |
| 231 | + | |
229 | 232 | | |
230 | 233 | | |
231 | 234 | | |
232 | 235 | | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
233 | 257 | | |
234 | | - | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
235 | 263 | | |
236 | 264 | | |
237 | 265 | | |
| |||
276 | 304 | | |
277 | 305 | | |
278 | 306 | | |
279 | | - | |
| 307 | + | |
280 | 308 | | |
281 | 309 | | |
282 | 310 | | |
283 | 311 | | |
284 | 312 | | |
285 | 313 | | |
286 | 314 | | |
287 | | - | |
| 315 | + | |
288 | 316 | | |
289 | 317 | | |
290 | 318 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
38 | 38 | | |
39 | 39 | | |
40 | 40 | | |
41 | | - | |
42 | | - | |
43 | | - | |
44 | | - | |
45 | | - | |
46 | | - | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
47 | 46 | | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
48 | 62 | | |
49 | 63 | | |
50 | 64 | | |
| |||
54 | 68 | | |
55 | 69 | | |
56 | 70 | | |
| 71 | + | |
57 | 72 | | |
58 | 73 | | |
59 | 74 | | |
60 | | - | |
61 | | - | |
62 | | - | |
63 | | - | |
64 | | - | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
65 | 87 | | |
66 | | - | |
67 | | - | |
68 | | - | |
69 | | - | |
70 | | - | |
71 | | - | |
72 | | - | |
73 | | - | |
74 | | - | |
75 | | - | |
76 | | - | |
77 | | - | |
78 | | - | |
79 | | - | |
80 | | - | |
81 | | - | |
82 | | - | |
83 | | - | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
84 | 105 | | |
85 | 106 | | |
86 | 107 | | |
| |||
122 | 143 | | |
123 | 144 | | |
124 | 145 | | |
| 146 | + | |
125 | 147 | | |
126 | 148 | | |
127 | 149 | | |
| |||
0 commit comments