#22897: fix(exec): guard onUpdate callback type in runtime
agents
size: S
Cluster:
Update Handling Fixes
## 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
#22424: fix: prevent crash when onUpdate is truthy but not callable (fixes ...
by mcaxtr · 2026-02-21
82.4%
#17237: fix(update): guard post-install imports after npm global update
by tdjackey · 2026-02-15
75.9%
#18647: fix(agents): guard against undefined paths in injectedFiles
by kleinpanic · 2026-02-16
75.8%
#6577: fix: add null checks for stdout/stderr when using inherit-stdio fal...
by ncmalan · 2026-02-01
75.6%
#20851: fix: harden resolveUserPath and compact against undefined workspaceDir
by davidrudduck · 2026-02-19
74.8%
#22087: Preserve assistant reply when exec fails under suppressToolErrors
by graysurf · 2026-02-20
72.8%
#7085: test: skip flaky workspace-paths & safe-bins tests on non-Linux/CI ...
by ThinkIbrokeIt · 2026-02-02
72.5%
#12498: fix: guard against incomplete onboarding adapters missing getStatus
by hakityc · 2026-02-09
72.5%
#12982: fix(cron): prevent status/list from advancing overdue job nextRunAtMs
by hclsys · 2026-02-10
72.5%
#17393: fix(ci): resolve TS2742 type error blocking all PRs
by miloudbelarebia · 2026-02-15
72.5%