Task execution doesn't set DUCTOR_TOPIC_ID env var, breaking sub-task routing
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:
- 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.
- create_task.py inside a task reads
os.environ.get("DUCTOR_TOPIC_ID", "")and gets empty string, so notopic_idis 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
- User sends a message to group topic (e.g. Media, thread_id=1498)
- Agent creates a background task from that topic
- The task creates a sub-task via
create_task.py - 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
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.