#11107: fix(models): auto-allow selected model on sessions.patch
gateway
extensions: memory-lancedb
stale
Cluster:
Model Management Enhancements
## Summary
- When `sessions.patch` fails with `model not allowed: ...`, parse the disallowed model key.
- Auto-add that model to `agents.defaults.models` in config.
- Persist config via `writeConfigFile(...)`, reload config, and retry `applySessionsPatchToStore(...)` once.
## Why
Users can select a valid model in UI/TUI but still hit `model not allowed` if allowlist is missing that key. This change unblocks the update flow without requiring a manual config edit.
## Scope
- File: `src/gateway/server-methods/sessions.ts`
- No behavior change for other error types.
- No change if model already exists in allowlist.
## Validation
- Manual: reproduced `model not allowed` on `sessions.patch`, then verified retry succeeds after auto-allowlist write.
- Diff is intentionally minimal and isolated to `sessions.patch` path.
<!-- greptile_comment -->
<h2>Greptile Overview</h2>
<h3>Greptile Summary</h3>
This PR changes the `sessions.patch` handler to detect `model not allowed: …` failures, persist the selected model into `agents.defaults.models` in the user config, reload config, and retry applying the patch once.
The change is isolated to `src/gateway/server-methods/sessions.ts` and wraps the existing session store update/apply flow with a single retry after a config write when the failure is specifically a disallowed model.
<h3>Confidence Score: 3/5</h3>
- This PR is mostly safe, but the new auto-allow retry path may not trigger due to error-shape mismatch.
- Changes are localized and gated behind a specific failure, but the implementation assumes `applied.error.message` contains the canonical `model not allowed: …` text; if the error is a string or a non-Error shape, the regex extraction fails and the intended fix won’t work.
- src/gateway/server-methods/sessions.ts
<!-- greptile_other_comments_section -->
<sub>(3/5) Reply to the agent's comments like "Can you suggest a fix for this @greptileai?" or ask follow-up questions!</sub>
<!-- /greptile_comment -->
Most Similar PRs
#9583: fix(models): allow models in agents.defaults.models even if not in ...
by hotzen100 · 2026-02-05
82.3%
#10608: fix(agents): honor spawn model override in gateway and session spaw...
by 1kuna · 2026-02-06
82.1%
#21556: fix(agents): graceful fallback when spawned model is not in allowlist
by irchelper · 2026-02-20
81.2%
#21088: fix: sessions_sspawn model override ignored for sub-agents
by Slats24 · 2026-02-19
80.9%
#13376: fix: pass model directly to agent for sub-agent runs
by jrbobbyhansen-pixel · 2026-02-10
80.8%
#6603: fix: use allowAny flag instead of size check for model override val...
by gavinbmoore · 2026-02-01
80.6%
#9822: fix: allow local/custom model providers for sub-agent inference
by stammtobias91 · 2026-02-05
79.2%
#6673: fix: preserve allowAny flag in createModelSelectionState for custom...
by tenor0 · 2026-02-01
78.8%
#19328: Fix: preserve modelOverride in agent handler (#5369)
by CodeReclaimers · 2026-02-17
78.1%
#7570: fix: allow models from providers with auth profiles configured
by DonSqualo · 2026-02-03
78.0%