GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fix: handle dangling tool_use blocks for LiteLLM proxy compatibility by hendem · Pull Request #8497 · anomalyco/opencode

Conversation

@hendem

@hendem hendem commented Jan 14, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown

Problem

When using OpenCode with LiteLLM proxies (e.g., for Vertex AI, Bedrock), session compaction fails with:

invalid_request_error: messages.2: `tool_use` ids were found without `tool_result` blocks immediately after

or:

litellm.UnsupportedParamsError: Anthropic doesn't support tool calling without `tools=` param specified

This affects users who route Anthropic/Claude API calls through corporate LiteLLM proxies and cannot modify proxy settings (e.g., modify_params=True).

Root Cause Analysis

There are two distinct issues causing these errors:

Issue 1: Missing tools parameter during compaction

When compaction runs, it calls processor.process() with tools: {} (compaction.ts:149):

const result = await processor.process({
  // ...
  tools: {},  // <-- Empty tools object
  messages: [
    ...MessageV2.toModelMessage(input.messages),  // <-- Contains tool_use/tool_result from history
    // ...
  ],
})

LiteLLM validates that if message history contains tool_use/tool_result blocks, the tools parameter must be present. While Anthropic's native API now handles this gracefully, LiteLLM enforces stricter validation.

Issue 2: Dangling tool_use blocks without tool_result

When a session is interrupted or aborted, tool calls may be left in pending or running state. The toModelMessage() function in message-v2.ts currently skips these incomplete tool calls:

if (part.state.status === "completed")
  assistantMessage.parts.push({ /* tool-result */ })
if (part.state.status === "error")
  assistantMessage.parts.push({ /* tool-result with error */ })
// pending/running are NOT handled - creates dangling tool_use!

This creates tool_use blocks in the assistant message without corresponding tool_result blocks, which Anthropic/Claude APIs strictly reject.

Solution

Fix 1: Add dummy _noop tool when message history contains tool calls

In llm.ts, detect when messages contain tool calls but no tools are provided, and inject a placeholder tool:

if (Object.keys(tools).length === 0 && hasToolCalls(input.messages)) {
  tools["_noop"] = tool({
    description: "Internal placeholder tool - not for use",
    inputSchema: jsonSchema({ type: "object", properties: {} }),
    execute: async () => ({ output: "", title: "", metadata: {} }),
  })
}

The _noop tool is excluded from activeTools so it won't be suggested or called by the LLM.

Fix 2: Convert pending/running tool calls to error results

In message-v2.ts, handle pending and running tool states by generating error tool_result blocks:

if (part.state.status === "pending" || part.state.status === "running")
  assistantMessage.parts.push({
    type: ("tool-" + part.tool) as `tool-${string}`,
    state: "output-error",
    toolCallId: part.callID,
    input: part.state.input,
    errorText: "[Tool execution was interrupted]",
    callProviderMetadata: part.metadata,
  })

This ensures every tool_use has a corresponding tool_result, satisfying Anthropic's API requirements.

Files Changed

File Change
packages/opencode/src/session/llm.ts Add hasToolCalls() helper and dummy _noop tool injection
packages/opencode/src/session/message-v2.ts Handle pending/running tool states → error results
packages/opencode/test/session/message-v2.test.ts Add test for pending/running tool conversion

Testing

  • Added unit test verifying pending/running tool calls are converted to error results
  • Manual testing needed with actual LiteLLM proxy setup

Related

Fixes #8246
Fixes #2915
Related to #3243 (stale PR with merge conflicts addressing similar ordering issue)

Prior Art

  • Commit 0af450575 attempted a fix but was later simplified away
  • LiteLLM has a modify_params=True workaround, but many corporate proxy deployments cannot change this setting

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Mark Henderson Mark Henderson
fix: handle dangling tool_use blocks for LiteLLM proxy compatibility
d805c88
When sessions are compacted or interrupted, tool calls may be left in
pending/running state without corresponding tool_result blocks. This
causes Anthropic/Claude APIs (especially through LiteLLM proxies) to
reject requests with validation errors.

This change:
1. Converts pending/running tool calls to error results in toModelMessage
   to ensure every tool_use has a corresponding tool_result
2. Adds a dummy _noop tool when message history contains tool calls but
   no tools are provided (required by LiteLLM proxies)

Fixes anomalyco#8246
Fixes anomalyco#2915
Copilot AI review requested due to automatic review settings January 14, 2026 16:17
Copilot started reviewing on behalf of hendem January 14, 2026 16:17
View session
@github-actions

github-actions Bot commented Jan 14, 2026

Copy link
Copy Markdown
Contributor

The following comment was made by an LLM, it may be inaccurate:

Based on my search, I found one potential duplicate/related PR:

Related PR Found

PR #8248: fix: avoid Anthropic tool-history requests without tools

  • fix: avoid Anthropic tool-history requests without tools #8248

Why it's related: This PR addresses a very similar issue - handling requests that contain tool calls/history but lack the tools parameter. PR #8497 includes adding a dummy _noop tool when message history contains tool calls but no tools are provided (for LiteLLM proxy compatibility), which appears to be the same problem space that PR #8248 was tackling.

Also note: PR #3243 mentioned in the description ("Fix: Each tool_use block must have a corresponding tool_result block in the next message") is the stale/conflicted PR that #8497 is intended to supersede/fix properly.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@hendem
Merge branch 'dev' into fix/litellm-compaction-tool-calls
6c41388
Copilot AI reviewed Jan 14, 2026
View reviewed changes

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes session compaction failures when using OpenCode with LiteLLM proxies by ensuring every tool call has a corresponding tool result and that the tools parameter is present when needed.

Changes:

  • Pending and running tool calls now generate error tool results to prevent dangling tool_use blocks
  • A dummy _noop tool is added when message history contains tool calls but no tools are provided
  • Test coverage added for pending/running tool call conversion

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
packages/opencode/src/session/message-v2.ts Adds handling for pending/running tool states to convert them to error results
packages/opencode/src/session/llm.ts Adds dummy tool for LiteLLM proxy compatibility and helper function to detect tool calls
packages/opencode/test/session/message-v2.test.ts Adds test coverage for pending/running tool call error result generation

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread packages/opencode/src/session/llm.ts Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread packages/opencode/src/session/llm.ts Resolved

Uh oh!

There was an error while loading. Please reload this page.

Mark Henderson Mark Henderson
address review: improve _noop description and add hasToolCalls tests
b734de4
@hendem

hendem commented Jan 14, 2026

Copy link
Copy Markdown
Author

Re: Related PR #8248

Thanks for flagging the potential duplicate. I've reviewed PR #8248 and here's how this PR differs:

PR #8248 only addresses Issue 1 (missing tools parameter) and:

  • Only applies the fix for providers with "litellm" in their ID
  • Does not address dangling tool_use blocks from interrupted sessions

This PR (#8497) addresses both issues:

  1. Missing tools parameter - Adds dummy _noop tool universally (not just LiteLLM) since other proxies may have the same validation
  2. Dangling tool_use blocks - Converts pending/running tool calls to error results, ensuring every tool_use has a corresponding tool_result

The second fix is critical because even with the dummy tool, if there are dangling tool_use blocks from interrupted/aborted tool calls, the API will still reject the request with:

messages.2: `tool_use` ids were found without `tool_result` blocks immediately after

I'd suggest either closing #8248 in favor of this more comprehensive fix, or we could cherry-pick the provider-specific check from #8248 if the team prefers a more targeted approach for Issue 1.

seilk and sinwoobang reacted with heart emoji
All reactions
  • ❤️ 2 reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@hendem
hendem requested a review from Copilot January 14, 2026 16:46
Copilot started reviewing on behalf of hendem January 14, 2026 16:47
View session
Copilot AI reviewed Jan 14, 2026
View reviewed changes

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated no new comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@github-actions github-actions Bot mentioned this pull request Jan 15, 2026
fix: anthropic patch #8566
Closed
@seilk seilk mentioned this pull request Jan 15, 2026
feat: add litellmProxy provider option for explicit LiteLLM compatibility #8658
Merged
@seilk

seilk commented Jan 15, 2026

Copy link
Copy Markdown
Contributor

I've created #8658 which builds on this PR and addresses @rekram1-node's feedback from #8248.

The key change: Restricts _noop tool injection to only LiteLLM-backed providers instead of applying it unconditionally.

Detection logic:

const isLiteLLMProxy =
  provider.options?.["litellmProxy"] === true ||
  input.model.providerID.toLowerCase().includes("litellm") ||
  input.model.api.id.toLowerCase().includes("litellm")

Why this matters:

  • Your PR injects _noop for ALL providers unconditionally
  • Per @rekram1-node's comment: "There are a LOT of providers that don't have this issue... ideally this would be strictly limited to litellm"
  • My change adds auto-detection (provider ID contains "litellm") + explicit opt-in (litellmProxy: true option)

Config example for custom gateways:

{
  "provider": {
    "my-gateway": {
      "options": { "litellmProxy": true }
    }
  }
}

Happy to discuss merging this into your PR or keeping them separate.

hendem, sinwoobang, and seilk reacted with thumbs up emoji
All reactions
  • 👍 3 reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@github-actions github-actions Bot mentioned this pull request Jan 22, 2026
fix: include _noop tool in activeTools for LiteLLM proxy compatibility #9912
Merged
@wcpaxx wcpaxx mentioned this pull request Jan 22, 2026
LiteLLM proxy error: "Anthropic doesn't support tool calling without tools=" even with litellmProxy: true (v1.1.31) #10037
Closed
@thdxr
thdxr force-pushed the dev branch from cbab81f to 2d3c7a0 Compare January 30, 2026 04:50
@opencode-agent
opencode-agent Bot force-pushed the dev branch from 00637c0 to 71e0ba2 Compare January 30, 2026 14:32
@thdxr
thdxr force-pushed the dev branch 3 times, most recently from f1ae801 to 08fa7f7 Compare January 30, 2026 14:37
@jakvbs jakvbs mentioned this pull request Feb 16, 2026
[FEATURE]: Preserve partial bash output for the model after abort #13809
Closed
1 task done
@randomm randomm mentioned this pull request Feb 19, 2026
feat(tool-use-fix): cherry-pick upstream PR #8497 — fix dangling tool_use blocks on abort/crash randomm/opencode#218
Closed
12 tasks
@github-actions github-actions Bot mentioned this pull request Feb 20, 2026
fix(core): repair interleaved text/tool-call parts in assistant messages #14456
Closed
3 of 6 tasks
@sinwoobang

sinwoobang commented Feb 26, 2026

Copy link
Copy Markdown

What's the blocker of this PR? I need this to be merged.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

This was referenced Feb 26, 2026
fix: prevent infinite retry loop from orphaned tool_use blocks #15152
Closed
fix(zen): guard against empty tool_result content in Anthropic provider #15375
Closed
This was referenced Mar 9, 2026
fix(session): fix root causes and reconstruction of tool_use/tool_result mismatch (#16749) #16751
Closed
fix: filter empty content blocks for Bedrock provider #17381
Closed
@github-actions github-actions Bot mentioned this pull request Mar 21, 2026
fix: discourage _noop tool call during LiteLLM compaction #18539
Merged
3 of 6 tasks
This was referenced Apr 11, 2026
fix(opencode): ensure tool-call/tool-result pairing after normalizeMessages #22001
Closed
feat(provider): add LiteLLM provider support #22008
Closed
@opencode-agent
opencode-agent Bot force-pushed the dev branch from 2f2ed11 to 9f201d6 Compare April 16, 2026 21:55
@zxkane zxkane mentioned this pull request Apr 22, 2026
fix: allow messages with tool blocks when tools array is omitted aws-samples/bedrock-access-gateway#239
Open
@github-actions

github-actions Bot commented Apr 27, 2026

Copy link
Copy Markdown
Contributor

Closing this pull request because it has had no updates for more than 60 days. If you plan to continue working on it, feel free to reopen or open a new PR.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@github-actions github-actions Bot closed this Apr 27, 2026
This was referenced Jun 29, 2026
Session permanently stuck after auto-compaction: post-compaction auto-trigger fires tool_use without tool_result error and is non-recoverable #27594
Closed
fix(provider): Anthropic normalize splits tool-call from tool-result causing dangling tool_use error #25774
Closed
Tool use id bug #5750
Closed
Each tool_use block must have a corresponding tool_result block in the next message. griffinmartin/opencode-claude-auth#212
Closed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

Copilot code review Copilot
Copilot review effort
Applies to this pull request for everyone.Learn more about Copilot code review.
Copilot left review comments

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

fix: Anthropic via LiteLLM/proxies rejects requests with tool history but no tools param LiteLLM error: Anthropic doesn't support tool calling without tools= param specified

Uh oh!

There was an error while loading. Please reload this page.

4 participants

@hendem @seilk @sinwoobang
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.