The checks that caught my own mistakes, including in my vibe-coded evals.

Follow-up to Integrating on-device and cloud AI in a Kotlin Multiplatform app, which ended with
The architecture was built to route requests to local models when local models made sense. Measurement showed that the per-move coach was not one of those places.
Since then I’ve measured the app’s AI features on phones and simulators, against the same inputs, again. Most bad results traced back to my own code, and some of that code was the evals I had vibe coded to do the original measuring. The model was at fault just once.
This article is about what held up: an architecture where the model is optional, what the measurements changed in it, and the processes that caught my errors, in the app and in the evals.
The architecture: code decides, the model phrases
The chess app has an AI coaching layer on top of the engine, and two of its features matter here. The move coach explains your last move. Rules Q&A answers rules questions from 30 rule passages bundled with the app. On Android the language model is Gemini Nano through ML Kit’s GenAI API, and on iOS it’s Apple’s Foundation Models.
Five rules shape both features.
- Code detects, and the model only narrates. Stockfish’s evaluation, the move class, the tactical motifs and the better alternative are all computed, and DeterministicCoach turns them into a sentence before any model runs. The model’s job is to rephrase that sentence, and the headline is never model-written.
- There’s one routing authority. AiRoutePolicyDecider.decide() runs once per request and returns the route itself, so no platform code can disagree with it. What a device can run is data from a probe rather than an expect, which lets commonTest sweep every combination on every target.
- A validator gates every model answer. It checks length, forbidden phrases and the facts, in plain Kotlin. If it rejects the answer, the user gets the code’s sentence. There’s no retry.
- Fallbacks are built into the product states so a missing or slow model still produces a valid screen. A sealed FallbackReason maps to three states: silent (the code’s sentence, shown as ordinary text), labeled (quota, because waiting changes the outcome) and retryable (timeout). The panel is never blank, even under critical thermal.
- A build offers a feature only if it can run it, so no screen has a control that does nothing.
Rules Q&A applies the same idea to search. Code searches the bundled rules, the model phrases the answer and cites a passage id, and if the wording fails validation the user gets the matching passage verbatim. Only an empty search reaches “I couldn’t verify that rule.”
The opponent follows the same shape. By default its moves come from Maia-3, a 5M-parameter network trained to predict what human players do at a given rating; it’s not a language model. It runs on-device through LiteRT on Android and iOS, LiteRT.js on the web and ONNX Runtime on desktop, at the rating band the user’s Easy/Medium/Hard/Max setting maps to. It plugs in through OpponentMoveChooser, a seam in :chess-core that knows nothing about any model:
interface OpponentMoveChooser {
val name: String
suspend fun chooseMove(fenHistory: List<String>): String? // null: let the engine move
}
A null, an illegal move and an exception all mean the same thing: Stockfish moves instead, and the built-in CPU player covers a build without Stockfish. Stockfish also keeps the hints, the move assessments and the draw offers. The same predictor powers a new view in History: step through a finished game and see what players at a chosen rating play in each position.
The model is optional everywhere, and that made every measurement below cheap to act on. Removing a model never meant removing a feature.
What the measurements changed
Running each feature with and without a model, on the same inputs, decided most of the architecture’s current shape.
Every model I tried through Cactus lost to the code’s sentence on a Galaxy Z Fold 3. The smallest echoed its own prompt, one took 20 to 36 seconds per answer, and the most fluent one was fluent and false. Cactus is gone.
Gemini Nano beat the code’s sentence 52 to 48 in a blind comparison over 100 positions, with another model as the judge. That’s a coin flip against text that costs nothing and arrives instantly. Neither phone attaches a model to the move coach today.
Inspecting the model’s answers (with agent help to slice and surface suspicious rows) turned up false claims the validator had passed. I directed plain Kotlin checks for each one, and those checks are now the gate a model has to pass before it’s attached again.
In Game Summary, sending the full move list in the prompt proved too noisy. Dropping it and keeping only the turning points code had picked took iOS from 4 of 12 games answered to 12 of 12, and Android’s unsourced claims from 6 of 12 to none. But a short summary of turning points fell short of explaining “why did I lose?” so the feature is out of the app for now.
When the model lost, the replacement was deterministic code. I scoped and reviewed Habits to scan saved games and flag cases like “You’ve hung a piece in 4 of your last 10 games,” complete with positions and engine alternatives. It doesn’t use a model or network.
I vibe coded the evals, and they misled me. An LLM judge that never failed, a keyword check that misread ‘material’ as checkmate, and a phone benchmark that passed a placeholder sentence instead of game facts. None of it showed up as a failure, each problem surfaced only when I looked under a number. Measurement code needs the same review as product code, because a wrong number looks exactly like a right one.
Processes that catch errors
These are the habits that found my mistakes:
Compare against the free answer
Every benchmark row carries the code’s sentence next to the model’s, scored the same way. Every model output has to beat the deterministic text I would ship on its own.
Make every check fail once
The routing sweep includes a test that deliberately breaks the decider to verify the suite fails, because a check that never failed hasn’t been tested.
Read the answers, not the pass rate
Rules Q&A on a Pixel 10 Pro XL passed every gate in every pass (Gemini Nano via ML Kit, 37 questions, per clean pass: 35/37 model answers shown, 0 with no citation, 0 citing an unseen passage, 28/34 right passage cited, 2/3 uncovered questions falling back, 4.1 s median latency within a 20 s budget).
The answers told a different story. Four were wrong, the same four every time, and each one cited a real passage. The prompt builder was to blame instead:
val passages = (fromQuestion + refined).distinctBy { it.id }.take(ANSWER_PASSAGES)
ANSWER_PASSAGES was left at 2 from an earlier, tiny model. For every wrong answer on a covered rule, search ranked the right passage third or fourth, so .take(2) cut it off before the prompt, and the model’s own search hits never reached the prompt at all.
Stale constants hid behind unit tests stubbed to a single passage; raising the cap and fixing a copied example answer resolved all but the second-queen case (where Gemini Nano contradicted its own promotion text while iOS hedged). Reviewing outputs also caught stripConversationalFiller trimming the first sentence of 97 of 100 move-coach responses.
Find the failing layer before fixing anything
“There is no on-device model on this phone” was my ML Kit client asking for preference = FAST. Google’s sample configuration reports the model available on the same Pixel. “AICore gets stuck in a repetition loop” was my streaming code appending both the tokens and a final copy of the text. Only one of four generators broke that contract, so I had an agent add FinalTextContractTest and verified it pins the behavior across all four.
Treat one sentence as an anecdote
The iOS number I first published, “1.8 s, correct, specific and validated,” came from one sentence about 1. e4. Across 100 positions with identical prompts, it looked different:

iOS was shorter and less truthful: it called a best move bad and offered the player’s own hanging pawn as the reason a move was good. Its speed came from a simulator on a Mac, so read that row as a best case. iOS was the one store build with a model attached to the coach, so I detached it.
Record which layer answered
On an iOS 26.5 simulator every Foundation Models call failed in milliseconds, and the safety net still returned 35 of 37 fluent, cited answers. Only the column recording “Grounded” instead of “Model” gave it away. A safety net that guarantees a good answer also guarantees that a broken model looks fine, unless you log which layer answered.
Check the rig before reading results
AICore refuses to generate in the background, and a locked phone counts as background, so a block of sub-second fallbacks means the lock screen won. The iOS simulator kept launching a three-month-old build after store prep changed the bundle ID, ran the wrong suite and reported “Benchmark Complete.”
Re-measure after a library fixes it for you
Rendering also competed for headroom whenever an idle 3D board kept drawing at full panel refresh rates (120 fps on a Galaxy Z Fold 3 and heavy GPU/CPU usage on a Pixel 7a) burning thermal headroom and battery while competing with on-device models. An agent-implemented dirty-flag gate fixed it. Then SceneView shipped render-on-demand and replaced that gate, and the idle board measured 50 to 60 fps again, because every camera write counts as a change and the camera code wrote on every frame. After tracing that and directing the fix, it now writes only on a real change, and an emulator trace shows 0 frames in 15 idle seconds.
The real work
Three lines called the model, while the surrounding code carried the real cost. Making models optional and fallbacks explicit kept those mistakes survivable; checking outputs, comparing against free deterministic text, testing failure paths, and logging which layer answered caught them. Models sometimes win, but here they lost the move coach outright and caused one of four wrong Rules Q&A answers, a conclusion I only trusted after ruling out everything built around them.
Try it, and tell me what to build next
AI Chess Coach 3D is free on Google Play and TestFlight, and runs in the browser at compose-chess-web.fly.dev. On-device Rules Q&A needs an eligible phone. The source is on GitHub.
Lichess is in progress via draft PR #170, adding Lichess multiplayer and private cloud saves. It also asks the Lichess opening explorer what players at your rating play, falling back to Maia-3 when you’re signed out, offline, or in a position too rare to have data. During a live game the panel is hidden, as Lichess’s fair-play rules require.
What should come after that? These are the candidates I’m weighing:
- A real game review. Game Summary is out of the app because it wasn’t good enough. The replacement would show an evaluation curve, key turning points, and a focused next step to practice.
- Practice from your own games. You’d replay the positions Habits and the review flag, with the engine’s answer hidden until you try.
- Feedback pitched at your level. Stockfish says whether a move was best, and Maia-3 says whether a player at your rating would have found the better one. Together they can tell you a move was reasonable for you, not just that it wasn’t perfect.
- Threats and defenders drawn on the board, on both the 2D and the 3D boards. You’d see what your opponent is attacking and which pieces protect which.
- An opponent you can see. On an iPhone Duo or an Android foldable there’s room for a person beside the board: animated reactions tied to move quality and high-tension moments. I haven’t found a chess app I’d call good-looking, and this would be my attempt.
Which of these would you use? What’s missing, or not worth building? Tell me in the comments. And if something in the app looks wrong, report it in GitHub issues or via TestFlight/Google Play.
I’m a mobile engineer (Android, Compose, KMP, also open to iOS, Swift UI) located near the Bay Area. Find me on LinkedIn.
Keeping On-Device AI Optional was originally published in ProAndroidDev on Medium, where people are continuing the conversation by highlighting and responding to this story.