Skip to content

Sub-agent errors and un-yielded completions are silently dropped without injecting results into parent context #742

Closed

Description

@philippeback

Problem

When delegating tasks to sub-agents in the agent loop:

  1. Silent Error Swallowing: If a sub-agent encounters an exception (e.g. model API error, rate limit, invalid tool parameters), the error is never reported back to the parent agent. The parent receives no output and may hang or stall waiting for results.
    • In cecli/helpers/agents/service.py, _run_generate() calls await self._inject_sub_agent_result(info) inside the except Exception as exc: block before setting info.status = SubAgentStatus.ERROR and info.error = str(exc).
    • _inject_sub_agent_result(info) checks if info.status == SubAgentStatus.ERROR: ... elif info.status == SubAgentStatus.FINISHED: ... else: return. Because info.status is still RUNNING, it returns immediately and drops the error completely.
  2. Missing Output on Normal Completion without Yield: If a sub-agent completes its turns by replying with assistant text or writing files without explicitly invoking Yield(summary="..."):
    • _inject_sub_agent_result(info) is also called while info.status is still RUNNING, dropping the output.
    • When info.status is subsequently updated to FINISHED, _inject_sub_agent_result is not re-invoked, and info.summary defaults to "Task completed" without extracting the actual response generated by the worker.
  3. Task Gather Crash in wait(): In AgentService.wait(), await asyncio.gather(*tasks) does not specify return_exceptions=True. An exception in one sub-agent causes wait() to fail immediately instead of returning summaries and statuses.
  4. Model Token Leaks in File Paths on Windows: When local or open-weights models leak tool delimiter tokens into arguments (e.g., doc/test.md}<tool_call|><|channel>...), file resolution fails on Windows with OSError: [Errno 22] Invalid argument.

Proposed Solution

  1. Fix Result Injection Lifecycle:
    • In cecli/helpers/agents/service.py (_run_generate), update info.status and info.error / info.summary before calling await self._inject_sub_agent_result(info).
    • Add info.result_injected guard to guarantee results/errors are injected exactly once.
  2. Fallback Summary Extraction:
    • Implement _extract_sub_agent_summary(info) to extract the sub-agent's last assistant reply from its conversation if no explicit summary was passed via Yield.
  3. Resilient wait():
    • Pass return_exceptions=True to asyncio.gather(*tasks) in AgentService.wait().
  4. Path Sanitization:
    • Add sanitize_file_path() in cecli/tools/utils/helpers.py to strip enclosing quotes and trim hallucinated tool tokens (}<tool_call, <|tool_call, <|channel, </tool_call>) before resolving paths.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions