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

fix provider context window metadata

Adam Eivy80c6b0869034
diff --git a/client/src/utils/providers.js b/client/src/utils/providers.js
index a9b11f5c16..46990038fc 100644
--- a/client/src/utils/providers.js
+++ b/client/src/utils/providers.js
@@ -9,14 +9,20 @@ export const CODEX_CONFIGURED_DEFAULT = 'codex-configured-default';
export const ANTIGRAVITY_CONFIGURED_DEFAULT = 'antigravity-configured-default';
export const DEFAULT_LARGE_CONTEXT_WINDOW = 128_000;
+export const CODEX_CONTEXT_WINDOW = 1_000_000;
+export const GEMINI_CONTEXT_WINDOW = 1_048_576;
-// Keep in sync with server/lib/stageRunner.js. Only Opus 4.8 is special-cased
-// at 1M; unknown Opus 4 variants intentionally keep the conservative provider
-// fallback until their windows are explicitly known.
+// Keep in sync with server/lib/stageRunner.js.
const KNOWN_MODEL_CONTEXT_WINDOWS = Object.freeze([
+ [/gpt[-_.:/]?5\.5(?:[-_.:/]|\b)/i, CODEX_CONTEXT_WINDOW],
+ [/gpt[-_.:/]?5\.4[-_.:/]?mini(?:[-_.:/]|\b)/i, 400_000],
+ [/gpt[-_.:/]?5\.4(?![-_.:/]?(?:mini|nano))(?:[-_.:/]|\b)/i, CODEX_CONTEXT_WINDOW],
+ [/claude[-_.:/]?fable[-_.:/]?5(?:[-_.:/]|\b)/i, 1_000_000],
+ [/claude[-_.:/]?mythos[-_.:/]?5(?:[-_.:/]|\b)/i, 1_000_000],
[/claude[-_.:/]?opus[-_.:/]?4[-_.:/]?8/i, 1_000_000],
- [/claude[-_.:/]?sonnet[-_.:/]?4(?:[-_.:/]|\b)/i, 200_000],
+ [/claude[-_.:/]?sonnet[-_.:/]?4[-_.:/]?6(?:[-_.:/]|\b)/i, 1_000_000],
[/claude[-_.:/]?haiku[-_.:/]?4(?:[-_.:/]|\b)/i, 200_000],
+ [/gemini[-_.:/]?2\.5[-_.:/]?pro(?:[-_.:/]|\b)/i, GEMINI_CONTEXT_WINDOW],
]);
export const knownModelContextWindow = (model) => {
@@ -25,6 +31,15 @@ export const knownModelContextWindow = (model) => {
return found ? found[1] : null;
};
+export const knownProviderContextWindow = (provider) => {
+ if (!isProcessProvider(provider)) return null;
+ const id = String(provider?.id || '').toLowerCase();
+ const command = String(provider?.command || '').toLowerCase();
+ if (id === 'codex' || id === 'codex-tui' || command === 'codex') return CODEX_CONTEXT_WINDOW;
+ if (id === 'antigravity-cli' || id === 'antigravity-tui' || command === 'agy') return GEMINI_CONTEXT_WINDOW;
+ return null;
+};
+
/**
* Provider-type enum mirrored from server/lib/aiToolkit/constants.js#PROVIDER_TYPES.
* The aiToolkit directory is kept self-contained (no imports out to other PortOS
@@ -128,6 +143,8 @@ export const effectiveModelContextWindow = (provider, model) => {
if (Number.isFinite(explicit) && explicit > 0) return explicit;
const known = knownModelContextWindow(model);
if (known) return known;
+ const providerKnown = knownProviderContextWindow(provider);
+ if (providerKnown) return providerKnown;
const numCtx = Number(provider?.numCtx);
if (Number.isFinite(numCtx) && numCtx > 0) return numCtx;
return isLikelyLargeContextProvider(provider) ? DEFAULT_LARGE_CONTEXT_WINDOW : null;
diff --git a/client/src/utils/providers.test.js b/client/src/utils/providers.test.js
index 15689a0c39..e4e66c1d27 100644
--- a/client/src/utils/providers.test.js
+++ b/client/src/utils/providers.test.js
@@ -239,8 +239,19 @@ describe('localBackendForProvider', () => {
describe('effectiveModelContextWindow', () => {
it('matches known model windows before provider defaults', () => {
+ expect(effectiveModelContextWindow({ type: 'tui' }, 'gpt-5.5')).toBe(1_000_000);
+ expect(effectiveModelContextWindow({ type: 'tui' }, 'gpt-5.4')).toBe(1_000_000);
+ expect(effectiveModelContextWindow({ type: 'tui' }, 'gpt-5.4-mini')).toBe(400_000);
+ expect(effectiveModelContextWindow({ type: 'tui' }, 'gpt-5.4-nano')).toBe(128_000);
expect(effectiveModelContextWindow({ type: 'tui' }, 'claude-opus-4-8')).toBe(1_000_000);
- expect(effectiveModelContextWindow({ type: 'api', endpoint: 'https://api.example.test/v1' }, 'claude-sonnet-4-6')).toBe(200_000);
+ expect(effectiveModelContextWindow({ type: 'api', endpoint: 'https://api.example.test/v1' }, 'claude-sonnet-4-6')).toBe(1_000_000);
+ expect(effectiveModelContextWindow({ type: 'api', endpoint: 'https://api.example.test/v1' }, 'claude-haiku-4-5')).toBe(200_000);
+ expect(effectiveModelContextWindow({ type: 'api', endpoint: 'https://generativelanguage.googleapis.com/v1beta' }, 'gemini-2.5-pro')).toBe(1_048_576);
+ });
+
+ it('uses canonical provider windows for configured-default process providers', () => {
+ expect(effectiveModelContextWindow({ id: 'codex-tui', type: 'tui', command: 'codex' }, CODEX_CONFIGURED_DEFAULT)).toBe(1_000_000);
+ expect(effectiveModelContextWindow({ id: 'antigravity-cli', type: 'cli', command: 'agy' }, ANTIGRAVITY_CONFIGURED_DEFAULT)).toBe(1_048_576);
});
it('matches the server planner for local and cloud api defaults', () => {
diff --git a/server/lib/aiToolkit/defaults/providers.sample.json b/server/lib/aiToolkit/defaults/providers.sample.json
index d574cc4916..b0ecc4e8fb 100644
--- a/server/lib/aiToolkit/defaults/providers.sample.json
+++ b/server/lib/aiToolkit/defaults/providers.sample.json
@@ -49,6 +49,7 @@
"lightModel": "codex-configured-default",
"mediumModel": "codex-configured-default",
"heavyModel": "codex-configured-default",
+ "contextWindow": 1000000,
"timeout": 300000,
"enabled": true,
"envVars": {},
@@ -65,6 +66,7 @@
"lightModel": "codex-configured-default",
"mediumModel": "codex-configured-default",
"heavyModel": "codex-configured-default",
+ "contextWindow": 1000000,
"timeout": 600000,
"enabled": false,
"envVars": {},
@@ -119,6 +121,7 @@
"lightModel": "antigravity-configured-default",
"mediumModel": "antigravity-configured-default",
"heavyModel": "antigravity-configured-default",
+ "contextWindow": 1048576,
"timeout": 600000,
"enabled": false,
"envVars": {},
@@ -137,6 +140,7 @@
"lightModel": "antigravity-configured-default",
"mediumModel": "antigravity-configured-default",
"heavyModel": "antigravity-configured-default",
+ "contextWindow": 1048576,
"timeout": 300000,
"enabled": true,
"envVars": {},
diff --git a/server/lib/aiToolkit/providers.js b/server/lib/aiToolkit/providers.js
index 7be8b50ebb..98c9a55ec1 100644
--- a/server/lib/aiToolkit/providers.js
+++ b/server/lib/aiToolkit/providers.js
@@ -23,6 +23,22 @@ const execFileAsync = promisify(execFile);
const CODEX_CONFIGURED_DEFAULT = 'codex-configured-default';
const CODEX_MODEL_KEYS = ['defaultModel', 'lightModel', 'mediumModel', 'heavyModel'];
const ANTIGRAVITY_MODEL_KEYS = ['defaultModel', 'lightModel', 'mediumModel', 'heavyModel'];
+const CODEX_CONTEXT_WINDOW = 1_000_000;
+const GEMINI_CONTEXT_WINDOW = 1_048_576;
+const STALE_GENERIC_CONTEXT_WINDOW = 128_000;
+
+function shouldUpgradeContextWindow(value) {
+ return value == null || Number(value) === STALE_GENERIC_CONTEXT_WINDOW;
+}
+
+function canonicalProviderContextWindow(provider) {
+ if (provider?.type !== 'cli' && provider?.type !== 'tui') return null;
+ const id = String(provider?.id || '').toLowerCase();
+ const command = String(provider?.command || '').toLowerCase();
+ if (id === 'codex' || id === 'codex-tui' || command === 'codex') return CODEX_CONTEXT_WINDOW;
+ if (id === ANTIGRAVITY_CLI_ID || id === ANTIGRAVITY_TUI_ID || command === 'agy') return GEMINI_CONTEXT_WINDOW;
+ return null;
+}
// Auto-migrate legacy codex provider configs that pin a real model id
// (e.g. "gpt-5.2") to the sentinel "codex-configured-default" so the Codex
@@ -105,6 +121,20 @@ function migrateAntigravityProviders(data) {
return changed;
}
+function migrateProviderContextWindows(data) {
+ if (!data?.providers) return false;
+ let changed = false;
+
+ for (const provider of Object.values(data.providers)) {
+ const contextWindow = canonicalProviderContextWindow(provider);
+ if (!contextWindow || !shouldUpgradeContextWindow(provider.contextWindow)) continue;
+ provider.contextWindow = contextWindow;
+ changed = true;
+ }
+
+ return changed;
+}
+
export function createProviderService(config = {}) {
const {
dataDir = './data',
@@ -192,10 +222,12 @@ export function createProviderService(config = {}) {
const migratedCodex = migrateCodexProvider(data);
const migratedAntigravity = migrateAntigravityProviders(data);
- if (migratedCodex || migratedAntigravity) {
+ const migratedContextWindows = migrateProviderContextWindows(data);
+ if (migratedCodex || migratedAntigravity || migratedContextWindows) {
await atomicWrite(PROVIDERS_PATH, data);
if (migratedCodex) console.log('🔧 Migrated codex provider config to codex-configured-default sentinel');
if (migratedAntigravity) console.log('🔧 Migrated Gemini provider config to Antigravity CLI (agy)');
+ if (migratedContextWindows) console.log('🔧 Migrated provider context windows to current canonical values');
}
return data;
diff --git a/server/lib/aiToolkit/providers.test.js b/server/lib/aiToolkit/providers.test.js
index a7db88b601..11309e23e7 100644
--- a/server/lib/aiToolkit/providers.test.js
+++ b/server/lib/aiToolkit/providers.test.js
@@ -138,6 +138,9 @@ describe('Provider Service', () => {
mediumModel: 'model-a',
heavyModel: 'model-c',
fallbackProvider: 'fallback-provider-id',
+ fallbackModel: 'fallback-model-id',
+ numCtx: 32768,
+ contextWindow: 1000000,
timeout: 600000,
enabled: false,
envVars: { OPENAI_BASE_URL: 'https://example.com', LOG_LEVEL: 'debug' },
@@ -178,6 +181,8 @@ describe('Provider Service', () => {
const bedrock = samples.find(p => p.id === 'claude-code-bedrock');
expect(bedrock).toBeDefined();
expect(bedrock.name).toBe('Claude Code CLI: Bedrock');
+ expect(samples.find(p => p.id === 'codex-tui')?.contextWindow).toBe(1000000);
+ expect(samples.find(p => p.id === 'antigravity-cli')?.contextWindow).toBe(1048576);
});
it('should exclude providers already in user config', async () => {
@@ -415,6 +420,77 @@ describe('Provider Service', () => {
expect(codex.defaultModel).toBe(CODEX_SENTINEL);
});
+ it('upgrades default Codex and Antigravity context windows on first read', async () => {
+ await writeProvidersFile({
+ activeProvider: 'codex-tui',
+ providers: {
+ codex: {
+ id: 'codex',
+ name: 'Codex CLI',
+ type: 'cli',
+ command: 'codex',
+ contextWindow: 128000,
+ models: [CODEX_SENTINEL],
+ defaultModel: CODEX_SENTINEL
+ },
+ 'codex-tui': {
+ id: 'codex-tui',
+ name: 'Codex TUI',
+ type: 'tui',
+ command: 'codex',
+ models: [CODEX_SENTINEL],
+ defaultModel: CODEX_SENTINEL
+ },
+ 'antigravity-cli': {
+ id: 'antigravity-cli',
+ name: 'Antigravity CLI',
+ type: 'cli',
+ command: 'agy',
+ contextWindow: 128000,
+ models: ['antigravity-configured-default'],
+ defaultModel: 'antigravity-configured-default'
+ },
+ custom: {
+ id: 'custom',
+ name: 'Custom CLI',
+ type: 'cli',
+ command: 'custom',
+ contextWindow: 128000
+ }
+ }
+ });
+
+ const codex = await providerService.getProviderById('codex');
+ const codexTui = await providerService.getProviderById('codex-tui');
+ const antigravity = await providerService.getProviderById('antigravity-cli');
+ const custom = await providerService.getProviderById('custom');
+
+ expect(codex.contextWindow).toBe(1000000);
+ expect(codexTui.contextWindow).toBe(1000000);
+ expect(antigravity.contextWindow).toBe(1048576);
+ expect(custom.contextWindow).toBe(128000);
+ });
+
+ it('preserves user-tuned context windows above the stale generic value', async () => {
+ await writeProvidersFile({
+ activeProvider: 'codex',
+ providers: {
+ codex: {
+ id: 'codex',
+ name: 'Codex CLI',
+ type: 'cli',
+ command: 'codex',
+ contextWindow: 512000,
+ models: [CODEX_SENTINEL],
+ defaultModel: CODEX_SENTINEL
+ }
+ }
+ });
+
+ const codex = await providerService.getProviderById('codex');
+ expect(codex.contextWindow).toBe(512000);
+ });
+
it('migrates legacy Gemini providers to Antigravity agy providers', async () => {
await writeProvidersFile({
activeProvider: 'gemini-cli',
@@ -450,9 +526,11 @@ describe('Provider Service', () => {
expect(antigravity.command).toBe('agy');
expect(antigravity.args).toEqual(['--print', '--dangerously-skip-permissions']);
expect(antigravity.defaultModel).toBe('antigravity-configured-default');
+ expect(antigravity.contextWindow).toBe(1048576);
expect(antigravity.envVars).toEqual({ KEEP_ME: '1' });
expect(antigravityTui.command).toBe('agy');
expect(antigravityTui.args).toEqual(['--dangerously-skip-permissions']);
+ expect(antigravityTui.contextWindow).toBe(1048576);
});
});
diff --git a/server/lib/stageRunner.js b/server/lib/stageRunner.js
index 48fac66cca..5515121be1 100644
--- a/server/lib/stageRunner.js
+++ b/server/lib/stageRunner.js
@@ -90,14 +90,20 @@ export function resolveModel(provider, modelHint) {
// whole manuscript fits in one call" without over-promising. Users with very
// large manuscripts can set an explicit `contextWindow` to lift it further.
export const DEFAULT_LARGE_CONTEXT_WINDOW = 128_000;
+export const CODEX_CONTEXT_WINDOW = 1_000_000;
+export const GEMINI_CONTEXT_WINDOW = 1_048_576;
-// Keep in sync with client/src/utils/providers.js. Only Opus 4.8 is
-// special-cased at 1M; unknown Opus 4 variants intentionally keep the
-// conservative provider fallback until their windows are explicitly known.
+// Keep in sync with client/src/utils/providers.js.
const KNOWN_MODEL_CONTEXT_WINDOWS = Object.freeze([
+ [/gpt[-_.:/]?5\.5(?:[-_.:/]|\b)/i, CODEX_CONTEXT_WINDOW],
+ [/gpt[-_.:/]?5\.4[-_.:/]?mini(?:[-_.:/]|\b)/i, 400_000],
+ [/gpt[-_.:/]?5\.4(?![-_.:/]?(?:mini|nano))(?:[-_.:/]|\b)/i, CODEX_CONTEXT_WINDOW],
+ [/claude[-_.:/]?fable[-_.:/]?5(?:[-_.:/]|\b)/i, 1_000_000],
+ [/claude[-_.:/]?mythos[-_.:/]?5(?:[-_.:/]|\b)/i, 1_000_000],
[/claude[-_.:/]?opus[-_.:/]?4[-_.:/]?8/i, 1_000_000],
- [/claude[-_.:/]?sonnet[-_.:/]?4(?:[-_.:/]|\b)/i, 200_000],
+ [/claude[-_.:/]?sonnet[-_.:/]?4[-_.:/]?6(?:[-_.:/]|\b)/i, 1_000_000],
[/claude[-_.:/]?haiku[-_.:/]?4(?:[-_.:/]|\b)/i, 200_000],
+ [/gemini[-_.:/]?2\.5[-_.:/]?pro(?:[-_.:/]|\b)/i, GEMINI_CONTEXT_WINDOW],
]);
export function knownModelContextWindow(model) {
@@ -106,6 +112,15 @@ export function knownModelContextWindow(model) {
return found ? found[1] : null;
}
+export function knownProviderContextWindow(provider) {
+ if (provider?.type !== 'cli' && provider?.type !== 'tui') return null;
+ const id = String(provider?.id || '').toLowerCase();
+ const command = String(provider?.command || '').toLowerCase();
+ if (id === 'codex' || id === 'codex-tui' || command === 'codex') return CODEX_CONTEXT_WINDOW;
+ if (id === 'antigravity-cli' || id === 'antigravity-tui' || command === 'agy') return GEMINI_CONTEXT_WINDOW;
+ return null;
+}
+
const LOCAL_ENDPOINT_RE = /^(https?:\/\/)?(localhost|127\.0\.0\.1|0\.0\.0\.0|\[?::1\]?)(:|\/|$)/i;
const isLocalEndpoint = (endpoint) =>
typeof endpoint === 'string' && LOCAL_ENDPOINT_RE.test(endpoint.trim());
@@ -121,6 +136,7 @@ const isLikelyLargeContextProvider = (provider) => {
// Planning-time context window for a provider/model: an explicit
// `contextWindow` wins, else a known model window for the resolved model, else
+// a known provider-level window for configured-default process providers, else
// the Ollama per-request `numCtx`, else a large default for frontier providers,
// else null (the budgeter applies a conservative floor for unknown local
// backends).
@@ -128,6 +144,8 @@ export function effectiveContextWindow(provider, model) {
if (Number(provider?.contextWindow) > 0) return Number(provider.contextWindow);
const modelWindow = knownModelContextWindow(model);
if (modelWindow) return modelWindow;
+ const providerWindow = knownProviderContextWindow(provider);
+ if (providerWindow) return providerWindow;
if (Number(provider?.numCtx) > 0) return Number(provider.numCtx);
if (isLikelyLargeContextProvider(provider)) return DEFAULT_LARGE_CONTEXT_WINDOW;
return null;
diff --git a/server/lib/stageRunner.test.js b/server/lib/stageRunner.test.js
index c736ed86de..1a3c9daaa3 100644
--- a/server/lib/stageRunner.test.js
+++ b/server/lib/stageRunner.test.js
@@ -28,8 +28,11 @@ const {
resolveModel,
extractJson,
DEFAULT_LARGE_CONTEXT_WINDOW,
+ CODEX_CONTEXT_WINDOW,
+ GEMINI_CONTEXT_WINDOW,
effectiveContextWindow,
knownModelContextWindow,
+ knownProviderContextWindow,
resolveStageContext,
} = await import('./stageRunner.js');
@@ -83,12 +86,22 @@ describe('stageRunner — resolveModel', () => {
describe('stageRunner — context windows', () => {
it('resolves known model windows from the selected model id', () => {
+ expect(knownModelContextWindow('gpt-5.5')).toBe(CODEX_CONTEXT_WINDOW);
+ expect(knownModelContextWindow('gpt-5.4')).toBe(CODEX_CONTEXT_WINDOW);
+ expect(knownModelContextWindow('gpt-5.4-mini')).toBe(400_000);
+ expect(knownModelContextWindow('gpt-5.4-nano')).toBeNull();
expect(knownModelContextWindow('claude-opus-4-8')).toBe(1_000_000);
- expect(knownModelContextWindow('claude-sonnet-4-6')).toBe(200_000);
+ expect(knownModelContextWindow('claude-sonnet-4-6')).toBe(1_000_000);
expect(knownModelContextWindow('us.anthropic.claude-sonnet-4-5-20250929-v1:0')).toBe(200_000);
+ expect(knownModelContextWindow('gemini-2.5-pro')).toBe(GEMINI_CONTEXT_WINDOW);
expect(knownModelContextWindow('unknown-model')).toBeNull();
});
+ it('resolves configured-default provider windows by provider identity', () => {
+ expect(knownProviderContextWindow({ id: 'codex-tui', type: 'tui', command: 'codex' })).toBe(CODEX_CONTEXT_WINDOW);
+ expect(knownProviderContextWindow({ id: 'antigravity-cli', type: 'cli', command: 'agy' })).toBe(GEMINI_CONTEXT_WINDOW);
+ });
+
it('keeps an explicit provider contextWindow above model defaults', () => {
expect(effectiveContextWindow(
{ type: 'tui', contextWindow: 64_000 },
@@ -96,11 +109,15 @@ describe('stageRunner — context windows', () => {
)).toBe(64_000);
});
- it('uses model windows before provider numCtx', () => {
+ it('uses model and provider windows before provider numCtx', () => {
expect(effectiveContextWindow(
{ type: 'api', endpoint: 'http://localhost:11434/v1', numCtx: 32_768 },
'claude-sonnet-4-6'
- )).toBe(200_000);
+ )).toBe(1_000_000);
+ expect(effectiveContextWindow(
+ { id: 'codex', type: 'cli', command: 'codex', numCtx: 32_768 },
+ 'codex-configured-default'
+ )).toBe(CODEX_CONTEXT_WINDOW);
});
it('falls back to numCtx, large-provider default, or null', () => {