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

feat: run the Codex harness on LM Studio, completing the marker's second consumer (#6309)

[._.]/ Adam Eivy76faf6c8dfd6
diff --git a/client/src/utils/providers.js b/client/src/utils/providers.js
index 8d90968054..5dc809e4e4 100644
--- a/client/src/utils/providers.js
+++ b/client/src/utils/providers.js
@@ -1535,6 +1535,7 @@ export const isGatewayBackedProvider = (provider) => gatewayForProvider(provider
*/
export const localRuntimeNamespace = (provider) => {
if (provider?.ollamaBacked === true) return 'ollama';
+ if (provider?.lmstudioBacked === true) return 'lmstudio';
if (provider?.mtplxBacked === true) return 'mtplx';
if (provider?.llamaBacked === true) return 'llama';
if (provider?.vllmBacked === true) return 'vllm';
diff --git a/client/src/utils/providers.test.js b/client/src/utils/providers.test.js
index 8715a2a7af..d9c16cc028 100644
--- a/client/src/utils/providers.test.js
+++ b/client/src/utils/providers.test.js
@@ -1208,7 +1208,8 @@ describe('supportsModelRefresh', () => {
expect(withButton).toEqual([
'antigravity-cli', 'antigravity-tui', 'cerebras', 'claude-code',
'claude-code-bedrock', 'claude-ollama', 'claude-ollama-tui',
- 'claude-sglang', 'claude-sglang-tui', 'codex', 'codex-ollama', 'codex-tui',
+ 'claude-sglang', 'claude-sglang-tui', 'codex', 'codex-lmstudio',
+ 'codex-ollama', 'codex-tui',
'cursor-cli',
'cursor-tui', 'grok', 'lmstudio', 'mtplx', 'nvidia-kimi', 'ollama',
'opencode-llama-tui',
diff --git a/data.reference/providers.json b/data.reference/providers.json
index ae8b4238b5..8b886b8d23 100644
--- a/data.reference/providers.json
+++ b/data.reference/providers.json
@@ -124,6 +124,23 @@
"secretEnvVars": [],
"headlessArgs": []
},
+ "codex-lmstudio": {
+ "id": "codex-lmstudio",
+ "name": "Codex LM Studio (local model)",
+ "type": "cli",
+ "command": "codex",
+ "args": [],
+ "endpoint": "http://localhost:1234/v1",
+ "models": [],
+ "defaultModel": null,
+ "lmstudioBacked": true,
+ "numCtx": 32768,
+ "timeout": 600000,
+ "enabled": false,
+ "envVars": {},
+ "secretEnvVars": [],
+ "headlessArgs": []
+ },
"claude-code-tui": {
"id": "claude-code-tui",
"name": "Claude Code TUI",
@@ -226,6 +243,7 @@
"models": [],
"defaultModel": null,
"lmstudioBacked": true,
+ "numCtx": 32768,
"timeout": 600000,
"enabled": false,
"envVars": {
@@ -243,6 +261,7 @@
"models": [],
"defaultModel": null,
"lmstudioBacked": true,
+ "numCtx": 32768,
"timeout": 600000,
"enabled": false,
"envVars": {
diff --git a/scripts/migrations/346-opencode-lmstudio-providers.js b/scripts/migrations/346-opencode-lmstudio-providers.js
deleted file mode 100644
index 5f3d304414..0000000000
--- a/scripts/migrations/346-opencode-lmstudio-providers.js
+++ /dev/null
@@ -1,70 +0,0 @@
-/**
- * Ship disabled OpenCode LM Studio provider presets to existing installs.
- *
- * LM Studio was the one local backend PortOS already managed (`lmStudioManager.js`,
- * the `lmstudio` API record, its Models → LLMs tab) that no coding harness could
- * be pointed at: the OpenCode wrappers key on a `*Backed` marker, and there was
- * no `lmstudioBacked`. These two presets are what makes the new marker reachable
- * — a headless `cli` twin and the attachable `tui` that CoS agent tasks run in.
- *
- * Both presets are DISABLED and this migration installs nothing: it does not
- * start LM Studio, download a model, or contact the endpoint. `models` ships
- * EMPTY and `defaultModel` null — LM Studio serves whatever the operator has
- * downloaded, so the list is filled by an explicit refresh (the `lmstudio` row
- * in `server/lib/aiToolkit/internal/modelFetchers.js`), never guessed here.
- *
- * No API preset: `lmstudio` already exists as one. And no `numCtx` pin, unlike
- * the Ollama presets — LM Studio fixes a model's context window when the
- * instance is LOADED, so a stored window would be a value nothing reads (see the
- * `lmstudio` row in `server/lib/localProviderRuntime.js` for why PortOS does no
- * pre-spawn preparation for this backend).
- *
- * An install that already owns one of these ids is left untouched, so a user who
- * renamed or disabled the row keeps their record.
- *
- * Kept in lockstep with data.reference/providers.json and
- * server/lib/aiToolkit/defaults/providers.sample.json. These frozen literals are
- * the historical upgrade payload; later default changes require a new migration
- * rather than rewriting this record.
- */
-
-import { makeProviderSeedMigration } from './_lib.js';
-
-const OPENCODE_CONFIG_CONTENT = '{"permission":"allow","provider":{"lmstudio":{"npm":"@ai-sdk/openai-compatible","name":"LM Studio (local)","options":{"baseURL":"http://localhost:1234/v1"}}}}';
-
-const OPENCODE_LMSTUDIO_CLI = {
- id: 'opencode-lmstudio',
- name: 'OpenCode LM Studio (local model)',
- type: 'cli',
- command: 'opencode',
- args: ['run'],
- models: [],
- defaultModel: null,
- lmstudioBacked: true,
- timeout: 600000,
- enabled: false,
- envVars: { OPENCODE_CONFIG_CONTENT },
- secretEnvVars: [],
- headlessArgs: [],
-};
-
-const OPENCODE_LMSTUDIO_TUI = {
- id: 'opencode-lmstudio-tui',
- name: 'OpenCode LM Studio TUI (local model)',
- type: 'tui',
- command: 'opencode',
- args: [],
- models: [],
- defaultModel: null,
- lmstudioBacked: true,
- timeout: 600000,
- enabled: false,
- envVars: { OPENCODE_CONFIG_CONTENT },
- secretEnvVars: [],
- tuiPromptDelayMs: 2500,
-};
-
-export default makeProviderSeedMigration({
- label: 'OpenCode LM Studio (local model)',
- defs: [OPENCODE_LMSTUDIO_CLI, OPENCODE_LMSTUDIO_TUI],
-});
diff --git a/scripts/migrations/347-lmstudio-harness-providers.js b/scripts/migrations/347-lmstudio-harness-providers.js
new file mode 100644
index 0000000000..7f55287226
--- /dev/null
+++ b/scripts/migrations/347-lmstudio-harness-providers.js
@@ -0,0 +1,119 @@
+/**
+ * Ship the disabled LM Studio harness presets to existing installs.
+ *
+ * LM Studio was the one local backend PortOS already manages end to end — its
+ * own manager, an `lmstudio` API record, a Models → LLMs tab — that no coding
+ * harness could be pointed at, because every wrapper resolves its backend from a
+ * `*Backed` marker and there was no `lmstudioBacked` (#6309). These three
+ * presets are what make the new marker reachable: the OpenCode `cli` twin, the
+ * attachable OpenCode `tui` that CoS agent tasks run in, and the Codex wrapper
+ * that rides codex's native `--oss --local-provider lmstudio` (migration 346 did
+ * the same for Ollama and left this row for the marker).
+ *
+ * All three are DISABLED and this migration installs nothing: it does not start
+ * LM Studio, download a model, or contact the endpoint (AGENTS.md, "No
+ * cold-bootstrap LLM calls"). `models` ships EMPTY and `defaultModel` null — LM
+ * Studio serves whatever the operator downloaded, so the list is filled by an
+ * explicit refresh (the `lmstudio` row in
+ * `server/lib/aiToolkit/internal/modelFetchers.js`), never guessed here.
+ *
+ * No API preset: `lmstudio` already exists as one.
+ *
+ * Two things about these records are load-bearing:
+ *
+ * 1. **`numCtx` is a DECLARATION here, not an instruction.** On the Ollama
+ * presets PortOS enforces it by reloading the daemon
+ * (`ensureOllamaAgentContext`). LM Studio fixes a model's window when the
+ * INSTANCE is loaded, and the only lever PortOS holds
+ * (`lmStudioManager.loadModelWithArgs`) unloads whatever the user has
+ * resident and cold-loads the weights again — too costly to pay on every
+ * agent spawn, and it would evict a model the operator loaded in the app.
+ * So the field is still worth pinning, because the prompt budget reads it
+ * (`stageRunner.js`, `providerStatus.js`), but the operator adjusts it to
+ * match the instance they actually loaded rather than PortOS applying it.
+ * 2. **`lmstudioBacked: true`, not a codex-specific flag** on the Codex row —
+ * the same axis the OpenCode wrappers ride, so `localRuntimeNamespace` and
+ * `codexOssLocalProvider` pick it up with no new call site.
+ *
+ * An install that already owns one of these ids is left untouched, so a user who
+ * renamed or disabled the row keeps their record.
+ *
+ * Kept in lockstep with data.reference/providers.json and
+ * server/lib/aiToolkit/defaults/providers.sample.json. These frozen literals are
+ * the historical upgrade payload; later default changes require a new migration
+ * rather than rewriting this record.
+ */
+
+import { makeProviderSeedMigration } from './_lib.js';
+
+const OPENCODE_CONFIG_CONTENT = '{"permission":"allow","provider":{"lmstudio":{"npm":"@ai-sdk/openai-compatible","name":"LM Studio (local)","options":{"baseURL":"http://localhost:1234/v1"}}}}';
+
+// The window PortOS budgets prompts against, and the one an operator should
+// load the LM Studio instance with. Deliberately smaller than the Codex Ollama
+// preset's 131072: PortOS cannot reload LM Studio at this window, so the shipped
+// number has to be one a default install plausibly already has rather than one
+// PortOS would go make true.
+const NUM_CTX = 32768;
+
+const OPENCODE_LMSTUDIO_CLI = {
+ id: 'opencode-lmstudio',
+ name: 'OpenCode LM Studio (local model)',
+ type: 'cli',
+ command: 'opencode',
+ args: ['run'],
+ models: [],
+ defaultModel: null,
+ lmstudioBacked: true,
+ numCtx: NUM_CTX,
+ timeout: 600000,
+ enabled: false,
+ envVars: { OPENCODE_CONFIG_CONTENT },
+ secretEnvVars: [],
+ headlessArgs: [],
+};
+
+const OPENCODE_LMSTUDIO_TUI = {
+ id: 'opencode-lmstudio-tui',
+ name: 'OpenCode LM Studio TUI (local model)',
+ type: 'tui',
+ command: 'opencode',
+ args: [],
+ models: [],
+ defaultModel: null,
+ lmstudioBacked: true,
+ numCtx: NUM_CTX,
+ timeout: 600000,
+ enabled: false,
+ envVars: { OPENCODE_CONFIG_CONTENT },
+ secretEnvVars: [],
+ tuiPromptDelayMs: 2500,
+};
+
+const CODEX_LMSTUDIO = {
+ id: 'codex-lmstudio',
+ name: 'Codex LM Studio (local model)',
+ type: 'cli',
+ command: 'codex',
+ args: [],
+ // Codex reaches the daemon through its own `--local-provider lmstudio`
+ // resolution, so this endpoint is what PortOS's readiness probe checks, not a
+ // value handed to the CLI.
+ endpoint: 'http://localhost:1234/v1',
+ models: [],
+ defaultModel: null,
+ lmstudioBacked: true,
+ numCtx: NUM_CTX,
+ timeout: 600000,
+ enabled: false,
+ // No `textTransport`: the codex app-server transport is the ChatGPT
+ // subscription path, while a local-backed record runs the ordinary
+ // `codex exec` argv — which is what carries the `--oss` flags.
+ envVars: {},
+ secretEnvVars: [],
+ headlessArgs: [],
+};
+
+export default makeProviderSeedMigration({
+ label: 'LM Studio harness wrappers',
+ defs: [OPENCODE_LMSTUDIO_CLI, OPENCODE_LMSTUDIO_TUI, CODEX_LMSTUDIO],
+});
diff --git a/scripts/migrations/346-opencode-lmstudio-providers.test.js b/scripts/migrations/347-lmstudio-harness-providers.test.js
similarity index 61%
rename from scripts/migrations/346-opencode-lmstudio-providers.test.js
rename to scripts/migrations/347-lmstudio-harness-providers.test.js
index 7cd7b85383..0b0f093d64 100644
--- a/scripts/migrations/346-opencode-lmstudio-providers.test.js
+++ b/scripts/migrations/347-lmstudio-harness-providers.test.js
@@ -3,24 +3,26 @@ import { mkdtempSync, rmSync, writeFileSync, readFileSync, mkdirSync, existsSync
import { tmpdir } from 'os';
import { join } from 'path';
-import migration from './346-opencode-lmstudio-providers.js';
+import migration from './347-lmstudio-harness-providers.js';
const writeJson = (path, value) => writeFileSync(path, JSON.stringify(value, null, 2) + '\n');
const readJson = (path) => JSON.parse(readFileSync(path, 'utf-8'));
-describe('migration 346 — OpenCode LM Studio providers', () => {
+const IDS = ['opencode-lmstudio', 'opencode-lmstudio-tui', 'codex-lmstudio'];
+
+describe('migration 347 — LM Studio harness providers', () => {
let rootDir;
let providersPath;
beforeEach(() => {
- rootDir = mkdtempSync(join(tmpdir(), 'migration-346-'));
+ rootDir = mkdtempSync(join(tmpdir(), 'migration-347-'));
mkdirSync(join(rootDir, 'data'), { recursive: true });
providersPath = join(rootDir, 'data/providers.json');
});
afterEach(() => rmSync(rootDir, { recursive: true, force: true }));
- it('adds both OpenCode LM Studio presets, disabled, without changing the active provider', async () => {
+ it('adds all three presets, disabled, without changing the active provider', async () => {
writeJson(providersPath, {
activeProvider: 'claude-code',
providers: { 'claude-code': { id: 'claude-code', type: 'cli', command: 'claude' } },
@@ -44,6 +46,17 @@ describe('migration 346 — OpenCode LM Studio providers', () => {
enabled: false,
tuiPromptDelayMs: 2500,
});
+ // The Codex wrapper rides the SAME marker as the OpenCode pair — that is
+ // what makes `codexOssLocalProvider` emit `--local-provider lmstudio`
+ // without a codex-specific flag.
+ expect(out.providers['codex-lmstudio']).toMatchObject({
+ name: 'Codex LM Studio (local model)',
+ type: 'cli',
+ command: 'codex',
+ lmstudioBacked: true,
+ enabled: false,
+ });
+ expect(out.providers['codex-lmstudio'].textTransport).toBeUndefined();
expect(out.activeProvider).toBe('claude-code');
});
@@ -55,33 +68,38 @@ describe('migration 346 — OpenCode LM Studio providers', () => {
const config = JSON.parse(readJson(providersPath).providers[id].envVars.OPENCODE_CONFIG_CONTENT);
expect(config.provider.lmstudio.options.baseURL).toBe('http://localhost:1234/v1');
}
+ // Codex resolves the daemon itself from `--local-provider lmstudio`, so its
+ // wrapper carries no OpenCode config at all.
+ expect(readJson(providersPath).providers['codex-lmstudio'].envVars).toEqual({});
});
- it('pins no numCtx or thinking default — both are load-time choices in LM Studio', async () => {
+ it('pins numCtx as a prompt budget and seeds no thinking default', async () => {
writeJson(providersPath, { providers: {} });
await migration.up({ rootDir });
const out = readJson(providersPath);
- for (const id of ['opencode-lmstudio', 'opencode-lmstudio-tui']) {
- expect(out.providers[id].numCtx).toBeUndefined();
+ for (const id of IDS) {
+ // PortOS cannot reload LM Studio at this window — it is what the prompt
+ // budget reads, and what the operator should load the instance with.
+ expect(out.providers[id].numCtx).toBe(32768);
expect(out.providers[id].thinking).toBeUndefined();
}
});
it('is a no-op on a second run and never resurrects a renamed or disabled row', async () => {
const customized = {
- id: 'opencode-lmstudio-tui',
- name: 'My LM Studio TUI',
- type: 'tui',
- command: 'opencode',
+ id: 'codex-lmstudio',
+ name: 'My Codex on LM Studio',
+ type: 'cli',
+ command: 'codex',
lmstudioBacked: true,
enabled: false,
};
- writeJson(providersPath, { providers: { 'opencode-lmstudio-tui': customized } });
+ writeJson(providersPath, { providers: { 'codex-lmstudio': customized } });
await migration.up({ rootDir });
const first = readJson(providersPath);
- expect(first.providers['opencode-lmstudio-tui']).toEqual(customized);
+ expect(first.providers['codex-lmstudio']).toEqual(customized);
expect(first.providers['opencode-lmstudio']).toBeDefined();
await migration.up({ rootDir });
diff --git a/server/lib/aiToolkit/defaults/providers.sample.json b/server/lib/aiToolkit/defaults/providers.sample.json
index 24e934c983..f49a300653 100644
--- a/server/lib/aiToolkit/defaults/providers.sample.json
+++ b/server/lib/aiToolkit/defaults/providers.sample.json
@@ -123,6 +123,7 @@
"models": [],
"defaultModel": null,
"lmstudioBacked": true,
+ "numCtx": 32768,
"timeout": 600000,
"enabled": false,
"envVars": {
@@ -140,6 +141,7 @@
"models": [],
"defaultModel": null,
"lmstudioBacked": true,
+ "numCtx": 32768,
"timeout": 600000,
"enabled": false,
"envVars": {
@@ -547,6 +549,23 @@
"secretEnvVars": [],
"headlessArgs": []
},
+ "codex-lmstudio": {
+ "id": "codex-lmstudio",
+ "name": "Codex LM Studio (local model)",
+ "type": "cli",
+ "command": "codex",
+ "args": [],
+ "endpoint": "http://localhost:1234/v1",
+ "models": [],
+ "defaultModel": null,
+ "lmstudioBacked": true,
+ "numCtx": 32768,
+ "timeout": 600000,
+ "enabled": false,
+ "envVars": {},
+ "secretEnvVars": [],
+ "headlessArgs": []
+ },
"claude-code-tui": {
"id": "claude-code-tui",
"name": "Claude Code TUI",
diff --git a/server/lib/aiToolkit/internal/modelFetchers.test.js b/server/lib/aiToolkit/internal/modelFetchers.test.js
index 1ff5ac14b7..47e414be27 100644
--- a/server/lib/aiToolkit/internal/modelFetchers.test.js
+++ b/server/lib/aiToolkit/internal/modelFetchers.test.js
@@ -40,7 +40,7 @@ const SHIPPED_REFRESHABLE = [
// LM Studio publishes its downloaded catalog on the same OpenAI-compatible
// `/v1/models` endpoint the bare `lmstudio` API record already refreshes from,
// so the `lmstudioBacked` wrappers refresh through it too.
- 'opencode-lmstudio', 'opencode-lmstudio-tui',
+ 'opencode-lmstudio', 'opencode-lmstudio-tui', 'codex-lmstudio',
// SGLang publishes its served catalog through the same OpenAI-compatible
// `/v1/models` contract as the vLLM pair, so its wrappers refresh too.
'opencode-sglang', 'opencode-sglang-tui',
diff --git a/server/lib/codexLocalBacking.test.js b/server/lib/codexLocalBacking.test.js
index ba2d36ed0e..108c353bf4 100644
--- a/server/lib/codexLocalBacking.test.js
+++ b/server/lib/codexLocalBacking.test.js
@@ -141,6 +141,47 @@ describe('the public-review recipe keeps its posture AND gains the backing', ()
});
});
+// Codex's SECOND `--local-provider` value. It shipped unmapped because PortOS
+// had no LM Studio backing marker; with `lmstudioBacked` on the axis (#6309) the
+// table row is the whole change, and everything below has to follow from it —
+// including the `codexLocalRuntime` finding no longer firing, which is the same
+// switch that decides whether the record routes at all.
+describe('the lmstudio marker rides the same seam as ollama', () => {
+ const codexLmstudio = { id: 'codex-lmstudio', type: 'cli', command: 'codex', args: [], lmstudioBacked: true };
+ const lmstudioTriple = ['--oss', '--local-provider', 'lmstudio'];
+ const hasLmstudioTriple = (args) => {
+ const i = args.indexOf('--oss');
+ return i !== -1 && args.slice(i, i + 3).join(' ') === lmstudioTriple.join(' ');
+ };
+
+ it('maps the marker onto codex\'s own value rather than reporting it unsupported', () => {
+ expect(codexOssLocalProvider(codexLmstudio)).toBe('lmstudio');
+ expect(codexUnsupportedLocalRuntime(codexLmstudio)).toBeNull();
+ });
+
+ it('carries the flags on the ordinary and the public-review argv', () => {
+ expect(hasLmstudioTriple(buildVendorCliArgs(codexLmstudio, [], { model: 'qwen3-coder-30b', effort: null }))).toBe(true);
+ expect(hasLmstudioTriple(buildVendorSpawnConfig(codexLmstudio, { effectiveModel: 'qwen3-coder-30b' }).args)).toBe(true);
+ const review = buildVendorSpawnConfig(codexLmstudio, {
+ effectiveModel: 'qwen3-coder-30b',
+ safetyProfile: PUBLIC_REVIEW_ACTIONS_EXECUTION_PROFILE,
+ }).args;
+ expect(review.slice(0, 6)).toEqual([
+ 'exec', '--sandbox', 'workspace-write', '--approve-for-me', '--ephemeral', '--ignore-user-config',
+ ]);
+ expect(hasLmstudioTriple(review)).toBe(true);
+ });
+
+ it('raises neither the unsupported-runtime nor the ChatGPT-account finding', () => {
+ expect(providerPrerequisites(codexLmstudio, { codexOssSupport: { supported: true } }).missing).toEqual([]);
+ expect(isCodexSubscriptionProvider(codexLmstudio)).toBe(false);
+ expect(providerPrerequisites(codexLmstudio, {
+ codexAccount: { status: 'signed-out' },
+ codexOssSupport: { supported: true },
+ }).missing).toEqual([]);
+ });
+});
+
describe('prerequisites fail closed and legibly', () => {
it('reports nothing while the flag probe has not answered', () => {
// `null` is NOT PROBED — an unprobed CLI must never take a working provider
diff --git a/server/lib/providerModels.js b/server/lib/providerModels.js
index 93c0086abd..44654fa147 100644
--- a/server/lib/providerModels.js
+++ b/server/lib/providerModels.js
@@ -719,10 +719,12 @@ export function localRuntimeNamespace(provider) {
* rejects, and forwarding nothing would silently run the record against the
* OpenAI cloud — which is why `codexUnsupportedLocalRuntime` below exists.
*
- * `lmstudio` is absent because PortOS has no LM Studio backing marker yet; the
- * row lands with the marker, not before it.
+ * Both of Codex's values are mapped: `lmstudio` joined the axis with the
+ * `lmstudioBacked` marker (#6309). The remaining three (mtplx / vllm / sglang)
+ * have no Codex spelling at all, which is what `codexUnsupportedLocalRuntime`
+ * below is for.
*/
-export const CODEX_OSS_LOCAL_PROVIDERS = Object.freeze({ ollama: 'ollama' });
+export const CODEX_OSS_LOCAL_PROVIDERS = Object.freeze({ ollama: 'ollama', lmstudio: 'lmstudio' });
/**
* The first Codex CLI release that ships `--oss` / `--local-provider`. Used