-
-
Notifications
You must be signed in to change notification settings - Fork 276
feat(tools): save large task outputs to file to prevent truncation #269
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: dev
Are you sure you want to change the base?
feat(tools): save large task outputs to file to prevent truncation #269
Conversation
When background-task or call-omo-agent responses exceed 15000 characters, save full output to ~/.local/share/opencode/storage/task-outputs/ and return file path with 2000 char preview. This prevents tool output truncation and avoids main agent re-reading codebase unnecessarily.
Greptile SummaryAdded file-based storage for large outputs (>15k chars) in Key Changes
Issues Found
Confidence Score: 3/5
Important Files Changed
Sequence DiagramsequenceDiagram
participant Agent as Main Agent
participant Tool as background_task/call_omo_agent
participant Check as Output Size Check
participant Storage as File Storage
participant Return as Tool Return
Agent->>Tool: Execute tool with prompt
Tool->>Tool: Process task/agent execution
Tool->>Check: Check output.length > 15,000?
alt Output exceeds 15k chars
Check->>Storage: getTaskOutputsDir()
Storage->>Storage: Create ~/.local/share/opencode/storage/task-outputs/
Check->>Storage: saveOutputToFile(id, content)
Storage->>Storage: Write {tool}_{id}_{timestamp}.md
Storage-->>Check: Return file path
Check->>Check: truncateText(content, 2000)
Check->>Return: Format with file path + preview
Return-->>Agent: Large Output message with file ref
else Output within limit
Check->>Return: Return full output directly
Return-->>Agent: Complete output inline
end
|
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.
Additional Comments (3)
-
src/tools/background-task/tools.ts, line 96-116 (link)style: these helper functions (
getTaskOutputsDir,saveOutputToFile,truncateText) are duplicated incall-omo-agent/tools.ts. extract to shared utility file to maintain DRY principleNote: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
-
src/tools/background-task/tools.ts, line 104-111 (link)logic: wrap file write in try-catch to handle potential errors (disk full, permission denied, etc.)
-
src/tools/call-omo-agent/tools.ts, line 20-27 (link)logic: wrap file write in try-catch to handle potential errors (disk full, permission denied, etc.)
2 files reviewed, 3 comments
|
This is cool! |
|
i am thinking of where to save that file between tmp/ or persistence file path |
- Extract duplicated functions to src/shared/task-output.ts - Use temp directory for ephemeral storage (auto-cleaned on reboot) - Add try/catch error handling for file I/O operations - Graceful fallback to inline output if file write fails Addresses PR code-yeongyu#269 review comments from Greptile
|
I think i am talking with another agent lool |
I'd recommend tmp/ for this use case. Here's why: Context: Replicating Claude Code's BehaviorClaude Code handles large outputs (100k+ chars) by saving to disk to prevent context bloat. Their pattern:
Why tmp/ makes sense for us:
Proposed path structure:Additional fixes in this update:
Let me know if you'd prefer persistent storage instead! |
|
Ha! Yes, same agent here — just continuing across sessions. 🙂 Updates are done and pushed:
Ready for your review when you have a chance! |
haha its actually me here im using omo to code this feature as well. im basically tryna replicate the claude code feature with this plugin which was recently added |
great- can you give me some time to review? i think i have to organize of my thoughts! |
yeah no worries take your time im resolving conflicts now, basically added this feature on the fly while i was coding in another session and the session crashed a few times cause of context limits during agent and tool calls |
Keep our file-based large output implementation using shared task-output utilities
Mirrors Claude Code's behavior - when output is saved to file, include clear requirements for the agent to read the file content before summarization.
Summary
When
background-taskorcall-omo-agentresponses exceed 15,000 characters, the tool output can be truncated, causing the main agent to lose context and often re-read the entire codebase unnecessarily.This PR saves large outputs to
~/.local/share/opencode/storage/task-outputs/and returns:Changes
formatTaskResultwhen output exceeds thresholdImplementation Details
~/.local/share/opencode/storage/task-outputs/{tool}_{task-id}_{timestamp}.mdgetOpenCodeStorageDir()helper for consistent data path handlingTesting