← Back to PRs

#22897: fix(exec): guard onUpdate callback type in runtime

by Phineas1500 open 2026-02-21 20:04 View on GitHub →
agents size: S
## Summary - fix a crash path in `runExecProcess` by guarding `opts.onUpdate` with a strict function check - previously, truthy non-function values could pass the falsy guard and throw `TypeError: opts.onUpdate is not a function` - add a regression test that simulates a truthy non-function `onUpdate` value while stdout updates are emitted ## Testing - `pnpm vitest run src/agents/bash-tools.exec-runtime.on-update-guard.test.ts` ## AI Transparency - [x] AI-assisted - [x] Lightly tested (targeted test) Fixes #22206 <!-- greptile_comment --> <h3>Greptile Summary</h3> Fixed a crash path in `runExecProcess` by adding a strict type check for the `opts.onUpdate` callback. Previously, the code used a falsy check (`if (!opts.onUpdate)`) which would allow truthy non-function values (like `true`, `1`, objects, etc.) to pass through, resulting in a `TypeError: opts.onUpdate is not a function` when invoked. The fix implements `typeof opts.onUpdate !== "function"` guard, which aligns with the codebase's existing pattern for callback validation and prevents runtime errors. **Changes:** - Updated callback guard in `emitUpdate` function from falsy check to explicit function type check - Added regression test that verifies truthy non-function `onUpdate` values are safely ignored - Import order changes (auto-formatted by oxfmt) <h3>Confidence Score: 5/5</h3> - This PR is safe to merge with minimal risk - it's a defensive bug fix with proper test coverage. - The change is a focused, defensive fix that prevents a specific crash scenario. The fix uses a well-established pattern (`typeof !== "function"`) that appears throughout the codebase (20+ occurrences). The regression test adequately simulates the failure case, and the change doesn't affect any other logic paths. - No files require special attention <sub>Last reviewed commit: f704f20</sub> <!-- greptile_other_comments_section --> <!-- /greptile_comment -->

Most Similar PRs