Skip to content

fix(opencode): forward parent attachments to subagents#32302

Open
21pounder wants to merge 3 commits into
anomalyco:devfrom
21pounder:subtask-image-forward
Open

fix(opencode): forward parent attachments to subagents#32302
21pounder wants to merge 3 commits into
anomalyco:devfrom
21pounder:subtask-image-forward

Conversation

@21pounder

@21pounder 21pounder commented Jun 14, 2026

Copy link
Copy Markdown
Contributor

Issue for this PR

Closes #25553

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

This fixes the attachment handoff for @mention subagents in the task path.

In the failing #25553 flow, the parent agent could spawn the subagent, but TaskTool only rebuilt child prompt parts from params.prompt, so the image attached to the parent user message never reached the child session.

This change forwards file parts from the triggering parent user message into the child prompt, but only when that parent message explicitly targets the same subagent. That keeps the fix scoped to the actual handoff boundary and lets multimodal subagents receive the attached image once they are spawned.

This does not try to solve cases where the parent LLM does not choose to call task at all. That routing decision is upstream model behavior, not something this patch can make deterministic.

sequenceDiagram
    participant U as User
    participant P as Parent session
    participant B as build model
    participant T as TaskTool
    participant V as Child subagent

    U->>P: text + @vision + image
    P->>B: parent message
    B->>T: call task(subagent, prompt)
    T->>V: child prompt from params.prompt only
    Note over V: image missing
Loading
sequenceDiagram
    participant U as User
    participant P as Parent session
    participant B as build model
    participant T as TaskTool
    participant V as Child subagent

    U->>P: text + @vision + image
    P->>B: parent message
    B->>T: call task(subagent, prompt)
    T->>T: collect file parts from the triggering parent user message
    T->>V: child prompt + forwarded image
    V-->>P: image analysis result
Loading

How did you verify your code works?

  • Sent one POST /session/:id/message request with text + agent + file parts
  • Confirmed via GET /session/:id/message that the session stored the @vision mention and the image attachment
  • Confirmed in the server log that a child session was created with agent=vision
  • Confirmed in the server log that the child session streamed with agent=vision and mode=subagent
  • Ran bun typecheck from packages/opencode
  • Ran bun test --timeout 15000 test/tool/task.test.ts from packages/opencode

Screenshots / recordings

POST request with text + agent + file parts:
屏幕截图 2026-06-13 232928

Stored session message with @vision and image attachment:

屏幕截图 2026-06-13 233020

Child session creation for the subagent:
屏幕截图 2026-06-13 233630

Child subagent stream:
屏幕截图 2026-06-13 233703

Regression test passing:
屏幕截图 2026-06-13 233824

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

@github-actions github-actions Bot added contributor needs:compliance This means the issue will auto-close after 2 hours. and removed needs:compliance This means the issue will auto-close after 2 hours. labels Jun 14, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Thanks for updating your PR! It now meets our contributing guidelines. 👍

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug: @mention subagent with attached image in Web UI — image not forwarded to multimodal subagent

1 participant