diff --git a/packages/coding-agent/CHANGELOG.md b/packages/coding-agent/CHANGELOG.md index 84c741b138cf..34bc43f2d32b 100644 --- a/packages/coding-agent/CHANGELOG.md +++ b/packages/coding-agent/CHANGELOG.md @@ -4,6 +4,7 @@ ### Fixed +- Fixed subagents whose role has an explicitly empty fallback chain falling back through the `default` chain when the default role uses the same model ([#1](https://github.com/eggpeat/oh-my-pi/pull/1) by [@eggpeat](https://github.com/eggpeat)) - Fixed Mnemopi memory completions ignoring the memory role's thinking suffix, including one inherited from `tiny` or `smol` when `modelRoles.memory` is unset; each `retry.fallbackChains.memory` entry sends its own level, and `:off` disables reasoning ([#16378](https://github.com/can1357/oh-my-pi/pull/16378) by [@alphastorm](https://github.com/alphastorm)) - Fixed `/move` path completion jumping into a subfolder on Tab: `..`, `.`, and `~` now complete to `../`, `./`, and `~/` before listing their children, a trailing `\` lists a folder on Windows, absolute Windows paths (`C:/…`) are no longer rewritten as relative paths, and the project directory is offered as `./` instead of `/` diff --git a/packages/coding-agent/src/sdk.ts b/packages/coding-agent/src/sdk.ts index fb8c68260839..8db8bfaade0f 100644 --- a/packages/coding-agent/src/sdk.ts +++ b/packages/coding-agent/src/sdk.ts @@ -605,7 +605,7 @@ export interface CreateAgentSessionOptions { modelPatternAuthFallback?: string; /** Role name used to install retry fallbacks after deferred subagent patterns resolve. */ modelPatternFallbackRole?: string; - /** Validated default retry chain to install when a deferred singleton pattern resolves. */ + /** Validated inherited retry chain for a deferred singleton pattern; empty explicitly disables fallbacks. */ modelPatternDefaultFallbackChain?: string[]; /** Thinking selector. Default: from settings, else unset */ thinkingLevel?: ConfiguredThinkingLevel; @@ -2044,6 +2044,7 @@ async function createAgentSessionScoped(options: CreateAgentSessionOptions): Pro let model = options.model; let modelFallbackMessage: string | undefined; let initialRetryFallback: InitialRetryFallbackState | undefined; + let modelPatternRetryFallbackRole: string | undefined; // Identify session model strings to restore in fallback order. We do an // initial pass here so model-dependent setup (thinking-level resolution, // host preconnect) can use the restored model; extension-registered @@ -3189,11 +3190,12 @@ async function createAgentSessionScoped(options: CreateAgentSessionOptions): Pro fallbackSelectors.push(selector); } } - if (fallbackSelectors.length > 0) { + if (fallbackSelectors.length > 0 || options.modelPatternDefaultFallbackChain?.length === 0) { installRetryFallbackRole(settings, options.modelPatternFallbackRole, { primary: primarySelector, chain: fallbackSelectors, }); + modelPatternRetryFallbackRole = options.modelPatternFallbackRole; } } model = selectedModel; @@ -4623,7 +4625,7 @@ async function createAgentSessionScoped(options: CreateAgentSessionOptions): Pro } else { // Save initial model, thinking level, and service tier for new sessions so they can be restored on resume. if (model) { - sessionManager.appendModelChange(`${model.provider}/${model.id}`); + sessionManager.appendModelChange(`${model.provider}/${model.id}`, modelPatternRetryFallbackRole); } if (!autoThinking) { // Do not write the `auto` selector before the first turn resolves; auto diff --git a/packages/coding-agent/src/session/retry-fallback-chains.ts b/packages/coding-agent/src/session/retry-fallback-chains.ts index 86d01b6d2a49..dfcc1bec3a05 100644 --- a/packages/coding-agent/src/session/retry-fallback-chains.ts +++ b/packages/coding-agent/src/session/retry-fallback-chains.ts @@ -180,15 +180,15 @@ export function getRetryFallbackChains(settings: Settings): RetryFallbackChains export interface RetryFallbackRole { /** Selector the role is assigned (the chain's primary). */ primary: string; - /** Fallback selectors walked after the primary. */ + /** Fallback selectors walked after the primary; empty explicitly disables fallbacks. */ chain: string[]; } -/** Reads the primary and non-empty chain installed for `role`, if any. */ +/** Reads the primary and chain installed for `role`, including an explicitly empty chain. */ export function getRetryFallbackRole(settings: Settings, role: string): RetryFallbackRole | undefined { const primary = settings.getModelRole(role); const chain = cfgRetryFallbackChains.get(settings)[role]; - if (!primary || !Array.isArray(chain) || chain.length === 0) return undefined; + if (!primary || !Array.isArray(chain)) return undefined; return { primary, chain }; } diff --git a/packages/coding-agent/src/task/executor.ts b/packages/coding-agent/src/task/executor.ts index 47a8072e1896..4b255ac0e3dc 100644 --- a/packages/coding-agent/src/task/executor.ts +++ b/packages/coding-agent/src/task/executor.ts @@ -301,11 +301,7 @@ function resolveSubagentInheritedRetryFallbackChain( // An explicitly emptied role chain means "no fallbacks", not "inherit // default" — mirrors expandDefaultRetryFallbackChains. const fallbackChain = (role !== undefined ? configuredChains?.[role] : undefined) ?? configuredChains?.default; - if ( - !Array.isArray(fallbackChain) || - fallbackChain.length === 0 || - !fallbackChain.every(entry => typeof entry === "string") - ) { + if (!Array.isArray(fallbackChain) || !fallbackChain.every(entry => typeof entry === "string")) { return undefined; } const disabledProviders = new Set(cfgDisabledProviders.get(settings)); @@ -333,11 +329,7 @@ function installSubagentRetryFallbackChain(args: { const fallbackSelectors = candidates.slice(selectedIndex + 1).map(candidate => candidate.selector); // A single configured model may reuse its role's (or the default) configured chain, but never an implicit parent fallback. const fallbackChain = fallbackSelectors.length > 0 ? fallbackSelectors : inheritedFallbackChain; - if ( - !Array.isArray(fallbackChain) || - fallbackChain.length === 0 || - !fallbackChain.every(entry => typeof entry === "string") - ) { + if (!Array.isArray(fallbackChain) || !fallbackChain.every(entry => typeof entry === "string")) { return undefined; } diff --git a/packages/coding-agent/test/issue-2750-subagent-runtime-fallback.test.ts b/packages/coding-agent/test/issue-2750-subagent-runtime-fallback.test.ts index 05b0c9b0f049..02b4553b760e 100644 --- a/packages/coding-agent/test/issue-2750-subagent-runtime-fallback.test.ts +++ b/packages/coding-agent/test/issue-2750-subagent-runtime-fallback.test.ts @@ -219,6 +219,79 @@ describe("subagent runtime model resolution", () => { expect(candidates).toEqual(["fallback/working-model"]); }); + it("refuses default fallbacks for an explicitly empty subagent role chain but inherits when unset", async () => { + const primary = model("primary", "bad-runtime-model"); + const fallback = model("fallback", "working-model"); + const resolutions: Array<{ keys: string[]; candidates: string[] }> = []; + vi.spyOn(sdkModule, "createAgentSession").mockImplementation(async options => { + if (!options?.settings || !options.sessionManager) throw new Error("Expected child settings and history"); + const recovery = new TurnRecovery({ + model: () => primary, + thinkingLevel: () => undefined, + sessionManager: options.sessionManager, + settings: options.settings, + modelRegistry: { + find: (provider: string, id: string) => + [primary, fallback].find(m => m.provider === provider && m.id === id), + hasProvider: () => true, + getAvailable: () => [primary, fallback], + }, + configWarnings: [], + } as unknown as TurnRecoveryHost); + return { + session: createYieldingSession("none", async () => { + const selector = "primary/bad-runtime-model"; + const keys = recovery.retryFallbackChainKeys(selector); + resolutions.push({ + keys, + candidates: keys.flatMap(role => + recovery.findRetryFallbackCandidates(role, selector).map(candidate => candidate.raw), + ), + }); + }), + extensionsResult: {}, + setToolUIContext: () => {}, + } as never; + }); + for (const explicitlyEmpty of [true, false]) { + await runSubprocess({ + cwd: "/tmp", + agent: { + name: "implementer-11", + description: "test", + systemPrompt: "test", + source: "bundled", + model: ["@implementer-11"], + }, + task: "work", + index: 0, + id: explicitlyEmpty ? "empty-role-chain" : "unset-role-chain", + modelOverride: ["primary/bad-runtime-model"], + modelRole: "implementer-11", + settings: Settings.isolated({ + modelRoles: { + default: "primary/bad-runtime-model", + "implementer-11": "primary/bad-runtime-model", + }, + "retry.fallbackChains": { + default: ["fallback/working-model"], + ...(explicitlyEmpty ? { "implementer-11": [] } : {}), + }, + }), + modelRegistry: { + refresh: async () => {}, + getAvailable: () => [primary, fallback], + getApiKey: async () => "test-key", + } as never, + enableLsp: false, + }); + } + expect(resolutions).toEqual([ + { keys: ["subagent:empty-role-chain"], candidates: [] }, + { keys: ["subagent:unset-role-chain"], candidates: ["fallback/working-model"] }, + ]); + }); + it("passes ordered subagent candidates as a child retry fallback chain", async () => { const primary = model("primary", "bad-runtime-model"); const fallback = model("fallback", "working-model");