[PR #10995] fix: maxOutputTokens was accidentally hardcoded to undefined #13626

Closed
opened 2026-02-16 18:18:28 -05:00 by yindo · 0 comments
Owner

Original Pull Request: https://github.com/anomalyco/opencode/pull/10995

State: closed
Merged: Yes


Summary

Problem

Since v1.1.37, users experienced errors like:

[Pasted⚙ invalid tool=write, error=Invalid input for tool write: JSON parsing failed: Text: {"content": "...
Error message: JSON Parse error: Unterminated string

This occurred when the LLM generated write tool calls with large content (e.g., pasting long code files).

Changes

  • Restored the correct maxOutputTokens calculation in packages/opencode/src/session/llm.ts
  • Added logging for max_output_tokens to aid future debugging

Explanation of the Question

https://github.com/anomalyco/opencode/issues/10967#issuecomment-3814885708

Root Cause

In commit ac53a372b, the maxOutputTokens was accidentally hardcoded to undefined:

// Before (broken)
const maxOutputTokens = isCodex ? undefined : undefined
// After (fixed)
const maxOutputTokens = isCodex
  ? undefined
  : ProviderTransform.maxOutputTokens(...)

Without proper output token limits, some providers would truncate the response at their own default limits, cutting off JSON mid-string and causing parse failures.
When JSON parsing fails, the experimental_repairToolCall of AI SDK cannot fix the malformed input, so it falls back to the invalid tool, resulting in the [Pasted⚙ invalid [tool=write, error=... error message shown to users.

**Original Pull Request:** https://github.com/anomalyco/opencode/pull/10995 **State:** closed **Merged:** Yes --- ## Summary - Fixes tool call JSON parsing failures that started in v1.1.37 - Restores the `maxOutputTokens` calculation that was accidentally disabled - Fixes #10967 - Fixes #11072 (I think it's the same problem). ## Problem Since v1.1.37, users experienced errors like: ``` [Pasted⚙ invalid tool=write, error=Invalid input for tool write: JSON parsing failed: Text: {"content": "... Error message: JSON Parse error: Unterminated string ``` This occurred when the LLM generated `write` tool calls with large content (e.g., pasting long code files). ## Changes - Restored the correct maxOutputTokens calculation in packages/opencode/src/session/llm.ts - Added logging for max_output_tokens to aid future debugging ## Explanation of the Question https://github.com/anomalyco/opencode/issues/10967#issuecomment-3814885708 ## Root Cause In commit ac53a372b, the `maxOutputTokens` was accidentally hardcoded to `undefined`: ```typescript // Before (broken) const maxOutputTokens = isCodex ? undefined : undefined // After (fixed) const maxOutputTokens = isCodex ? undefined : ProviderTransform.maxOutputTokens(...) ``` Without proper output token limits, some providers would truncate the response at their own default limits, cutting off JSON mid-string and causing parse failures. When JSON parsing fails, the experimental_repairToolCall of AI SDK cannot fix the malformed input, so it falls back to the invalid tool, resulting in the `[Pasted⚙ invalid [tool=write, error=...` error message shown to users.
yindo added the pull-request label 2026-02-16 18:18:28 -05:00
yindo closed this issue 2026-02-16 18:18:28 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#13626