← Back to PRs

#6603: fix: use allowAny flag instead of size check for model override validation (#6573)

by gavinbmoore open 2026-02-01 21:20 View on GitHub →
commands
## Summary Fixes #6573: `sessions_spawn` ignores the `model` parameter, always using the default model. ## Root Cause In `src/commands/agent.ts`, the condition for accepting a stored model override was: ```ts allowedModelKeys.size === 0 || allowedModelKeys.has(key) ``` When there's no explicit allowlist, `buildAllowedModelSet` returns `allowAny=true` but **still populates** `allowedKeys` with all catalog models. This means: - `allowedModelKeys.size === 0` is FALSE (size > 0) - `allowedModelKeys.has(key)` might be FALSE for a valid model not in the catalog - Result: valid model overrides get silently ignored ## Fix Capture the `allowAny` flag from `buildAllowedModelSet` and use it instead of checking `allowedModelKeys.size === 0`: ```ts // Before: if (allowedModelKeys.size === 0 || allowedModelKeys.has(key)) // After: if (allowAnyModel || allowedModelKeys.has(key)) ``` ## Testing - Added new test file: `src/commands/agent.model-override-respects-stored-override.test.ts` - All 26 related tests pass - TypeScript compiles without errors <!-- greptile_comment --> <h2>Greptile Overview</h2> <h3>Greptile Summary</h3> This PR fixes model override validation in `src/commands/agent.ts` by using the `allowAny` flag from `buildAllowedModelSet()` rather than inferring “no restrictions” from `allowedModelKeys.size === 0`. This ensures stored model overrides are respected when there’s no explicit allowlist, even if the model isn’t present in the static catalog. A new vitest file was added to cover the `allowAny` behavior and the intended acceptance/rejection rules depending on whether an explicit allowlist is configured. <h3>Confidence Score: 3/5</h3> - This PR is likely safe to merge; the functional change is small and targeted, but the added test coverage appears partially miswired. - The production change in `agent.ts` is straightforward (use `allowAny` instead of `Set.size` heuristics) and aligns with the described root cause. However, the new test file contains issues (wrong module mocked for `runEmbeddedPiAgent`, and the key regression test doesn’t actually exercise `agentCommand`), which reduces confidence in the PR’s ability to prevent regressions. - src/commands/agent.model-override-respects-stored-override.test.ts <!-- greptile_other_comments_section --> <sub>(4/5) You can add custom instructions or style guidelines for the agent [here](https://app.greptile.com/review/github)!</sub> <!-- /greptile_comment -->

Most Similar PRs