different-ai/openwork · error
Cannot create a task without a selected workspace.
Error message
Cannot create a task without a selected workspace.
What it means
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.
Source
Thrown at apps/app/src/react-app/domains/session/control/session-control-actions.ts:96
openModelPicker,
openworkClient,
opencodeClient,
refreshRouteState,
selectedSessionId,
selectedWorkspaceId,
selectedWorkspaceRoot,
sessionsByWorkspaceId,
workspaces,
} = input;
const createTaskControlAction = useMemo<OpenworkControlAction>(() => ({
id: "session.create_task",
label: "Create a new task",
description: "Create a new session in the selected workspace.",
sideEffect: "mutation",
disabled: !canCreateTask || !selectedWorkspaceId,
execute: async () => {
if (!selectedWorkspaceId) throw new Error("Cannot create a task without a selected workspace.");
const sessionId = await createTaskInWorkspace(selectedWorkspaceId);
if (sessionId === null) throw new Error("Task creation did not return a session ID.");
return sessionId;
},
}), [canCreateTask, createTaskInWorkspace, selectedWorkspaceId]);
useControlAction(createTaskControlAction);
const listSessionsControlAction = useMemo<OpenworkControlAction>(() => ({
id: "session.list_sessions",
label: "List available sessions",
description: "Return the list of sessions across workspaces so the user can ask to open one by name.",
kind: "query",
effects: { data: "read", ui: "none", external: false },
sideEffect: "none",
execute: () => {
const out: { sessionId: string; title: string; workspace: string; updatedAt: number }[] = [];
for (const workspace of workspaces) {
const list = sessionsByWorkspaceId[workspace.id] ?? [];View on GitHub (pinned to 2b7df46e8a)
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.
Example fix
// before
execute: async () => {
if (!selectedWorkspaceId) throw new Error("Cannot create a task without a selected workspace.");
...
}
// after (caller-side guard)
if (!selectedWorkspaceId) {
showToast("Select a workspace first");
return;
}
await executeCreateTask(); Defensive patterns
Strategy: validation
Validate before calling
if (typeof selectedWorkspaceId !== "string" || !selectedWorkspaceId) {
throw new Error("Select a workspace before creating a task");
}
await createTaskControlAction.execute(); Type guard
function hasSelectedWorkspace(s: { selectedWorkspaceId?: string | null }): s is { selectedWorkspaceId: string } {
return typeof s.selectedWorkspaceId === "string" && s.selectedWorkspaceId.length > 0;
} Try / catch
try {
await executeCreateTask();
} catch (e) {
if (e instanceof Error && e.message.includes("without a selected workspace")) {
openWorkspacePicker();
return;
}
throw e;
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- app.error_compact_empty
- Workspace path is unavailable; attachments could not be copi
- Workspace endpoint is unavailable; attachments could not be
- invalid_session_payload
- Unknown error
AI-assisted analysis of different-ai/openwork@2b7df46e8a (2026-09-01).
Data as JSON: /api/errors/ce56627ba7c98557.
Report an issue: GitHub.