fix(server): forward Small Model override to managed OpenCode config

OpenChamber's Settings → Chat → Small Model override only fed OpenChamber's
own /api/small-model/generate utility service; it never reached the managed
OpenCode server, whose internal title/summary generation reads small_model
from its config. With the override injected into OPENCODE_CONFIG_CONTENT at
managed-process launch, session title generation uses the user's explicit
model instead of falling back (or failing to resolve) — fixing sessions that
stayed untitled even with a Small Model configured.

Only an explicit override (smallModelUseDefault === false with a non-empty
smallModelOverride) is injected; "use default" leaves the config untouched
so OpenCode's own resolution chain stays authoritative. Malformed user config
is left unmodified. External OpenCode servers are unaffected (they are not
launched with this env).

Fixes #2497
This commit is contained in:
Serhii Dziupin
2026-08-05 13:46:30 +03:00
parent 34c221b07f
commit 8a85073261
4 changed files with 166 additions and 5 deletions
+14 -5
View File
@@ -75,6 +75,7 @@ import { createSessionRuntime } from './lib/opencode/session-runtime.js';
import { createOpenCodeWatcherRuntime } from './lib/opencode/watcher.js';
import { createSessionAssistRuntime } from './lib/session-assist/runtime.js';
import { createSessionGoalRuntime } from './lib/session-goal/runtime.js';
import { applySmallModelOverrideToOpenCodeConfig } from './lib/small-model/config-injection.js';
import { createContextObligatoryRuntime } from './lib/context-obligatory/runtime.js';
import { createScheduledTasksRuntime } from './lib/scheduled-tasks/runtime.js';
import { createServerStartupRuntime } from './lib/opencode/server-startup-runtime.js';
@@ -1084,11 +1085,19 @@ const openCodeLifecycleRuntime = createOpenCodeLifecycleRuntime({
const managedEnv = settings?.agentControlToolEnabled === false
? {}
: await (agentToolRuntime?.prepareManagedOpenCodeEnv() || {});
if (settings?.optimizeSystemPrompt !== true) return managedEnv;
const configContent = managedEnv.OPENCODE_CONFIG_CONTENT ?? process.env.OPENCODE_CONFIG_CONTENT;
const systemPromptEnv = await systemPromptRuntime.prepareManagedOpenCodeEnv(configContent);
return { ...managedEnv, ...systemPromptEnv };
const env = settings?.optimizeSystemPrompt === true
? { ...managedEnv, ...(await systemPromptRuntime.prepareManagedOpenCodeEnv(managedEnv.OPENCODE_CONFIG_CONTENT ?? process.env.OPENCODE_CONFIG_CONTENT)) }
: managedEnv;
// Apply the explicit Small Model override to the managed OpenCode config
// so OpenCode's own title/summary generation uses the user's chosen model.
const configContent = env.OPENCODE_CONFIG_CONTENT ?? process.env.OPENCODE_CONFIG_CONTENT;
const withSmallModel = applySmallModelOverrideToOpenCodeConfig({
configContent,
smallModelUseDefault: settings?.smallModelUseDefault,
smallModelOverride: settings?.smallModelOverride,
});
if (withSmallModel === configContent) return env;
return { ...env, OPENCODE_CONFIG_CONTENT: withSmallModel };
},
});