Skip to content

fix(ai): recognize an installed model on launch; never ask macOS for the GPU - #329

Merged
deepiq2022 merged 1 commit into
mainfrom
working
Aug 13, 2026
Merged

deepiq2022 merged 1 commit into
mainfrom
working

Conversation

@deepiq2022

Copy link
Copy Markdown
Contributor

Summary

  • refresh() had zero call sites — the interpreter boots at needsDownload and only refresh() checks disk, so a downloaded model read as missing on every relaunch. HomeShell now restores on mount and on onRestart (the mirror of the existing onPause dispose), gated on aiEnabled so an AI-off run never constructs the interpreter.
  • The "Download model" tap that followed found the file installed and fell through to the load, which SIGSEGV'd the process on macOS: with backend=gpu, LiteRT's ReplaceMagicNumbersIfAny reads num_configs=4294967300 (4 + 2^32), walks off the array, and faults inside its own logger on a null char*.
  • Backend selection extracted to a testable GemmaInterpreterService.backendsFor(platform); macOS joins iOS as CPU-only. A native crash kills the process before _loadModel's catch runs, so the step-down ladder can never fall back — same reasoning already documented for the iOS Metal null-deref.
  • New test/interpreter_restore_test.dart: backend table per platform, refresh-on-launch when AI is enabled, no interpreter touch when it's off.

Evidence: crash report juice-2026-08-12-181046.ips (KERN_INVALID_ADDRESS at 0x80 in LiteRtStandardLoggerT::Log ← ReplaceMagicNumbersIfAny) plus the plugin's native log naming backend=gpu and the bad config count.

Test plan

  • flutter analyze clean
  • flutter test passes (2362 tests)
  • Device-verified on macOS: launch logs Model gemma-4-E4B-it.litertlm installed: true, maps the model + XNNPACK weight cache, and stays up — previously it died ~2s in. Process sample shows engine creation completed rather than hung.
  • Confirm Settings shows AI "Ready" on a cold launch (screen capture blocked on the verifying machine)

🤖 Generated with Claude Code

…the GPU

Two defects from one device session. The interpreter boots at needsDownload
and only refresh() consults the disk, but nothing ever called refresh() — so
an already-downloaded model read as missing on every launch, and the shell's
onPause dispose() had no mirror, dropping the same way on a background cycle.
HomeShell now restores on mount and on onRestart, gated on aiEnabled so an
AI-off run never constructs the interpreter at all.

The "Download model" tap that followed then found the file already installed
and fell straight through to the load, which SIGSEGV'd the process on macOS:
with backend=gpu, LiteRT's ReplaceMagicNumbersIfAny reads a garbage config
count (num_configs=4294967300, i.e. 4 + 2^32), walks off the array, and
faults inside its own logger on a null char*. That is the same shape as the
iOS Metal null-deref already handled here — a native crash, so _loadModel's
step-down ladder can never catch it and fall back. The backend list moves
into a testable backendsFor(platform); macOS joins iOS as CPU-only, which is
the path that had been loading the file successfully all along.

Device-verified on macOS: the app restores the model on launch and stays up
where it previously died about two seconds in.

Co-Authored-By: Claude <noreply@anthropic.com>
@deepiq2022
deepiq2022 merged commit 5624e56 into main Aug 13, 2026
@deepiq2022
deepiq2022 deleted the working branch August 13, 2026 00:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants