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

address review (codex): only namespace ollama-backed OpenCode models

Adam Eivy95860550bd4f
diff --git a/server/lib/cliProviderArgs.test.js b/server/lib/cliProviderArgs.test.js
index b26e2c168a..a4c086dcb8 100644
--- a/server/lib/cliProviderArgs.test.js
+++ b/server/lib/cliProviderArgs.test.js
@@ -77,20 +77,20 @@ describe('cliProviderArgs', () => {
it('prepends the run subcommand when the saved args dropped it', () => {
const args = buildCliArgs({
- id: 'opencode-ollama', command: 'opencode', args: [],
+ id: 'opencode-ollama', command: 'opencode', args: [], ollamaBacked: true,
defaultModel: 'qwen2.5:7b',
});
expect(args).toEqual(['run', '-m', 'ollama/qwen2.5:7b']);
});
it('omits -m when no model is configured (opencode falls back to its own default)', () => {
- const args = buildCliArgs({ id: 'opencode-ollama', command: 'opencode', args: ['run'], defaultModel: null });
+ const args = buildCliArgs({ id: 'opencode-ollama', command: 'opencode', args: ['run'], ollamaBacked: true, defaultModel: null });
expect(args).toEqual(['run']);
});
it('respects a user-baked -m pin and skips injection', () => {
const args = buildCliArgs({
- id: 'opencode-ollama', command: 'opencode', args: ['run', '-m', 'ollama/custom'],
+ id: 'opencode-ollama', command: 'opencode', args: ['run', '-m', 'ollama/custom'], ollamaBacked: true,
defaultModel: 'qwen2.5:7b',
});
expect(args).toEqual(['run', '-m', 'ollama/custom']);
diff --git a/server/lib/providerModels.js b/server/lib/providerModels.js
index 3fad9c25cb..7ebf0546a6 100644
--- a/server/lib/providerModels.js
+++ b/server/lib/providerModels.js
@@ -25,14 +25,19 @@ export const resolveCliModel = (model) => isCodexConfiguredDefault(model) ? null
* `opencode run -m` / `opencode --model`. Idempotent — an id that already starts
* with `ollama/` is returned untouched, and a `/`-bearing Ollama id
* (`hf.co/user/model:tag`) is namespaced as `ollama/hf.co/...` since OpenCode
- * splits provider/model on the FIRST slash only. No-op for non-OpenCode
- * providers and empty models.
- * @param {{command?:string}} provider
+ * splits provider/model on the FIRST slash only.
+ *
+ * Gated on the `ollamaBacked` marker, NOT just `command === 'opencode'`: a
+ * user-configured OpenCode provider pointed at a different backend stores an
+ * already-qualified id (`openai/gpt-4o`, `anthropic/claude-sonnet`), and blindly
+ * prefixing `ollama/` would route it to the wrong backend. No-op for
+ * non-Ollama-backed / non-OpenCode providers and empty models.
+ * @param {{command?:string, ollamaBacked?:boolean}} provider
* @param {string|null|undefined} model
* @returns {string|null|undefined}
*/
export function prefixOpencodeModel(provider, model) {
- if (provider?.command !== 'opencode' || !model) return model;
+ if (provider?.command !== 'opencode' || provider?.ollamaBacked !== true || !model) return model;
const id = String(model);
return id.startsWith('ollama/') ? id : `ollama/${id}`;
}
diff --git a/server/lib/providerModels.test.js b/server/lib/providerModels.test.js
index 425e842bac..afc42ba85a 100644
--- a/server/lib/providerModels.test.js
+++ b/server/lib/providerModels.test.js
@@ -30,9 +30,9 @@ describe('providerModels', () => {
});
describe('prefixOpencodeModel', () => {
- const oc = { command: 'opencode' };
+ const oc = { command: 'opencode', ollamaBacked: true };
- it('namespaces a bare Ollama id under ollama/ for opencode providers', () => {
+ it('namespaces a bare Ollama id under ollama/ for ollama-backed opencode providers', () => {
expect(prefixOpencodeModel(oc, 'qwen2.5:7b')).toBe('ollama/qwen2.5:7b');
});
@@ -44,8 +44,16 @@ describe('providerModels', () => {
expect(prefixOpencodeModel(oc, 'hf.co/user/model:tag')).toBe('ollama/hf.co/user/model:tag');
});
+ it('does NOT prefix a non-ollama-backed opencode provider (keeps its qualified id)', () => {
+ // A user-configured OpenCode provider on another backend stores an
+ // already-qualified provider/model id — prefixing would mis-route it.
+ const ocOther = { command: 'opencode' };
+ expect(prefixOpencodeModel(ocOther, 'openai/gpt-4o')).toBe('openai/gpt-4o');
+ expect(prefixOpencodeModel({ command: 'opencode', ollamaBacked: false }, 'anthropic/claude-sonnet')).toBe('anthropic/claude-sonnet');
+ });
+
it('is a no-op for non-opencode providers', () => {
- expect(prefixOpencodeModel({ command: 'claude' }, 'qwen2.5:7b')).toBe('qwen2.5:7b');
+ expect(prefixOpencodeModel({ command: 'claude', ollamaBacked: true }, 'qwen2.5:7b')).toBe('qwen2.5:7b');
expect(prefixOpencodeModel({ command: 'codex' }, 'gpt-5')).toBe('gpt-5');
});
diff --git a/server/lib/tuiHandshake.test.js b/server/lib/tuiHandshake.test.js
index eccf4bae06..b6ac084521 100644
--- a/server/lib/tuiHandshake.test.js
+++ b/server/lib/tuiHandshake.test.js
@@ -375,7 +375,7 @@ describe('tuiHandshake.buildTuiInvocation', () => {
});
it('namespaces the Ollama model under ollama/ for an OpenCode TUI', () => {
- const provider = { id: 'opencode-ollama-tui', command: 'opencode', args: [] };
+ const provider = { id: 'opencode-ollama-tui', command: 'opencode', args: [], ollamaBacked: true };
const out = buildTuiInvocation(provider, 'qwen2.5:7b');
expect(out.command).toBe('opencode');
expect(out.args).toEqual(['--model', 'ollama/qwen2.5:7b']);
diff --git a/server/services/agentCliSpawning.test.js b/server/services/agentCliSpawning.test.js
index 01889a8bd6..aa22bac495 100644
--- a/server/services/agentCliSpawning.test.js
+++ b/server/services/agentCliSpawning.test.js
@@ -201,14 +201,14 @@ describe('buildCliSpawnConfig', () => {
});
it('prepends the run subcommand for OpenCode even if saved args dropped it', () => {
- const config = buildCliSpawnConfig({ id: 'opencode-ollama', command: 'opencode', args: [] }, 'qwen2.5:7b');
+ const config = buildCliSpawnConfig({ id: 'opencode-ollama', command: 'opencode', args: [], ollamaBacked: true }, 'qwen2.5:7b');
expect(config.args).toEqual(['run', '-m', 'ollama/qwen2.5:7b']);
});
it('respects a user-baked -m pin on an OpenCode provider and does not duplicate it', () => {
const config = buildCliSpawnConfig(
- { id: 'opencode-ollama', command: 'opencode', args: ['run', '-m', 'ollama/custom'] },
+ { id: 'opencode-ollama', command: 'opencode', args: ['run', '-m', 'ollama/custom'], ollamaBacked: true },
'qwen2.5:7b',
);
diff --git a/server/services/agentTuiSpawning.test.js b/server/services/agentTuiSpawning.test.js
index 3bf7947bab..8a1ce22544 100644
--- a/server/services/agentTuiSpawning.test.js
+++ b/server/services/agentTuiSpawning.test.js
@@ -106,7 +106,7 @@ vi.mock('../lib/providerModels.js', () => ({
resolveBedrockCliModel: vi.fn((m) => m),
// Mirror the real ollama/ namespacing for opencode providers (fully unit-
// tested in providerModels.test.js).
- prefixOpencodeModel: vi.fn((p, m) => (p?.command === 'opencode' && m && !String(m).startsWith('ollama/')) ? `ollama/${m}` : m)
+ prefixOpencodeModel: vi.fn((p, m) => (p?.command === 'opencode' && p?.ollamaBacked === true && m && !String(m).startsWith('ollama/')) ? `ollama/${m}` : m)
}));
// Shrink buffer thresholds so the truncation tests can trip them with tiny
@@ -217,7 +217,7 @@ describe('agent TUI spawning', () => {
it('namespaces the Ollama model under ollama/ for an OpenCode TUI', () => {
const config = buildTuiSpawnConfig({
- id: 'opencode-ollama-tui', type: 'tui', command: 'opencode', args: [],
+ id: 'opencode-ollama-tui', type: 'tui', command: 'opencode', args: [], ollamaBacked: true,
}, 'qwen2.5:7b');
expect(config.command).toBe('opencode');
expect(config.args).toEqual(['--model', 'ollama/qwen2.5:7b']);