Skip to content
Draft
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
12 changes: 10 additions & 2 deletions src/cli/doctor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -944,8 +944,16 @@ export async function runDoctor(args: string[] = []): Promise<void> {
}

console.log("\nCodex agent role files");
const tomlFallbackRoles = scanCodexAgentRolesWithTomlModelFallback(resolveCodexHomeDirImpl());
if (tomlFallbackRoles.length === 0) {
let roleScanError: unknown;
const tomlFallbackRoles = scanCodexAgentRolesWithTomlModelFallback(
resolveCodexHomeDirImpl(),
cause => {
roleScanError = cause;
},
);
if (roleScanError) {
console.log(` [WARN] unable to scan $CODEX_HOME/agents/*.toml: ${String(roleScanError)}`);
} else if (tomlFallbackRoles.length === 0) {
console.log(" ok no per-role model_fallback fields in $CODEX_HOME/agents/*.toml");
} else {
console.log(` [WARN] ${tomlFallbackRoles.length} agent role file${tomlFallbackRoles.length === 1 ? "" : "s"} contain${tomlFallbackRoles.length === 1 ? "s" : ""} \`model_fallback\`: ${tomlFallbackRoles.join(", ")}`);
Expand Down
12 changes: 10 additions & 2 deletions src/codex/subagent-model-fallback.ts
Original file line number Diff line number Diff line change
Expand Up @@ -765,8 +765,16 @@ export function hasCodexAgentModelFallbackField(role: string, codexHome = CODEX_
}

/** Roles whose TOML still carries `model_fallback`, including empty arrays. */
export function scanCodexAgentRolesWithTomlModelFallback(codexHome = CODEX_HOME): string[] {
return listCodexAgentRoles(codexHome).filter(role => hasCodexAgentModelFallbackField(role, codexHome));
export function scanCodexAgentRolesWithTomlModelFallback(
codexHome = CODEX_HOME,
onListError?: (cause: unknown) => void,
): string[] {
try {
return listCodexAgentRoles(codexHome).filter(role => hasCodexAgentModelFallbackField(role, codexHome));
} catch (cause) {
onListError?.(cause);
return [];
}
}

export function listCodexAgentRoles(codexHome = CODEX_HOME): string[] {
Expand Down
12 changes: 12 additions & 0 deletions tests/subagent-model-fallback.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1054,6 +1054,18 @@ describe("subagent model fallback chain", () => {
expect(readCodexAgentModelFallback("empty_fallback", dir)).toEqual([]);
});

test("scanCodexAgentRolesWithTomlModelFallback tolerates a malformed agents path", () => {
const dir = codexHomeFixture();
rmSync(join(dir, "agents"), { recursive: true });
writeFileSync(join(dir, "agents"), "not a directory", "utf8");
let scanError: unknown;

expect(scanCodexAgentRolesWithTomlModelFallback(dir, cause => {
scanError = cause;
})).toEqual([]);
expect(scanError).toBeInstanceOf(Error);
});

test("scanCodexAgentRolesWithTomlModelFallback recognizes quoted model_fallback keys", () => {
const dir = codexHomeFixture();
writeFileSync(join(dir, "agents", "quoted_key.toml"), [
Expand Down
Loading