Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/coding-agent/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 `/`

Expand Down
8 changes: 5 additions & 3 deletions packages/coding-agent/src/sdk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions packages/coding-agent/src/session/retry-fallback-chains.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 };
}

Expand Down
12 changes: 2 additions & 10 deletions packages/coding-agent/src/task/executor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down Expand Up @@ -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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
Loading