From 5ab41d649a6693da66141fcfbcd645f501654c6a Mon Sep 17 00:00:00 2001 From: Shuchang Zheng Date: Fri, 21 Nov 2025 20:18:31 -0800 Subject: [PATCH] avoid unnecessary code regeneration when the workflow has non task based blocks (#4071) --- skyvern/forge/sdk/workflow/service.py | 35 ++++++++++++++++++++++++--- 1 file changed, 31 insertions(+), 4 deletions(-) diff --git a/skyvern/forge/sdk/workflow/service.py b/skyvern/forge/sdk/workflow/service.py index e1d60d14..4c8626f3 100644 --- a/skyvern/forge/sdk/workflow/service.py +++ b/skyvern/forge/sdk/workflow/service.py @@ -127,6 +127,16 @@ DEFAULT_FIRST_BLOCK_LABEL = "block_1" DEFAULT_WORKFLOW_TITLE = "New Workflow" CacheInvalidationReason = Literal["updated_block", "new_block", "removed_block"] +BLOCK_TYPES_THAT_SHOULD_BE_CACHED = { + BlockType.TASK, + BlockType.TaskV2, + BlockType.VALIDATION, + BlockType.ACTION, + BlockType.NAVIGATION, + BlockType.EXTRACTION, + BlockType.LOGIN, + BlockType.FILE_DOWNLOAD, +} @dataclass @@ -961,6 +971,7 @@ class WorkflowService: and block.label and block_result.status == BlockStatus.completed and not getattr(block, "disable_cache", False) + and block.block_type in BLOCK_TYPES_THAT_SHOULD_BE_CACHED ): blocks_to_update.add(block.label) if block_result.status == BlockStatus.canceled: @@ -3320,12 +3331,16 @@ class WorkflowService: if script_block.script_block_label: cached_block_labels.add(script_block.script_block_label) - definition_labels = {block.label for block in workflow.workflow_definition.blocks if block.label} - definition_labels.add(settings.WORKFLOW_START_BLOCK_LABEL) + should_cache_block_labels = { + block.label + for block in workflow.workflow_definition.blocks + if block.label and block.block_type in BLOCK_TYPES_THAT_SHOULD_BE_CACHED + } + should_cache_block_labels.add(settings.WORKFLOW_START_BLOCK_LABEL) cached_block_labels.add(settings.WORKFLOW_START_BLOCK_LABEL) - if cached_block_labels != definition_labels: - missing_labels = definition_labels - cached_block_labels + if cached_block_labels != should_cache_block_labels: + missing_labels = should_cache_block_labels - cached_block_labels if missing_labels: blocks_to_update.update(missing_labels) # Always rebuild the orchestrator if the definition changed @@ -3345,6 +3360,18 @@ class WorkflowService: ) return + LOG.info( + "deleting old workflow script and generating new script", + workflow_id=workflow.workflow_id, + workflow_run_id=workflow_run.workflow_run_id, + cache_key_value=rendered_cache_key_value, + script_id=existing_script.script_id, + script_revision_id=existing_script.script_revision_id, + run_with=workflow_run.run_with, + blocks_to_update=list(blocks_to_update), + code_gen=code_gen, + ) + # delete the existing workflow scripts if any await app.DATABASE.delete_workflow_scripts_by_permanent_id( organization_id=workflow.organization_id,