Skip to content

The all-in-one local AI studio for your desktop: chat, image and video generation and a coding agent in one free, open source app. Windows and Linux. No Docker, no terminal, no cloud required.

fix: stale-manifest regex handles JSON-escaped quotes in proxy wrapping

PurpleDoubleD53c48a440fb7
diff --git a/src/api/providers/__tests__/ollama-error-extract.test.ts b/src/api/providers/__tests__/ollama-error-extract.test.ts
new file mode 100644
index 00000000..56f26287
--- /dev/null
+++ b/src/api/providers/__tests__/ollama-error-extract.test.ts
@@ -0,0 +1,44 @@
+import { describe, it, expect } from 'vitest'
+
+// Inline copy of extractError for direct testing — keep in sync with
+// OllamaProvider.extractError in ../ollama-provider.ts.
+async function extractError(res: Response, fallback: string): Promise<string> {
+ try {
+ const data = await res.json()
+ const raw = data.error || fallback
+ const m = typeof raw === 'string' && raw.match(/[\\'"]*([\w.:/\-]+?)[\\'"]*\s+does not support (chat|completion)/i)
+ if (m) {
+ const name = m[1]
+ return `Ollama rejected "${name}" — its manifest is stale (pulled before Ollama 0.15). Open a terminal and run: ollama pull ${name} Then reload the model.`
+ }
+ return raw
+ } catch {
+ return fallback
+ }
+}
+
+describe('Ollama stale-manifest error extraction', () => {
+ it('raw Ollama body with quoted model name', async () => {
+ const body = JSON.stringify({ error: '"gemma4:e4b" does not support chat' })
+ const res = new Response(body, { status: 400 })
+ const msg = await extractError(res, 'fallback')
+ expect(msg).toContain('Ollama rejected')
+ expect(msg).toContain('gemma4:e4b')
+ })
+
+ it('Rust-proxy-wrapped body', async () => {
+ const wrapped = `HTTP 400: ${JSON.stringify({ error: '"gemma4:e4b" does not support chat' })}`
+ const body = JSON.stringify({ error: wrapped })
+ const res = new Response(body, { status: 500 })
+ const msg = await extractError(res, 'fallback')
+ expect(msg).toContain('Ollama rejected')
+ expect(msg).toContain('gemma4:e4b')
+ })
+
+ it('unknown 400 error falls through to raw message', async () => {
+ const body = JSON.stringify({ error: 'some other error' })
+ const res = new Response(body, { status: 400 })
+ const msg = await extractError(res, 'fallback')
+ expect(msg).toBe('some other error')
+ })
+})
diff --git a/src/api/providers/ollama-provider.ts b/src/api/providers/ollama-provider.ts
index 13eae5c2..41bab9b0 100644
--- a/src/api/providers/ollama-provider.ts
+++ b/src/api/providers/ollama-provider.ts
@@ -246,8 +246,10 @@ export class OllamaProvider implements ProviderClient {
// (pulled before Ollama 0.15). Give the user an actionable remediation
// instead of the cryptic "X does not support chat/completion".
// Regex is tolerant to prefixes (e.g. Rust proxy wraps as "HTTP 400: {...}")
- // and to the model name being quoted or not.
- const m = typeof raw === 'string' && raw.match(/['"]?([\w.:/\-]+?)['"]?\s+does not support (chat|completion)/i)
+ // with embedded \"…\" escapes, and to the model name being quoted or not.
+ // The [\\'"]* classes swallow any combination of escape backslashes and
+ // JSON-encoded quotes around the model identifier.
+ const m = typeof raw === 'string' && raw.match(/[\\'"]*([\w.:/\-]+?)[\\'"]*\s+does not support (chat|completion)/i)
if (m) {
const name = m[1]
return `Ollama rejected "${name}" — its manifest is stale (pulled before Ollama 0.15). Open a terminal and run: ollama pull ${name} Then reload the model.`