Skip to content

Commit 6acc796

Browse files
committed
docs(teams): justify per-thread keying of _active_streams
Three separate review bots flagged the thread-id keying of ``_active_streams`` as a potential cross-handler corruption risk on the DM streaming path. Add an inline comment at the registration site pointing readers at the upstream parallel and the concurrency invariant that makes per-thread keying safe today, plus a note that a per-handler ContextVar is a tracked Python-only follow-up rather than in-scope for the parity sync.
1 parent 1cedd58 commit 6acc796

1 file changed

Lines changed: 9 additions & 0 deletions

File tree

src/chat_sdk/adapters/teams/adapter.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -435,6 +435,15 @@ async def _handle_message_activity(
435435
# task — the local ``await`` is purely so we know when to reap the
436436
# session.
437437
session = _TeamsStreamSession()
438+
# Keyed by ``thread_id`` to match upstream ``activeStreams.set(threadId, …)``
439+
# in ``packages/chat-teams/src/index.ts``. Safe because the default
440+
# per-thread concurrency strategy in ``Chat.handle_incoming_message``
441+
# serialises DM handlers for the same thread (overlapping webhooks are
442+
# deduped or dropped before they reach a handler, so two ``stream()``
443+
# calls cannot share a session). A per-handler ``ContextVar`` would
444+
# decouple this from the concurrency strategy but would be a Python-only
445+
# divergence — tracked as a follow-up rather than landed inside the
446+
# parity sync.
438447
self._active_streams[thread_id] = session
439448
loop = asyncio.get_running_loop()
440449
processing_done: asyncio.Future[None] = loop.create_future()

0 commit comments

Comments
 (0)