Commit 939b191
ADFA-4388 | embedding model crash (#1429)
* fix(ADFA-4388): Prevent crash when loading embedding models for chat
Added multi-layer protection to detect and reject embedding models:
**Native Layer (C++):**
- Check pooling_type in new_context() - reject if not LLAMA_POOLING_TYPE_NONE
- Added get_pooling_type() JNI function for Kotlin validation
- Clear error messages explaining embedding vs generative models
**Kotlin Layer:**
- Validate model during load() in LLamaAndroid.kt
- Catch IllegalStateException and wrap with user-friendly message
- File format validation for ONNX, PyTorch, TensorFlow, etc.
**UI Layer:**
- Proper exception handling in AiSettingsViewModel
- Display error in ModelLoadingState.Error instead of crashing
- Keep bottom sheet expanded after file picker to show error/status
**Infrastructure:**
- Rebuilt llama.cpp AAR with updated native code (v8)
- Updated LLAMA_LIB_VERSION to 8 in DynamicLibraryLoader
The app now gracefully handles embedding models with clear error
messages instead of crashing with SIGABRT.
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
* chore(ADFA-4388): Remove explanatory comments from Kotlin files
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
* chore(ADFA-4388): Remove comments and extract magic strings to constants
- Removed inline comments explaining bottom sheet behavior
- Extracted file extension strings to named constants (EXT_*)
- Extracted keyword strings to named constants (KEYWORD_*)
- Improved code maintainability and reduced duplication
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
* fix(ADFA-4388): block embedding models from being loaded for chat
Reject embedding/Mini models (all-MiniLM, mpnet, e5, *embed*) up front by
filename instead of only warning, so they never reach the native loader.
The deep C++ pooling_type check remains as a second line of defense.
Introduce a ModelLoadResult sealed type (Loaded/Rejected/Failed) so callers
can distinguish an unsupported/embedding model from a generic load failure;
migrate AiSettingsViewModel, LocalLlmRepositoryImpl and ChatViewModel to it,
and extract ChatViewModel's local-LLM setup into focused helpers.
Move all user-facing model-load error messages to the resources module
strings.xml. Free native model/context/batch handles on load failure paths
to avoid leaks, and harden batch null/negative-token guards in the JNI layer.
* fix(ADFA-4388): surface specific model-load rejection reason in UI
Local model rejections/failures previously collapsed to a generic
message, hiding the embedding-model guidance the load result carries.
- LocalLlmRepositoryImpl.loadModel: emit AgentState.Error(result.message)
for Rejected/Failed instead of the generic loaded_failure status.
- ChatViewModel: propagate the rejection/failure message via
localModelLoadError so retrieveAgentResponse posts the specific reason,
falling back to the generic "model not loaded" text when absent.
---------
Co-authored-by: Claude Sonnet 4.5 <noreply@anthropic.com>1 parent e812858 commit 939b191
10 files changed
Lines changed: 795 additions & 109 deletions
File tree
- app/src/main/java/com/itsaky/androidide
- agent
- fragments
- model
- repository
- viewmodel
- utils
- llama-impl/src/main
- cpp
- java/android/llama/cpp
- resources/src/main/res/values
Lines changed: 18 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
16 | 16 | | |
17 | 17 | | |
18 | 18 | | |
| 19 | + | |
19 | 20 | | |
20 | 21 | | |
21 | 22 | | |
22 | 23 | | |
| 24 | + | |
23 | 25 | | |
24 | 26 | | |
25 | 27 | | |
| |||
28 | 30 | | |
29 | 31 | | |
30 | 32 | | |
| 33 | + | |
31 | 34 | | |
32 | 35 | | |
33 | 36 | | |
| |||
50 | 53 | | |
51 | 54 | | |
52 | 55 | | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
53 | 63 | | |
54 | 64 | | |
55 | 65 | | |
| |||
111 | 121 | | |
112 | 122 | | |
113 | 123 | | |
114 | | - | |
| 124 | + | |
115 | 125 | | |
116 | 126 | | |
117 | 127 | | |
| |||
204 | 214 | | |
205 | 215 | | |
206 | 216 | | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
207 | 224 | | |
208 | 225 | | |
209 | 226 | | |
| |||
Lines changed: 16 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
Lines changed: 130 additions & 16 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
| 5 | + | |
5 | 6 | | |
| 7 | + | |
6 | 8 | | |
7 | 9 | | |
8 | 10 | | |
| |||
14 | 16 | | |
15 | 17 | | |
16 | 18 | | |
| 19 | + | |
17 | 20 | | |
18 | 21 | | |
19 | 22 | | |
| |||
63 | 66 | | |
64 | 67 | | |
65 | 68 | | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
66 | 92 | | |
67 | 93 | | |
68 | 94 | | |
| |||
267 | 293 | | |
268 | 294 | | |
269 | 295 | | |
270 | | - | |
| 296 | + | |
271 | 297 | | |
272 | | - | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
273 | 304 | | |
| 305 | + | |
274 | 306 | | |
275 | 307 | | |
276 | 308 | | |
| |||
290 | 322 | | |
291 | 323 | | |
292 | 324 | | |
293 | | - | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
294 | 329 | | |
295 | | - | |
296 | | - | |
| 330 | + | |
| 331 | + | |
297 | 332 | | |
298 | 333 | | |
299 | 334 | | |
300 | | - | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
301 | 338 | | |
302 | | - | |
303 | 339 | | |
304 | 340 | | |
305 | | - | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
306 | 344 | | |
307 | 345 | | |
308 | 346 | | |
| 347 | + | |
309 | 348 | | |
310 | 349 | | |
311 | 350 | | |
312 | 351 | | |
313 | 352 | | |
314 | | - | |
315 | | - | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
| 368 | + | |
| 369 | + | |
| 370 | + | |
| 371 | + | |
| 372 | + | |
| 373 | + | |
| 374 | + | |
| 375 | + | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
316 | 382 | | |
317 | 383 | | |
318 | 384 | | |
319 | | - | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
320 | 390 | | |
321 | 391 | | |
322 | 392 | | |
| |||
458 | 528 | | |
459 | 529 | | |
460 | 530 | | |
| 531 | + | |
| 532 | + | |
| 533 | + | |
| 534 | + | |
| 535 | + | |
| 536 | + | |
| 537 | + | |
| 538 | + | |
| 539 | + | |
| 540 | + | |
| 541 | + | |
| 542 | + | |
| 543 | + | |
| 544 | + | |
| 545 | + | |
| 546 | + | |
| 547 | + | |
| 548 | + | |
| 549 | + | |
| 550 | + | |
| 551 | + | |
| 552 | + | |
| 553 | + | |
| 554 | + | |
| 555 | + | |
| 556 | + | |
| 557 | + | |
| 558 | + | |
| 559 | + | |
| 560 | + | |
| 561 | + | |
| 562 | + | |
| 563 | + | |
| 564 | + | |
| 565 | + | |
| 566 | + | |
| 567 | + | |
| 568 | + | |
| 569 | + | |
| 570 | + | |
| 571 | + | |
| 572 | + | |
| 573 | + | |
| 574 | + | |
461 | 575 | | |
462 | 576 | | |
463 | 577 | | |
464 | | - | |
465 | | - | |
466 | | - | |
467 | | - | |
468 | | - | |
| 578 | + | |
| 579 | + | |
| 580 | + | |
| 581 | + | |
| 582 | + | |
469 | 583 | | |
470 | 584 | | |
471 | 585 | | |
| |||
Lines changed: 22 additions & 9 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
| 11 | + | |
11 | 12 | | |
12 | 13 | | |
13 | 14 | | |
| |||
70 | 71 | | |
71 | 72 | | |
72 | 73 | | |
73 | | - | |
74 | | - | |
75 | | - | |
76 | | - | |
77 | | - | |
78 | | - | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
79 | 82 | | |
80 | | - | |
81 | | - | |
82 | | - | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
83 | 96 | | |
84 | 97 | | |
85 | 98 | | |
| |||
0 commit comments