Skip to content

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

@alexeymorozua

Description

@alexeymorozua

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions