[liblitertlm_jni.so] Java_com_google_ai_edge_litertlm_LiteRtLmJni_nativeSendMessageAsync
SIGSEGV · In production · Google Pixel 9a · Android 16 · Version 0.0.95
backtrace:
#00 pc 0x00000000004c6c8c …/liblitertlm_jni.so (BuildId: c2c27170ba409dbd0bc01820fa738580)
#02 pc 0x00000000004b2af4 …/liblitertlm_jni.so (…nativeSendMessageAsync+608)
#05 pc 0x000000000021be2a …/base.apk (com.google.ai.edge.litertlm.Conversation$JniMessageCallbackImpl.onDone+58)
#19 pc 0x000000000007b3b4 /apex/…/bionic/libc.so (__start_thread+68)
That is all we got. No user, no steps, no logs: a few frames copied out of Play Console. Off Grid is a private, on-device AI app, so we never shipped a crash SDK either. No Sentry, no Crashlytics, and when we reconsidered one in June we dropped it again for the same privacy reason. This post is the case file from the months when our Android vitals turned red: how we read reports like the one above, what we tried that didn't work, and what's still open.
Before reading a single frame, put the report in one of three buckets. To a user they look the same ("the app died"). To us they need completely different fixes.
Then rank by share, not by how scary a stack looks. In v0.0.100, one native library was two thirds of every Android crash:
Our sources were Play Console, Xcode Organizer, adb logcat on our own phones, and GitHub issues. In July we started filing Play Vitals crashes and store reviews as GitHub issues automatically: 87 of them in two and a half weeks. That's the closest we got to a crash SDK without shipping one.
SIGSEGV in liblitertlm_jni.so, Google's LiteRT-LM library that runs our second AI engine. 65.2% of Android crashes in v0.0.100.We don't have the library's source. But every native frame carries a Build ID, and that's enough to start. The .so inside litertlm-android:0.11.0, the version we shipped, has the same Build ID: c2c27170…. So we were looking at the exact machine code that crashed. Then llvm-objdump on frame #00:
; frame #00 pc 0x4c6c8c liblitertlm_jni.so (an internal function)
ldr x8, [x21] ; load the object's vtable
ldr x9, [x8, #0x40] ; load one of its virtual methods
add x8, sp, #0x88
blr x9 ; call it ← the object is already gone
A virtual method call faults like this when the object it calls into has already been freed. And nativeDeleteConversation is just 36 bytes: run the destructor, operator delete(848), done. It doesn't wait for anything still running. So: a native worker thread still uses a conversation that our close() already freed.
What we tried, in order:
cancelProcess() first. It turns out that's only a signal, and close() ran right after it anyway.@Volatile, set it to null before closing. That stopped our code from closing twice. It didn't stop the native thread.The best lead came from re-reading frame #05: JniMessageCallbackImpl.onDone. In early June we let LiteRT run the tool-calling loop natively. In that loop, when a reply finishes, onDone sends the pending tool result back to the model on the worker thread, without checking whether the conversation is still alive. Our tool handler waits for its result inside a blocking call. When we close, we cancel pending tool calls, the handler returns at once, and the library re-sends on a conversation we are deleting. It fits the stack frame for frame. We haven't reproduced it yet, so it's our leading hypothesis, not a finding.
"After v89 update. The app has become super laggy to the extent each UI interaction takes 10-15seconds to respond."
GitHub issue #324 · 26 AprilThat clue was exact, and we missed it for two months. v0.0.88 is the release that added a persistent log file, and it ran in production. Every logger.* call made an exists, an append and a stat, each a round trip across the React Native bridge. Once the file passed 2 MB, it read the whole file, kept the last 4,000 lines and wrote it back. We had about 480 log calls on hot paths: the tool loop, the AI engine, downloads, speech.
// src/utils/logger.ts (v0.0.88 to v0.0.96)
writeQueue = writeQueue.then(async () => {
if (await RNFS.exists(path)) { await RNFS.appendFile(path, line, 'utf8'); }
const stat = await RNFS.stat(path);
if (size > MAX_LOG_FILE_BYTES) { // 2 MB
const content = await RNFS.readFile(path, 'utf8'); // the whole file
...
function capture(level, args) { appendPersistentLog(level, args); } // not __DEV__-gated
The fix in v0.0.97: logger.* does nothing in release builds. For debugging we later added a separate sink that buffers lines and flushes every 800 ms or 50 lines, capped at 5 MB, in dev builds only.
The read was slow, but the real bug was the shape of boot: the app awaited the whole download-recovery chain before showing any UI. Every step sat on the critical path.
The fix kept the recovery steps in the same order but took them off the boot gate. Screens read from stores and fill in when recovery lands. We proved it with a test that renders the real App with a database call that never returns. It was red before the fix ("loader stays forever") and green after:
// __tests__/integration/app/bootNotBlockedByDownloadDb.rendered.test.tsx
NativeModules.DownloadManagerModule = { ...NativeModules.DownloadManagerModule,
getActiveDownloads: jest.fn(() => new Promise(() => {})) }; // never resolves
const view = rtl.render(React.createElement(App));
await rtl.waitFor(() => {
expect(view.queryByTestId('app-loading')).toBeNull();
}, { timeout: 8000 });
On every flush, each message in the chat re-parsed its markdown, not just the one being written.
freezeOnBlur and removed it the same day: it froze the download progress on the Models tab.React.memo is not the gap." Ten days later, a manual React.memo was the fix. The list passed a new renderItem and new callbacks on every render, so the compiler's automatic memo always saw "changed" props.// src/screens/ChatScreen/MessageRenderer.tsx (v0.0.101)
-export const MessageRenderer: React.FC<MessageRendererProps> = (props) => {
+export function messageRendererPropsEqual(prev, next): boolean {
+ return prev.item === next.item && prev.index === next.index
+ && prev.isStreaming === next.isStreaming; // on* callbacks deliberately NOT compared
+}
+export const MessageRenderer = React.memo(MessageRendererInner, messageRendererPropsEqual);
The comparator ignores the callbacks on purpose: "Comparing them would defeat the memo." Now only the message being written re-renders. That one message still re-parses its whole growing text on every flush, which is the part still open.
Kills have no stack. On one Nothing Phone, logcat showed Out of memory: Killed process with 2.1 GB of file-backed memory: we were loading an image model while a text model was still in RAM. A user's diagnostics from a Galaxy S25 Ultra showed 3.6 GB of process memory, 605 MB of graphics memory and 2.4 GB of swap in use.
The fix for a kill is a memory budget: refuse a load that won't fit. Getting the budget right was harder than any crash. We reverted five of our own memory gates in two weeks. One estimate let an image model through that then crashed a 6 GB iPhone 15. Another, measured after freeing memory, refused loads that would have fit.
Not every crash is yours. One SIGSEGV in libgui had no app frame at all: a system bug on one maker's Android 12, and we left it alone. TextLayoutManager (13%) and dispatchDraw (4.3%) are still on our list, waiting for a reproduction. Without one, a fix is a guess.
"remarkably slow and stutters even with plenty of ram and small models."
App Store review, mirrored as GitHub issue #486 · JulyThe LiteRT teardown is the big one: proving or killing the tool-resend hypothesis, and making teardown wait for the library's native thread. Streaming still re-parses the growing message. And the hardest question isn't technical: how to see crashes clearly without sending anything off the phone.