ductor icon indicating copy to clipboard operation
ductor copied to clipboard

Task execution doesn't set DUCTOR_TOPIC_ID env var, breaking sub-task routing

Open alexeymorozua opened this issue 8 months ago • 1 comments

Bug

When a task is executed, thread_id is not passed to AgentRequest in hub.py:_run(). As a result, DUCTOR_TOPIC_ID is never set in the task's CLI environment. This causes two problems:

  1. Sub-tasks created by a task lose the topic context — they route to the base group chat (General/topic 1) instead of the originating topic.
  2. create_task.py inside a task reads os.environ.get("DUCTOR_TOPIC_ID", "") and gets empty string, so no topic_id is passed in the sub-task creation request.

Root Cause

In ductor_bot/tasks/hub.py, the _run() method builds AgentRequest without thread_id:

request = AgentRequest(
    prompt=prompt,
    chat_id=entry.chat_id,      # ✅ passed
    # thread_id missing ❌
    ...
)

entry.thread_id exists and is used correctly for result delivery (lines 459, 485, 516), but is never injected into the subprocess environment via AgentRequest.

In executor.py, DUCTOR_TOPIC_ID is only set when config.topic_id is present — so tasks always run without it.

Fix

Pass thread_id to AgentRequest in _run():

request = AgentRequest(
    prompt=prompt,
    chat_id=entry.chat_id,
    thread_id=entry.thread_id,  # add this
    ...
)

Reproduction

  1. User sends a message to group topic (e.g. Media, thread_id=1498)
  2. Agent creates a background task from that topic
  3. The task creates a sub-task via create_task.py
  4. Sub-task result is delivered to General (thread_id=1) instead of Media (thread_id=1498)

Environment

  • Multi-agent Ductor setup with Telegram forum group topics
  • Confirmed by inspecting hub.py source and matching against real log behavior

alexeymorozua avatar Mar 15 '26 15:03 alexeymorozua

Fixed in v0.16.0 (commit 3c2fa71).

topic_id is now plumbed through AgentRequest into the subprocess env (DUCTOR_TOPIC_ID) for every nested task spawn. Verified with an integration test: a sub-task started in a Telegram forum topic now sees the correct topic ID in its environment, so its reply routes back to the right thread. Grouped with #73 into the same commit.

PleasePrompto avatar Apr 21 '26 10:04 PleasePrompto