Skip to content

Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS

fix: retry local code review without reasoning_effort when a model rejects thinking (#5960)

Adam Eivy3fdc83911b1a
diff --git a/server/scripts/run-local-code-review.mjs b/server/scripts/run-local-code-review.mjs
index c1293657c1..757cfe0d18 100644
--- a/server/scripts/run-local-code-review.mjs
+++ b/server/scripts/run-local-code-review.mjs
@@ -19,8 +19,12 @@ try {
: runLocalCodeReview;
const result = await review({ ...request, model, effort });
process.stdout.write(`${JSON.stringify(result)}\n`);
- if (!result.ok) process.exitCode = 1;
+ if (!result.ok) {
+ process.stderr.write(`${result.error}\n`);
+ process.exitCode = 1;
+ }
} catch (err) {
process.stdout.write(`${JSON.stringify({ ok: false, error: err.message })}\n`);
+ process.stderr.write(`${err.message}\n`);
process.exitCode = 1;
}
diff --git a/server/services/codeReview.js b/server/services/codeReview.js
index baca0b4e26..34e26d5842 100644
--- a/server/services/codeReview.js
+++ b/server/services/codeReview.js
@@ -322,43 +322,75 @@ function adaptiveFence(content) {
return '`'.repeat(Math.max(3, ...(content.match(/`+/g) || ['']).map((run) => run.length + 1)))
}
-async function runToolFreeLocalCompletion({ backend, model, messages, effort, timeoutMs, baseUrl: requestedBaseUrl = null }) {
- if (!isLocalLlmReviewer(backend)) {
- return { ok: false, error: `Unsupported reviewer backend: ${backend}` }
- }
- if (!model || typeof model !== 'string') {
- return { ok: false, error: `No model configured for ${backend} reviewer — set one on the Settings → Code Reviewers page.` }
- }
+// Ollama translates the OpenAI-compatible `reasoning_effort` field into its
+// own `thinking` parameter, and a model that never implements thinking 400s
+// on the whole request rather than ignoring the field. There is no reliable
+// per-model "supports thinking" capability flag to probe ahead of time, so
+// this remembers which `backend:model` pairs have already 400'd on it — for
+// the life of the process — so a multi-round review loop pays the retry once
+// instead of on every round.
+const thinkingUnsupportedModels = new Map()
+export function __resetThinkingUnsupportedCache() { thinkingUnsupportedModels.clear() }
- const resolvedEffort = normalizeReviewerEffort(effort, backend) || null
- // Local runtime records are normalized to the OpenAI `/v1` root, while the
- // legacy backend managers return the host root. Keep both forms compatible
- // with the one endpoint suffix below.
- const baseUrl = String(requestedBaseUrl || await BACKEND_BASE_URLS[backend]())
- .replace(/\/+$/, '')
- .replace(/\/v\d+$/i, '')
+async function sendChatCompletion(baseUrl, { model, messages, timeoutMs }, effortForRequest) {
const body = {
model,
messages,
temperature: 0.2,
stream: false,
- ...(resolvedEffort ? { reasoning_effort: resolvedEffort } : {}),
+ ...(effortForRequest ? { reasoning_effort: effortForRequest } : {}),
}
const response = await fetchWithTimeout(`${baseUrl}/v1/chat/completions`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(body),
}, timeoutMs).catch((err) => ({ ok: false, _fetchError: err.message }))
-
if (response._fetchError !== undefined) {
- return { ok: false, backend, model, error: `${backend} request failed: ${response._fetchError}` }
+ return { ok: false, error: `request failed: ${response._fetchError}` }
}
if (!response.ok) {
const text = await response.text().catch(() => '')
- return { ok: false, backend, model, error: `${backend} API error ${response.status}: ${text.slice(0, 300)}` }
+ return { ok: false, status: response.status, text }
+ }
+ return { ok: true, response }
+}
+
+async function runToolFreeLocalCompletion({ backend, model, messages, effort, timeoutMs, baseUrl: requestedBaseUrl = null }) {
+ if (!isLocalLlmReviewer(backend)) {
+ return { ok: false, error: `Unsupported reviewer backend: ${backend}` }
+ }
+ if (!model || typeof model !== 'string') {
+ return { ok: false, error: `No model configured for ${backend} reviewer — set one on the Settings → Code Reviewers page.` }
}
- const data = await readResponseJson(response, { fallback: (raw) => ({ _nonJson: raw }) })
+ const cacheKey = `${backend}:${model}`
+ let resolvedEffort = normalizeReviewerEffort(effort, backend) || null
+ let effortUnsupported = thinkingUnsupportedModels.get(cacheKey) === true
+ if (effortUnsupported) resolvedEffort = null
+
+ // Local runtime records are normalized to the OpenAI `/v1` root, while the
+ // legacy backend managers return the host root. Keep both forms compatible
+ // with the one endpoint suffix below.
+ const baseUrl = String(requestedBaseUrl || await BACKEND_BASE_URLS[backend]())
+ .replace(/\/+$/, '')
+ .replace(/\/v\d+$/i, '')
+
+ let attempt = await sendChatCompletion(baseUrl, { model, messages, timeoutMs }, resolvedEffort)
+
+ if (!attempt.ok && attempt.status === 400 && resolvedEffort && /does not support thinking/i.test(attempt.text || '')) {
+ console.warn(`⚠️ ${backend} model ${model} ignores reasoning_effort — retried without it`)
+ thinkingUnsupportedModels.set(cacheKey, true)
+ resolvedEffort = null
+ effortUnsupported = true
+ attempt = await sendChatCompletion(baseUrl, { model, messages, timeoutMs }, null)
+ }
+
+ if (!attempt.ok) {
+ if (attempt.error) return { ok: false, backend, model, error: `${backend} ${attempt.error}` }
+ return { ok: false, backend, model, error: `${backend} API error ${attempt.status}: ${(attempt.text || '').slice(0, 300)}` }
+ }
+
+ const data = await readResponseJson(attempt.response, { fallback: (raw) => ({ _nonJson: raw }) })
if (data?._nonJson !== undefined) {
return { ok: false, backend, model, error: `${backend} returned a non-JSON response: ${data._nonJson.slice(0, 300)}` }
}
@@ -366,7 +398,14 @@ async function runToolFreeLocalCompletion({ backend, model, messages, effort, ti
if (!content || typeof content !== 'string') {
return { ok: false, backend, model, error: `${backend} returned no content.` }
}
- return { ok: true, backend, model, effort: resolvedEffort, content: content.trim() }
+ return {
+ ok: true,
+ backend,
+ model,
+ effort: resolvedEffort,
+ ...(effortUnsupported ? { effortUnsupported: true } : {}),
+ content: content.trim(),
+ }
}
/**
@@ -420,7 +459,14 @@ export async function runLocalCodeReview({ backend, model, diff, effort = null,
],
})
if (!result.ok) return result
- return { ok: true, backend, model, effort: result.effort, findings: result.content }
+ return {
+ ok: true,
+ backend,
+ model,
+ effort: result.effort,
+ ...(result.effortUnsupported ? { effortUnsupported: true } : {}),
+ findings: result.content,
+ }
}
/**
@@ -495,6 +541,7 @@ export async function runLocalClaimCommentReview({ backend, model, comments, cur
backend,
model,
effort: result.effort,
+ ...(result.effortUnsupported ? { effortUnsupported: true } : {}),
claimant,
suspicious: parsed.suspicious,
reviewedCommentCount: normalizedComments.length,
diff --git a/server/services/codeReview.test.js b/server/services/codeReview.test.js
index f6f545ce53..ecaae95836 100644
--- a/server/services/codeReview.test.js
+++ b/server/services/codeReview.test.js
@@ -38,6 +38,7 @@ import {
getReviewerCliInstalled,
__resetCodeReviewDefaultsCache,
__resetReviewerCliInstalledCache,
+ __resetThinkingUnsupportedCache,
} from './codeReview.js'
import { MODEL_SELECTABLE_REVIEWERS, EFFORT_SELECTABLE_REVIEWERS } from '../lib/cosValidation.js'
@@ -55,6 +56,7 @@ describe('codeReview helpers', () => {
mockedActiveProvider.current = null
__resetCodeReviewDefaultsCache()
__resetReviewerCliInstalledCache()
+ __resetThinkingUnsupportedCache()
commandExistsMock.impl = async () => true
vi.restoreAllMocks()
})
@@ -682,4 +684,68 @@ describe('codeReview helpers', () => {
expect(global.fetch).not.toHaveBeenCalled()
})
})
+
+ describe('reasoning_effort downgrade for backends that reject thinking', () => {
+ // Real ollama 400 body shape (server/services/codeReview.js's regex
+ // matches on the message text, not the JSON envelope).
+ const thinkingRejectedBody = JSON.stringify({
+ error: { message: '"m" does not support thinking', type: 'invalid_request_error' },
+ })
+
+ it('retries without reasoning_effort when the backend rejects thinking', async () => {
+ global.fetch = vi.fn()
+ .mockResolvedValueOnce(mockTextResponse(thinkingRejectedBody, { ok: false, status: 400 }))
+ .mockResolvedValueOnce(mockJsonResponse({ choices: [{ message: { content: 'No findings.' } }] }))
+
+ const r = await runLocalCodeReview({ backend: 'ollama', model: 'nonthinking-model', diff: 'd', effort: 'low' })
+
+ expect(global.fetch).toHaveBeenCalledTimes(2)
+ const secondBody = JSON.parse(global.fetch.mock.calls[1][1].body)
+ expect('reasoning_effort' in secondBody).toBe(false)
+ expect(r).toMatchObject({ ok: true, effort: null, effortUnsupported: true, findings: 'No findings.' })
+ })
+
+ it('does not retry a 400 that is unrelated to thinking', async () => {
+ global.fetch = vi.fn().mockResolvedValue(mockTextResponse('bad request: missing field', { ok: false, status: 400 }))
+
+ const r = await runLocalCodeReview({ backend: 'ollama', model: 'other-400-model', diff: 'd', effort: 'low' })
+
+ expect(global.fetch).toHaveBeenCalledTimes(1)
+ expect(r.ok).toBe(false)
+ expect(r.error).toMatch(/API error 400/)
+ })
+
+ it('caches the downgrade for the same backend+model across sequential calls', async () => {
+ global.fetch = vi.fn()
+ .mockResolvedValueOnce(mockTextResponse(thinkingRejectedBody, { ok: false, status: 400 }))
+ .mockResolvedValueOnce(mockJsonResponse({ choices: [{ message: { content: 'No findings.' } }] }))
+ .mockResolvedValueOnce(mockJsonResponse({ choices: [{ message: { content: 'No findings.' } }] }))
+
+ await runLocalCodeReview({ backend: 'ollama', model: 'cached-model', diff: 'd1', effort: 'low' })
+ const second = await runLocalCodeReview({ backend: 'ollama', model: 'cached-model', diff: 'd2', effort: 'low' })
+
+ expect(global.fetch).toHaveBeenCalledTimes(3)
+ const thirdBody = JSON.parse(global.fetch.mock.calls[2][1].body)
+ expect('reasoning_effort' in thirdBody).toBe(false)
+ expect(second).toMatchObject({ ok: true, effort: null, effortUnsupported: true })
+ })
+
+ it('runLocalClaimCommentReview benefits from the same retry-and-downgrade', async () => {
+ global.fetch = vi.fn()
+ .mockResolvedValueOnce(mockTextResponse(thinkingRejectedBody, { ok: false, status: 400 }))
+ .mockResolvedValueOnce(mockJsonResponse({ choices: [{ message: { content: '{"claimant":null,"suspicious":false}' } }] }))
+
+ const r = await runLocalClaimCommentReview({
+ backend: 'ollama',
+ model: 'claim-nonthinking-model',
+ comments: [{ login: 'alice', type: 'User', body: 'Taking this', createdAt: '2026-01-01T00:00:00Z' }],
+ effort: 'low',
+ })
+
+ expect(global.fetch).toHaveBeenCalledTimes(2)
+ const secondBody = JSON.parse(global.fetch.mock.calls[1][1].body)
+ expect('reasoning_effort' in secondBody).toBe(false)
+ expect(r).toMatchObject({ ok: true, claimant: null, suspicious: false, effort: null, effortUnsupported: true })
+ })
+ })
})