windmill-labs/windmill · error

Failed to start test run - testFlow returned undefined

Error message

Failed to start test run - testFlow returned undefined

What it means

The flow 'test run' copilot tool wraps helpers.testFlow() and requires it to return a job ID for the started test run. When testFlow resolves to undefined (falsy), the tool throws this error instead of silently tracking a run it cannot monitor. It indicates the test-run starter failed to produce a job, typically before the backend actually queued anything.

Source

Thrown at frontend/src/lib/components/copilot/chat/flow/core.ts:423

			const { flow } = helpers.getFlowAndSelectedId()

			if (!flow || !flow.value) {
				toolCallbacks.setToolStatus(toolId, {
					content: 'No flow available to test',
					error: 'No flow found in current context'
				})
				throw new Error(
					'No flow available to test. Please ensure you have a flow open in the editor.'
				)
			}

			const parsedArgs = await buildTestRunArgs(args, this.def)
			// Use the UI test mechanism - this opens the preview panel
			return executeTestRun({
				jobStarter: async () => {
					const jobId = await helpers.testFlow(parsedArgs)
					if (!jobId) {
						throw new Error('Failed to start test run - testFlow returned undefined')
					}
					return jobId
				},
				workspace,
				toolCallbacks,
				toolId,
				startMessage: 'Starting flow test run...',
				contextName: 'flow'
			})
		},
		setSchema: async function (helpers: FlowAIChatHelpers) {
			await buildSchemaForTool(this.def, async () => {
				const flowInputsSchema = await helpers.getFlowInputsSchema()
				return flowInputsSchema
			})
		},
		requiresConfirmation: true,
		confirmationMessage: 'Run a test of the current flow',

View on GitHub (pinned to e474e8803c)

Solutions

  1. Ensure a valid flow is open and saved in the editor, then re-run the test tool.
  2. Check the browser network/console logs for the failing test-run API call (it likely returned an error that testFlow swallowed).
  3. Verify helpers.testFlow is wired to the current preview/run service and returns the created job's id on success.
  4. Retry the test run; if it persists, restart the frontend dev server to clear stale editor state.

Example fix

// before
const jobId = await helpers.testFlow(parsedArgs)
if (!jobId) throw new Error('Failed to start test run - testFlow returned undefined')
// after: make testFlow surface the real failure
const jobId = await helpers.testFlow(parsedArgs)
if (!jobId) throw new Error('testFlow returned no job id — check the run/start API response')
Defensive patterns

Strategy: try-catch

Validate before calling

const { flow } = helpers.getFlowAndSelectedId()
if (!flow?.value) throw new Error('Open a valid flow before testing')
const parsedArgs = await buildTestRunArgs(args, def)

Type guard

function hasJobId(v: unknown): v is string { return typeof v === 'string' && v.length > 0 }

Try / catch

try {
  const jobId = await helpers.testFlow(parsedArgs)
  if (!jobId) throw new Error('testFlow returned no job id')
} catch (e) {
  showStatus(`Test run failed to start: ${e.message}; check the run API response and retry`)
}

Prevention

When it happens

Trigger: Calling the test_run_flow tool when helpers.testFlow(parsedArgs) resolves without a job ID — e.g. the underlying preview/test-run API returned no id, the flow value was stale or empty, or a UI-layer guard in testFlow short-circuits and returns undefined.

Common situations: Flow editor not fully hydrated when the AI triggers a test; backend request failed but testFlow swallowed the error and returned undefined; running against a stale/invalid flow draft that the test mechanism refuses to start.

Related errors


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