feat(tool): concise error output for failed shell commands - #39982
feat(tool): concise error output for failed shell commands#39982openchat-ai wants to merge 2 commits into
Conversation
There was a problem hiding this comment.
Pull request overview
This PR implements part 3 of #39771 by making shell-command failures return a concise tail of output (50 lines / 8 KB) while saving the full output to the truncation file, reducing noisy context on repeated CI/build failures.
Changes:
- Add failure-specific tail limits for shell output to keep error context short on non-zero exit.
- When truncation occurs on failure, include an exit-code status line and a pointer to the saved full output.
- Add/extend tests to cover truncation behavior for failed commands and ensure full output is persisted.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| packages/opencode/src/tool/shell.ts | Adds failure-specific tail truncation and formats truncated failure output with exit code + saved-log pointer. |
| packages/opencode/test/tool/shell.test.ts | Adds a failing-output generator and new test cases for failed-command truncation and persistence. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| if (cut && file) { | ||
| output = `...output truncated...\n\nFull output saved to: ${file}\n\n` + output | ||
| const status = failed ? `Command failed with exit code ${code}.\n\n` : "" | ||
| output = | ||
| `...output truncated...\n\n${status}Full output saved to: ${file}\n\n` + output | ||
| } |
| }) | ||
| expect(result.metadata.exit).toBe(3) | ||
| expect(result.metadata.truncated).toBe(false) | ||
| expect(result.output).toBe("(no output)") | ||
| }), |
|
Thanks for updating your PR! It now meets our contributing guidelines. 👍 |
|
Hi there! First-time contributor here, and I noticed the CI checks on this PR are currently waiting for approval to run (they show as action_required). I'd be grateful if you could approve the workflow run whenever you have a moment — no rush at all. Happy to make any adjustments if needed, thanks! |
Issue for this PR
Closes #39771
Type of change
What does this PR do?
Part 3 of issue #39771 (concise error output). Parts 1-2 (smart timeouts: network 15s, build 300s) were already implemented in #39978.
Before, when a shell command failed (non-zero exit code), the tool returned the full output (up to 50 KB / 2000 lines), which flooded the model context with ~5000 tokens of stack-trace noise on every failed build/CI cycle.
After, failed commands return:
Command failed with exit code N.status line, whether or not the output was truncatedSuccessful commands are unchanged.
How did you verify your code works?
Added two tests:
truncates failed command output to a short tail and saves full output to filedoes not truncate failed command output when it is smallBoth pass.
bun typecheckpasses.Screenshots / recordings
N/A
Checklist