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 — feat: add file persistence for large tool outputs by ben-vargas · Pull Request #6234 · anomalyco/opencode Conversation
|
| Aspect | Upstream Truncation | This PR |
|---|---|---|
| Prompt size | ✅ Controlled | ✅ Controlled |
| Data access | ❌ Lost permanently | ✅ Preserved on disk |
| Model exploration | ❌ Cannot access | ✅ Via Read/Grep/jq |
All tools automatically get file persistence:
Tool.define() wrapperfromPlugin()
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
I'm constantly having the prompt is too long error so this PR would be greatly appreciated. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Can we get this prioritized @fwang |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
This seems likely to fix the single biggest usability issue with opencode that I keep hitting over and over and over... literally daily, multiple times per day with normal use of opencode. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
It's worked for me over the past few days. Haven't hit the "prompt too long" issue once. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
Cherry-picked from PR anomalyco#6234 (ben-vargas/ai-opencode) When tool outputs exceed 30,000 characters, save to disk instead of passing to model context. This prevents 'prompt is too long' errors caused by large WebFetch, Bash, or MCP tool outputs. Changes: - Add tool-results.ts: Storage helper for large outputs - Update bash.ts, webfetch.ts, websearch.ts, codesearch.ts: File persistence - Update prompt.ts: MCP tools save large outputs to file - Update session/index.ts: Cleanup tool_results on session delete - Add OPENCODE_EXPERIMENTAL_MCP_MAX_OUTPUT_LENGTH flag for configurability
Just wanted to note, this actually hasn't completely fixed the bug for me. It has significantly lowered the frequency that I run into it, but it still happens a few times a day now. Seems like the team is working on a fix though. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
@codyw912 - yeah, this is just addressing one possible cause (tool use and specifically mcp tools) which often caused it for me. But i'm certain there are other edge cases to be addressed, hopefully their team gets all of them if not wanting to merge this PR. I do hope they retain or implement a feature similar to writing to a file rather than just returning truncated data, the models are much more effective when they can be warned of the truncation and take a couple attempts at reading/exploring the large data, especially useful when using tools in enterprise (think reading data from salesforce or servicenow APIs). Flat out truncation of what the model gets back from tools alone isn't great. @thdxr - Any thoughts on having this kind of file write rather than pure truncation of tools? |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
496ae0e to
0339c06
Compare
|
+1 |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
Refactors the file persistence feature to work with the new centralized
truncation architecture in upstream. Instead of modifying each tool
individually, this integrates file persistence directly into the
Truncate namespace.
When tool output exceeds 50KB/2000 lines, the full output is saved to
disk and the model receives a head+tail preview with instructions for
exploring the data using Read/Grep/jq tools.
Changes:
- truncation.ts: Add outputWithPersistence() function with:
- Head (67%) + tail (33%) preview respecting caller's maxLines
- Preview byte cap respecting min(caller's maxBytes, 20KB)
- JSON detection (.json extension + jq hint)
- 10MB hard cap on persisted files (using Buffer for both detection
AND truncation to handle multibyte chars correctly)
- Tool name sanitization (64 char limit, safe chars only)
- Path traversal protection (sessionID validation + resolve check)
- cleanupSessionFiles() for session deletion
- tool.ts: Update Tool.define() wrapper to use outputWithPersistence
- registry.ts: Update fromPlugin() to use outputWithPersistence
- session/index.ts: Call Truncate.cleanupSessionFiles on session delete
Benefits over previous per-tool approach:
- Single point of change - all tools automatically get file persistence
- Aligns with upstream's centralized truncation architecture
- No duplicate truncation logic across multiple files
- Cleaner integration with existing session lifecycle
2e5a12e to
ce28fd3
Compare
MCP tools have a separate execution path in prompt.ts that wasn't covered by the centralized truncation changes. This adds Truncate.outputWithPersistence() to the MCP tool wrapper so that large outputs from MCP tools (like firecrawl) are also saved to disk instead of overflowing the context window. Also improves the truncation notice to be more explicit that the preview is INCOMPLETE and the model MUST read the file for accurate results - prevents models from answering based on partial data.
When a tool output is truncated and saved to file, the TUI now shows a [truncated] indicator in the tool call line so users can see at a glance that the output was truncated. Shows in warning color on both InlineTool and BlockTool displays.
|
@rekram1-node one thing I found really helpful on the tool truncation persistence was the small little indicator to the user I added in the refactor which was done after your PR merging concepts. You might consider adding something similar to 5e0aca1 in this branch so the user knows when a tool was truncated... helpful because sometimes I have to know truncation happened and prompt it to look a little deeper at the persisted tool output, and user doesn't know unless there is an indicator of some kind. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Also, thanks for considering and landing the persistence!! |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
00637c0 to
71e0ba2
Compare
f1ae801 to
08fa7f7
Compare
|
mostly addressed by other commits referenced above |
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.
[FEATURE]: Context protection for tool calls when response is large
There was an error while loading. Please reload this page.