Skip to content

delegate_task broken in cron sessions since 0.18.2: forced background=true prevents subagent results from returning #63142

Description

@lidonyx

What happened

delegate_task was working correctly in cron jobs from 7/1 through 7/8 (v0.18.1). After upgrading to 0.18.2 on 7/9, all delegate_task calls from cron agents became fire-and-forget — returning only a 300-char dispatch confirmation instead of waiting for the actual subagent results (1000-23000 chars of analysis).

Evidence (from agent.log)

Before 0.18.2 (7/1-7/8):

delegate_task completed (35.42s, 3,419 chars)  ✓ sync, real results
delegate_task completed (402.71s, 15,075 chars) ✓ sync, real results

After 0.18.2 (7/9+):

Dispatched async delegation batch deleg_xxx
delegate_task completed (0.05s, 322 chars)  ✗ async, dispatch confirm only

Root cause

run_agent._dispatch_delegate_task (line 5685) forces background=True for all top-level agents:

_is_subagent = getattr(self, "_delegate_depth", 0) > 0
return _delegate_task(
    ...
    background=(not _is_subagent),  # top-level → always async
)

In interactive sessions this is fine — async results re-enter the conversation. But cron sessions produce ONE final response and exit. The subagent results never arrive because the session is already closed.

Impact

Any cron job that uses delegate_task silently produces incomplete output. The agent dispatches subagents, gets back "dispatched" confirmations, then outputs its final response — which contains only placeholder text like "waiting for results" instead of actual analysis.

This affects the evening portfolio report cron (6-role investment committee) and any other scheduled job that relies on parallel subagent analysis.

Suggested fix

Detect cron/stateless session context and fall back to synchronous execution (inline the subagent results), similar to how the stateless HTTP API path already falls back at lines 2778-2796:

if not _async_ok:
    # ... run synchronously instead

A cron session is effectively stateless — it should get the same treatment.

Workaround

Currently working around by removing delegate_task from cron prompts entirely and having the main agent simulate multiple analyst roles in its own context. This loses the benefit of isolated subagent contexts and adds significant prompt complexity.

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Medium — degraded but workaround existsarea/sessionsSession lifecycle, resume, persistence, historycomp/agentCore agent runtime: loop, agent_init, prompt builder, context-compression, responses endpointcomp/cronCron scheduler and job managementduplicateThis issue or pull request already existsneeds-reproBug needs reproduction stepstool/delegateSubagent delegationtype/bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions