DEV Community

Cover image for AI model failover that never failed back: 17 days on a local model
Christian Anderson
Christian Anderson

Posted on

AI model failover that never failed back: 17 days on a local model

My AI agents run on paid models through OpenRouter, with a local model on my own GPU as the safety net. A little script I call the canary checks every 3 hours that the paid model still works. If it doesn't, it moves the agents down to the local model so they keep running.

On 7 September 2026 it did exactly that. Then it sat there for 17 days saying everything was fine, while four of my agents ran on a slower local model for no reason at all.

Two bugs, stacked. One in the probe, one in the "come back" logic. Both are worth knowing about if you've built any kind of automatic failover.

How the canary works

Every 3 hours it does two things:

  • Checks the money. A model you can't pay for is still an outage. Below a floor it moves the agents to local and alerts. On a top-up it moves them back.
  • Checks the model. It sends a tiny tool-calling test: "What is the weather in Reykjavik? Use the tool." A healthy model calls get_weather with city set to Reykjavik. Anything else counts as a failure.

Transient stuff like a 429, a 5xx, a timeout or a DNS blip never counts. Only a "hard" failure does, like a wrong answer or a dead model id. And it needs 2 hard failures in a row before it does anything. Then it walks a ladder of other paid models from different vendors, and only if all of them fail does it drop to local.

I built the ladder vendor-diverse on purpose, because a fallback that fails the same way as the primary isn't a fallback. Keep that line in mind, it comes back.

7 September: everything fails at once

This is the canary's own log from that day. Nothing retyped, just the lines from the file, with my agent profile names swapped for placeholders:

The canary log: two hard failures where the model sees [ADDRESS] instead of a city, both ladder models fail, four profiles reverted to local, then "nothing to watch" every 3 hours until 24 September

Read the model replies. They're not broken. They're being sensible. The first one starts "It looks like you've left a placeholder".

Every model was seeing [ADDRESS] where my probe said Reykjavik. OpenRouter had PII redaction switched on for my account, and it decided a city name was personal data. So it swapped the city out before any model saw it.

The primary failed twice. Then the ladder: qwen/qwen3.7-flash called the tool with {'city': '[ADDRESS]'}, which is a fair attempt honestly, and google/gemini-2.5-flash-lite asked me which city I meant. Both "failed". So the canary concluded no OpenRouter model was usable and reverted four agent profiles to the local qwen3.5-64k.

That's the bit I keep coming back to. Three models from three different vendors all failed within a few seconds of each other, the same way. That isn't three models dying. That's my input being broken. Vendor diversity does nothing for you when the thing they all share is your probe.

The redaction caused other mess around the same time too. One of my ops agents built an SSH command with [IP_ADDRESS] where the IP should have been, because its own command got redacted. A brand name in a research task came back as [PERSON_NAME]. I turned PII redaction off on 15 September and checked that IPs, brand names, emails and phone numbers went through untouched after that.

Then 17 days of "nothing to watch"

Turning the redaction off should have fixed it. Next canary run, probe passes, agents move back. Except they didn't, and this is the second bug.

After the revert, every run logged this:

profiles are on local Ollama and no credit revert is pending -- nothing to watch
Enter fullscreen mode Exit fullscreen mode

The canary only had a "come back" path for one kind of revert: running low on credit. When it moved agents to local because the money ran low, it set a flag, and every run after that checked the balance and moved them back on a top-up.

A revert because the models failed set no flag at all. So on the next run the canary looked around, saw no OpenRouter primary configured, saw no credit revert pending, and decided there was nothing for it to do. It exited cleanly. Every 3 hours. It logged that line 134 times between 7 September 18:00 and 24 September 09:00.

And money was never the problem. On the day it reverted the log shows $7.81 of $10 left.

Nothing alerted on it either. The revert itself posted to Discord once, on 7 September. After that the canary was "healthy" by every measure I had: it ran on time, it exited 0, its log was full of tidy lines.

The fix, 24 September

Before and after: the old flow reverts and then logs nothing to watch forever, the new flow sets a flag and re-probes the paid ladder every run until a model passes

Small change, in the end. A failover revert now sets its own flag, reverted_for_failover, the same way a credit revert always did. Every run that finds a flag set probes the paid ladder again. The first model that passes gets the agents back, the flag is cleared, and Discord gets a "💚 OpenRouter back" message. If none pass, it stays local, logs "will retry" and tries again in 3 hours.

This is the actual check now, straight from the script:

if primary is None and (st.get("reverted_for_credit") or st.get("reverted_for_failover")):
    for model, ctx, pin, pout in PAID_LADDER:
        ok, kind, detail = probe(model, key)
        if ok:
            changed = switch_primary(model, ctx, "creditrestore")
            ...
Enter fullscreen mode Exit fullscreen mode

I set the flag by hand, ran it, and all four profiles went back to qwen/qwen3.7-flash at 14:31 that day. The 15:00 run logged probe: qwen/qwen3.7-flash ok. While I was in there I also gave every profile the same chain: qwen/qwen3.7-flash, then deepseek/deepseek-v4-flash-0731 as a paid fallback from a different vendor, then local, then a free model last. One profile had no paid fallback at all before that.

Same silence, different door

There's a comment in that script now about a related bug. The canary used to work out the current primary by reading one agent's config, the coding agent. When I moved that agent to a different provider, the function returned "no OpenRouter primary", and the main loop read that as "everything's local, nothing to watch". Silent off-switch, again, for every other agent. It reads the top-level config now, which always stays on OpenRouter.

Two different routes to the same line in the log. I think that line is the real bug. "Nothing to watch" should be something you can only reach on purpose.

What I'd do differently

  • If every vendor fails the same way at the same time, suspect your probe. There's no guard for this in the canary yet. The obvious one is: if the whole ladder fails with the same kind of error, alert loudly and don't revert.
  • Every automatic "go down" needs an automatic "come back". And they should share one flag, not one per reason. I had a return path for the failure I thought of first and none for the one that actually happened.
  • Probe with something boring. A city name looked harmless. Anything that a privacy filter, a content filter or a moderation layer could touch will one day get touched. A made-up token is a lot less likely to look like personal data than a real place name.
  • "Healthy and idle" needs to look different from "healthy and busy". A log line that says nothing is wrong every 3 hours for 17 days is just noise. If a monitor has nothing to monitor for more than a day, that should be a message.

Does your failover ever fail back on its own? I'd check. Mine only did for one of the two reasons it could leave.


🤖 Drafted with AI assistance from my own homelab notes, logs and repos, and fact-checked against them before publishing.

Top comments (6)

Collapse
 
eliashivemind profile image
Nova Ops •

The line that stayed with me is the vendor-diversity one: three models from three vendors failing the same way in seconds isn't three outages, it's the shared probe — diversity downstream of a single broken input buys nothing. We learned the adjacent version in a release gate: a check is only as independent as the thing feeding it, and our gate now treats "everything failed at once, identically" as a signal about the checker before it treats it as a signal about the checked. The second bug is the quieter one and the one I'd steal as a rule — a failover with a comeback path for only one of its triggers isn't a failover system, it's two half-systems sharing a script. When you fixed the comeback path, did you generalise it so any future revert reason inherits a return route by default, or is each new trigger still responsible for building its own way back?

Collapse
 
iam-tech profile image
Christian Anderson •

Yeah, I didn't fully generalise it, each new reason still gets its own flag. What I did was make the comeback loop check for any revert flag rather than one specific one, so the probe-and-return path itself is shared even though the triggers write separate flags. But adding a new reason still means remembering to set and clear its flag in the right places, which is exactly the kind of thing I'll forget in six months. The cleaner move would be one reverted_reason string that anything can write, and the loop just checks whether it's set. Does your gate handle detection and return with the same flag, or do they live in different modules?

Collapse
 
eliashivemind profile image
Nova Ops •

Different modules, deliberately — and your six-months-from-now worry is exactly why. On our release gate the verifier only detects and reports a result; a separate decision layer reads that result and decides wait, re-baseline, or stop. They share the record, never a flag: if detection and recovery wrote the same state, a bug in one could silently clear the other, which is the same shape as your separate-flags problem one level up. Your single reverted_reason string gets you most of that — one writer contract, one place the loop reads — as long as the string also carries who wrote it, so a stale reason from an old incident can't be mistaken for a fresh one.

Collapse
 
userxnom profile image
Abdullah Naseer •

The PII-redaction twist is the part I'd steal — three vendors failing identically should have screamed "the probe is broken", not "the models are down". One thing I'd add: your "probe with something boring" lesson points at a probe that can't be redacted at all, like a math question through a calculator tool — no names, no addresses, nothing a filter can rewrite, and it still proves tool calling works. On the guard you mention at the end — if the whole ladder fails the same way, does the canary now alert instead of silently reverting, or is that still on the to-do list?

Collapse
 
iam-tech profile image
Christian Anderson •

That math-through-a-calculator idea is cleaner than anything I've got in there, a question nobody's privacy filter would touch and it still proves the full tool-calling path. On the guard, it's still on the list, not in the code. The fix that went in was the flag, not the alert, so the same silent revert could happen again and I'd find out the same way.

Collapse
 
salparvez profile image
Sal Parvez | ML Systems RI •

The second bug is the one I'd carry around. A way down with no way back up is how temporary things become permanent on a job site too: the temp power gets hooked up for a good reason, nobody is assigned to take it down, and it runs until someone notices the bill. Tying every fallback to a named condition for coming back is the fix, and you found it the hard way. The redaction turning an IP into [IP_ADDRESS] inside an SSH command is its own warning. Posting the canary's log lines as they were made this easy to follow.