Skip to content

feat(tool): concise error output for failed shell commands - #39982

Open
openchat-ai wants to merge 2 commits into
anomalyco:devfrom
openchat-ai:concise-shell-errors
Open

feat(tool): concise error output for failed shell commands#39982
openchat-ai wants to merge 2 commits into
anomalyco:devfrom
openchat-ai:concise-shell-errors

Conversation

@openchat-ai

@openchat-ai openchat-ai commented Aug 1, 2026

Copy link
Copy Markdown

Issue for this PR

Closes #39771

Type of change

  • New feature

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:

  • A short tail of the output (50 lines / 8 KB), where errors usually live
  • An explicit Command failed with exit code N. status line, whether or not the output was truncated
  • When truncated, the full output is still saved to the truncation file with a hint to read it

Successful 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 file
  • does not truncate failed command output when it is small

Both pass. bun typecheck passes.

Screenshots / recordings

N/A

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

Copilot AI review requested due to automatic review settings August 1, 2026 01:23
@github-actions github-actions Bot added the needs:compliance This means the issue will auto-close after 2 hours. label Aug 1, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.

Comment on lines 584 to 588
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
}
Comment on lines +1234 to +1238
})
expect(result.metadata.exit).toBe(3)
expect(result.metadata.truncated).toBe(false)
expect(result.output).toBe("(no output)")
}),
@github-actions github-actions Bot removed the needs:compliance This means the issue will auto-close after 2 hours. label Aug 1, 2026
@github-actions

github-actions Bot commented Aug 1, 2026

Copy link
Copy Markdown
Contributor

Thanks for updating your PR! It now meets our contributing guidelines. 👍

@openchat-ai

Copy link
Copy Markdown
Author

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!

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.

[FEATURE]: Fast failure on network errors and concise error output

2 participants