Merged
Size
S
Change Breakdown
Bug Fix100%
#57056fix: pass parent delivery context to ACP stream relay for correct thread routing

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

  1. Open a Telegram DM with forum topics enabled
  2. In a topic, ask your agent to spawn an ACP session with streamTo="parent"
  3. 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:

  1. resolveSystemEventDeliveryContext() returns no thread routing info
  2. resolveSessionDeliveryTarget in heartbeat mode only uses turnSourceThreadId — it does not fall back to lastThreadId
  3. Without turnSourceThreadId, threadId resolves to undefined → delivery falls back to main DM

Fix

  1. acp-spawn-parent-stream.ts: Accept optional deliveryContext param, pass to every enqueueSystemEvent call
  2. acp-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 optional deliveryContext param, pass to enqueueSystemEvent
  • src/agents/acp-spawn.ts (+16): Resolve parent delivery context from session store, pass to both relay creation points
© 2026 · via Gitpulse