{"record":{"id":"93131d5f4b68ef46","repo":"mihomo-party-org/clash-party","slug":"core-is-not-running-restarting-core-before-config","errorCode":null,"errorMessage":"Core is not running, restarting core before config patch","messagePattern":"Core is not running, restarting core before config patch","errorType":"console","errorClass":null,"httpStatus":null,"severity":"info","filePath":"src/main/core/mihomoApi.ts","lineNumber":217,"sourceCode":"  )\n  return axiosIns\n}\n\nexport async function mihomoVersion(): Promise<IMihomoVersion> {\n  const instance = await getAxios()\n  return await instance.get('/version')\n}\n\nexport const patchMihomoConfig = async (patch: Partial<IMihomoConfig>): Promise<void> => {\n  const patchConfig = async (): Promise<void> => {\n    const instance = await getAxios()\n    await instance.patch('/configs', patch)\n  }\n\n  // Configuration patches can also be the first recovery action after startup\n  // failed. Do not start the core during pre-ready migrations.\n  if (!hasCoreProcess() && app.isReady()) {\n    mihomoApiLogger.warn('Core is not running, restarting core before config patch')\n    await restartCore()\n  }\n\n  try {\n    await patchConfig()\n  } catch (error) {\n    if (hasCoreProcess() || !app.isReady()) throw error\n\n    mihomoApiLogger.warn('Core exited before config patch completed, restarting core', error)\n    await restartCore()\n    await patchConfig()\n  }\n}\n\nexport const mihomoCloseConnection = async (id: string): Promise<void> => {\n  const instance = await getAxios()\n  return await instance.delete(`/connections/${encodeURIComponent(id)}`)\n}","sourceCodeStart":199,"sourceCodeEnd":235,"githubUrl":"https://github.com/mihomo-party-org/clash-party/blob/911e090537acdf7c50bee1c3aebecc2ef119a8b5/src/main/core/mihomoApi.ts#L199-L235","documentation":"patchMihomoConfig patches the running core's configuration via its REST API. If there is no core process and the app is ready (i.e. this is not a pre-ready migration), the patch would fail, so the function logs this warning and restarts the core first. This makes config patches double as a recovery path after a failed startup.","triggerScenarios":"A config change (e.g. mode switch, port change, rule update) is applied while the core is not running — typically right after a failed startup or a manual core stop; app.isReady() is true so the patch is treated as a user action needing a live core.","commonSituations":"User toggles settings after the core crashed at startup; core was stopped by the watchdog after repeated crashes; core failed to start due to a bad config and the user edits settings, triggering a patch; switching profiles while the core is down.","solutions":["No action needed — the function restarts the core automatically before patching; watch logs to confirm restartCore succeeds.","If restarts keep happening, fix why the core dies: inspect the core log for config errors and correct the profile/config.","Verify the core binary runs (correct version, permissions, ports not occupied by another process).","After the automatic restart, confirm the patch was applied by checking the core's /configs or app UI state."],"exampleFix":"// before\nif (!hasCoreProcess() && app.isReady()) {\n  mihomoApiLogger.warn('Core is not running, restarting core before config patch')\n  await restartCore()\n}\nawait patchConfig()\n// after\nif (!hasCoreProcess() && app.isReady()) {\n  mihomoApiLogger.warn('Core is not running, restarting core before config patch')\n  await restartCore()\n}\ntry {\n  await patchConfig()\n} catch (error) {\n  mihomoApiLogger.error('Config patch failed after core restart', error)\n  throw error\n}","handlingStrategy":"try-catch","validationCode":"// Caller-side check before patching:\nimport { hasCoreProcess } from './core/manager'\nif (!hasCoreProcess()) {\n  console.warn('Core not running — the next patch will trigger a core restart')\n}","typeGuard":null,"tryCatchPattern":"try {\n  await patchMihomoConfig(patch)\n} catch (e) {\n  // patchMihomoConfig already restarts the core; failure here means restart or API call failed\n  mihomoApiLogger.error('Config patch failed even after core restart — inspect core logs', e)\n  throw e\n}","preventionTips":["Fix recurring core startup failures (invalid profile config, occupied ports) so the core stays up.","Inspect core logs after each automatic restart to confirm it became healthy.","Ensure the core binary is installed, executable, and up to date.","Apply config changes through the app UI so the restart-before-patch logic runs as designed."],"tags":["config","process","recovery"],"backgroundTag":"core-not-running-config-restart","analyzedSha":"911e090537acdf7c50bee1c3aebecc2ef119a8b5","analyzedAt":"2026-08-30T13:00:49.174Z","schemaVersion":2},"datasetVersion":"2026-08-30T13:17:10.514Z"}