Skip to content

fix(tools): include trailing output in error briefs and render brief as plain text#2389

Open
liruifengv wants to merge 1 commit into
mainfrom
fix/tool-error-brief-tail
Open

fix(tools): include trailing output in error briefs and render brief as plain text#2389
liruifengv wants to merge 1 commit into
mainfrom
fix/tool-error-brief-tail

Conversation

@liruifengv
Copy link
Copy Markdown
Collaborator

@liruifengv liruifengv commented May 28, 2026

Shell: Show trailing output in tool error briefs when commands fail


Open in Devin Review

…as plain text

- Add ToolResultBuilder.tail() to extract last non-empty lines from output
- Include tail output in Shell tool error briefs on non-zero exit
- Include tail output in ACP Terminal tool error briefs on timeout/signal/error
- Render Brief display blocks as plain text instead of Markdown
Copilot AI review requested due to automatic review settings May 28, 2026 09:56
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: d74c4fb234

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment on lines +136 to +137
for chunk in reversed(self._buffer):
for line in reversed(chunk.splitlines()):
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Track tail output after truncation

For commands that emit more than the builder limit before failing (for example a verbose test run that prints >50 KB and then writes the actual failure at the end), write() has already stopped accepting new data, so scanning _buffer here returns the tail of the retained prefix rather than the command's real trailing stderr/stdout. Because the shell failure brief now displays this value, users can still miss the actionable error or see misleading context; keep a small rolling tail independently of the capped output buffer before using it in failure briefs.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

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 improves Shell tool failure reporting by adding trailing command output to error briefs (to surface actionable context) and by rendering briefs as plain text in the shell UI.

Changes:

  • Add ToolResultBuilder.tail() and tests to extract the last non-empty output lines for brief/error context.
  • Include trailing output in Shell/ACP error briefs when commands fail.
  • Render BriefDisplayBlock as plain text (rich.Text) instead of Markdown, and update changelogs.

Reviewed changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
tests/utils/test_result_builder.py Adds unit tests covering the new ToolResultBuilder.tail() behavior.
src/kimi_cli/tools/utils.py Implements ToolResultBuilder.tail() for extracting trailing non-empty lines with truncation.
src/kimi_cli/tools/shell/init.py Appends trailing output to Shell tool error brief for non-zero exit codes.
src/kimi_cli/acp/tools.py Appends trailing output to ACP Terminal tool error briefs (timeout/signal/exit code).
src/kimi_cli/ui/shell/visualize/_blocks.py Renders brief blocks as plain text (not Markdown) in the shell UI.
CHANGELOG.md Adds an Unreleased entry describing the new brief behavior.
docs/en/release-notes/changelog.md Mirrors the Unreleased changelog entry in English docs.
docs/zh/release-notes/changelog.md Adds the corresponding Unreleased entry in Chinese docs.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +130 to +134
def tail(self, max_lines: int = 5, max_line_len: int = 200) -> str:
"""Return the last non-empty lines from the buffer, joined with newlines.

Useful for surfacing actionable error context (stderr) in tool result briefs.
"""
Comment on lines +120 to 124
brief = f"Failed with exit code: {exitcode}"
tail = builder.tail()
if tail:
brief += f"\n{tail}"
return builder.error(
Comment thread src/kimi_cli/acp/tools.py
Comment on lines +145 to +146
tail = builder.tail()
tail_md = f"\n{tail}" if tail else ""

## 未发布

- Shell:工具执行失败时显示完整错误信息
Copy link
Copy Markdown
Contributor

@devin-ai-integration devin-ai-integration Bot left a comment

Choose a reason for hiding this comment

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

Devin Review found 1 potential issue.

View 3 additional findings in Devin Review.

Open in Devin Review

Comment on lines 128 to 129
except TimeoutError:
return builder.error(
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.

🟡 Shell tool omits tail output in timeout error brief, inconsistent with ACP Terminal

The Shell tool only appends builder.tail() to the brief for non-zero exit code errors (lines 120-123), but omits it for TimeoutError (lines 128-132). Meanwhile, the ACP Terminal tool (src/kimi_cli/acp/tools.py:145-150) consistently includes the tail in all error cases including timeout. Before the TimeoutError is raised, stdout_cb/stderr_cb have already written output to the builder (via _run_shell_command at src/kimi_cli/tools/shell/__init__.py:247-254), so builder.tail() would contain useful context about what the command was doing before it timed out.

(Refers to lines 128-132)

Open in Devin Review

Was this helpful? React with 👍 or 👎 to provide feedback.

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.

2 participants