Skip to content

fix: preserve tool output when execution fails - #1

Merged
Balanov merged 1 commit into
Balanov:mainfrom
Zenty-Me:fix/preserve-failed-tool-output
Nov 13, 2026
Merged

Balanov merged 1 commit into
Balanov:mainfrom
Zenty-Me:fix/preserve-failed-tool-output

Conversation

@Zenty-Me

@Zenty-Me Zenty-Me commented Nov 4, 2026

Copy link
Copy Markdown
Contributor

When a tool returns both diagnostic output and an error, the agent currently replaces the output with the error message. For example, a failing test command loses its failure details before the next model request and in the saved session, leaving only the exit-status error.

Preserve the tool output and append the error message. Add offline, table-driven coverage that checks both the next model request and the persisted transcript for failed tools with and without output, successful tools, and empty results.

Validation:

  • Confirmed the new failure-with-output case fails against the original implementation because both the model request and saved transcript omit the diagnostics.
  • go fmt ./...
  • go test ./...
  • go vet ./...
  • git diff --check

@Zenty-Me
Zenty-Me marked this pull request as ready for review November 4, 2026 03:34
@Balanov

Balanov commented Nov 5, 2026

Copy link
Copy Markdown
Owner

Thanks for the focused fix. I independently confirmed that the new regression test fails against the original main: both the next model request and the persisted transcript lose the diagnostic output. On this PR, local Windows test, vet, and build checks pass.

I’m not merging over a red check. The latest Ubuntu attempt (#3) fails again in the unchanged TestStdioMCPTool, while macOS/Windows and Ubuntu’s internal/agent tests pass. I opened #2 with the exact logs and current evidence so the MCP stdio failure can be investigated separately rather than hidden by repeated reruns.

The code review is otherwise complete; this PR remains open pending a trustworthy Linux CI result.

@Balanov

Balanov commented Nov 13, 2026

Copy link
Copy Markdown
Owner

Thanks. The failure mode is real and worth fixing: internal/tools/shell.go already returns the captured output together with the error (return out.String(), fmt.Errorf("command failed: %w", err)), and internal/agent/agent.go was throwing that output away and substituting the error string, so the failing test output never reached the next model request nor the saved transcript.

The table-driven coverage is the right shape — it checks both the next request and the persisted transcript, with and without output.

One nit: the two parts are joined with a newline, so an output that already ends in a newline produces a blank line before Error: .... strings.TrimRight(result, "\n") before joining keeps the transcript tidy. Not blocking.

@Balanov
Balanov merged commit 2df6eb5 into Balanov:main Nov 13, 2026
4 of 6 checks passed
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