openassistant: say which file broke the model load (#901)
- Commit
4b4a39af28eb912dae02edc0097adffc5a9beda5- Author
- Vayun Mathur <[email protected]>
- When
- 2026-11-06 05:01 UTC (1 month ago)
- Parents
52a2ce8
MamlChatEngine.model() logged one flat line and InferenceService threw the bare path from the issue report, so a truncated download was indistinguishable from an unsupported device. The engine now keeps lastLoadError (short-file actual/expected sizes plus native's own failure message via Gemma4Handle.loadError) and the service appends it to the thrown message, e.g. 'Model missing or failed to load at .../gemma4: short files: gemma4_text.maml 812345678/1101593392'. User-visible effect: the next #901-style report names the broken file and its sizes instead of just the directory. No behavior change when the model loads; verified by :openassistant:testDevUnitTest (77 tests green).
Diff
openassistant/src/main/java/com/vayunmathur/openassistant/platform/MamlChatEngine.kt
diff --git a/openassistant/src/main/java/com/vayunmathur/openassistant/platform/MamlChatEngine.kt b/openassistant/src/main/java/com/vayunmathur/openassistant/platform/MamlChatEngine.ktindex 5b8790d26f..876b2d2881 100644--- a/openassistant/src/main/java/com/vayunmathur/openassistant/platform/MamlChatEngine.kt+++ b/openassistant/src/main/java/com/vayunmathur/openassistant/platform/MamlChatEngine.kt@@ -7,6 +7,7 @@ import com.vayunmathur.library.ml.Gemma4AudioHandle import com.vayunmathur.library.ml.Gemma4Handle import com.vayunmathur.library.ml.Gemma4VisionHandle import com.vayunmathur.library.ml.Sampling+import com.vayunmathur.library.ml.shortFiles import com.vayunmathur.openassistant.domain.ChatGenerator import com.vayunmathur.openassistant.domain.ParsedToolCall import com.vayunmathur.openassistant.domain.ToolLoopOutcome@@ -66,6 +67,9 @@ class MamlChatEngine(private val modelDir: File) : AutoCloseable { /** Loads the model if needed; false when it cannot come up. */ suspend fun load(): Boolean = mutex.withLock { withContext(engineThread) { model() != null } } + /** Why the last load failed, for the error the user sees. Null when loaded. */+ suspend fun loadError(): String? = mutex.withLock { lastLoadError }+ suspend fun chat(request: ChatRequest, tools: AssistantTools, onText: (String) -> Boolean): ChatResult = mutex.withLock { val model = withContext(engineThread) { model() } ?: return@withLock ChatResult.Unavailable@@ -123,16 +127,34 @@ class MamlChatEngine(private val modelDir: File) : AutoCloseable { handle?.close() val opened = Gemma4Handle.inDirectory(modelDir) if (!opened.isAvailable) {- Log.status(TAG, "gemma4 did not load from $modelDir")+ // Carry the cause here so the failure the user sees says *which*+ // file broke, not just that the directory did not load (#901's+ // undifferentiated error): short-file sizes first, then whatever+ // native logged (already in logcat) via the handle's report. opened.close() handle = null+ lastLoadError = listOfNotNull(shortFilesReport(), opened.loadError).joinToString("; ") return null } handle = opened+ lastLoadError = null prefixKey = null return opened } + /**+ * Why the last [model] attempt failed, for the error the user sees.+ * Null when the model is up or no load has been attempted yet.+ */+ var lastLoadError: String? = null+ private set++ /** `name actual/expected` for short gemma4 files, or null when none are short. */+ private fun shortFilesReport(): String? {+ val short = shortFiles(modelDir)+ return short.takeIf { it.isNotEmpty() }?.let { "short files: ${it.joinToString()}" }+ }+ private fun seedPrefix(model: Gemma4Handle, system: String, tools: List<Gemma4Handle.ToolDeclaration>) { val declared = Gemma4Handle.declareTools(tools) val key = (system + "\u0000" + declared).hashCode()
openassistant/src/main/java/com/vayunmathur/openassistant/util/InferenceService.kt
diff --git a/openassistant/src/main/java/com/vayunmathur/openassistant/util/InferenceService.kt b/openassistant/src/main/java/com/vayunmathur/openassistant/util/InferenceService.ktindex 7f8d895da5..b25bbfbb08 100644--- a/openassistant/src/main/java/com/vayunmathur/openassistant/util/InferenceService.kt+++ b/openassistant/src/main/java/com/vayunmathur/openassistant/util/InferenceService.kt@@ -378,8 +378,14 @@ class InferenceService : Service() { val dir = ModelUrls.GemmaMaml.modelDir(applicationContext) val created = MamlChatEngine(dir) if (!created.load()) {+ val detail = created.loadError() created.close()- throw IllegalStateException("Model missing or failed to load at ${dir.absolutePath}")+ throw IllegalStateException(+ buildString {+ append("Model missing or failed to load at ${dir.absolutePath}")+ if (!detail.isNullOrBlank()) append(": $detail")+ },+ ) } engine = created }