← Back to PRs

#6577: fix: add null checks for stdout/stderr when using inherit-stdio fallback

by ncmalan open 2026-02-01 20:34 View on GitHub →
agents
## 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