Commit 481bdbc
fix: return task immediately when blocking=False in on_message_send
When `blocking=False` is set in MessageSendConfiguration, the handler
now returns the Task object immediately without waiting for executor
events. Event consumption and push notifications are processed entirely
in the background.
Previously, even with `blocking=False`, the handler waited for the first
event from the EventConsumer polling loop (0.5s timeout per iteration).
When the event loop was busy with background work, this caused 5-7s
delays before the HTTP response was sent, leading to client timeouts.
The new non-blocking fast path:
1. Creates the task and starts the executor (via _setup_message_execution)
2. Returns the task in 'submitted' state immediately
3. Consumes events and sends push notifications in a background task
The blocking path remains unchanged for backward compatibility.
Fixes #951
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>1 parent b941eef commit 481bdbc
1 file changed
Lines changed: 49 additions & 1 deletion
Lines changed: 49 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
41 | 41 | | |
42 | 42 | | |
43 | 43 | | |
| 44 | + | |
44 | 45 | | |
45 | 46 | | |
46 | 47 | | |
| |||
295 | 296 | | |
296 | 297 | | |
297 | 298 | | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
298 | 306 | | |
299 | 307 | | |
300 | 308 | | |
| |||
311 | 319 | | |
312 | 320 | | |
313 | 321 | | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
314 | 362 | | |
315 | 363 | | |
316 | 364 | | |
| |||
325 | 373 | | |
326 | 374 | | |
327 | 375 | | |
328 | | - | |
| 376 | + | |
329 | 377 | | |
330 | 378 | | |
331 | 379 | | |
| |||
0 commit comments