windmill-labs/windmill · error

error (from getWorkspaceMutationTargetError)

Error message

error (from getWorkspaceMutationTargetError)

What it means

requireWorkspaceMutationTarget resolves the 'current script or flow' context (helpers) into a mutation target and validates it. getWorkspaceMutationTargetError returns a message when the target is missing or not deployed ('the script or flow needs to be deployed before doing this action'); when present, this Error is thrown. Tools like create_schedule/create_trigger use it as a precondition, so it fires before any API call.

Source

Thrown at frontend/src/lib/components/copilot/chat/workspaceTools.ts:119

		return 'the script or flow needs to be deployed before doing this action'
	}
	if (!emptyString(target.path) && target.deployed) {
		return undefined
	}
	return `the ${target.kind} needs to be deployed before doing this action`
}

function validateWorkspaceMutationTarget(helpers: unknown): string | undefined {
	return getWorkspaceMutationTargetError(getWorkspaceMutationTarget(helpers))
}

function requireWorkspaceMutationTarget(
	helpers: unknown
): WorkspaceMutationTarget & { path: string } {
	const target = getWorkspaceMutationTarget(helpers)
	const error = getWorkspaceMutationTargetError(target)
	if (error) {
		throw new Error(error)
	}
	return target as WorkspaceMutationTarget & { path: string }
}

function getWorkspaceMutationTargetFields(
	helpers: unknown
): Pick<NewSchedule, 'script_path' | 'is_flow'> {
	const target = requireWorkspaceMutationTarget(helpers)
	return {
		script_path: target.path,
		is_flow: target.kind === 'flow'
	}
}

const createScheduleToolDef = createToolDef(
	createScheduleToolSchema,
	'create_schedule',
	'Create a schedule for the current script or flow. For anything beyond a plain cron (retry, pausing, tags, error-handler tuning), call get_schedule_schema first and pass those through `advanced`.',

View on GitHub (pinned to e474e8803c)

Solutions

  1. Deploy the current script or flow (Save/Deploy in the editor) before asking the copilot to create schedules or triggers
  2. Open the script/flow in the editor so the chat has a mutation target in its helpers
  3. Use the chat's save/deploy tooling first, then retry the schedule/trigger creation
Defensive patterns

Strategy: validation

Validate before calling

const target = getWorkspaceMutationTarget(helpers)
const err = getWorkspaceMutationTargetError(target)
if (err) return err // surface before attempting the tool call

Try / catch

try {
  await createScheduleTool.fn(ctx)
} catch (e) {
  if (/needs to be deployed/.test((e as Error).message)) {
    await deployCurrentScriptOrFlow(); return createScheduleTool.fn(ctx)
  }
  throw e
}

Prevention

When it happens

Trigger: Calling create_schedule / create_trigger (or getWorkspaceMutationTargetFields) while the copilot has no script/flow open, or while the open script/flow is a draft that has never been deployed (target.deployed false or empty path).

Common situations: User asks the AI chat to schedule a brand-new unsaved script; the editor is on a new untitled flow; chat is opened in a context where no script/flow is active; the draft has edits so the deployed flag is stale.

Related errors


AI-assisted analysis of windmill-labs/windmill@e474e8803c (2026-09-03). Data as JSON: /api/errors/8027ffff83c885da. Report an issue: GitHub.