GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | |||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | |||||||||||||||||||||
GeezerVison is showing github.com — fix: handle dangling tool_use blocks for LiteLLM proxy compatibility by hendem · Pull Request #8497 · anomalyco/opencode Conversation
|
| 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 |
Fixes #8246
Fixes #2915
Related to #3243 (stale PR with merge conflicts addressing similar ordering issue)
modify_params=True workaround, but many corporate proxy deployments cannot change this setting
Sorry, something went wrong.
There was an error while loading. Please reload this page.
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
|
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 FoundPR #8248: fix: avoid Anthropic tool-history requests without tools Why it's related: This PR addresses a very similar issue - handling requests that contain tool calls/history but lack the 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. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
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:
_noop tool is added when message history contains tool calls but no tools are providedCopilot 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.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Re: Related PR #8248Thanks for flagging the potential duplicate. I've reviewed PR #8248 and here's how this PR differs: PR #8248 only addresses Issue 1 (missing
This PR (#8497) addresses both issues:
The second fix is critical because even with the dummy tool, if there are dangling 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. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
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.
There was an error while loading. Please reload this page.
|
I've created #8658 which builds on this PR and addresses @rekram1-node's feedback from #8248. The key change: Restricts Detection logic: const isLiteLLMProxy = provider.options?.["litellmProxy"] === true || input.model.providerID.toLowerCase().includes("litellm") || input.model.api.id.toLowerCase().includes("litellm") Why this matters:
Config example for custom gateways: {
"provider": {
"my-gateway": {
"options": { "litellmProxy": true }
}
}
}Happy to discuss merging this into your PR or keeping them separate. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
00637c0 to
71e0ba2
Compare
f1ae801 to
08fa7f7
Compare
|
What's the blocker of this PR? I need this to be merged. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
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. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
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
There was an error while loading. Please reload this page.