Skip to content

Automate browser based workflows with AI

Guard undefined block parameters in workflow editor (SKY-12405) (#7543)

Aaron Pereza30096188afc
diff --git a/skyvern-frontend/src/routes/workflows/editor/undefinedParametersGuard.test.ts b/skyvern-frontend/src/routes/workflows/editor/undefinedParametersGuard.test.ts
new file mode 100644
index 000000000..eb4279cf2
--- /dev/null
+++ b/skyvern-frontend/src/routes/workflows/editor/undefinedParametersGuard.test.ts
@@ -0,0 +1,52 @@
+import { describe, expect, test } from "vitest";
+
+import { ProxyLocation } from "@/api/types";
+
+import type { WorkflowBlock, WorkflowSettings } from "../types/workflowTypes";
+
+import { getElements } from "./workflowEditorUtils";
+
+const DEFAULT_SETTINGS: WorkflowSettings = {
+ proxyLocation: ProxyLocation.Residential,
+ webhookCallbackUrl: null,
+ persistBrowserSession: false,
+ pinSavedSessionIp: false,
+ browserProfileId: null,
+ browserProfileKey: null,
+ model: null,
+ maxScreenshotScrolls: null,
+ maxElapsedTimeMinutes: null,
+ extraHttpHeaders: null,
+ cdpConnectHeaders: null,
+ runWith: "code",
+ codeVersion: 2,
+ scriptCacheKey: null,
+ aiFallback: true,
+ enableSelfHealing: false,
+ runSequentially: false,
+ sequentialKey: null,
+ finallyBlockLabel: null,
+ workflowSystemPrompt: null,
+ errorCodeMapping: null,
+};
+
+describe("getElements is robust to blocks with undefined parameters", () => {
+ test("a task block whose parameters is missing does not throw", () => {
+ // Malformed / legacy persisted workflows can omit parameters entirely, which
+ // violates the WorkflowBlock type; convertToNode previously called
+ // block.parameters.map() unconditionally and crashed on load.
+ const block = {
+ label: "task_1",
+ block_type: "task",
+ continue_on_failure: false,
+ model: null,
+ next_block_label: null,
+ // parameters intentionally omitted (undefined at runtime)
+ } as unknown as WorkflowBlock;
+
+ expect(() => getElements([block], DEFAULT_SETTINGS, false)).not.toThrow();
+ const { nodes } = getElements([block], DEFAULT_SETTINGS, false);
+ const taskNode = nodes.find((node) => node.type === "task");
+ expect(taskNode).toBeDefined();
+ });
+});
diff --git a/skyvern-frontend/src/routes/workflows/editor/workflowEditorUtils.ts b/skyvern-frontend/src/routes/workflows/editor/workflowEditorUtils.ts
index d6f67a9b1..ab21cd33e 100644
--- a/skyvern-frontend/src/routes/workflows/editor/workflowEditorUtils.ts
+++ b/skyvern-frontend/src/routes/workflows/editor/workflowEditorUtils.ts
@@ -709,7 +709,7 @@ function convertToNode(
downloadSuffix: block.download_suffix ?? null,
maxRetries: block.max_retries ?? null,
maxStepsOverride: block.max_steps_per_run ?? null,
- parameterKeys: block.parameters.map((p) => p.key),
+ parameterKeys: (block.parameters ?? []).map((p) => p.key),
totpIdentifier: block.totp_identifier ?? null,
totpVerificationUrl: block.totp_verification_url ?? null,
disableCache: block.disable_cache ?? false,
@@ -763,7 +763,7 @@ function convertToNode(
errorCodeMapping: JSON.stringify(block.error_code_mapping, null, 2),
completeCriterion: block.complete_criterion ?? "",
terminateCriterion: block.terminate_criterion ?? "",
- parameterKeys: block.parameters.map((p) => p.key),
+ parameterKeys: (block.parameters ?? []).map((p) => p.key),
disableCache: block.disable_cache ?? false,
},
};
@@ -781,7 +781,7 @@ function convertToNode(
allowDownloads: block.complete_on_download ?? false,
downloadSuffix: block.download_suffix ?? null,
maxRetries: block.max_retries ?? null,
- parameterKeys: block.parameters.map((p) => p.key),
+ parameterKeys: (block.parameters ?? []).map((p) => p.key),
totpIdentifier: block.totp_identifier ?? null,
totpVerificationUrl: block.totp_verification_url ?? null,
disableCache: block.disable_cache ?? false,
@@ -803,7 +803,7 @@ function convertToNode(
allowDownloads: block.complete_on_download ?? false,
downloadSuffix: block.download_suffix ?? null,
maxRetries: block.max_retries ?? null,
- parameterKeys: block.parameters.map((p) => p.key),
+ parameterKeys: (block.parameters ?? []).map((p) => p.key),
totpIdentifier: block.totp_identifier ?? null,
totpVerificationUrl: block.totp_verification_url ?? null,
disableCache: block.disable_cache ?? false,
@@ -855,7 +855,7 @@ function convertToNode(
: typeof block.data_schema === "string"
? block.data_schema
: JSON.stringify(block.data_schema, null, 2),
- parameterKeys: block.parameters.map((p) => p.key),
+ parameterKeys: (block.parameters ?? []).map((p) => p.key),
maxRetries: block.max_retries ?? null,
maxStepsOverride: block.max_steps_per_run ?? null,
disableCache: block.disable_cache ?? false,
@@ -874,7 +874,7 @@ function convertToNode(
navigationGoal: block.navigation_goal ?? "",
errorCodeMapping: JSON.stringify(block.error_code_mapping, null, 2),
maxRetries: block.max_retries ?? null,
- parameterKeys: block.parameters.map((p) => p.key),
+ parameterKeys: (block.parameters ?? []).map((p) => p.key),
totpIdentifier: block.totp_identifier ?? null,
totpVerificationUrl: block.totp_verification_url ?? null,
disableCache: block.disable_cache ?? false,
@@ -910,7 +910,7 @@ function convertToNode(
errorCodeMapping: JSON.stringify(block.error_code_mapping, null, 2),
downloadSuffix: block.download_suffix ?? null,
maxRetries: block.max_retries ?? null,
- parameterKeys: block.parameters.map((p) => p.key),
+ parameterKeys: (block.parameters ?? []).map((p) => p.key),
totpIdentifier: block.totp_identifier ?? null,
totpVerificationUrl: block.totp_verification_url ?? null,
disableCache: block.disable_cache ?? false,
@@ -949,7 +949,7 @@ function convertToNode(
data: {
...commonData,
code: block.code,
- parameterKeys: block.parameters.map((p) => p.key),
+ parameterKeys: (block.parameters ?? []).map((p) => p.key),
prompt: block.prompt ?? null,
steps: block.steps ?? null,
},
@@ -983,7 +983,7 @@ function convertToNode(
...commonData,
prompt: block.prompt,
jsonSchema: JSON.stringify(block.json_schema, null, 2),
- parameterKeys: block.parameters.map((p) => p.key),
+ parameterKeys: (block.parameters ?? []).map((p) => p.key),
},
};
}
@@ -1148,7 +1148,7 @@ function convertToNode(
files: JSON.stringify(block.files || {}, null, 2),
timeout: block.timeout,
followRedirects: block.follow_redirects,
- parameterKeys: block.parameters.map((p) => p.key),
+ parameterKeys: (block.parameters ?? []).map((p) => p.key),
downloadFilename: block.download_filename ?? "",
saveResponseAsFile: block.save_response_as_file ?? false,
secretResponsePaths: block.secret_response_paths ?? [],
@@ -1167,7 +1167,7 @@ function convertToNode(
format: block.format ?? "A4",
landscape: block.landscape ?? false,
printBackground: block.print_background ?? true,
- parameterKeys: block.parameters.map((p) => p.key),
+ parameterKeys: (block.parameters ?? []).map((p) => p.key),
},
};
}
@@ -1185,7 +1185,7 @@ function convertToNode(
? block.payload
: JSON.stringify(block.payload || {}, null, 2),
llmKey: block.llm_key ?? "",
- parameterKeys: block.parameters.map((p) => p.key),
+ parameterKeys: (block.parameters ?? []).map((p) => p.key),
},
};
}
@@ -1199,7 +1199,7 @@ function convertToNode(
fileUrl: block.file_url ?? "",
prompt: block.prompt ?? "",
llmKey: block.llm_key ?? "",
- parameterKeys: block.parameters.map((p) => p.key),
+ parameterKeys: (block.parameters ?? []).map((p) => p.key),
},
};
}
@@ -1216,7 +1216,7 @@ function convertToNode(
waitForCompletion: block.wait_for_completion ?? true,
browserSessionId: block.browser_session_id ?? "",
useParentBrowserSession: block.use_parent_browser_session ?? false,
- parameterKeys: block.parameters.map((p) => p.key),
+ parameterKeys: (block.parameters ?? []).map((p) => p.key),
},
};
}
@@ -1236,7 +1236,7 @@ function convertToNode(
newerThanDays: block.newer_than_days ?? null,
maxResults: block.max_results ?? 25,
includeBody: block.include_body ?? true,
- parameterKeys: block.parameters.map((p) => p.key),
+ parameterKeys: (block.parameters ?? []).map((p) => p.key),
},
};
}
@@ -1252,7 +1252,7 @@ function convertToNode(
range: block.range ?? "",
credentialId: block.credential_id ?? "",
hasHeaderRow: block.has_header_row ?? true,
- parameterKeys: block.parameters.map((p) => p.key),
+ parameterKeys: (block.parameters ?? []).map((p) => p.key),
},
};
}
@@ -1273,7 +1273,7 @@ function convertToNode(
? JSON.stringify(block.column_mapping, null, 2)
: "",
createSheetIfMissing: block.create_sheet_if_missing ?? false,
- parameterKeys: block.parameters.map((p) => p.key),
+ parameterKeys: (block.parameters ?? []).map((p) => p.key),
},
};
}
@@ -4327,7 +4327,7 @@ function convertBlocksToBlockYAML(
max_steps_per_run: block.max_steps_per_run,
complete_on_download: block.complete_on_download,
download_suffix: block.download_suffix,
- parameter_keys: block.parameters.map((p) => p.key),
+ parameter_keys: (block.parameters ?? []).map((p) => p.key),
totp_identifier: block.totp_identifier,
totp_verification_url: block.totp_verification_url,
disable_cache: block.disable_cache ?? false,
@@ -4357,7 +4357,7 @@ function convertBlocksToBlockYAML(
complete_criterion: block.complete_criterion,
terminate_criterion: block.terminate_criterion,
error_code_mapping: block.error_code_mapping,
- parameter_keys: block.parameters.map((p) => p.key),
+ parameter_keys: (block.parameters ?? []).map((p) => p.key),
};
return blockYaml;
}
@@ -4404,7 +4404,7 @@ function convertBlocksToBlockYAML(
max_retries: block.max_retries,
complete_on_download: block.complete_on_download,
download_suffix: block.download_suffix,
- parameter_keys: block.parameters.map((p) => p.key),
+ parameter_keys: (block.parameters ?? []).map((p) => p.key),
totp_identifier: block.totp_identifier,
totp_verification_url: block.totp_verification_url,
disable_cache: block.disable_cache ?? false,
@@ -4426,7 +4426,7 @@ function convertBlocksToBlockYAML(
max_steps_per_run: block.max_steps_per_run,
complete_on_download: block.complete_on_download,
download_suffix: block.download_suffix,
- parameter_keys: block.parameters.map((p) => p.key),
+ parameter_keys: (block.parameters ?? []).map((p) => p.key),
totp_identifier: block.totp_identifier,
totp_verification_url: block.totp_verification_url,
disable_cache: block.disable_cache ?? false,
@@ -4447,7 +4447,7 @@ function convertBlocksToBlockYAML(
data_schema: block.data_schema,
max_retries: block.max_retries,
max_steps_per_run: block.max_steps_per_run,
- parameter_keys: block.parameters.map((p) => p.key),
+ parameter_keys: (block.parameters ?? []).map((p) => p.key),
disable_cache: block.disable_cache ?? false,
engine: block.engine,
};
@@ -4463,7 +4463,7 @@ function convertBlocksToBlockYAML(
error_code_mapping: block.error_code_mapping,
max_retries: block.max_retries,
max_steps_per_run: block.max_steps_per_run,
- parameter_keys: block.parameters.map((p) => p.key),
+ parameter_keys: (block.parameters ?? []).map((p) => p.key),
totp_identifier: block.totp_identifier,
totp_verification_url: block.totp_verification_url,
disable_cache: block.disable_cache ?? false,
@@ -4494,7 +4494,7 @@ function convertBlocksToBlockYAML(
max_retries: block.max_retries,
max_steps_per_run: block.max_steps_per_run,
download_suffix: block.download_suffix,
- parameter_keys: block.parameters.map((p) => p.key),
+ parameter_keys: (block.parameters ?? []).map((p) => p.key),
totp_identifier: block.totp_identifier,
totp_verification_url: block.totp_verification_url,
disable_cache: block.disable_cache ?? false,
@@ -4570,7 +4570,7 @@ function convertBlocksToBlockYAML(
...base,
block_type: "code",
code: block.code,
- parameter_keys: block.parameters.map((p) => p.key),
+ parameter_keys: (block.parameters ?? []).map((p) => p.key),
prompt: block.prompt,
steps: block.steps,
};
@@ -4583,7 +4583,7 @@ function convertBlocksToBlockYAML(
llm_key: block.llm_key,
prompt: block.prompt,
json_schema: block.json_schema,
- parameter_keys: block.parameters.map((p) => p.key),
+ parameter_keys: (block.parameters ?? []).map((p) => p.key),
};
return blockYaml;
}
@@ -4684,7 +4684,7 @@ function convertBlocksToBlockYAML(
files: block.files,
timeout: block.timeout,
follow_redirects: block.follow_redirects,
- parameter_keys: block.parameters.map((p) => p.key),
+ parameter_keys: (block.parameters ?? []).map((p) => p.key),
download_filename: block.download_filename,
secret_response_paths: serializeSecretResponsePaths(
block.secret_response_paths ?? [],
@@ -4701,7 +4701,7 @@ function convertBlocksToBlockYAML(
format: block.format,
landscape: block.landscape,
print_background: block.print_background,
- parameter_keys: block.parameters.map((p) => p.key),
+ parameter_keys: (block.parameters ?? []).map((p) => p.key),
};
return blockYaml;
}
@@ -4713,7 +4713,7 @@ function convertBlocksToBlockYAML(
prompt: block.prompt,
payload: block.payload,
llm_key: block.llm_key,
- parameter_keys: block.parameters.map((p) => p.key),
+ parameter_keys: (block.parameters ?? []).map((p) => p.key),
};
return blockYaml;
}
@@ -4724,7 +4724,7 @@ function convertBlocksToBlockYAML(
file_url: block.file_url,
prompt: block.prompt,
llm_key: block.llm_key,
- parameter_keys: block.parameters.map((p) => p.key),
+ parameter_keys: (block.parameters ?? []).map((p) => p.key),
};
return blockYaml;
}
@@ -4737,7 +4737,7 @@ function convertBlocksToBlockYAML(
wait_for_completion: block.wait_for_completion,
browser_session_id: block.browser_session_id,
use_parent_browser_session: block.use_parent_browser_session,
- parameter_keys: block.parameters.map((p) => p.key),
+ parameter_keys: (block.parameters ?? []).map((p) => p.key),
};
return blockYaml;
}
@@ -4754,7 +4754,7 @@ function convertBlocksToBlockYAML(
newer_than_days: block.newer_than_days,
max_results: block.max_results,
include_body: block.include_body,
- parameter_keys: block.parameters.map((p) => p.key),
+ parameter_keys: (block.parameters ?? []).map((p) => p.key),
};
return blockYaml;
}
@@ -4767,7 +4767,7 @@ function convertBlocksToBlockYAML(
range: block.range,
credential_id: block.credential_id,
has_header_row: block.has_header_row,
- parameter_keys: block.parameters.map((p) => p.key),
+ parameter_keys: (block.parameters ?? []).map((p) => p.key),
};
return blockYaml;
}
@@ -4783,7 +4783,7 @@ function convertBlocksToBlockYAML(
values: block.values,
column_mapping: block.column_mapping,
create_sheet_if_missing: block.create_sheet_if_missing,
- parameter_keys: block.parameters.map((p) => p.key),
+ parameter_keys: (block.parameters ?? []).map((p) => p.key),
};
return blockYaml;
}