Skip to content

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

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

fix(session): stop malformed tool-call loops#34039
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
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