Skip to content

fix(session): stop malformed tool-call loops - #34039

Closed
Nomadcxx wants to merge 1 commit into
anomalyco:devfrom
Nomadcxx:copilot-tool-loop
Closed

Nomadcxx wants to merge 1 commit into
anomalyco:devfrom
Nomadcxx:copilot-tool-loop

Conversation

@Nomadcxx

Copy link
Copy Markdown
Contributor

Issue for this PR

Fixes #31247

Type of change

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

What does this PR do?

Copilot Claude Opus 4.8 can return finish=tool-calls without sending a structured tool call. OpenCode treated that as a tool-loop turn and asked the provider again, which can lead to Copilot rejecting the next request as assistant prefill.

This PR stops the loop when that malformed response shape appears. It records a session APIError, marks the assistant turn as finish=error, publishes the existing session error event, and leaves valid tool-call turns unchanged.

How did you verify your code works?

cd packages/opencode
bun test --timeout 30000 test/session/prompt.test.ts -t "loop stops when finish is tool-calls without tool parts"
bun test --timeout 30000 test/session/prompt.test.ts

Observed:

targeted regression: 1 pass, 0 fail, 11 expect() calls
prompt.test.ts: 57 pass, 1 skip, 0 fail, 232 expect() calls

From repo root:

bun run typecheck
git diff --check HEAD~1..HEAD

Observed:

typecheck: 29 successful, 29 total
git diff --check: no output

Screenshots / recordings

Not applicable. This PR changes session-loop behavior, not UI.

Checklist

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

@Nomadcxx
Nomadcxx force-pushed the copilot-tool-loop branch from 9814246 to fc9c86d Compare June 26, 2026 12:34
@github-actions

Copy link
Copy Markdown
Contributor

Automated PR Cleanup

Thank you for contributing to opencode.

Due to the high volume of PRs from users and AI agents, we periodically close older PRs using automated criteria so maintainers can focus review time on the most active and community-supported contributions.

This PR was closed because it matched the following cleanup criteria:

  • The PR was created more than 1 month ago
  • The PR had fewer than 2 positive reactions
  • Positive reactions are counted as thumbs-up, heart, celebration, or rocket reactions on the PR

PRs created within the last month are not affected by this cleanup.

If you believe this PR was closed incorrectly, or if you are still actively working on it, please leave a comment explaining why it should be reopened. A maintainer can review and reopen it if appropriate.

Thanks again for taking the time to contribute.

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.

Copilot Claude Opus 4.8 emits pseudo tool-call text instead of structured tool calls

1 participant