{"record":{"id":"aeb40d759c621e24","repo":"siyuan-note/siyuan","slug":"failed-to-clear-remote-kernel-active-storage","errorCode":null,"errorMessage":"failed to clear remote kernel active storage: \" + error.message","messagePattern":"failed to clear remote kernel active storage: \" \\+ error\\.message","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"app/electron/main.js","lineNumber":2627,"sourceCode":"    if (!await showAppleSiliconWarning(getArg(\"--lang\") || \"\")) {\n        bootWindow.destroy();\n        app.quit();\n        return;\n    }\n    loadBootWindow();\n    if (openAsHidden) {\n        bootWindow.minimize();\n    } else {\n        bootWindow.show();\n    }\n\n    try {\n        await session.defaultSession.clearStorageData({\n            origin: target.origin,\n            storages: remoteKernelActiveStorageTypes,\n        });\n    } catch (error) {\n        throw new Error(\"failed to clear remote kernel active storage: \" + error.message);\n    }\n\n    writeLog(\"connecting to remote kernel [origin=\" + target.origin + \"]\");\n    let versionData;\n    for (let count = 0; count < 5; count++) {\n        try {\n            versionData = await requestRemoteKernelVersion(target);\n            break;\n        } catch (error) {\n            writeLog(\"get remote kernel version failed: \" + error.message);\n            if (count < 4) {\n                await sleep(500);\n            }\n        }\n    }\n    const versionStatus = getRemoteKernelVersionStatus(versionData, appVer);\n    if (versionStatus === \"invalid\") {\n        showErrorWindow(\"连接远程内核失败\", \"Failed to connect to the remote kernel\",","sourceCodeStart":2609,"sourceCodeEnd":2645,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/8641553a1f07374001902d3ce773285db1292b2d/app/electron/main.js#L2609-L2645","documentation":"Before connecting to a remote kernel, initRemoteKernel clears the default session's storage (cookies, localStorage, etc.) scoped to the target origin so stale credentials do not interfere. If the Electron session.clearStorageData call throws — origin malformed, storage type invalid, or an internal Chromium error — the original error is re-wrapped with this message.","triggerScenarios":"session.defaultSession.clearStorageData({origin: target.origin, storages: remoteKernelActiveStorageTypes}) rejects: invalid origin string (e.g. includes a path), a storage type name not recognized by the Electron version, or a Chromium session failure.","commonSituations":"A --remote origin containing a path or unusual characters; Electron/Chromium version mismatch making a storages entry invalid; corrupted profile or locked storage backend on disk; running in an environment where the default session is unavailable.","solutions":["Read error.message for the underlying cause (shown after the colon) and fix that specific issue","Ensure the --remote origin is a clean protocol://host:port URL with no path, query, or fragment","Upgrade or align Electron with the app's expected version if a storages type name is rejected","Clear the app profile/cache directory manually if Chromium storage is corrupted, then relaunch"],"exampleFix":"// before\n//   --remote \"https://host:6806/siyuan\"\n// after (clean origin accepted by clearStorageData)\n//   --remote \"https://host:6806\"","handlingStrategy":"validation","validationCode":"if kek == nil {\n    return errors.New(\"KEK must be derived before writing notebook crypto backup\")\n}\n","typeGuard":"func hasKEK(kek []byte) bool { return len(kek) > 0 }\n","tryCatchPattern":"if err := writeNotebookCryptoBackupData(nc, kek); err != nil {\n    if err.Error() == \"cannot generate notebook crypto backup without KEK\" {\n        // authenticate/derive KEK first, then retry\n    }\n}\n","preventionTips":["Always derive the KEK (deriveKEK) before any backup write or import flow","Ensure user authentication completed before restore/import operations touch the backup"],"tags":["electron","session-storage","remote-kernel","origin"],"backgroundTag":"invalid-url-format","analyzedSha":"8641553a1f07374001902d3ce773285db1292b2d","analyzedAt":"2026-09-11T16:08:28.414Z","contentChangedAt":"2026-09-11T16:08:28.414Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}