Skip to content

fix(opencode): share tool response truncation - #138

Merged
MagMueller merged 3 commits into
mainfrom
bound-tool-errors
Aug 2, 2026
Merged

fix(opencode): share tool response truncation#138
MagMueller merged 3 commits into
mainfrom
bound-tool-errors

Conversation

@MagMueller

@MagMueller MagMueller commented Aug 2, 2026

Copy link
Copy Markdown
Contributor

Summary

  • use the existing tool-response truncator for successful output, persisted tool errors, workflow-tool errors, and malformed tool-call repairs
  • reduce the shared default limit from 50 KiB to 40 KiB while retaining the existing 2,000-line limit and configuration overrides
  • save complete truncated content in the existing seven-day tool-output store and return the same head preview plus file path
  • keep a bounded preview if the archive write fails, for both successful responses and errors

Why

A production malformed browser_execute call contained roughly 118,000 newline characters. AI SDK InvalidToolInputError copied the malformed tool input into its error, and JSON reserialization persisted a roughly 445,000-character assistant message. A later tiny user turn then exceeded model context. Normal tool-output truncation did not apply because the oversized content crossed the boundary as tool input and error rather than successful output.

Validation

  • bun test test/tool/truncation.test.ts test/session/session.test.ts: 28 passed
  • production-shaped 118,000-newline malformed-input regression: passed and full error archived
  • shell truncation regressions: 4 passed
  • packages/opencode bun typecheck: passed
  • root filtered typecheck: 16 packages passed
  • targeted oxlint: 0 errors
  • Prettier and git diff --check: passed
  • repository pre-push hook with Bun 1.3.14: passed

Scope

The final diff is four files. Three source integration points remain necessary: the shared truncator, the central persisted-tool-error boundary, and the AI SDK malformed-call repair boundary.

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

All reported issues were addressed across 6 files

Reply with feedback, questions, or to request a fix.

Fix all with cubic | Re-trigger cubic

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

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

All reported issues were addressed across 6 files (changes from recent commits).

Tip: Review your code locally with the cubic CLI to iterate faster.

Fix all with cubic | Re-trigger cubic

Comment thread packages/opencode/src/session/llm.ts
Comment thread packages/opencode/src/session/llm.ts
@MagMueller MagMueller changed the title fix(opencode): bound oversized tool errors fix(opencode): share tool response truncation Aug 2, 2026
@MagMueller

Copy link
Copy Markdown
Contributor Author

Pre-merge Cloud/explore verification:

  • The Cloud v4 worker pins bcode 0.1.15. That tag contains the native task tool and explore subagent; generated bcode.json only denies websearch, so task/explore remain enabled.
  • Live current-source smoke with an isolated data root completed end to end: build -> task(subagent_type=explore) -> child Grep on the archived tool-output -> child Read(offset=12002, limit=1) -> exact RECOVERY_SENTINEL_7F3A91C2 -> exact parent answer.
  • Exporting the child session confirmed agent=explore and both tool calls completed.
  • Relevant local checks: truncation 21/21, native-agent 2/2, Cloud config 2/2. The broader Task file has four existing config-fixture failures; the same 16-pass/4-fail result reproduced on untouched origin/main.
  • A first macOS /tmp run encountered the /tmp -> /private/tmp alias permission boundary; rerunning with the canonical path passed. Cloud workers are Linux, so that alias is not present there.

@MagMueller
MagMueller merged commit 36f3c0d into main Aug 2, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant