Commit 17009a9
committed
fix(teams): prevent webhook deadlock when no chat task is scheduled
Address CodeRabbit Critical on PR #88. ``Chat.process_message`` invokes
``wait_until`` synchronously only if a chat task is actually scheduled.
If the message is deduped, dropped by the concurrency strategy, or
otherwise short-circuited, no task is created and ``wait_until`` is
never called — leaving ``processing_done`` unresolved and ``await
processing_done`` hanging the webhook indefinitely.
After ``process_message`` returns, check whether ``processing_done`` was
resolved (which can only happen via ``_chained_wait_until``, which is
only invoked when a task is scheduled). If not, resolve immediately —
there's no in-flight handler to wait on, no streaming will happen, and
``await processing_done`` should fall through to the ``finally`` cleanup.
Also addresses Codex P2 (lines 471): caller-supplied
``WebhookOptions.wait_until`` raising synchronously now logs and
continues instead of escaping through ``Chat.process_message``,
preventing the same-class deadlock-via-finally issue.
Both fixes together close the two paths where the streaming session
could be torn down while the chat task was still scheduled (or never
scheduled): a synchronous wait_until exception, and a deduped/dropped
message.
Tests:
- New ``test_caller_wait_until_raise_does_not_kill_native_streaming``
verifies the wait_until-raise path keeps the session alive long
enough for the chat task to call ``thread.stream()`` natively.
- Existing 23 native-streaming tests still pass.
Skipped CodeRabbit's other comment (``_active_streams`` thread-id
keying) — same as Codex P2 #2, matches upstream TS behavior and would
be a heavy-lift Python-only divergence.
https://claude.ai/code/session_01FyMxQn2BEAzmwKS1GZczKj1 parent 07df4b7 commit 17009a9
2 files changed
Lines changed: 96 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
468 | 468 | | |
469 | 469 | | |
470 | 470 | | |
471 | | - | |
| 471 | + | |
| 472 | + | |
| 473 | + | |
| 474 | + | |
| 475 | + | |
| 476 | + | |
| 477 | + | |
| 478 | + | |
| 479 | + | |
| 480 | + | |
| 481 | + | |
| 482 | + | |
| 483 | + | |
| 484 | + | |
| 485 | + | |
472 | 486 | | |
473 | 487 | | |
474 | 488 | | |
475 | 489 | | |
476 | 490 | | |
| 491 | + | |
| 492 | + | |
| 493 | + | |
| 494 | + | |
| 495 | + | |
| 496 | + | |
| 497 | + | |
| 498 | + | |
477 | 499 | | |
478 | 500 | | |
479 | 501 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
540 | 540 | | |
541 | 541 | | |
542 | 542 | | |
543 | | - | |
| 543 | + | |
| 544 | + | |
| 545 | + | |
| 546 | + | |
| 547 | + | |
| 548 | + | |
| 549 | + | |
| 550 | + | |
| 551 | + | |
| 552 | + | |
| 553 | + | |
| 554 | + | |
| 555 | + | |
| 556 | + | |
| 557 | + | |
| 558 | + | |
| 559 | + | |
| 560 | + | |
| 561 | + | |
| 562 | + | |
| 563 | + | |
| 564 | + | |
| 565 | + | |
| 566 | + | |
| 567 | + | |
| 568 | + | |
| 569 | + | |
| 570 | + | |
| 571 | + | |
| 572 | + | |
| 573 | + | |
| 574 | + | |
| 575 | + | |
| 576 | + | |
| 577 | + | |
| 578 | + | |
| 579 | + | |
| 580 | + | |
| 581 | + | |
| 582 | + | |
| 583 | + | |
| 584 | + | |
| 585 | + | |
| 586 | + | |
| 587 | + | |
| 588 | + | |
| 589 | + | |
| 590 | + | |
| 591 | + | |
| 592 | + | |
| 593 | + | |
| 594 | + | |
| 595 | + | |
| 596 | + | |
| 597 | + | |
| 598 | + | |
| 599 | + | |
| 600 | + | |
| 601 | + | |
| 602 | + | |
| 603 | + | |
| 604 | + | |
| 605 | + | |
| 606 | + | |
| 607 | + | |
| 608 | + | |
| 609 | + | |
| 610 | + | |
| 611 | + | |
| 612 | + | |
| 613 | + | |
| 614 | + | |
| 615 | + | |
544 | 616 | | |
545 | 617 | | |
546 | 618 | | |
| |||
0 commit comments