fix: preserve foreground exec output (#202177) Root cause: src/agents/bash-tools.exec-runtime.ts:722 builds the exec outcome from `session.aggregated.trim()`, and that one trimmed string becomes both the model-facing text and the structured `aggregated` value that Code Mode hands to the program, so leading and trailing whitespace in command output is lost. Fixes #202173 Thanks @sasan1200 for the report and the fix. ## What Problem This Solves When a Code Mode program runs a command with `exec` and reuses its output, leading and trailing whitespace is gone. A unified diff that ends in a blank context line comes back 3 bytes short, and Git rejects it as a corrupt patch. ## User Impact Programs get the exact output of a successful foreground command, so diffs and other whitespace-sensitive output can be passed on to the next command. The text the model reads for a direct `exec` call is unchanged. ## Why This Change Was Made For a successful command (exit 0), the structured result now uses the process output the session already keeps. Failures and nonzero exits keep their current text with the diagnostics. Nothing new is shown to the model. Consumers of the structured value: the Code Mode value (now exact), the `/bash` chat reply, command-exec replies and cron diagnostics (they all trim before showing it, so no change), live command-output events (may now end in a newline), and stored transcripts (keep the exact bytes, still under the same caps). The other test updates show the same change: those tests assert the real output of commands like `pwd` and `cat`, which ends in a newline. None of them tested trimming on purpose. ## Evidence Proof comment: https://github.com/openclaw/openclaw/pull/202177#issuecomment-7028677391 (CI follow-up: https://github.com/openclaw/openclaw/pull/202177#issuecomment-7029040640) - Isolated Gateway, Code Mode, scripted local model, same 84-byte patch. Base 0eb1fa3f7471 returns 81 bytes, and `git apply --check` on the returned patch exits 128 (`corrupt patch at <stdin>:6`). This head returns 84 bytes and the check exits 0. - Control: with Code Mode off, the tool text the model receives for ordinary `exec` output is byte-identical on base and head. - The strengthened Code Mode agent-loop test fails on base and passes here. Focused suites: 6 files, 100 tests passed, plus a sweep of 19 exec and Code Mode files (259 passed). The group-cleanup test also expected the trimmed heredoc output and now expects its newline. Merge danger: a two-way door. A revert fully undoes it, and it writes no state or config. Blast radius: Code Mode programs and anything that reads the structured `aggregated` value of a successful foreground exec, which now keeps leading and trailing whitespace. Production +3 lines, tests +1 line (9 files). Co-authored-by: Ayaan Zaidi <hi@obviy.us>
Current
·
C2
·2026-11
fix: preserve foreground exec output (#202177)
Find Your Interest
Current
·
C2
·2026-11





