← Back to PRs

#15130: fix: guard against undefined modelId to prevent .trim() crash in subagent spawn (#15125)

by echoVic open 2026-02-13 02:34 View on GitHub →
agents size: XS
## Problem All subagent spawns crash with: ``` TypeError: Cannot read properties of undefined (reading 'trim') ``` 100% reproducible. The crash occurs in `resolveModel()` and `normalizeCliModel()` when `modelId` is `undefined`. ## Root Cause Session model overrides or misconfigured model references can pass `undefined` as `modelId` to functions that call `.trim()` without checking. ## Fix Add defensive guards with `console.warn()` in both `resolveModel()` and `normalizeCliModel()` so: 1. The crash is prevented (returns error/empty string instead) 2. A warning is logged with the invalid value, making it easy to trace the upstream caller ## Changes (v2) - **Removed** unrelated compaction reset changes (now covered by the `totalTokensFresh` approach in #15133) - **Added** `console.warn()` to both guards so the root cause caller can be traced in logs - **Added** DCO sign-off - Rebased on latest `main` Fixes #15125

Most Similar PRs