Skip to content

OpenCode export drops the results of parallel tool calls written one call per message #98

Open

Description

@acaprino

What happened?

When parallel tool calls are recorded one call per assistant message, with each result in its own later user message, converting to opencode drops the results: every call is written with an empty output.

The OpenCode writer folds a ToolResult into its call's state.output only when the result sits in the message right after the call (src/harness/opencode.rs, assistant_part, messages.get(*idx + 1)). With calls A and B written as separate assistant messages followed by result A and result B, call A's next message is call B, and call B's next message holds only result A, so neither call finds its result.

Expected: each call keeps its own result, wherever it sits in the following user messages of the same turn.

How to reproduce

run.json (Simple document):

{
  "messages": [
    { "role": "user", "content": "read both" },
    { "role": "assistant", "content": [{ "type": "tool_use", "id": "call_a", "name": "Read", "input": { "file_path": "/a" } }] },
    { "role": "assistant", "content": [{ "type": "tool_use", "id": "call_b", "name": "Read", "input": { "file_path": "/b" } }] },
    { "role": "user", "content": [{ "type": "tool_result", "tool_use_id": "call_a", "content": "content a" }] },
    { "role": "user", "content": [{ "type": "tool_result", "tool_use_id": "call_b", "content": "content b" }] },
    { "role": "assistant", "content": "done" }
  ]
}

convert(run, "simple", "opencode") (or txcript continue ./run.json --with opencode) writes both tool parts with "output": "".

The same conversation as a library test, on main at c60e686:

assertion `left == right` failed
  left: [("call_a", ""), ("call_b", "")]
 right: [("call_a", "content a"), ("call_b", "content b")]

Versions

I have a fix with this test ready: look past the next message, through the following user messages of the turn, for the call's result.

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