ACP stream relay thread routing fixed
ACP session progress updates now route to the correct Telegram forum topic or Discord thread when spawned from there, instead of falling back to the main DM.
When agents spawn ACP sessions with streamTo="parent" from a Telegram forum topic or Discord thread, system events like progress updates and completion notices were landing in the main DM instead of the originating conversation. This fix passes the parent's delivery context through to the ACP stream relay so events route to the correct thread or topic. Users following a conversation no longer need to check multiple places for ACP session updates — everything arrives where they started the request.
View Original GitHub Description
Problem
When an agent spawns ACP sessions with streamTo="parent" from a Telegram forum topic (or Discord thread), the relay's system events — progress updates, stall warnings, and completion notices — all route to the main DM instead of the originating topic/thread.
This means the user sees ACP progress in the wrong conversation, and the agent's judge/report reply also lands in the wrong place.
Reproduction
- Open a Telegram DM with forum topics enabled
- In a topic, ask your agent to spawn an ACP session with
streamTo="parent" - Observe: all
System:events (progress, "run completed") arrive in the main DM, not the topic
Expected
System events should route back to the same topic/thread that initiated the spawn.
Root Cause
startAcpSpawnParentStreamRelay calls enqueueSystemEvent without a deliveryContext. When the heartbeat runner processes queued system events:
resolveSystemEventDeliveryContext()returns no thread routing inforesolveSessionDeliveryTargetin heartbeat mode only usesturnSourceThreadId— it does not fall back tolastThreadId- Without
turnSourceThreadId,threadIdresolves toundefined→ delivery falls back to main DM
Fix
acp-spawn-parent-stream.ts: Accept optionaldeliveryContextparam, pass to everyenqueueSystemEventcallacp-spawn.ts: Resolve parent session delivery context from session store at relay creation time, pass to relay
Graceful fallback: if parent session has no delivery context, behavior is identical to before.
Changes
src/agents/acp-spawn-parent-stream.ts(+7): Add optionaldeliveryContextparam, pass toenqueueSystemEventsrc/agents/acp-spawn.ts(+16): Resolve parent delivery context from session store, pass to both relay creation points