#21215: Windows PowerShell reliability fixes (exec shim + Discord numeric parse + sanitized tool errors)
channel: discord
agents
size: M
Cluster:
Tool Execution and Error Handling
## Summary
Ports and validates Windows workflow fixes on top of current main (2026.2.19 line).
### Included
- sanitize terminal control sequences in logger/tool error text
- normalize xec tool commands on Windows to run via cmd /d /s /c when command contains && or ||
- parse numeric guildId/channelId Discord targets correctly
- apply messages.suppressToolErrors before tool-error warning fallback
### Validation
- src/logger.test.ts
- src/discord/resolve-channels.test.ts
- src/agents/pi-tool-definition-adapter.e2e.test.ts
- src/agents/pi-embedded-runner/run/payloads.e2e.test.ts
<!-- greptile_comment -->
<h3>Greptile Summary</h3>
This PR consolidates Windows PowerShell reliability fixes into the current main branch. The changes address terminal control sequence sanitization, Windows command execution with shell operators, Discord numeric channel resolution, and tool error suppression behavior.
Key changes:
- Sanitizes terminal control sequences (ANSI escape codes, OSC sequences) from logger error messages and tool error text to prevent log pollution
- Wraps Windows `exec` tool commands containing `&&` or `||` with `cmd /d /s /c` to ensure proper shell operator handling
- Fixes Discord channel resolution to correctly parse numeric guild/channel ID pairs (e.g., `111/222`) by checking if both parts are numeric before routing to channel ID lookup
- Reorders `suppressToolErrors` check to occur before mutating tool error detection, ensuring `messages.suppressToolErrors` config properly suppresses all tool errors including mutating ones
- Changes tool execution error logging from `logError` to `logDebug` for cleaner console output
<h3>Confidence Score: 4/5</h3>
- This PR is safe to merge with minor considerations about edge case handling
- The changes are well-tested with comprehensive unit tests covering the main scenarios. The terminal sanitization and tool error suppression logic are straightforward and correct. The Discord numeric parsing fix addresses a real bug. The Windows cmd shim has potential edge cases with complex escaping scenarios (backslashes in paths), but these are likely rare in practice and the basic functionality is sound. No security issues or critical bugs detected.
- Pay attention to `src/agents/pi-tool-definition-adapter.ts` for potential Windows command escaping edge cases with file paths containing backslashes
<sub>Last reviewed commit: bebfd19</sub>
<!-- greptile_other_comments_section -->
<sub>(3/5) Reply to the agent's comments like "Can you suggest a fix for this @greptileai?" or ask follow-up questions!</sub>
<!-- /greptile_comment -->
Most Similar PRs
#5168: Fix: force UTF-8 for Windows exec
by ManojINaik · 2026-01-31
79.6%
#19632: fix: suppressToolErrors now suppresses exec tool failure notifications
by Gitjay11 · 2026-02-18
79.1%
#21271: fix(commands): pass channel/capabilities/shell/os to runtime in com...
by evansantos · 2026-02-19
77.5%
#9250: Fix: Add shell:true for Windows .cmd files to prevent spawn EINVAL ...
by vishaltandale00 · 2026-02-05
76.9%
#21463: fix(discord): prevent WebSocket death spiral + fix numeric channel ID…
by akropp · 2026-02-20
76.5%
#5950: Improvement/windows shell enhancement
by zzjj7000 · 2026-02-01
76.3%
#7507: test(ci): make tests cross-platform (Windows) + add basic sanitizat...
by ThinkIbrokeIt · 2026-02-02
76.0%
#11300: feat(exec): make shell configurable via tools.exec.shell
by imjszhang · 2026-02-07
76.0%
#19235: fix(telegram): tool error warnings no longer overwrite streamed rep...
by gatewaybuddy · 2026-02-17
75.9%
#18143: fix(windows): wrap shell builtins with cmd.exe /c for proper execution
by brandonwise · 2026-02-16
75.9%