google-gemini/gemini-cli · critical · Error
Model policy chain must include an `isLastResort` model.
Error message
Model policy chain must include an `isLastResort` model.
What it means
Thrown by validateModelPolicyChain() when the chain is non-empty but no entry has isLastResort set to true. The last-resort model is the terminal fallback the system uses when all other models in the chain have exhausted their maxAttempts. Without one, the availability loop could fail without a guaranteed recovery path, leaving the user with no model to serve requests.
Source
Thrown at packages/core/src/availability/policyCatalog.ts:158
}
/**
* Provides a default policy scaffold for models not present in the catalog.
*/
export function createDefaultPolicy(
model: string,
options?: { isLastResort?: boolean },
): ModelPolicy {
return definePolicy({ model, isLastResort: options?.isLastResort });
}
export function validateModelPolicyChain(chain: ModelPolicyChain): void {
if (chain.length === 0) {
throw new Error('Model policy chain must include at least one model.');
}
const lastResortCount = chain.filter((policy) => policy.isLastResort).length;
if (lastResortCount === 0) {
throw new Error('Model policy chain must include an `isLastResort` model.');
}
if (lastResortCount > 1) {
throw new Error('Model policy chain must only have one `isLastResort`.');
}
}
/**
* Helper to define a ModelPolicy with default actions and state transitions.
* Ensures every policy is a fresh instance to avoid shared state.
*/
function definePolicy(config: PolicyConfig): ModelPolicy {
return {
model: config.model,
isLastResort: config.isLastResort,
maxAttempts: config.maxAttempts,
actions: { ...DEFAULT_ACTIONS, ...(config.actions ?? {}) },
stateTransitions: {
...DEFAULT_STATE,View on GitHub (pinned to 5024443c72)
Solutions
- Mark exactly one entry as isLastResort: true — typically the most reliable, highest-quota model (e.g., the Flash model).
- Use createSingleModelChain(model) for single-model setups, which automatically sets isLastResort: true.
- Use the built-in chain builders (getDefaultPolicyChain, getFlashLitePolicyChain) which already include a correct last-resort entry.
- When customizing a chain, always end with: chain[chain.length - 1].isLastResort = true.
Example fix
// before — no last-resort entry
const chain = [
definePolicy({ model: 'gemini-pro' }),
definePolicy({ model: 'gemini-flash' }),
];
validateModelPolicyChain(chain); // throws
// after — mark the fallback
const chain = [
definePolicy({ model: 'gemini-pro' }),
definePolicy({ model: 'gemini-flash', isLastResort: true }),
]; Defensive patterns
Strategy: validation
Validate before calling
// Ensure the chain has exactly one last-resort entry
const hasLastResort = chain.some((p) => p.isLastResort);
if (!hasLastResort && chain.length > 0) {
chain[chain.length - 1].isLastResort = true;
}
validateModelPolicyChain(chain); Type guard
function chainHasLastResort(chain: ModelPolicyChain): boolean {
return chain.some((p) => p.isLastResort === true);
} Try / catch
try {
validateModelPolicyChain(chain);
} catch (e) {
if (e instanceof Error && e.message.includes('isLastResort')) {
// Auto-fix: mark the last entry as last-resort
chain[chain.length - 1].isLastResort = true;
validateModelPolicyChain(chain);
} else throw e;
} Prevention
- Always use built-in chain builders which include a correct last-resort entry.
- After customizing a chain, verify the last-resort invariant.
- Document that every chain must have exactly one isLastResort entry.
- Add a unit test for chain validity after every transformation.
When it happens
Trigger: Calling validateModelPolicyChain(chain) where chain has entries but none have isLastResort: true. For example, [{ model: 'gemini-pro', isLastResort: false }, { model: 'gemini-flash', isLastResort: false }].
Common situations: Building a chain programmatically and forgetting to mark the final fallback model as isLastResort; overriding a chain via settings.json that omits the last-resort flag; copying a chain template and stripping the isLastResort field during a transform; all models set isLastResort to false explicitly.
Related errors
- Model policy chain must only have one `isLastResort`.
- Model policy chain must include at least one model.
- ${originalMessage}. The initial COMPUTE_ADC attempt also fai
- Invalid taskId: ${taskId}
- Security violation: Null byte detected in path.
AI-assisted analysis of google-gemini/gemini-cli@5024443c72 (2026-08-12).
Data as JSON: /api/errors/cfdf8f81485046e1.
Report an issue: GitHub.