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

clamp per-model reasoning effort for OpenCode runs so NIM Kimi K3 stops 400ing at launch

[._.]/ Adam Eivy1b71684368df
diff --git a/server/lib/opencodeConfig.js b/server/lib/opencodeConfig.js
index cd2d76be16..d957ba0104 100644
--- a/server/lib/opencodeConfig.js
+++ b/server/lib/opencodeConfig.js
@@ -37,6 +37,7 @@ import {
getOpencodeLocalProviderNamespace,
isOpencodeCommand,
prefixOpencodeModel,
+ resolveCliEffort,
parseOpencodeConfigContent,
OPENCODE_BUILD_AGENT,
OPENCODE_PUBLIC_REVIEW_AGENT,
@@ -464,6 +465,31 @@ export function buildOpencodeConfigContent(models, base = null, providerKey = 'o
return JSON.stringify(buildOpencodeConfig(models, base, providerKey, generation));
}
+/**
+ * The provider record as a GENERATION source for THIS run's model: identical,
+ * except that a stored effort the model rejects is clamped to the nearest rung
+ * it accepts (`resolveCliEffort`).
+ *
+ * OpenCode forwards `agent.build.reasoningEffort` verbatim to the upstream
+ * vendor, which is the only party that validates it — NVIDIA NIM answers
+ * Moonshot's Kimi K3 with HTTP 400 `Unsupported Kimi K3
+ * thinking_effort="medium"` and the agent wedges at launch with its prompt
+ * still in the TUI. The provider-wide ladder cannot see that; this caller is
+ * the first that knows both the record and the model, so the clamp lands here.
+ *
+ * Returns the input untouched when there is nothing to clamp, so a record with
+ * no effort (and its non-enumerable gateway `apiKey`) rides through unspread.
+ * @param {object|null|undefined} provider
+ * @param {string|null|undefined} model - the model this spawn runs
+ * @returns {object|null|undefined}
+ */
+function generationForModel(provider, model) {
+ const stored = typeof provider?.effort === 'string' ? provider.effort.trim() : '';
+ if (!stored) return provider;
+ const resolved = resolveCliEffort(stored, provider, model || provider?.defaultModel || null);
+ return resolved === stored ? provider : { ...provider, effort: resolved || null };
+}
+
/**
* Build dynamic env vars for an OpenCode spawn. Returns an object with
* `OPENCODE_CONFIG_CONTENT` for a provider that names a backend namespace
@@ -509,7 +535,7 @@ export function buildOpencodeEnvVars(provider, model, { safetyProfile = null } =
provider?.defaultModel,
model,
];
- const config = buildOpencodeConfig(ids, base, providerKey, provider);
+ const config = buildOpencodeConfig(ids, base, providerKey, generationForModel(provider, model));
// Pin the auxiliary model OpenCode uses for its OWN side work (session titles,
// summarization). Left unset it falls back to its built-in default, which is a
// real hosted model nobody here chose — an OpenRouter run on the free
diff --git a/server/lib/opencodeConfig.test.js b/server/lib/opencodeConfig.test.js
index a4d5c225ca..b3f5d1f010 100644
--- a/server/lib/opencodeConfig.test.js
+++ b/server/lib/opencodeConfig.test.js
@@ -224,6 +224,35 @@ describe('buildOpencodeEnvVars', () => {
expect(cfg.agent.build).toEqual({ temperature: 0.25, think: true, reasoningEffort: 'high' });
});
+ it('clamps an effort the run model rejects instead of wedging the launch', () => {
+ // NVIDIA NIM: `Unsupported Kimi K3 thinking_effort="medium"; supported
+ // values are low, high, and max` — a 400 the agent hits on its first turn,
+ // with the pasted prompt still sitting in the TUI.
+ const provider = {
+ command: 'opencode',
+ gatewayBacked: 'nvidia-nim',
+ models: ['moonshotai/kimi-k3'],
+ defaultModel: 'moonshotai/kimi-k3',
+ effort: 'medium',
+ };
+ const cfg = JSON.parse(
+ buildOpencodeEnvVars(provider, 'moonshotai/kimi-k3').OPENCODE_CONFIG_CONTENT,
+ );
+ expect(cfg.agent.build).toEqual({ reasoningEffort: 'low' });
+ // The record itself is untouched — the clamp is per-run.
+ expect(provider.effort).toBe('medium');
+ });
+
+ it('leaves an effort the run model accepts exactly as stored', () => {
+ const cfg = JSON.parse(buildOpencodeEnvVars({
+ command: 'opencode',
+ gatewayBacked: 'nvidia-nim',
+ models: ['moonshotai/kimi-k2.5'],
+ effort: 'medium',
+ }, 'moonshotai/kimi-k2.5').OPENCODE_CONFIG_CONTENT);
+ expect(cfg.agent.build).toEqual({ reasoningEffort: 'medium' });
+ });
+
it('sends llama.cpp its generation defaults, routing thinking through the chat template', () => {
// The OpenCode llama TUI is the headline case: llama.cpp has no native
// `think` flag, so a toggle emitted as Ollama's would be silently dropped.
diff --git a/server/lib/providerModels.js b/server/lib/providerModels.js
index d6d9d2ed28..d296a54c8b 100644
--- a/server/lib/providerModels.js
+++ b/server/lib/providerModels.js
@@ -133,6 +133,38 @@ export const ANTIGRAVITY_EFFORT_LEVELS = Object.freeze(['low', 'medium', 'high']
// to whichever local backend it is wired to (Ollama, llama.cpp, MTPLX,
// OrcaRouter). Keep it separate from vendor-CLI-only levels.
export const OPENCODE_LOCAL_EFFORT_LEVELS = Object.freeze(['low', 'medium', 'high']);
+
+// A model behind that gateway can still refuse a rung of the ladder above: the
+// value is forwarded verbatim to the upstream vendor, whose own contract
+// decides. NVIDIA NIM answers Moonshot's Kimi K3 with HTTP 400
+// `Unsupported Kimi K3 thinking_effort="medium"; supported values are low,
+// high, and max` — so an effort the picker offered wedged the agent at launch
+// with the prompt still sitting in the TUI (the same failure shape as codex's
+// `minimal` rejection above, and handled the same way).
+//
+// Keyed on the MODEL, not the gateway: the rejection is Moonshot's contract,
+// so it holds for Kimi K3 behind NIM, OpenRouter, or any other front end.
+// Matched as a family prefix for the reason CODEX_NO_MINIMAL_MODEL_RE is —
+// missing a new spelling reships the 400, while over-matching a build that
+// would have taken `medium` only clamps it one rung down to `low`.
+const OPENCODE_MODEL_EFFORT_LEVELS = Object.freeze([
+ Object.freeze([/(^|\/)kimi-k3([.-]|$)/, Object.freeze(['low', 'high', 'max'])]),
+]);
+
+/**
+ * The effort ladder an OpenCode run offers for one model — the portable
+ * low/medium/high set, narrowed for the models whose upstream vendor rejects a
+ * rung of it. A blank/unknown model gets the full ladder (never an empty one:
+ * "we do not know this model" must not read as "this model has no effort").
+ * @param {string|null|undefined} model - bare or namespace-prefixed id
+ * @returns {readonly string[]}
+ */
+export function opencodeEffortLevelsForModel(model) {
+ const id = String(model || '').trim().toLowerCase();
+ if (!id) return OPENCODE_LOCAL_EFFORT_LEVELS;
+ return OPENCODE_MODEL_EFFORT_LEVELS.find(([re]) => re.test(id))?.[1] ?? OPENCODE_LOCAL_EFFORT_LEVELS;
+}
+
// Cursor Agent's ladder. Cursor has NO `--effort` flag — the level is a
// parameter of the model id itself (`gpt-5[effort=max]`), folded in by
// `foldCursorEffortIntoModel` — so `buildEffortArgs` deliberately emits nothing
@@ -515,7 +547,9 @@ export function foldCursorEffortIntoModel(model, effort) {
*
* `model` narrows the Antigravity ladder to the tiers that base model actually
* offers (agy rejects `gemini-3.1-pro --effort medium`), read off
- * `provider.models`. Omit it — or leave the catalog empty — to get the full
+ * `provider.models`. It ALSO narrows the OpenCode ladder for a model whose
+ * upstream vendor rejects a rung (NVIDIA NIM 400s Kimi K3 on `medium` — see
+ * `opencodeEffortLevelsForModel`). Omit it — or leave the catalog empty — to get the full
* low/medium/high ladder. Returns null for an Antigravity model the catalog
* says has no tiers at all (`claude-sonnet-4-6`), so no `--effort` is emitted.
*
@@ -534,7 +568,7 @@ export function effortLevelsForProvider(provider, model = null) {
// a bootstrap-wrapped spawn still offers its rungs.
const harness = provider.harnessId ?? null;
if (harness === 'opencode' || isOpencodeLocalProvider(provider)) {
- return isOpencodeLocalProvider(provider) ? OPENCODE_LOCAL_EFFORT_LEVELS : null;
+ return isOpencodeLocalProvider(provider) ? opencodeEffortLevelsForModel(model) : null;
}
if (harness === 'codex' || isCodexProvider(provider)) return codexEffortLevelsForModel(model);
if (harness === 'antigravity' || isAntigravityProvider(provider)) {
diff --git a/server/lib/providerModels.test.js b/server/lib/providerModels.test.js
index 9988792fb1..525e7531cd 100644
--- a/server/lib/providerModels.test.js
+++ b/server/lib/providerModels.test.js
@@ -263,6 +263,17 @@ describe('providerModels', () => {
expect(effortLevelsForProvider({ id: 'opencode-ollama', command: 'opencode' })).toBeNull();
});
+ it('drops the rung a gateway model rejects (NIM 400s Kimi K3 on "medium")', () => {
+ const nim = { id: 'opencode-nvidia-nim-tui', command: 'opencode', gatewayBacked: 'nvidia-nim' };
+ expect(effortLevelsForProvider(nim, 'moonshotai/kimi-k3')).toEqual(['low', 'high', 'max']);
+ // The rejection is Moonshot's, so the narrowing follows the model to any front end.
+ expect(effortLevelsForProvider({ id: 'opencode-ollama', command: 'opencode', ollamaBacked: true }, 'kimi-k3'))
+ .toEqual(['low', 'high', 'max']);
+ // Every other model keeps the portable ladder, including the neighbouring K2 family.
+ expect(effortLevelsForProvider(nim, 'moonshotai/kimi-k2.5')).toEqual(['low', 'medium', 'high']);
+ expect(effortLevelsForProvider(nim, null)).toEqual(['low', 'medium', 'high']);
+ });
+
it('returns the cursor ladder for cursor ids and the cursor-agent command', () => {
expect(effortLevelsForProvider({ id: 'cursor-cli', command: 'cursor-agent' })).toBe(CURSOR_EFFORT_LEVELS);
expect(effortLevelsForProvider({ id: 'cursor-tui' })).toBe(CURSOR_EFFORT_LEVELS);