{"record":{"id":"c15f5a0ec58f9959","repo":"different-ai/openwork","slug":"opencode-is-not-configured-for-a-local-workspace","errorCode":null,"errorMessage":"OpenCode is not configured for a local workspace","messagePattern":"OpenCode is not configured for a local workspace","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"apps/desktop/electron/runtime.mjs","lineNumber":2185,"sourceCode":"      lifecycleState = \"healthy\";\n      return snapshotEngineState(engineState);\n    } catch (error) {\n      lifecycleState = \"error\";\n      throw error;\n    }\n  }\n\n  async function engineStop() {\n    lifecycleState = \"stopping\";\n    await stopAllRuntimeChildren();\n    lifecycleState = \"idle\";\n    return snapshotEngineState(engineState);\n  }\n\n  async function engineRestart(options = {}) {\n    const projectDir = engineState.projectDir;\n    if (!projectDir) {\n      throw new Error(\"OpenCode is not configured for a local workspace\");\n    }\n    const openworkRemoteAccess = typeof options.openworkRemoteAccess === \"boolean\"\n      ? options.openworkRemoteAccess\n      : openworkServerState.remoteAccessEnabled;\n    return engineStart(projectDir, {\n      runtime: engineState.runtime,\n      workspacePaths: [projectDir],\n      opencodeEnableExa: options.opencodeEnableExa,\n      openworkRemoteAccess,\n      forceRestart: true,\n    });\n  }\n\n  async function engineInfo() {\n    if (inProcessServer?.managedOpencode) {\n      engineState.managedPid = inProcessServer.managedOpencode.pid ?? null;\n    }\n    return { ...snapshotEngineState(engineState), lifecycleState };","sourceCodeStart":2167,"sourceCodeEnd":2203,"githubUrl":"https://github.com/different-ai/openwork/blob/2b7df46e8ae1517d64c896c7793d2d52ec845669/apps/desktop/electron/runtime.mjs#L2167-L2203","documentation":"engineRestart() restarts the engine in the workspace it was previously started in, read from engineState.projectDir. If there is no current projectDir — the engine was never started, or was started without a local workspace (e.g. remote-access-only mode) — this error is thrown. Restart is only defined for a configured local workspace.","triggerScenarios":"Calling engineRestart() before any engineStart() succeeded, after engine stop cleared engineState.projectDir, or when the engine was configured for a remote workspace so no local projectDir exists.","commonSituations":"App boots and auto-restart fires with no prior session; a crash handler restarts the engine after state was reset; user hits 'Restart' on a fresh window; workspace switched to remote access so projectDir is intentionally absent.","solutions":["Call engineStart(projectDir) first to establish a local workspace, then restart as needed.","Check engineState (or snapshotEngineState) for a non-empty projectDir before offering/invoking restart.","Disable or hide the Restart action in the UI when no local workspace is active.","If state was cleared unexpectedly, fix the code path that reset engineState (e.g. on stop or error) to preserve projectDir."],"exampleFix":"// before\nawait engineRestart(); // throws if never started\n// after\nif (snapshotEngineState(engineState).projectDir) {\n  await engineRestart();\n} else {\n  await engineStart(await pickWorkspaceDir());\n}","handlingStrategy":"validation","validationCode":"const state = snapshotEngineState(engineState);\nif (!state.projectDir) {\n  throw new Error(\"No local workspace configured; call engineStart first\");\n}\nawait engineRestart();","typeGuard":"function canRestart(state) {\n  return typeof state?.projectDir === \"string\" && state.projectDir.trim().length > 0;\n}","tryCatchPattern":"try {\n  await engineRestart();\n} catch (err) {\n  if (err.message === \"OpenCode is not configured for a local workspace\") {\n    await engineStart(persistedLastWorkspaceDir ?? (await pickWorkspaceDir()));\n  } else { throw err; }\n}","preventionTips":["Only enable Restart UI affordances when engineState.projectDir is set.","Persist projectDir across app restarts so auto-restart has a workspace to use.","After engine stop/error, decide explicitly whether to clear or retain projectDir.","For remote-access sessions, route restart through the remote path instead of the local engine restart."],"tags":["state","lifecycle","validation"],"backgroundTag":"engine-not-initialized","analyzedSha":"2b7df46e8ae1517d64c896c7793d2d52ec845669","analyzedAt":"2026-09-01T07:59:23.713Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T15:18:49.778Z"}