Skip to content

agents: subagent "work in background" pattern leads to hallucinated answers when no independent work exists #63785

Open

Description

@aymenbidasap

Summary

When a subagent is spawned to explore a codebase, the agent is instructed to "keep working on non-overlapping tasks" while the subagent runs. When there are no other independent tasks to work on, the agent fills the gap by generating an answer without real data — producing hallucinated code snippets and file paths that don't exist. The user receives a confident but fabricated response before the real exploration results arrive.

Environment

  • opencode version: 2.3.0
  • OS: Darwin 27.2.0 (darwin arm64)
  • Terminal: TERM_PROGRAM=vscode, TERM=xterm-256color, COLORTERM=truecolor
  • Shell: /bin/zsh
  • Install/channel: latest
  • Active plugins: None found

Reproduction

  1. Ask the agent a question about the codebase that requires exploration (e.g., "does removing field X from config break anything?")
  2. The agent spawns an explore subagent to search the codebase
  3. Instead of waiting for results, the agent immediately provides an answer with fabricated code snippets and file paths
  4. When the subagent returns with real results, the initial answer turns out to contain hallucinated content

Expected Behavior

When a subagent is spawned and there is no other independent work to do, the agent should tell the user the exploration is in progress and wait for the results before answering.

Actual Behavior

The agent generates a full answer with fabricated code snippets, file paths, and type definitions while the subagent is still running. The hallucinated content looks authoritative but references files and types that don't exist. The user has no way to distinguish this from a real answer until they verify manually or the subagent returns.

Additional Context

  • The root cause appears to be the instruction: "Keep working on non-overlapping tasks, or briefly tell the user what you launched and end your response." The second option ("briefly tell the user and end your response") is the correct behavior when there's nothing else to work on, but the agent defaults to the first option and treats "answering the user's question" as a non-overlapping task — even though it depends on the subagent's results.
  • Reproducibility: Observed in this session. Frequency unknown — may depend on model, prompt complexity, or other factors.
  • This was first noticed after upgrading to opencode 2.3.0. The subagent/background pattern may be new or changed in this version.

Activity

  1. opencodejr commented on Nov 13, 2026

    @opencodejr
    Contributor

    Thanks for the detailed report. You're right that 2.3.0 changed this: since #63382, subagents always run in the background. The call returns right away, and the agent gets a <subagent> message when the child goes idle. The tool tells the model to "keep working on non-overlapping tasks, or briefly tell the user what you launched and end your response". Your expected behavior matches the second option.

    Whether a model answers early like this depends a lot on which model it is, so we need a bit more to reproduce it:

    1. Provider and model you were using (e.g. anthropic/claude-..., openai/..., a Zen or Go model), and the variant if you picked one.
    2. The prompt you sent, or one close to it, and whether you used the default build agent or a custom one.
    3. If you can, an export of the session (or the relevant part): the subagent tool call, the answer the agent gave right after it, and the <subagent> result that came later.
    4. Whether it happens every time or only sometimes with that model.

    You can reply here with the details, or edit the issue. If you edit it, please still leave a comment saying you've updated it, so we know when you're done.

    I didn't find an existing report of this. These are related, ordered by likelihood:

  2. added
    area/core
    type/bug
    version/v2
    on Nov 13, 2026
  3. aymenbidasap commented on Nov 13, 2026

    @aymenbidasap
    Author

    Thanks for the quick response. Here are the details:

    1. Provider and model: anthropic/claude-opus-4-6 (Anthropic Claude Opus 4.6)
    2. Agent: Default plan agent (Plan mode)
    3. Prompt: "if activities from configuration do not have skuItemId inside them does this breaks anything?" — a codebase exploration question.
    4. What happened:
      • The agent spawned an explore subagent to search the codebase
      • Instead of waiting, it immediately provided a full answer with fabricated code snippets referencing files and types that don't exist in the codebase (e.g., service/src/lib/activity/activity.ts, service/src/lib/activity/entitlement.ts, service/src/lib/configuration/configuration.ts, a ConfigurationActivity type, a hasSkuEntitlement function)
      • When the subagent returned with real results, the hallucinated content was clearly wrong
    5. Frequency: Tried again with the same model and it produced a similar hallucinated response.
  4. opencodejr commented on Nov 13, 2026

    @opencodejr
    Contributor

    Thanks for the model, agent and prompt details. I couldn't reproduce this here. It depends on how anthropic/claude-opus-4-6 itself responds after the subagent starts, and this sandbox has no Anthropic account. A simulated model would only send back what I scripted, so it can't show this behavior.

    What I could confirm from the 2.3.0 code: subagent calls now always run in the background and return right away. Nothing in the code holds back the parent's answer until the subagent's result arrives. Whether it waits depends on the model following the tool's instructions. A maintainer with access to that model will need to try your steps (plan agent, a question that makes it start an explore subagent, then check whether it answers before the results come back).

    If you can, attaching an export of one of the affected sessions would help them see exactly what the model received and replied.

  5. aymenbidasap commented on Nov 13, 2026

    @aymenbidasap
    Author

    No I can't

  6. DEV-S-SHAH commented on Nov 19, 2026

    @DEV-S-SHAH

    I've implemented a fix for this.

    Root cause: The subagent tool's description and background result told models to 'work on non-overlapping tasks, or briefly tell the user what you launched and end your response.' Models misread 'answering the user's question' as a non-overlapping task when it actually depends on the subagent's results, producing confident but fabricated answers.

    Fix: Added an explicit warning to both the tool description and the background result:

    Do not answer the user's original question until you have the subagent's results - the answer depends on what the subagent finds.

    This makes it unambiguous that when there's nothing independent to do, the correct action is to briefly say what was launched and end - not to fabricate an answer.

    Changes:

    • packages/core/src/tool/plugin/subagent.ts - added warning to description and backgroundResult, exported backgroundResult for testing
    • packages/core/test/tool/subagent-output.test.ts - 2 new tests verifying both strings contain the warning

    All subagent tests pass (30/30). TypeScript passes.

    PR ready for review.

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

    area/coreplatform/macostype/bugversion/v2

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions