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
JavaScript ai-agentsdashboarddeveloper-toolsdigital-twinquantified-selfsecond-brainself-hostedtailscale
fix: normalize CLI command basename in knownProviderContextWindow (#2337)
Adam Eivyb225b4d6d925
diff --git a/.changelog/NEXT.md b/.changelog/NEXT.mdindex 2eb8c95740..674ecb17ae 100644--- a/.changelog/NEXT.md+++ b/.changelog/NEXT.md@@ -16,6 +16,8 @@## Fixed+- **[issue-2337] Path-configured CLI/TUI providers now resolve their real vendor context window.** `knownProviderContextWindow` (mirrored in `server/lib/stageRunner.js` and `client/src/utils/providers.js`) matched the provider `command` with exact equality, so a Codex/Antigravity/Grok provider configured with an absolute or relative command path (e.g. `/opt/homebrew/bin/grok`) was missed and fell back to the generic 128K CLI default instead of the vendor window (Codex 1M, Antigravity 1.05M, Grok 256K). Both mirrors now normalize the command to its basename before comparing — the server reuses `commandBasename` from `providerModels.js` and the client uses an inline lockstep helper — matching how the arg-builder predicates already route. Low impact in practice (shipped providers carry an explicit `contextWindow`; only hand-configured path-based providers without one were affected).+- **[issue-2328] Auto-fixer now has a circuit breaker so a persistently-failing resource can't flood the task queue.** The auto-fixer only deduped identical errors within a 60-second window, so a provider/model (or critical error) that failed every ~minute would queue a fresh investigation/fix task indefinitely — a runaway loop that exhausts the plan queue and never gets healed by yet another identical task. It now trips a per-resource circuit after more than 3 task-worthy failures within a rolling 1-hour window, suppressing further task creation (logged as `🔌 Auto-fix circuit OPEN …`) until the failure rate ages out and the circuit auto-closes. (Partial delivery of #2328's guardrails; the tiered fallback chain, structured failure-reason telemetry, and dashboard metrics remain.)- **[issue-2328] Auto-fixer now classifies every failure into a fallback tier and records structured per-attempt diagnostics.** A deterministic classifier maps each error category (config/env, schema/type, transient, or unknown) to one of four fallback tiers — 1 config/env, 2 schema/type, 3 constrained-agent-retry, 4 escalate — with unrecognized categories always escalating so nothing is silently swallowed. Each auto-fix attempt now builds a structured `{ triggerEvent, target, errorType, category, tier, fixStrategy, failureReason }` diagnostics object that rides on the investigation/fix task record (and its agent-facing context) and is surfaced inline in the existing single-line log (`… tier=1 (config/env) …`), so failures can be broken out by tier / category / reason. (Further #2328 slices remain: dashboard telemetry surfacing, time-to-recovery metric, full 4-tier execution wiring.)- **[issue-2328] Auto-fix diagnostics are now persisted as structured task metadata instead of being silently dropped.** The tier/category/failure-reason diagnostics the classifier builds for every error-driven task were only ever embedded into the free-text context string and the log line — `addTask` never copied the structured object into task metadata, so it couldn't be queried or aggregated afterward. It now persists `taskData.diagnostics` as first-class `metadata.diagnostics` (round-tripping through the markdown store via the existing JSON sentinel, with a defensive non-object guard), and `createCosTaskSchema` validates it for schema parity. This is the prerequisite for the remaining #2328 telemetry slice: aggregating auto-fix outcomes by tier / failure reason / time-to-recovery and surfacing them on the dashboard.diff --git a/client/src/utils/providers.js b/client/src/utils/providers.jsindex 329fc0a956..b1f43656a8 100644--- a/client/src/utils/providers.js+++ b/client/src/utils/providers.js@@ -34,10 +34,19 @@ export const knownModelContextWindow = (model) => {return found ? found[1] : null;};+// Inline mirror of server/lib/providerModels.js#commandBasename — the client can't+// import server-side modules. Strip the directory + a Windows `.exe` suffix so a+// path-configured command (/opt/homebrew/bin/grok) matches the bare vendor name.+// Keep in lockstep with the server helper (only `.exe` is stripped, not `.cmd`).+const commandBasename = (command) =>+ typeof command === 'string' && command !== ''+ ? command.split(/[\\/]/).pop().toLowerCase().replace(/\.exe$/, '')+ : '';+export const knownProviderContextWindow = (provider) => {if (!isProcessProvider(provider)) return null;const id = String(provider?.id || '').toLowerCase();- const command = String(provider?.command || '').toLowerCase();+ const command = commandBasename(provider?.command);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;if (id === 'grok-cli' || id === 'grok-tui' || command === 'grok') return GROK_CONTEXT_WINDOW;diff --git a/client/src/utils/providers.test.js b/client/src/utils/providers.test.jsindex 27316fc67f..be11674d35 100644--- a/client/src/utils/providers.test.js+++ b/client/src/utils/providers.test.js@@ -11,6 +11,10 @@ import {isToolUseModel,toolUseLocalModelFilter,localBackendForProvider,+ knownProviderContextWindow,+ CODEX_CONTEXT_WINDOW,+ GEMINI_CONTEXT_WINDOW,+ GROK_CONTEXT_WINDOW,effectiveModelContextWindow,mergeModelLists,modelOptionLabel,@@ -293,6 +297,28 @@ describe('localBackendForProvider', () => {});});+describe('knownProviderContextWindow (mirror of server stageRunner)', () => {+ it('resolves vendor windows for bare commands', () => {+ 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);+ expect(knownProviderContextWindow({ id: 'grok-cli', type: 'cli', command: 'grok' })).toBe(GROK_CONTEXT_WINDOW);+ expect(knownProviderContextWindow({ id: 'grok-tui', type: 'tui', command: 'grok' })).toBe(GROK_CONTEXT_WINDOW);+ });++ it('normalizes command paths to the basename for vendor windows (#2337)', () => {+ expect(knownProviderContextWindow({ id: 'custom', type: 'cli', command: '/opt/homebrew/bin/grok' })).toBe(GROK_CONTEXT_WINDOW);+ expect(knownProviderContextWindow({ id: 'custom', type: 'tui', command: '/usr/local/bin/codex' })).toBe(CODEX_CONTEXT_WINDOW);+ expect(knownProviderContextWindow({ id: 'custom', type: 'cli', command: '/opt/homebrew/bin/agy' })).toBe(GEMINI_CONTEXT_WINDOW);+ expect(knownProviderContextWindow({ id: 'custom', type: 'cli', command: './bin/codex' })).toBe(CODEX_CONTEXT_WINDOW);+ expect(knownProviderContextWindow({ id: 'custom', type: 'cli', command: 'C:\\tools\\grok.exe' })).toBe(GROK_CONTEXT_WINDOW);+ expect(knownProviderContextWindow({ id: 'custom', type: 'cli', command: '/opt/homebrew/bin/mycli' })).toBeNull();+ });++ it('returns null for non-process providers', () => {+ expect(knownProviderContextWindow({ id: 'codex', type: 'api', command: 'codex' })).toBeNull();+ });+});+describe('effectiveModelContextWindow', () => {it('matches known model windows before provider defaults', () => {expect(effectiveModelContextWindow({ type: 'tui' }, 'gpt-5.5')).toBe(1_000_000);diff --git a/server/lib/stageRunner.js b/server/lib/stageRunner.jsindex 0ec7a433cd..06e1b5f192 100644--- a/server/lib/stageRunner.js+++ b/server/lib/stageRunner.js@@ -20,6 +20,7 @@ import { resolveEffectiveModel, runPromptThroughProvider, DEFAULT_TIMEOUT_MS, isimport { stripCodeFences } from './aiProvider.js';import { extractCodexAssistant } from './codexAssistantExtract.js';import { getActiveProvider, getProviderById } from '../services/providers.js';+import { commandBasename } from './providerModels.js';import { buildPrompt, getStage } from '../services/promptService.js';import { createRun, patchRunMetadata } from '../services/runner.js';import { MIN_TIMEOUT as STAGE_TIMEOUT_MIN_MS, MAX_TIMEOUT as STAGE_TIMEOUT_MAX_MS } from './aiToolkit/constants.js';@@ -145,7 +146,10 @@ export function knownModelContextWindow(model) {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();+ // Normalize to the basename so a path-configured command (/opt/homebrew/bin/grok)+ // resolves the same vendor window as a bare `grok` on PATH — matching how the+ // arg-builder predicates (isOpencodeCommand/isGrokCommand) key on commandBasename.+ const command = commandBasename(provider?.command);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;if (id === 'grok-cli' || id === 'grok-tui' || command === 'grok') return GROK_CONTEXT_WINDOW;diff --git a/server/lib/stageRunner.test.js b/server/lib/stageRunner.test.jsindex 345101ad55..4a12a8340e 100644--- a/server/lib/stageRunner.test.js+++ b/server/lib/stageRunner.test.js@@ -111,6 +111,19 @@ describe('stageRunner — context windows', () => {expect(knownProviderContextWindow({ id: 'grok-tui', type: 'tui', command: 'grok' })).toBe(GROK_CONTEXT_WINDOW);});+ it('normalizes command paths to the basename for vendor windows (#2337)', () => {+ // Absolute path to the binary (common when the service PATH can't resolve the CLI).+ expect(knownProviderContextWindow({ id: 'custom', type: 'cli', command: '/opt/homebrew/bin/grok' })).toBe(GROK_CONTEXT_WINDOW);+ expect(knownProviderContextWindow({ id: 'custom', type: 'tui', command: '/usr/local/bin/codex' })).toBe(CODEX_CONTEXT_WINDOW);+ expect(knownProviderContextWindow({ id: 'custom', type: 'cli', command: '/opt/homebrew/bin/agy' })).toBe(GEMINI_CONTEXT_WINDOW);+ // Relative path.+ expect(knownProviderContextWindow({ id: 'custom', type: 'cli', command: './bin/codex' })).toBe(CODEX_CONTEXT_WINDOW);+ // Windows .exe suffix + backslash separators.+ expect(knownProviderContextWindow({ id: 'custom', type: 'cli', command: 'C:\\tools\\grok.exe' })).toBe(GROK_CONTEXT_WINDOW);+ // Unrelated custom command still falls through to null.+ expect(knownProviderContextWindow({ id: 'custom', type: 'cli', command: '/opt/homebrew/bin/mycli' })).toBeNull();+ });+it('keeps an explicit provider contextWindow above model defaults', () => {expect(effectiveContextWindow({ type: 'tui', contextWindow: 64_000 },