{"record":{"id":"ce56627ba7c98557","repo":"different-ai/openwork","slug":"cannot-create-a-task-without-a-selected-workspace","errorCode":null,"errorMessage":"Cannot create a task without a selected workspace.","messagePattern":"Cannot create a task without a selected workspace\\.","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"apps/app/src/react-app/domains/session/control/session-control-actions.ts","lineNumber":96,"sourceCode":"    openModelPicker,\n    openworkClient,\n    opencodeClient,\n    refreshRouteState,\n    selectedSessionId,\n    selectedWorkspaceId,\n    selectedWorkspaceRoot,\n    sessionsByWorkspaceId,\n    workspaces,\n  } = input;\n\n  const createTaskControlAction = useMemo<OpenworkControlAction>(() => ({\n    id: \"session.create_task\",\n    label: \"Create a new task\",\n    description: \"Create a new session in the selected workspace.\",\n    sideEffect: \"mutation\",\n    disabled: !canCreateTask || !selectedWorkspaceId,\n    execute: async () => {\n      if (!selectedWorkspaceId) throw new Error(\"Cannot create a task without a selected workspace.\");\n      const sessionId = await createTaskInWorkspace(selectedWorkspaceId);\n      if (sessionId === null) throw new Error(\"Task creation did not return a session ID.\");\n      return sessionId;\n    },\n  }), [canCreateTask, createTaskInWorkspace, selectedWorkspaceId]);\n  useControlAction(createTaskControlAction);\n\n  const listSessionsControlAction = useMemo<OpenworkControlAction>(() => ({\n    id: \"session.list_sessions\",\n    label: \"List available sessions\",\n    description: \"Return the list of sessions across workspaces so the user can ask to open one by name.\",\n    kind: \"query\",\n    effects: { data: \"read\", ui: \"none\", external: false },\n    sideEffect: \"none\",\n    execute: () => {\n      const out: { sessionId: string; title: string; workspace: string; updatedAt: number }[] = [];\n      for (const workspace of workspaces) {\n        const list = sessionsByWorkspaceId[workspace.id] ?? [];","sourceCodeStart":78,"sourceCodeEnd":114,"githubUrl":"https://github.com/different-ai/openwork/blob/2b7df46e8ae1517d64c896c7793d2d52ec845669/apps/app/src/react-app/domains/session/control/session-control-actions.ts#L78-L114","documentation":"The 'Create a new task' control action in the session control panel throws this when its execute() runs with no workspace selected. Even though the action is disabled when selectedWorkspaceId is missing, the guard re-checks inside execute so a race or stale action definition cannot create a session in an unknown workspace. It is an internal invariant protecting createTaskInWorkspace from a null workspace ID.","triggerScenarios":"Invoking the 'session.create_task' control action programmatically or via a stale UI snapshot while selectedWorkspaceId is null/undefined — e.g. the workspace list hasn't loaded, the selected workspace was deleted, or the action was dispatched before workspace selection state settled despite the disabled flag.","commonSituations":"Developers triggering session creation from tests, deep links, or automation that fires the control action before the workspace selector resolves; users whose previously selected workspace disappeared after a cloud account switch.","solutions":["Select a workspace in the UI (or set selectedWorkspaceId in state) before invoking the create-task control action.","Gate the invocation: check selectedWorkspaceId is truthy in the caller before dispatching the action.","If the disabled flag should have prevented this, check that workspace selection state has finished loading before rendering/enabling the action."],"exampleFix":"// before\nexecute: async () => {\n  if (!selectedWorkspaceId) throw new Error(\"Cannot create a task without a selected workspace.\");\n  ...\n}\n// after (caller-side guard)\nif (!selectedWorkspaceId) {\n  showToast(\"Select a workspace first\");\n  return;\n}\nawait executeCreateTask();","handlingStrategy":"validation","validationCode":"if (typeof selectedWorkspaceId !== \"string\" || !selectedWorkspaceId) {\n  throw new Error(\"Select a workspace before creating a task\");\n}\nawait createTaskControlAction.execute();","typeGuard":"function hasSelectedWorkspace(s: { selectedWorkspaceId?: string | null }): s is { selectedWorkspaceId: string } {\n  return typeof s.selectedWorkspaceId === \"string\" && s.selectedWorkspaceId.length > 0;\n}","tryCatchPattern":"try {\n  await executeCreateTask();\n} catch (e) {\n  if (e instanceof Error && e.message.includes(\"without a selected workspace\")) {\n    openWorkspacePicker();\n    return;\n  }\n  throw e;\n}","preventionTips":["Only enable/execute the create-task action after workspace selection state has loaded and is non-null.","Never fire control actions from effects or automation before async workspace data resolves.","Keep the disabled flag and the execute guard in sync with the same state source."],"tags":["workspace","session","precondition"],"backgroundTag":"missing-required-selection","analyzedSha":"2b7df46e8ae1517d64c896c7793d2d52ec845669","analyzedAt":"2026-09-01T07:59:23.713Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}