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.

v2.5.0 Bug AA: forward num_ctx to Ollama on chat

purple3524f17ca087
diff --git a/src/api/__tests__/provider-ollama.test.ts b/src/api/__tests__/provider-ollama.test.ts
index fd7b9aa6..1e842811 100644
--- a/src/api/__tests__/provider-ollama.test.ts
+++ b/src/api/__tests__/provider-ollama.test.ts
@@ -451,6 +451,51 @@ describe('OllamaProvider', () => {
expect(body.options.num_predict).toBe(1024)
})
+ it('Bug AA v2.5.0: forwards contextWindow as num_ctx when > 0', async () => {
+ // Kj103x Discord 2026-05-27: LU never forwarded num_ctx so Ollama
+ // silently used its 2048 default, clipping RAG payloads and long
+ // chats. This test locks in that the override flows through.
+ const provider = new OllamaProvider(makeConfig())
+ mockLocalFetch.mockResolvedValueOnce(
+ new Response(JSON.stringify({
+ message: { role: 'assistant', content: 'ok' },
+ done: true,
+ }), { status: 200 })
+ )
+
+ await provider.chatWithTools(
+ 'llama3.1:8b',
+ [{ role: 'user', content: 'test' }],
+ [],
+ { temperature: 0.7, contextWindow: 16384 },
+ )
+
+ const body = JSON.parse(mockLocalFetch.mock.calls[0][1]?.body as string)
+ expect(body.options.num_ctx).toBe(16384)
+ })
+
+ it('Bug AA v2.5.0: omits num_ctx when contextWindow is 0 or undefined', async () => {
+ // 0 means "let Ollama decide" — we must NOT pass num_ctx, otherwise
+ // we'd override the Modelfile/server defaults with garbage.
+ const provider = new OllamaProvider(makeConfig())
+ mockLocalFetch.mockResolvedValueOnce(
+ new Response(JSON.stringify({
+ message: { role: 'assistant', content: 'ok' },
+ done: true,
+ }), { status: 200 })
+ )
+
+ await provider.chatWithTools(
+ 'llama3.1:8b',
+ [{ role: 'user', content: 'test' }],
+ [],
+ { temperature: 0.7, contextWindow: 0 },
+ )
+
+ const body = JSON.parse(mockLocalFetch.mock.calls[0][1]?.body as string)
+ expect(body.options.num_ctx).toBeUndefined()
+ })
+
it('v2.4.6 Bug L: NEVER sets num_gpu — Ollama decides layer placement itself', async () => {
// Pre-v2.4.6 this asserted body.options === { num_gpu: 99 }, which
// forced all model layers onto the GPU and pushed the KV cache into
diff --git a/src/api/providers/ollama-provider.ts b/src/api/providers/ollama-provider.ts
index cea19dcc..b6e03091 100644
--- a/src/api/providers/ollama-provider.ts
+++ b/src/api/providers/ollama-provider.ts
@@ -97,6 +97,15 @@ export class OllamaProvider implements ProviderClient {
if (options?.topP !== undefined) ollamaOptions.top_p = options.topP
if (options?.topK !== undefined) ollamaOptions.top_k = options.topK
if (options?.maxTokens) ollamaOptions.num_predict = options.maxTokens
+ // Bug AA v2.5.0 — forward user's context-window override. Without this
+ // Ollama silently uses num_ctx=2048 (its default), which RAG payloads
+ // and long-turn chats blow through immediately. Kj103x Discord
+ // 2026-05-27: "LU caps VRAM ~5 GB regardless of context window UI
+ // setting" — the UI setting was never wired here. Setting num_ctx
+ // higher than the loaded model's max is harmless (Ollama clamps).
+ if (options?.contextWindow && options.contextWindow > 0) {
+ ollamaOptions.num_ctx = options.contextWindow
+ }
body.options = ollamaOptions
// Tri-state: true → explicit think on, false → explicit think off
// (saves tokens on QwQ / DeepSeek-R1 / Gemma 4 etc.), undefined →
@@ -177,6 +186,10 @@ export class OllamaProvider implements ProviderClient {
if (options?.topP !== undefined) ollamaOptions.top_p = options.topP
if (options?.topK !== undefined) ollamaOptions.top_k = options.topK
if (options?.maxTokens) ollamaOptions.num_predict = options.maxTokens
+ // Bug AA v2.5.0 — see chatStream() for the why.
+ if (options?.contextWindow && options.contextWindow > 0) {
+ ollamaOptions.num_ctx = options.contextWindow
+ }
body.options = ollamaOptions
// Tri-state think flag — see chatStream() for details.
if (options?.thinking === true) body.think = true
diff --git a/src/api/providers/types.ts b/src/api/providers/types.ts
index 41b064a5..e1d0ea12 100644
--- a/src/api/providers/types.ts
+++ b/src/api/providers/types.ts
@@ -98,6 +98,13 @@ export interface ChatOptions {
topK?: number // Ollama/Anthropic support this, OpenAI doesn't
maxTokens?: number
thinking?: boolean // Enable model thinking/reasoning mode
+ // Bug AA v2.5.0 — Kj103x Discord 2026-05-27. Ollama defaults `num_ctx` to
+ // 2048 if you don't pass it in /api/chat options, which silently caps RAG
+ // and long-turn chats even though the loaded model supports way more. When
+ // set, we forward this as `options.num_ctx` to Ollama. Other providers
+ // ignore it (they have their own context handling). 0/undefined = let the
+ // provider use its default.
+ contextWindow?: number
signal?: AbortSignal
}
diff --git a/src/components/settings/SettingsPage.tsx b/src/components/settings/SettingsPage.tsx
index 866181a6..10cce437 100644
--- a/src/components/settings/SettingsPage.tsx
+++ b/src/components/settings/SettingsPage.tsx
@@ -731,6 +731,24 @@ export function SettingsPage() {
className="w-20 px-1.5 py-0.5 rounded bg-transparent border border-white/8 text-[0.65rem] text-right text-gray-300 font-mono focus:outline-none focus:border-white/20"
/>
</div>
+ {/* Bug AA v2.5.0 — Ollama num_ctx override. 0 = use the provider
+ default (Ollama default = 2048 on most builds, which silently
+ clips RAG / long chats). Bump up to use the model's full
+ context window. Ignored by Anthropic / OpenAI providers. */}
+ <div className="flex items-center justify-between">
+ <span className="text-[0.7rem] text-gray-700 dark:text-gray-400" title="Forwarded as Ollama num_ctx. 0 = provider default (Ollama defaults to 2048, which clips RAG and long chats). Bump up to use the model's full context. Ignored by cloud providers.">Context window (Ollama)</span>
+ <input
+ type="number"
+ value={settings.contextWindowOverride ?? 0}
+ onChange={(e) => updateSettings({ contextWindowOverride: Math.max(0, parseInt(e.target.value) || 0) })}
+ min={0}
+ placeholder="0"
+ className="w-20 px-1.5 py-0.5 rounded bg-transparent border border-white/8 text-[0.65rem] text-right text-gray-300 font-mono focus:outline-none focus:border-white/20"
+ />
+ </div>
+ <div className="text-[0.6rem] text-gray-500 dark:text-gray-500 leading-relaxed pt-0.5">
+ 0 = let Ollama decide (defaults to 2048). Set to e.g. 8192 or 16384 if RAG / long chats get clipped. Cloud providers ignore this.
+ </div>
</Section>
<Section title="Image / Video Generation Timeouts">
diff --git a/src/hooks/useABCompare.ts b/src/hooks/useABCompare.ts
index 5a302823..e4052de0 100644
--- a/src/hooks/useABCompare.ts
+++ b/src/hooks/useABCompare.ts
@@ -47,6 +47,8 @@ export function useABCompare() {
topP: settings.topP,
topK: settings.topK,
maxTokens: settings.maxTokens || undefined,
+ // Bug AA v2.5.0 — forward num_ctx override to both A/B sides.
+ contextWindow: settings.contextWindowOverride || undefined,
}
// Stream Model A
diff --git a/src/hooks/useAgentChat.ts b/src/hooks/useAgentChat.ts
index f935303e..10f8c8a2 100644
--- a/src/hooks/useAgentChat.ts
+++ b/src/hooks/useAgentChat.ts
@@ -458,6 +458,8 @@ export function useAgentChat() {
topP: settings.topP,
topK: settings.topK,
maxTokens: settings.maxTokens || undefined,
+ // Bug AA v2.5.0 — Kj103x. Same num_ctx override flow as useChat.
+ contextWindow: settings.contextWindowOverride || undefined,
thinking: thinkOpt as unknown as boolean,
signal: abort.signal,
}
@@ -519,6 +521,8 @@ export function useAgentChat() {
temperature: chatOptions.temperature,
thinking: chatOptions.thinking,
maxTokens: chatOptions.maxTokens,
+ // Bug AA v2.5.0 — keep num_ctx override across the tool loop.
+ contextWindow: chatOptions.contextWindow,
signal: abort.signal,
},
(c) => {
@@ -547,6 +551,8 @@ export function useAgentChat() {
temperature: chatOptions.temperature,
thinking: undefined,
maxTokens: chatOptions.maxTokens,
+ // Bug AA v2.5.0 — keep num_ctx override on the no-think retry too.
+ contextWindow: chatOptions.contextWindow,
signal: abort.signal,
},
(c) => {
diff --git a/src/hooks/useChat.ts b/src/hooks/useChat.ts
index d01d26e8..eaa2dd4a 100644
--- a/src/hooks/useChat.ts
+++ b/src/hooks/useChat.ts
@@ -193,6 +193,10 @@ export function useChat() {
topP: settings.topP,
topK: settings.topK,
maxTokens: settings.maxTokens || undefined,
+ // Bug AA v2.5.0 — Kj103x. 0 in settings means "let provider decide";
+ // any positive value gets forwarded as Ollama `num_ctx`. Other
+ // providers ignore the field.
+ contextWindow: settings.contextWindowOverride || undefined,
thinking: useThinking,
signal: abort.signal,
}
diff --git a/src/lib/constants.ts b/src/lib/constants.ts
index dec27c23..c410e89e 100644
--- a/src/lib/constants.ts
+++ b/src/lib/constants.ts
@@ -35,6 +35,9 @@ export const DEFAULT_SETTINGS: Settings = {
// Generation timeouts (Bug P v2.4.7)
imageGenTimeoutMinutes: 20,
videoGenTimeoutMinutes: 60,
+ // Bug AA v2.5.0 — Ollama num_ctx override. 0 = use Ollama default (2048
+ // on most builds). Users with RAG / long chats can bump this up.
+ contextWindowOverride: 0,
// ── v2.5.0 Codex sprint A/B/C defaults (ported from uselu) ──────
codexArchitectMode: false,
codexArchitectModel: '',
diff --git a/src/lib/ollama-stream-tools.ts b/src/lib/ollama-stream-tools.ts
index 83eca051..9f44abee 100644
--- a/src/lib/ollama-stream-tools.ts
+++ b/src/lib/ollama-stream-tools.ts
@@ -27,7 +27,7 @@ export async function streamOllamaChatWithTools(
modelId: string,
messages: ChatMessage[],
tools: ToolDefinition[],
- options: { temperature?: number; thinking?: boolean; maxTokens?: number; signal?: AbortSignal },
+ options: { temperature?: number; thinking?: boolean; maxTokens?: number; contextWindow?: number; signal?: AbortSignal },
onContent: (content: string) => void,
onThinking: (thinking: string) => void,
): Promise<{ content: string; toolCalls: ToolCall[]; thinking: string }> {
@@ -50,6 +50,10 @@ export async function streamOllamaChatWithTools(
}
if (options.temperature !== undefined) body.options.temperature = options.temperature
if (options.maxTokens) body.options.num_predict = options.maxTokens
+ // Bug AA v2.5.0 — forward num_ctx override (0/undefined = use Ollama default).
+ if (options.contextWindow && options.contextWindow > 0) {
+ body.options.num_ctx = options.contextWindow
+ }
if (options.thinking === true) body.think = true
else if (options.thinking === false) body.think = false
diff --git a/src/lib/workflow-engine.ts b/src/lib/workflow-engine.ts
index 25782937..4bc3b3fe 100644
--- a/src/lib/workflow-engine.ts
+++ b/src/lib/workflow-engine.ts
@@ -216,6 +216,8 @@ export class WorkflowEngine {
} else {
const stream = provider.chatStream(modelToUse, messages, {
temperature: settings.temperature,
+ // Bug AA v2.5.0 — keep num_ctx override for workflow steps too.
+ contextWindow: settings.contextWindowOverride || undefined,
signal: this.abortController.signal,
})
for await (const chunk of stream) {
@@ -233,6 +235,8 @@ export class WorkflowEngine {
if (strategy === 'native') {
const turn = await provider.chatWithTools(modelToUse, messages, allowedTools, {
temperature: settings.temperature,
+ // Bug AA v2.5.0 — same num_ctx override on tool calls.
+ contextWindow: settings.contextWindowOverride || undefined,
signal: this.abortController.signal,
})
output = turn.content || ''
diff --git a/src/types/settings.ts b/src/types/settings.ts
index 7df884e1..70a09ae0 100644
--- a/src/types/settings.ts
+++ b/src/types/settings.ts
@@ -35,6 +35,14 @@ export interface Settings {
imageGenTimeoutMinutes: number
/** Video generation timeout in minutes. Default 60. */
videoGenTimeoutMinutes: number
+ // Bug AA v2.5.0 — Kj103x Discord 2026-05-27. Ollama defaults `num_ctx` to
+ // 2048, which silently caps RAG payloads and long-turn chats even on
+ // models that support way more. This override is forwarded to Ollama
+ // chat/chatWithTools as `options.num_ctx`. 0 = use Ollama default
+ // (recommended unless you have a specific reason to override). Other
+ // providers ignore this field — they manage context themselves.
+ /** User-side context-window override (forwarded as Ollama's num_ctx). 0 = auto. */
+ contextWindowOverride: number
// ── v2.5.0 Codex sprint A/B/C settings (ported from uselu) ──────
/**
* Codex Architect/Editor split. When on, a separate `codexArchitectModel`