Commit c8b5507
committed
fix(sdk): hydrate chat session handle from tool metadata in ai.toolExecute subtasks
`chat.stream.writer({ target: "root" })` and the rest of the
`chat.stream` helpers all funnel through `getChatSession()`, which
looked up the session handle in run-scoped `locals`. That key is only
populated inside a `chat.agent` run — `ai.toolExecute` subtasks
running in a separate worker process don't inherit it, so any chat
helper used from a subtask threw `"chat.agent session handle is not
initialized"`.
Resolve the handle lazily: if it's not in `locals`, fall back to the
`chatId` already threaded through tool metadata under `METADATA_KEY`
and call `sessions.open(chatId)` to materialize it. Cache the result
back into `locals` so subsequent calls in the same subtask hit the
fast path.1 parent 950c0b5 commit c8b5507
1 file changed
Lines changed: 25 additions & 10 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
658 | 658 | | |
659 | 659 | | |
660 | 660 | | |
661 | | - | |
662 | | - | |
663 | | - | |
664 | | - | |
| 661 | + | |
| 662 | + | |
| 663 | + | |
| 664 | + | |
| 665 | + | |
| 666 | + | |
| 667 | + | |
| 668 | + | |
| 669 | + | |
| 670 | + | |
| 671 | + | |
| 672 | + | |
665 | 673 | | |
666 | 674 | | |
667 | 675 | | |
668 | | - | |
669 | | - | |
670 | | - | |
671 | | - | |
672 | | - | |
| 676 | + | |
| 677 | + | |
| 678 | + | |
| 679 | + | |
| 680 | + | |
| 681 | + | |
| 682 | + | |
| 683 | + | |
| 684 | + | |
673 | 685 | | |
674 | | - | |
| 686 | + | |
| 687 | + | |
| 688 | + | |
| 689 | + | |
675 | 690 | | |
676 | 691 | | |
677 | 692 | | |
| |||
0 commit comments