diff --git a/docs/src/content/docs/connect/models.mdx b/docs/src/content/docs/connect/models.mdx
index c308b79fd..bf04f0320 100644
--- a/docs/src/content/docs/connect/models.mdx
+++ b/docs/src/content/docs/connect/models.mdx
@@ -69,7 +69,7 @@ If a model request stops your task, the failure message links to **Settings > Mo
Nod checks your selected model with a tiny request when you choose it, including choosing it again, and when you start Nod. While a model's last request failed, **Settings > Models** shows the provider's reason beside its connection and chat shows it above the message box, before you send anything.
-After a model fails a request, automatic work stops using that model on that connection. This includes background checks, background helpers and cache warming, and recurring schedules skip their runs. A one-time schedule still runs and reports the failure. Errors Nod retries on its own, such as an overload, and a conversation too long for the model's context don't count. Nod tries automatic work again after 2 minutes, and each further failure waits longer: 6, 18, 54 and 162 minutes, then 6 hours at most. A request that succeeds clears that model's failure. When a failing model works again, the connection's other paused models try again too. Requests you start always go through, and so does work that continues after you approve, sign in, pay, hand back the browser or connect an app. The failure survives a restart, and other connections stay available.
+After a model fails a request, automatic work stops using that model on that connection. This includes background checks, background helpers and cache warming, and recurring schedules skip their runs. A one-time schedule still runs and reports the failure. Errors Nod retries on its own, such as an overload, and a conversation too long for the model's context don't count. Nod tries automatic work again after 2 minutes, and each further failure waits longer: 6, 18, 54 and 162 minutes, then 6 hours at most. A request that succeeds clears that model's failure. When a failing model works again, the connection's other paused models try again too. Requests you start always go through, and so does work that continues after you approve, sign in, pay, hand back the browser or connect an app. The failure survives a restart, and other connections stay available. With [backup models](#backup-models), an automatic turn starts on the first backup that isn't paused instead. A recurring schedule then skips its run only when its model is paused and its connection needs attention, or no connected backup that can stand in is unpaused.
The exception is a key or sign-in the service rejects with HTTP 401, for example because it expired or was revoked. The connection then shows **Needs attention** and Nod stops sending requests through it, including yours. If it's your selected connection, chat asks you to reconnect. Add the key again or reconnect in **Manage**. A connection set in the server settings doesn't show **Needs attention**: change its key there and [apply the change](/deploy/configuration/#apply-configuration-changes).
@@ -277,10 +277,20 @@ You can also tell Nod, for example "Run my schedules on the light model" or "Use
A change applies from the next turn; work that's already running keeps its model until then. Checking what Nod may do, writing the questions it asks you and reading your answers always use your model. If a model you chose for some work is no longer available, that work fails with the reason instead of switching models, and **Settings > Models** shows it as unavailable so you can choose another. Removing a connection returns the work that used it to its default: the model for its kind of work, else your model. An audio model's **Text support** label names its companion from the same connection. Requests without recordings use that companion; follow-ups that still include recordings use the audio model. Both use the smaller context and output limits of the pair. Your saved model choice stays unchanged.
-If a model request fails, Nod doesn't switch to another connection on its own; the notice above the chat box offers one when you have it. Nod retries a temporary provider error up to three times, waiting 4, 8 and 16 seconds. Temporary errors include an overload, a rate limit, and, for hosted providers, a request that gets no response within 90 seconds of being sent, cache warming included. Requests to a model server you run have no such limit, because local models can take minutes to start answering.
+Without [backup models](#backup-models), a failed model request doesn't move to another connection; the notice above the chat box offers one when you have it. Nod retries a temporary provider error up to three times, waiting 4, 8 and 16 seconds, or once when you have backups. Temporary errors include an overload, a rate limit, and, for hosted providers, a request that gets no response within 90 seconds of being sent, cache warming included. Requests to a model server you run have no such limit, because local models can take minutes to start answering.
Background work, such as memory upkeep, uses a smaller model from the same connection when it has one, such as `gpt-6-luna` or `claude-haiku-5-5`. Otherwise it uses your model or, for an audio model, its text companion. The short line about your request in the app's chat status line uses only that smaller model. Without one, or without a known price for it, Nod skips the line. Background work and checks use the lightest reasoning their model offers: off, minimal, low or medium in that order, or the model's first effort level if it offers none of these.
+## Backup models
+
+Chat, tasks, schedules and work Nod starts on its own can continue on up to three backup models when their model can't answer. In **Settings > Models**, the sentence **If it's busy or unavailable, Nod tries …** lists them. Select a backup to replace it or choose **No backup** to remove it, and select **Add a backup model** to add one. The list starts empty, and Nod never adds a backup on its own, so your conversations only reach providers you chose.
+
+When a request fails before the model starts answering, it continues on the next backup. An error Nod retries on its own, such as an overload, a rate limit or a timeout, moves on after one retry. An error the provider returns before it starts answering, such as a used-up quota or an invalid request, moves on at once. A refusal from the model and a conversation too long for your model, which Nod compacts as usual, don't move, and your **Stop** ends the turn. A backup that can't read the conversation's images or hold all of it is skipped, and so is a paused one in automatic work. When your model's connection needs attention, for example after a rejected key, Nod asks you to fix it rather than switching.
+
+The rest of the turn, including its helpers, continues on the backup, and the next turn starts on your model again. The status line names the backup that took over, such as "Gemini 3.8 Flash failed, so this used GPT-6 Luna". Usage shows each attempt with the model that ran and its cost, and backups count toward the same check-in and monthly limit. A backup billed through a plan counts at its API price estimate. When every model fails, the error names each one and the provider's reason. Audio requests that include a recording stay on the audio model. Recalling memory for your message uses the same backups and moves on after one failed request. Checks, such as the action checker, and other memory upkeep keep their own model.
+
+A backup that is the model a kind of work already uses is skipped for that work. **Settings > Models** marks a backup that is your chat model; it can still stand in for schedules or work Nod starts on its own when they use another model.
+
## Models with a small context window
For a context window below 65,536 tokens, Nod uses short instructions and loads one detailed tool at a time. The `apps` tool for connected apps and the `send_message` tool for delivering results stay available; MCP server tools load when needed. It reads guides, saved memory and older messages when needed. Large tool results stay in workspace files, with a short preview in the conversation.
diff --git a/docs/src/content/docs/how-it-works/agent-runtime.md b/docs/src/content/docs/how-it-works/agent-runtime.md
index 372d6ff89..7554eb7eb 100644
--- a/docs/src/content/docs/how-it-works/agent-runtime.md
+++ b/docs/src/content/docs/how-it-works/agent-runtime.md
@@ -292,7 +292,7 @@ Nod keeps two things apart:
Live status covers work you started, including chat requests, tasks, replies, and work that continues after you answer or approve something. Scheduled runs show their live activity on their cards in **Scheduled**. Email event checks stay quiet, and a task Nod starts on its own shows its line on its card only. The turn state and tool events determine whether Nod is working. The model can supply an activity description.
-Nod derives live activity from the current work. For longer work and activity changes, a brief description arrives with a tool call, without a separate status action or model request. Quick replies and simple actions need no description. The description excludes internal tool names, reasoning, generic busy text, private details and completion claims. Nod does not start helpers to write activity descriptions. Its only separate model request for live status is the request line described below. Text the model writes before a tool call becomes the step when that call starts streaming, not after the call's arguments finish. When the model streams a reasoning summary whose block starts with a bold heading, the runtime records that heading as a `thought` event, and the line shows the newest step or thought; thoughts never appear in a task's activity list. When Pi retries a failed model request, the runtime records a `retry` event that names the model and the attempt, such as "Gemini 3.8 Flash failed, trying again (1 of 3)". The line shows it until any later event of that turn. Without either, a task's card falls back to the task's saved progress. When a running tool has a label but no description, the line says **Using** followed by that label. The label can name a website, connected app, MCP server, or local files; examples include **Using Gmail**, **Using Slack**, and **Using local files**. A known tool without such a label shows a fixed description of its kind of work, such as **Running code**, **Running a command**, **Reading files**, **Searching the web** or **Working with helpers**. A web search with a query shows **Searching** and its first query in quotes instead, and a page read shows **Reading** and its site. With a description, the label follows it after a dot. Other tools keep the rotating word. While the model works and nothing has happened for a minute, the line says **Waiting for** and the selected model's name. Otherwise it shows a rotating word, such as **Joining the dots…**, or the request line in its place. Screen readers hear **Working…**. A task's card shows **Working…** while its turn waits to start; the chat's line shows the rotating word from the moment you send. The chat's line follows only the chat session's turn, apart from owner messages that go to a task, described below. Each task's card shows its own. After a quiet minute it adds how long nothing has happened. A description written before the owner's newest message stops counting once Nod reads that message. You can still stop active work from the composer. The status is computed in [`src/server/activity.ts`](https://github.com/n8n-io/nod/blob/main/src/server/activity.ts), and the runtime records steps in [`src/runtime/index.ts`](https://github.com/n8n-io/nod/blob/main/src/runtime/index.ts).
+Nod derives live activity from the current work. For longer work and activity changes, a brief description arrives with a tool call, without a separate status action or model request. Quick replies and simple actions need no description. The description excludes internal tool names, reasoning, generic busy text, private details and completion claims. Nod does not start helpers to write activity descriptions. Its only separate model request for live status is the request line described below. Text the model writes before a tool call becomes the step when that call starts streaming, not after the call's arguments finish. When the model streams a reasoning summary whose block starts with a bold heading, the runtime records that heading as a `thought` event, and the line shows the newest step or thought; thoughts never appear in a task's activity list. When Pi retries a failed model request, the runtime records a `retry` event that names the model and the attempt, such as "Gemini 3.8 Flash failed, trying again (1 of 3)". When a [backup model](/connect/models/#backup-models) takes over, it records one more, such as "Gemini 3.8 Flash failed, so this used GPT-6 Luna". The line shows it until any later event of that turn. Without either, a task's card falls back to the task's saved progress. When a running tool has a label but no description, the line says **Using** followed by that label. The label can name a website, connected app, MCP server, or local files; examples include **Using Gmail**, **Using Slack**, and **Using local files**. A known tool without such a label shows a fixed description of its kind of work, such as **Running code**, **Running a command**, **Reading files**, **Searching the web** or **Working with helpers**. A web search with a query shows **Searching** and its first query in quotes instead, and a page read shows **Reading** and its site. With a description, the label follows it after a dot. Other tools keep the rotating word. While the model works and nothing has happened for a minute, the line says **Waiting for** and the selected model's name. Otherwise it shows a rotating word, such as **Joining the dots…**, or the request line in its place. Screen readers hear **Working…**. A task's card shows **Working…** while its turn waits to start; the chat's line shows the rotating word from the moment you send. The chat's line follows only the chat session's turn, apart from owner messages that go to a task, described below. Each task's card shows its own. After a quiet minute it adds how long nothing has happened. A description written before the owner's newest message stops counting once Nod reads that message. You can still stop active work from the composer. The status is computed in [`src/server/activity.ts`](https://github.com/n8n-io/nod/blob/main/src/server/activity.ts), and the runtime records steps in [`src/runtime/index.ts`](https://github.com/n8n-io/nod/blob/main/src/runtime/index.ts).
The request line fills the time before Nod names its own step. About a second after an owner message to the main chat in Nod web or desktop, a small model writes one short line about the request, such as "Checking the weather in Brno". It is the selected connection's small model, the same one task classification uses. A message that the chat's running turn takes in while it works gets its own line the same way, about a second after Nod picks it up. For an answer to Nod's question, it also gets that question as context. The line takes the rotating word's place until Nod's own step, a reasoning heading or a retry replaces it, and an active tool's label shows beside it meanwhile. It is never posted as a message, never reaches the main model and never claims a result. Messages to a task, confirmation replies, and schedule, event and proactive work get none, and neither do Telegram and WhatsApp. Nod skips it past the monthly limit, when the small model has no known price, or when no small model is set up. Each line is one small model request, recorded in Usage and model analytics like other auxiliary requests. It is not included in conversation traces.
diff --git a/docs/src/content/docs/how-it-works/memory.md b/docs/src/content/docs/how-it-works/memory.md
index 3eadfc0c5..d208a0d85 100644
--- a/docs/src/content/docs/how-it-works/memory.md
+++ b/docs/src/content/docs/how-it-works/memory.md
@@ -64,7 +64,7 @@ flowchart TD
rank --> answer[Pi answers, streaming as it writes]:::go
```
-The memory model selects existing notes. It can connect an indirect question to a preference or possession. It expands search terms with related concepts and source names, then ranks the returned messages. The server accepts only note paths and message IDs from the supplied records. Model-written facts do not enter this evidence packet or memory.
+The memory model selects existing notes. It can connect an indirect question to a preference or possession. It expands search terms with related concepts and source names, then ranks the returned messages. The server accepts only note paths and message IDs from the supplied records. Model-written facts do not enter this evidence packet or memory. When the memory model fails a request and you have [backup models](/connect/models/#backup-models), this selection moves to the next one.
For this selection, Nod sends at most 4,000 characters of the current request and 1,200 characters from each of up to six recent owner messages to the memory model. Long messages keep their beginning and end with an omission marker between them. Full messages remain available through conversation search when the task needs their contents.
diff --git a/docs/src/content/docs/how-it-works/threads-and-turns.md b/docs/src/content/docs/how-it-works/threads-and-turns.md
index 3aeafdcda..305d4dc30 100644
--- a/docs/src/content/docs/how-it-works/threads-and-turns.md
+++ b/docs/src/content/docs/how-it-works/threads-and-turns.md
@@ -151,7 +151,7 @@ The main **Stop** control aborts running turns, cancels queued and waiting turns
An aborted database transaction stops waiting for a free connection at once. If the pool supplies a connection later, Nod closes it without running the transaction.
-Turns and tool calls are never retried. Pi retries a model request that fails with a temporary provider error up to three times with backoff, and leaves the failed attempt out of the model context. A request to a hosted provider that gets no response within 90 seconds counts as a temporary error. Any other error, or a restart during execution, ends the turn `failed`. When an agent model request fails, the error identifies the model and provider and keeps the provider's specific reason, HTTP status and error codes when supplied. This includes any retry delay or limit source the provider reports. Nod does not replace a quota or rate limit with a generic billing warning. It removes secrets and limits the displayed error to 2,000 characters. Structured errors show their messages and error metadata without unrelated response fields. Diagnostic logs retain the provider error with known secrets removed. For work you started (a chat turn, a task, a reply to a task, or work that continues after you answer or approve), Nod posts the error in the main chat or as a reply to the task's message, and a restart posts an interruption notice instead. A model failure is posted as the plain error, because the model that failed can't write it, and names another connection you can switch to when one is set up. When a request to a hosted provider found no network (`ENOTFOUND`, `EAI_AGAIN`, `ENETUNREACH`, `EHOSTUNREACH` or `ENETDOWN`), the error names the provider and says Nod couldn't reach it because the computer had no internet connection, with that code. The provider's raw error stays in the diagnostic logs. The error and the notice above the chat box leave out the switch and the **Settings → Models** link, unless the notice is still showing an earlier model problem; the notice still offers **Try again**. An OpenAI-compatible, Azure OpenAI or Amazon Bedrock connection keeps the usual error and link, because its address or Region may be wrong or its server stopped. A provider whose adapter reports no transport cause, such as Google's, also keeps them. In the desktop app's local assistant, a schedule run or a task Nod started that fails this way also says that scheduled tasks need the computer awake and online, and links to [running Nod on a server](/deploy/self-host/). A schedule run's own model failure also carries a run track that the server writes from the run's record: due and start times, skipped runs, the cause and code, the next run and the schedule revision the run started with, which **Run now** sends. See [Schedules](/use/schedules/#keep-nod-running). Other errors are written by the model, or posted as the plain error when the model can't write them. A failed schedule run, or a task Nod started, posts the error naming that work; an event turn posts nothing. Errors also show in **Usage**, and a schedule's in its run history. The session's next turn receives the error as `previousFailure`, so Nod can work around it or tell you what to fix. When a turn's model request fails, a provider refusal included, Nod removes what that request added since the last answered one, such as your message or a tool result, from the session's model context, so the session doesn't send it again. A tool call whose result was removed is marked with an unknown outcome, so Nod checks before it runs that call again. Your message stays in the chat, and the saved transcript keeps everything removed. A restart keeps saved task sessions and waiting questions.
+Turns and tool calls are never retried. Pi retries a model request that fails with a temporary provider error up to three times with backoff, and leaves the failed attempt out of the model context. With [backup models](/connect/models/#backup-models), Pi retries a temporary error once, and a request that fails before the model answers then continues on the next backup. A refusal doesn't move. A request to a hosted provider that gets no response within 90 seconds counts as a temporary error. Any other error, or a restart during execution, ends the turn `failed`. When an agent model request fails, the error identifies the model and provider and keeps the provider's specific reason, HTTP status and error codes when supplied. This includes any retry delay or limit source the provider reports. Nod does not replace a quota or rate limit with a generic billing warning. It removes secrets and limits the displayed error to 2,000 characters. Structured errors show their messages and error metadata without unrelated response fields. Diagnostic logs retain the provider error with known secrets removed. For work you started (a chat turn, a task, a reply to a task, or work that continues after you answer or approve), Nod posts the error in the main chat or as a reply to the task's message, and a restart posts an interruption notice instead. A model failure is posted as the plain error, because the model that failed can't write it, and names another connection you can switch to when one is set up. When a request to a hosted provider found no network (`ENOTFOUND`, `EAI_AGAIN`, `ENETUNREACH`, `EHOSTUNREACH` or `ENETDOWN`), the error names the provider and says Nod couldn't reach it because the computer had no internet connection, with that code. The provider's raw error stays in the diagnostic logs. The error and the notice above the chat box leave out the switch and the **Settings → Models** link, unless the notice is still showing an earlier model problem; the notice still offers **Try again**. An OpenAI-compatible, Azure OpenAI or Amazon Bedrock connection keeps the usual error and link, because its address or Region may be wrong or its server stopped. A provider whose adapter reports no transport cause, such as Google's, also keeps them. In the desktop app's local assistant, a schedule run or a task Nod started that fails this way also says that scheduled tasks need the computer awake and online, and links to [running Nod on a server](/deploy/self-host/). A schedule run's own model failure also carries a run track that the server writes from the run's record: due and start times, skipped runs, the cause and code, the next run and the schedule revision the run started with, which **Run now** sends. See [Schedules](/use/schedules/#keep-nod-running). Other errors are written by the model, or posted as the plain error when the model can't write them. A failed schedule run, or a task Nod started, posts the error naming that work; an event turn posts nothing. Errors also show in **Usage**, and a schedule's in its run history. The session's next turn receives the error as `previousFailure`, so Nod can work around it or tell you what to fix. When a turn's model request fails, a provider refusal included, Nod removes what that request added since the last answered one, such as your message or a tool result, from the session's model context, so the session doesn't send it again. A tool call whose result was removed is marked with an unknown outcome, so Nod checks before it runs that call again. Your message stays in the chat, and the saved transcript keeps everything removed. A restart keeps saved task sessions and waiting questions.
When a turn that carries your message fails at the model provider, that turn is _withdrawn_. When you cancel work with **Stop**, `/stop`, a task's **Stop** or reset, the whole request is withdrawn: the stopped turn and the earlier turns it continues in that session, such as the turn that asked you a question or for a sign-in. A waiting turn that a later turn had already replaced isn't. Work that carries none of your words, such as an app check, has nothing to withdraw. When Nod stops tasks for you with `task stop`, or cancels a turn for another reason, nothing is withdrawn.
diff --git a/src/ports/agent.ts b/src/ports/agent.ts
index 2b141a899..98f4ac759 100644
--- a/src/ports/agent.ts
+++ b/src/ports/agent.ts
@@ -351,6 +351,7 @@ export type AgentEvent =
| { type: 'text_delta'; text: string }
| { type: 'thinking'; title: string }
| { type: 'retry'; model: string; attempt: number; attempts: number }
+ | { type: 'fallback'; from: string; to: string }
| { type: 'final'; text: string }
| ModelUsageObservation
| { type: 'error'; message: string; contextExhausted?: boolean };
diff --git a/src/ports/models.ts b/src/ports/models.ts
index 0c5b8456a..bccfe8570 100644
--- a/src/ports/models.ts
+++ b/src/ports/models.ts
@@ -68,6 +68,7 @@ export interface ModelDefinition {
}
export interface ModelAccess {
+ connectionId?: string;
provider: ModelProvider;
method: ModelMethod;
definition: ModelDefinition;
diff --git a/src/providers/pi/audio.ts b/src/providers/pi/audio.ts
index 61467c52c..38de2dc4b 100644
--- a/src/providers/pi/audio.ts
+++ b/src/providers/pi/audio.ts
@@ -26,6 +26,12 @@ export function readsNativeAudio(model: { provider: string; id: string; api: str
);
}
+export function hasNativeAudio(context: Context) {
+ return context.messages.some(
+ (message) => message.role === 'user' && Boolean((message as AudioMessage)[filesKey]),
+ );
+}
+
export function audioMessage(text: string, images: AgentImage[], audio: AgentAudioInput) {
const details = detailsSchema.parse({ id: randomUUID(), recordedAt: Date.now(), ...audio });
return {
diff --git a/src/providers/pi/fallback.ts b/src/providers/pi/fallback.ts
new file mode 100644
index 000000000..745d34717
--- /dev/null
+++ b/src/providers/pi/fallback.ts
@@ -0,0 +1,246 @@
+import {
+ clampThinkingLevel,
+ createAssistantMessageEventStream,
+ isContextOverflow,
+ isRetryableAssistantError,
+ type Api,
+ type AssistantMessage,
+ type AssistantMessageEvent,
+ type Context,
+ type Model,
+ type SimpleStreamOptions,
+} from '@earendil-works/pi-ai';
+import { estimateTokens } from '@earendil-works/pi-coding-agent';
+import type { ModelAccess } from '../../ports/models.ts';
+import type { createPiModelRuntime } from './models.ts';
+import { hasNativeAudio, readsNativeAudio } from './audio.ts';
+
+type Connection = Awaited>;
+type Stream = Connection['runtime']['streamSimple'];
+
+export function modelKey(access: ModelAccess) {
+ return `${access.connectionId ?? access.provider}/${access.method}/${access.definition.choice.id}`;
+}
+
+function fits(choice: ModelAccess['definition']['choice'], context: Context) {
+ const images = context.messages.some(
+ (message) =>
+ Array.isArray(message.content) && message.content.some((part) => part.type === 'image'),
+ );
+ if (images && !choice.images) return false;
+ const tokens =
+ context.messages.reduce((total, message) => total + estimateTokens(message as never), 0) +
+ (context.systemPrompt?.length ?? 0) / 4;
+ return !choice.contextWindow || tokens < choice.contextWindow * 0.9;
+}
+
+function failedRequest(
+ model: Pick, 'api' | 'provider' | 'id'>,
+ error: unknown,
+ aborted: boolean,
+): AssistantMessage {
+ return {
+ role: 'assistant',
+ content: [],
+ api: model.api,
+ provider: model.provider,
+ model: model.id,
+ usage: {
+ input: 0,
+ output: 0,
+ cacheRead: 0,
+ cacheWrite: 0,
+ totalTokens: 0,
+ cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0, total: 0 },
+ },
+ stopReason: aborted ? 'aborted' : 'error',
+ errorMessage: error instanceof Error ? error.message : String(error),
+ timestamp: Date.now(),
+ };
+}
+
+export function failedBeforeAnswer(message: AssistantMessage, phase: string | undefined) {
+ return (
+ message.stopReason === 'error' && (isRetryableAssistantError(message) || phase !== 'stream')
+ );
+}
+
+export function createTurnFallback(options: {
+ primary: { access: ModelAccess; connection: Connection; stream: Stream };
+ backups: ModelAccess[];
+ start: number;
+ automatic: boolean;
+ connect(access: ModelAccess): Promise;
+ retrying(): boolean;
+ shared(): number;
+ switched(at: number): void;
+ moved(from: number, to: number): void;
+ failed(message: AssistantMessage): void;
+}) {
+ const candidates: Array<{ access: ModelAccess; connection?: Promise }> = [
+ { access: options.primary.access, connection: Promise.resolve(options.primary.connection) },
+ ...options.backups.map((access) => ({ access })),
+ ];
+ const ready = new Map([[0, options.primary.connection]]);
+ const ranOn = new WeakMap
+ {chat && (
+
+ If it’s busy or unavailable, Nod tries{' '}
+ {backups.length
+ ? backups.map((choice, index) => (
+
+ {index ? ', then ' : ''}
+
+
+ ))
+ : 'no other model'}
+ .
+
+ )}
Schedules use {lane('schedule')}.
Work Nod starts on its own uses {lane('background')}.