Skip to content

fix(bot): stop stderr output from swallowing PR/MR URLs in bot responses#1709

Open
kilo-code-bot[bot] wants to merge 1 commit intomainfrom
fix/bot-stderr-swallows-pr-url
Open

fix(bot): stop stderr output from swallowing PR/MR URLs in bot responses#1709
kilo-code-bot[bot] wants to merge 1 commit intomainfrom
fix/bot-stderr-swallows-pr-url

Conversation

@kilo-code-bot
Copy link
Copy Markdown
Contributor

@kilo-code-bot kilo-code-bot bot commented Mar 30, 2026

Summary

  • Root cause: In runSessionToCompletion(), any stderr output event (git warnings, npm deprecation notices, linter messages) set hasError = true, causing the function to return the error response template which discarded the completionResult containing the PR/MR URL. This meant the Slack/Discord bot never relayed PR links to users when the cloud agent session produced any stderr — which is nearly every session.
  • Fix: Stderr output now sets a separate hasStderr flag instead of hasError. The hasError flag is reserved for actual fatal errors (stream failures, session interruptions, WebSocket errors). Additionally, even when a real error occurs, if the assistant produced a completionResult it is now included in the response so PR/MR URLs are never silently lost.
  • New field: RunSessionResult.hasStderr is added for diagnostic observability without affecting error semantics. No callers currently consume hasError so this is backwards-compatible.

Verification

  • Reviewed all three callers of runSessionToCompletion (slack-bot.ts, discord-bot.ts, spawn-cloud-agent-session.ts) — none consume hasError, they only use response and sessionId, so the behavioral change is safe.
  • Added unit tests for extractTextFromMessage and resolveStreamUrl pure functions.
  • Could not run pnpm typecheck or pnpm test in the sandbox (missing node_modules / tsgo), but changes are minimal and type-safe — only adding a new boolean field to the result type and changing which boolean is set by stderr events.

Visual Changes

N/A

Reviewer Notes

  • The bug existed since the initial implementation of run-session.ts (commit 451764ef), not a recent regression per se, but it became more impactful after the bot was switched to use Cloud Agent Next infrastructure.
  • Key files: src/lib/cloud-agent-next/run-session.ts:320-324 (stderr handler), src/lib/cloud-agent-next/run-session.ts:373-409 (result builder).
  • The error response now includes completionResult when available as a safety net for genuine errors that still produce useful output (e.g., session completed but had a non-zero exit code while the assistant already posted the PR URL).

Stderr output (git warnings, npm notices, etc.) was incorrectly setting
hasError=true, causing runSessionToCompletion to take the error branch
which discarded the completionResult containing the PR/MR URL.

Changes:
- Track stderr via separate hasStderr flag instead of hasError
- Include completionResult in error responses when available
- Add hasStderr to RunSessionResult for diagnostics
- Add tests for extractTextFromMessage and resolveStreamUrl
// When the assistant produced a completionResult (e.g. containing a PR/MR
// URL), prefer returning it even if a fatal error also occurred — losing the
// PR link is the worse outcome for users.
if (hasError) {
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

WARNING: Non-zero agent exits still bypass this error path

This branch only runs when hasError was set earlier, but the complete handler never marks a non-zero exitCode as fatal. After changing stderr to only flip hasStderr, a session that exits with code 1 and only writes to stderr will now fall through to the success response, so users won't see that the run actually failed. Treating complete.data.exitCode !== 0 as an error would preserve the original failure signal while still allowing completionResult to be appended here.

@kilo-code-bot
Copy link
Copy Markdown
Contributor Author

kilo-code-bot bot commented Mar 30, 2026

Code Review Summary

Status: 1 Issue Found | Recommendation: Address before merge

Overview

Severity Count
CRITICAL 0
WARNING 1
SUGGESTION 0

Fix these issues in Kilo Cloud

Issue Details (click to expand)

WARNING

File Line Issue
src/lib/cloud-agent-next/run-session.ts 378 Non-zero complete exit codes no longer reach the error response path, so failed runs with only stderr can be reported as success.
Other Observations (not in diff)

None.

Files Reviewed (2 files)
  • src/lib/cloud-agent-next/run-session.ts - 1 issue
  • src/lib/cloud-agent-next/run-session.test.ts - 0 issues

Reviewed by gpt-5.4-20260305 · 1,320,772 tokens

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.

0 participants