#6577: fix: add null checks for stdout/stderr when using inherit-stdio fallback
agents
Cluster:
Windows Path and Exec Fixes
## Summary
Fixes `Cannot read properties of null (reading 'on')` error when exec falls back to `inherit-stdio` mode.
## Problem
When the gateway has file descriptor pressure, spawn can fail with EBADF. The fallback mechanism correctly retries with `stdio: "inherit"`, but the stream listeners were calling `.on()` directly on potentially null stdout/stderr streams, causing crashes.
## Solution
Add optional chaining (`?.`) to the `.on()` calls in two locations:
- `src/agents/bash-tools.exec.ts` (lines 650-651)
- `src/tui/tui-local-shell.ts` (lines 112, 115)
## Files Changed
- `src/agents/bash-tools.exec.ts`
- `src/tui/tui-local-shell.ts`
## Test Plan
- [x] Build passes
- [x] Tested on machine with file descriptor pressure
- [x] Verified exec calls no longer crash when falling back to inherit-stdio
<!-- greptile_comment -->
<h2>Greptile Overview</h2>
<h3>Greptile Summary</h3>
This PR prevents crashes when `spawnWithFallback` falls back to `stdio: "inherit"` (where `child.stdout`/`child.stderr` can be `null`). It updates the two call sites that attach `data` listeners to use optional chaining so listener setup is skipped when streams are absent:
- `src/agents/bash-tools.exec.ts`: `runExecProcess` now uses `child.stdout?.on(...)` / `child.stderr?.on(...)`.
- `src/tui/tui-local-shell.ts`: the local shell runner similarly guards `child.stdout`/`child.stderr`.
These changes fit the existing fallback behavior: the process still runs with inherited stdio, but the code no longer assumes pipes are available to capture output.
<h3>Confidence Score: 5/5</h3>
- This PR is safe to merge with minimal risk.
- Change is narrowly scoped (adds null guards on stdout/stderr listener attachment) and directly addresses a known runtime crash in inherit-stdio fallback mode; it does not alter control flow beyond skipping listener setup when streams are absent.
- No files require special attention
<!-- 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
#8038: fix(exec): use spawnWithFallback to handle EBADF on macOS
by FelixFoster · 2026-02-03
81.2%
#7569: fix: add null checks to prevent TypeError in subagent spawn
by kaigritun · 2026-02-03
77.5%
#6273: fix: handle EPIPE errors gracefully in daemon operations
by batumilove · 2026-02-01
77.3%
#22424: fix: prevent crash when onUpdate is truthy but not callable (fixes ...
by mcaxtr · 2026-02-21
76.2%
#2541: fix(agents): add error handling to orphaned message cleanup
by Episkey-G · 2026-01-27
76.0%
#22897: fix(exec): guard onUpdate callback type in runtime
by Phineas1500 · 2026-02-21
75.6%
#10034: Don't crash gateway on transient unhandled fetch failures
by gigq · 2026-02-06
75.3%
#18647: fix(agents): guard against undefined paths in injectedFiles
by kleinpanic · 2026-02-16
75.3%
#12871: fix: use bash and warn about shell injection (issue #12836)
by ambicuity · 2026-02-09
75.2%
#15999: fix: handle null/undefined in activity feed filters
by pamnlambert · 2026-02-14
74.9%