← Back to PRs

#20185: fix(model): recognize default/reset/clear keywords to clear session model override (#20137)

by yxshee open 2026-02-18 16:30 View on GitHub →
size: S
## Problem When a user types `/model default`, `/model reset`, or `/model clear`, the keyword was treated as a literal model ID. The default provider was prepended (e.g. `anthropic/default`) and the allowlist check failed with: ``` Model "anthropic/default" is not allowed. Use /models to list providers... ``` ## Root Cause `resolveModelDirectiveSelection()` and `resolveModelSelectionFromDirective()` passed the raw argument directly to `resolveModelRefFromString()` without first checking for reserved keywords. The session layer (`model-overrides.ts`) already supports `isDefault: true` to delete overrides — but no caller ever sent that flag for keyword arguments. ## Fix - Intercept single-token keywords (`default`, `reset`, `clear`) **before** model ID resolution in both functions - Return `isDefault: true` which triggers the existing `delete entry.modelOverride` logic in `applyModelOverrideToSessionEntry` - `provider/default` (contains a slash) is still treated as a literal model ID - Keywords are case-insensitive (`DEFAULT`, `Reset`, `CLEAR` all work) - Updated `/model` help text to advertise the reset keywords ## Changes | File | Change | |------|--------| | `src/auto-reply/reply/directive-handling.model.ts` | Keyword interception in `resolveModelSelectionFromDirective`; help text update | | `src/auto-reply/reply/model-selection.ts` | Keyword interception in `resolveModelDirectiveSelection` | | `src/auto-reply/reply/model-selection.test.ts` | 7 new unit tests | ## Tests 7 new unit tests added covering: - `default`, `reset`, `clear` each return `isDefault: true` - Case-insensitivity (`DEFAULT`, `Reset`, `CLEAR`) - `provider/default` (with slash) treated as model ID, not keyword - Reset keyword bypasses allowlist entirely - Trailing whitespace trimmed correctly All 17 tests pass (10 existing + 7 new). Closes #20137 <!-- greptile_comment --> <h3>Greptile Summary</h3> Fixes `/model default`, `/model reset`, and `/model clear` commands to correctly clear the session model override instead of treating these keywords as literal model IDs (which would fail allowlist validation). The fix intercepts these reserved keywords at two entry points (`resolveModelSelectionFromDirective` and `resolveModelDirectiveSelection`) before model ID resolution, returning `isDefault: true` to trigger the existing override-clearing logic in `applyModelOverrideToSessionEntry`. Help text is updated to advertise the new keywords. - Keywords are case-insensitive and `provider/default` (with slash) is correctly treated as a literal model ID - Reset keywords bypass the allowlist since they revert to the configured default - 7 new unit tests cover keyword matching, case-insensitivity, slash guard, allowlist bypass, and whitespace handling - Minor style note: `buildModelPickerCatalog` is built unnecessarily for reset keywords in `maybeHandleModelDirectiveInfo` before returning `undefined` <h3>Confidence Score: 4/5</h3> - This PR is safe to merge — changes are well-scoped and thoroughly tested. - The fix is straightforward and correctly placed at both code paths that resolve model directives. The existing `isDefault: true` mechanism was already battle-tested, and the new keyword interception simply routes to it. All edge cases (case insensitivity, slash-containing IDs, allowlist bypass, whitespace) are covered by tests. The only minor concern is unnecessary `buildModelPickerCatalog` work for reset keywords. - Minor optimization opportunity in `src/auto-reply/reply/directive-handling.model.ts` (unnecessary catalog build for reset keywords) <sub>Last reviewed commit: d54b492</sub> <!-- greptile_other_comments_section --> <sub>(5/5) You can turn off certain types of comments like style [here](https://app.greptile.com/review/github)!</sub> <!-- /greptile_comment -->

Most Similar PRs