Add auto-sync of SDK sessions: directly read from OpenCode storage and import to Native mode
Some checks failed
Release Binaries / release (push) Has been cancelled
Some checks failed
Release Binaries / release (push) Has been cancelled
This commit is contained in:
@@ -390,15 +390,28 @@ async function fetchSessions(instanceId: string): Promise<void> {
|
||||
let responseData: any[] = []
|
||||
|
||||
if (isNative) {
|
||||
// Auto-import cached SDK sessions on native mode startup
|
||||
// Auto-sync SDK sessions from OpenCode's storage on native mode startup
|
||||
if (needsMigration(instanceId)) {
|
||||
try {
|
||||
const result = await autoImportCachedSessions(instanceId)
|
||||
if (result.imported > 0) {
|
||||
log.info({ instanceId, result }, "Auto-imported SDK sessions to native mode")
|
||||
// First try to sync directly from OpenCode's storage (most reliable)
|
||||
const folderPath = instance.folder
|
||||
if (folderPath) {
|
||||
log.info({ instanceId, folderPath }, "Syncing SDK sessions from OpenCode storage")
|
||||
const syncResult = await nativeSessionApi.syncFromSdk(instanceId, folderPath)
|
||||
if (syncResult.imported > 0) {
|
||||
log.info({ instanceId, syncResult }, "Synced SDK sessions from OpenCode storage")
|
||||
} else if (syncResult.message) {
|
||||
log.info({ instanceId, message: syncResult.message }, "SDK sync info")
|
||||
}
|
||||
}
|
||||
|
||||
// Also try the localStorage cache as fallback
|
||||
const cacheResult = await autoImportCachedSessions(instanceId)
|
||||
if (cacheResult.imported > 0) {
|
||||
log.info({ instanceId, cacheResult }, "Auto-imported cached SDK sessions")
|
||||
}
|
||||
} catch (error) {
|
||||
log.error({ instanceId, error }, "Failed to auto-import SDK sessions")
|
||||
log.error({ instanceId, error }, "Failed to sync SDK sessions")
|
||||
markMigrated(instanceId) // Mark as migrated to prevent repeated failures
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user