Skip to content

saveSession: strip a file:// prefix like loadSession does - #397

Merged
jhen0409 merged 1 commit into
mybigday:mainfrom
juliusbangert:patch-1
Sep 18, 2026
Merged

jhen0409 merged 1 commit into
mybigday:mainfrom
juliusbangert:patch-1

Conversation

@juliusbangert

Copy link
Copy Markdown
Contributor

loadSession accepts an Expo/RN-style file:// URI and strips it before calling native; saveSession passes the string straight through, and llama_state_save_file fopen()s it as given, so the save fails with "Failed to save session". Same on main (src/index.ts):

async loadSession(filepath: string): Promise<NativeSessionLoadResult> {
  const { llamaLoadSession } = getJsi()
  let path = filepath
  if (path.startsWith('file://')) path = path.slice(7)
  return llamaLoadSession(this.id, path)
}

async saveSession(filepath: string, options?: { tokenSize: number }): Promise<number> {
  const { llamaSaveSession } = getJsi()
  return llamaSaveSession(this.id, filepath, options?.tokenSize || -1)
}

Every other path-taking method in the file (loadSession, the multimodal and TTS ones) strips the prefix; saveSession is the odd one out. This makes it consistent:

   async saveSession(
     filepath: string,
     options?: { tokenSize: number },
   ): Promise<number> {
     const { llamaSaveSession } = getJsi()
-    return llamaSaveSession(this.id, filepath, options?.tokenSize || -1)
+    let path = filepath
+    if (path.startsWith('file://')) path = path.slice(7)
+    return llamaSaveSession(this.id, path, options?.tokenSize || -1)
   }

We hit it passing new File(Paths.cache, name).uri from expo-file-system, which is a file:// URI; loadSession on the same value works.

@jhen0409
jhen0409 merged commit 2af674a into mybigday:main Sep 18, 2026
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