Skip to content

Automate browser based workflows with AI

Make run_with non-nullable, default to agent (#5275)

pedrohsdb75d538105869
diff --git a/skyvern-frontend/src/routes/workflows/RunWorkflowForm.tsx b/skyvern-frontend/src/routes/workflows/RunWorkflowForm.tsx
index 70b7fd260..3ae5eaee8 100644
--- a/skyvern-frontend/src/routes/workflows/RunWorkflowForm.tsx
+++ b/skyvern-frontend/src/routes/workflows/RunWorkflowForm.tsx
@@ -275,7 +275,6 @@ function deriveRunWith(
return override as "agent" | "code";
if (workflow?.run_with === "agent") return "agent";
if (workflow?.run_with === "code") return "code";
- if ((workflow?.code_version ?? 0) >= 1) return "code";
return "agent";
}
diff --git a/skyvern-frontend/src/routes/workflows/WorkflowRun.tsx b/skyvern-frontend/src/routes/workflows/WorkflowRun.tsx
index 8f2c6e293..2ce8fb8ff 100644
--- a/skyvern-frontend/src/routes/workflows/WorkflowRun.tsx
+++ b/skyvern-frontend/src/routes/workflows/WorkflowRun.tsx
@@ -468,7 +468,7 @@ function WorkflowRun() {
proxyLocation,
webhookCallbackUrl: workflowRun?.webhook_callback_url ?? "",
maxScreenshotScrolls,
- runWith: workflowRun?.run_with,
+ runWith: workflowRun?.run_with ?? "agent",
}}
>
<PlayIcon className="mr-2 h-4 w-4" />
diff --git a/skyvern-frontend/src/routes/workflows/WorkflowRunParameters.tsx b/skyvern-frontend/src/routes/workflows/WorkflowRunParameters.tsx
index 081d3afb7..540785614 100644
--- a/skyvern-frontend/src/routes/workflows/WorkflowRunParameters.tsx
+++ b/skyvern-frontend/src/routes/workflows/WorkflowRunParameters.tsx
@@ -42,7 +42,7 @@ function WorkflowRunParameters() {
? (location.state.extraHttpHeaders as Record<string, string>)
: null;
- const runWith = (location.state?.runWith as string) ?? null;
+ const runWith = (location.state?.runWith as string) ?? undefined;
const initialValues = getInitialValues(location, workflowParameters ?? []);
diff --git a/skyvern-frontend/src/routes/workflows/components/WorkflowVisualComparisonDrawer.tsx b/skyvern-frontend/src/routes/workflows/components/WorkflowVisualComparisonDrawer.tsx
index 8bbaa42e6..604c88fbc 100644
--- a/skyvern-frontend/src/routes/workflows/components/WorkflowVisualComparisonDrawer.tsx
+++ b/skyvern-frontend/src/routes/workflows/components/WorkflowVisualComparisonDrawer.tsx
@@ -124,7 +124,7 @@ function getWorkflowElements(version: WorkflowVersion) {
extraHttpHeaders: version.extra_http_headers
? JSON.stringify(version.extra_http_headers)
: null,
- runWith: version.run_with,
+ runWith: version.run_with ?? "agent",
codeVersion: version.code_version ?? null,
scriptCacheKey: version.cache_key,
aiFallback: version.ai_fallback ?? true,
diff --git a/skyvern-frontend/src/routes/workflows/debugger/Debugger.tsx b/skyvern-frontend/src/routes/workflows/debugger/Debugger.tsx
index b7868c755..febd3014a 100644
--- a/skyvern-frontend/src/routes/workflows/debugger/Debugger.tsx
+++ b/skyvern-frontend/src/routes/workflows/debugger/Debugger.tsx
@@ -82,7 +82,7 @@ function Debugger() {
extraHttpHeaders: workflow.extra_http_headers
? JSON.stringify(workflow.extra_http_headers)
: null,
- runWith: workflow.run_with,
+ runWith: workflow.run_with ?? "agent",
codeVersion: workflow.code_version ?? null,
scriptCacheKey: workflow.cache_key,
aiFallback: workflow.ai_fallback ?? true,
diff --git a/skyvern-frontend/src/routes/workflows/editor/nodes/StartNode/types.ts b/skyvern-frontend/src/routes/workflows/editor/nodes/StartNode/types.ts
index 040b5b45d..eb64838f9 100644
--- a/skyvern-frontend/src/routes/workflows/editor/nodes/StartNode/types.ts
+++ b/skyvern-frontend/src/routes/workflows/editor/nodes/StartNode/types.ts
@@ -12,7 +12,7 @@ export type WorkflowStartNodeData = {
maxScreenshotScrolls: number | null;
extraHttpHeaders: string | Record<string, unknown> | null;
editable: boolean;
- runWith: string | null;
+ runWith: string;
codeVersion: number | null;
scriptCacheKey: string | null;
aiFallback: boolean;
diff --git a/skyvern-frontend/src/routes/workflows/editor/panels/WorkflowComparisonPanel.tsx b/skyvern-frontend/src/routes/workflows/editor/panels/WorkflowComparisonPanel.tsx
index 2322310f5..81cd127bd 100644
--- a/skyvern-frontend/src/routes/workflows/editor/panels/WorkflowComparisonPanel.tsx
+++ b/skyvern-frontend/src/routes/workflows/editor/panels/WorkflowComparisonPanel.tsx
@@ -156,7 +156,7 @@ function getWorkflowElements(version: WorkflowVersion) {
extraHttpHeaders: version.extra_http_headers
? JSON.stringify(version.extra_http_headers)
: null,
- runWith: version.run_with,
+ runWith: version.run_with ?? "agent",
codeVersion: version.code_version ?? null,
scriptCacheKey: version.cache_key,
aiFallback: version.ai_fallback ?? true,
diff --git a/skyvern-frontend/src/routes/workflows/editor/workflowEditorUtils.ts b/skyvern-frontend/src/routes/workflows/editor/workflowEditorUtils.ts
index 06a8157ac..1d6d12a47 100644
--- a/skyvern-frontend/src/routes/workflows/editor/workflowEditorUtils.ts
+++ b/skyvern-frontend/src/routes/workflows/editor/workflowEditorUtils.ts
@@ -4035,7 +4035,7 @@ function convert(workflow: WorkflowApiResponse): WorkflowCreateYAMLRequest {
},
is_saved_task: workflow.is_saved_task,
status: workflow.status,
- run_with: workflow.run_with,
+ run_with: workflow.run_with ?? "agent",
adaptive_caching: workflow.adaptive_caching ?? undefined,
code_version: workflow.code_version ?? undefined,
cache_key: workflow.cache_key,
diff --git a/skyvern-frontend/src/routes/workflows/types/workflowTypes.ts b/skyvern-frontend/src/routes/workflows/types/workflowTypes.ts
index b4faa5aaa..dac6f8e51 100644
--- a/skyvern-frontend/src/routes/workflows/types/workflowTypes.ts
+++ b/skyvern-frontend/src/routes/workflows/types/workflowTypes.ts
@@ -600,7 +600,7 @@ export type WorkflowApiResponse = {
created_at: string;
modified_at: string;
deleted_at: string | null;
- run_with: string | null; // 'agent' or 'code'
+ run_with: string; // 'agent' or 'code'
cache_key: string | null;
ai_fallback: boolean | null;
adaptive_caching: boolean | null;
@@ -618,7 +618,7 @@ export type WorkflowSettings = {
model: WorkflowModel | null;
maxScreenshotScrolls: number | null;
extraHttpHeaders: string | null;
- runWith: string | null; // 'agent' or 'code'
+ runWith: string; // 'agent' or 'code'
codeVersion: number | null;
scriptCacheKey: string | null;
aiFallback: boolean | null;
diff --git a/skyvern/cli/mcp_tools/workflow.py b/skyvern/cli/mcp_tools/workflow.py
index 747b05eab..e8fb47217 100644
--- a/skyvern/cli/mcp_tools/workflow.py
+++ b/skyvern/cli/mcp_tools/workflow.py
@@ -1113,7 +1113,10 @@ async def skyvern_workflow_run(
int, Field(description="Max wait time in seconds when wait=true (default 300)", ge=10, le=3600)
] = 300,
run_with: Annotated[
- str | None, Field(description="Execution mode override (e.g., 'code' for cached script execution)")
+ str | None,
+ Field(
+ description="Execution mode override (e.g., 'code' for cached script execution). Null inherits from workflow setting."
+ ),
] = None,
) -> dict[str, Any]:
"""Run a Skyvern workflow with parameters. Use when you need to execute an automation workflow.
diff --git a/skyvern/forge/sdk/workflow/models/validators.py b/skyvern/forge/sdk/workflow/models/validators.py
new file mode 100644
index 000000000..891e2efe0
--- /dev/null
+++ b/skyvern/forge/sdk/workflow/models/validators.py
@@ -0,0 +1,12 @@
+VALID_RUN_WITH_VALUES = ("agent", "code")
+
+
+def normalize_run_with(v: str | None) -> str:
+ """Normalize null and legacy 'code_v2' to valid run_with values."""
+ if v is None:
+ return "agent"
+ if v == "code_v2":
+ return "code"
+ if v not in VALID_RUN_WITH_VALUES:
+ raise ValueError(f"run_with must be 'agent' or 'code', got '{v}'")
+ return v
diff --git a/skyvern/forge/sdk/workflow/models/workflow.py b/skyvern/forge/sdk/workflow/models/workflow.py
index 7511aaeab..ff7bb7525 100644
--- a/skyvern/forge/sdk/workflow/models/workflow.py
+++ b/skyvern/forge/sdk/workflow/models/workflow.py
@@ -15,6 +15,7 @@ from skyvern.forge.sdk.workflow.exceptions import (
)
from skyvern.forge.sdk.workflow.models.block import BlockTypeVar, ForLoopBlock, get_all_blocks
from skyvern.forge.sdk.workflow.models.parameter import PARAMETER_TYPE, OutputParameter
+from skyvern.forge.sdk.workflow.models.validators import normalize_run_with
from skyvern.schemas.runs import ProxyLocationInput, ScriptRunResponse
from skyvern.schemas.workflows import WorkflowStatus
from skyvern.utils.url_validators import validate_url
@@ -102,7 +103,7 @@ class Workflow(BaseModel):
status: WorkflowStatus = WorkflowStatus.published
max_screenshot_scrolls: int | None = None
extra_http_headers: dict[str, str] | None = None
- run_with: str | None = None
+ run_with: str = "agent"
ai_fallback: bool = True
cache_key: str | None = None
adaptive_caching: bool = False
@@ -113,6 +114,11 @@ class Workflow(BaseModel):
folder_id: str | None = None
import_error: str | None = None
+ @field_validator("run_with", mode="before")
+ @classmethod
+ def _normalize_run_with(cls, v: str | None) -> str:
+ return normalize_run_with(v)
+
created_at: datetime
modified_at: datetime
deleted_at: datetime | None = None
@@ -182,6 +188,14 @@ class WorkflowRun(BaseModel):
trigger_type: WorkflowRunTriggerType | None = None
workflow_schedule_id: str | None = None
+ @field_validator("run_with", mode="before")
+ @classmethod
+ def _normalize_run_with(cls, v: str | None) -> str | None:
+ """Normalize legacy 'code_v2' but preserve None (means 'inherit from workflow')."""
+ if v == "code_v2":
+ return "code"
+ return v
+
queued_at: datetime | None = None
started_at: datetime | None = None
finished_at: datetime | None = None
@@ -195,21 +209,19 @@ def is_adaptive_caching(workflow: Workflow, workflow_run: WorkflowRun) -> bool:
Uses code_version >= 2 as the primary check. Falls back to the legacy
adaptive_caching bool for rows that haven't been backfilled yet
(code_version is None).
+
+ WorkflowRun.run_with is None when not explicitly set (inherits from workflow).
+ Workflow.run_with is always "code" or "agent" after normalization.
"""
run_with = workflow_run.run_with or workflow.run_with
- # Explicit agent mode → never adaptive
if run_with == "agent":
return False
- # When run_with is "code" (or legacy "code_v2"), check code_version
- if run_with in ("code", "code_v2"):
+ # run_with == "code": check code_version
+ if run_with == "code":
if workflow.code_version is not None:
return workflow.code_version >= 2
return workflow.adaptive_caching
- # run_with is None — check code_version as the implicit fallback
- # (workflows with code_version >= 2 implicitly run as code)
- if workflow.code_version is not None:
- return workflow.code_version >= 2
- return workflow.adaptive_caching
+ return False
class WorkflowRunParameter(BaseModel):
@@ -256,10 +268,15 @@ class WorkflowRunResponseBase(BaseModel):
browser_profile_id: str | None = None
max_screenshot_scrolls: int | None = None
browser_address: str | None = None
- run_with: str | None = None
+ run_with: str = "agent"
script_run: ScriptRunResponse | None = None
errors: list[dict[str, Any]] | None = None
+ @field_validator("run_with", mode="before")
+ @classmethod
+ def _normalize_run_with(cls, v: str | None) -> str:
+ return normalize_run_with(v)
+
class WorkflowRunWithWorkflowResponse(WorkflowRunResponseBase):
workflow: Workflow
diff --git a/skyvern/forge/sdk/workflow/service.py b/skyvern/forge/sdk/workflow/service.py
index fb61f244e..184b4b98d 100644
--- a/skyvern/forge/sdk/workflow/service.py
+++ b/skyvern/forge/sdk/workflow/service.py
@@ -623,6 +623,8 @@ class WorkflowService:
workflow_request.webhook_callback_url = workflow.webhook_callback_url
if workflow_request.extra_http_headers is None and workflow.extra_http_headers is not None:
workflow_request.extra_http_headers = workflow.extra_http_headers
+ if workflow_request.run_with is None:
+ workflow_request.run_with = workflow.run_with
# Force ai_fallback=True for adaptive caching (code_version >= 2) runs.
# Adaptive caching requires AI fallback to self-heal when cached scripts break.
@@ -630,7 +632,7 @@ class WorkflowService:
effective_code_version = (
workflow.code_version if workflow.code_version is not None else (2 if workflow.adaptive_caching else None)
)
- if (effective_code_version or 0) >= 2 and (workflow_request.run_with in ("code", None)):
+ if (effective_code_version or 0) >= 2 and (workflow_request.run_with == "code"):
if workflow_request.ai_fallback is False:
LOG.info(
"Overriding ai_fallback to True for adaptive caching run",
@@ -5425,22 +5427,11 @@ class WorkflowService:
) -> bool:
"""Determine whether this run should attempt to execute cached scripts.
- Priority: run-level run_with > workflow-level run_with > code_version fallback > default (agent).
- When code_version >= 1 at the workflow level and no explicit run_with is set,
- the run defaults to code mode so cached scripts are actually used.
+ Priority: run-level run_with (if set) > workflow-level run_with.
+ Workflow.run_with is always "code" or "agent" after normalization
+ (NULL and code_version fallback resolved at read time).
+ WorkflowRun.run_with is None when not explicitly set (inherits from workflow).
"""
- if workflow_run.run_with in ("code", "code_v2"):
- return True
- if workflow_run.run_with == "agent":
- return False
- if workflow.run_with in ("code", "code_v2"): # include legacy "code_v2" workflows
- return True
- if workflow.run_with == "agent":
- return False
- # No explicit run_with on either workflow or run — fall back to
- # code_version / adaptive_caching: if the workflow has caching enabled, run code.
- if workflow.code_version is not None:
- return workflow.code_version >= 1
- if workflow.adaptive_caching:
- return True
- return False
+ if workflow_run.run_with is not None:
+ return workflow_run.run_with == "code"
+ return workflow.run_with == "code"
diff --git a/skyvern/schemas/runs.py b/skyvern/schemas/runs.py
index 3837c7824..a75f77424 100644
--- a/skyvern/schemas/runs.py
+++ b/skyvern/schemas/runs.py
@@ -8,6 +8,7 @@ from zoneinfo import ZoneInfo
from pydantic import BaseModel, Field, field_validator
from skyvern.forge.sdk.schemas.files import FileInfo
+from skyvern.forge.sdk.workflow.models.validators import normalize_run_with
from skyvern.schemas.docs.doc_examples import (
BROWSER_SESSION_ID_EXAMPLES,
ERROR_CODE_MAPPING_EXAMPLES,
@@ -447,10 +448,17 @@ class TaskRunRequest(BaseModel):
)
run_with: str | None = Field(
default=None,
- description="Whether to run the task with agent or code.",
+ description="Whether to run the task with agent or code. Null means use the default.",
examples=["agent", "code"],
)
+ @field_validator("run_with", mode="before")
+ @classmethod
+ def _normalize_run_with(cls, v: str | None) -> str | None:
+ if v is None:
+ return None
+ return normalize_run_with(v)
+
@field_validator("url", "webhook_url", "totp_url")
@classmethod
def validate_urls(cls, url: str | None) -> str | None:
@@ -521,17 +529,16 @@ class WorkflowRunRequest(BaseModel):
)
run_with: str | None = Field(
default=None,
- description="Whether to run the workflow with agent or code.",
+ description="Whether to run the workflow with agent or code. Null inherits from the workflow setting.",
examples=["agent", "code"],
)
@field_validator("run_with", mode="before")
@classmethod
- def normalize_run_with(cls, v: str | None) -> str | None:
- """Normalize legacy 'code_v2' to 'code'."""
- if v == "code_v2":
- return "code"
- return v
+ def _normalize_run_with(cls, v: str | None) -> str | None:
+ if v is None:
+ return None
+ return normalize_run_with(v)
@field_validator("webhook_url", "totp_url")
@classmethod
@@ -640,19 +647,16 @@ class TaskRunResponse(BaseRunResponse):
class WorkflowRunResponse(BaseRunResponse):
run_type: Literal[RunType.workflow_run] = Field(description="Type of run - always workflow_run for workflow runs")
- run_with: str | None = Field(
- default=None,
+ run_with: str = Field(
+ default="agent",
description="Whether the workflow run was executed with agent or code",
examples=["agent", "code"],
)
@field_validator("run_with", mode="before")
@classmethod
- def normalize_run_with(cls, v: str | None) -> str | None:
- """Normalize legacy 'code_v2' to 'code' in API responses."""
- if v == "code_v2":
- return "code"
- return v
+ def _normalize_run_with(cls, v: str | None) -> str:
+ return normalize_run_with(v)
ai_fallback: bool | None = Field(
default=None,
diff --git a/skyvern/schemas/workflows.py b/skyvern/schemas/workflows.py
index ab1c1b33c..d938a70ab 100644
--- a/skyvern/schemas/workflows.py
+++ b/skyvern/schemas/workflows.py
@@ -11,6 +11,7 @@ from skyvern.config import settings
from skyvern.forge.sdk.api.llm.config_registry import LLMConfigRegistry
from skyvern.forge.sdk.settings_manager import SettingsManager
from skyvern.forge.sdk.workflow.models.parameter import OutputParameter, ParameterType, WorkflowParameterType
+from skyvern.forge.sdk.workflow.models.validators import normalize_run_with
from skyvern.schemas.runs import GeoTarget, ProxyLocation, RunEngine
from skyvern.utils.strings import sanitize_identifier
from skyvern.utils.templating import replace_jinja_reference
@@ -1074,7 +1075,7 @@ class WorkflowCreateYAMLRequest(BaseModel):
max_screenshot_scrolls: int | None = None
extra_http_headers: dict[str, str] | None = None
status: WorkflowStatus = WorkflowStatus.published
- run_with: str | None = None
+ run_with: str = "agent"
ai_fallback: bool = True
cache_key: str | None = "default"
adaptive_caching: bool = False
@@ -1084,6 +1085,11 @@ class WorkflowCreateYAMLRequest(BaseModel):
sequential_key: str | None = None
folder_id: str | None = None
+ @field_validator("run_with", mode="before")
+ @classmethod
+ def _normalize_run_with(cls, v: str | None) -> str:
+ return normalize_run_with(v)
+
class WorkflowRequest(BaseModel):
json_definition: WorkflowCreateYAMLRequest | None = Field(
diff --git a/tests/unit/test_mcp_workflow_create_defaults.py b/tests/unit/test_mcp_workflow_create_defaults.py
index 97fc23b5c..fa9b89f3c 100644
--- a/tests/unit/test_mcp_workflow_create_defaults.py
+++ b/tests/unit/test_mcp_workflow_create_defaults.py
@@ -130,5 +130,5 @@ def test_parse_definition_unaffected() -> None:
json_def, _, err = _parse_definition(definition, "json")
assert err is None
assert json_def is not None
- # run_with should be None (schema default), not "code"
- assert json_def.run_with is None
+ # run_with should be "agent" (schema default), not "code"
+ assert json_def.run_with == "agent"
diff --git a/tests/unit/test_should_run_script.py b/tests/unit/test_should_run_script.py
index 4d033c295..de4bdd76a 100644
--- a/tests/unit/test_should_run_script.py
+++ b/tests/unit/test_should_run_script.py
@@ -2,10 +2,9 @@
Verifies the priority chain:
run-level run_with > workflow-level run_with > code_version fallback > default (agent).
-When code_version >= 1 and no explicit run_with is set, the run defaults to code mode.
-Also verifies that the script reviewer only fires when the script was actually
-executed (should_run_script=True), not merely when adaptive caching is enabled.
+run_with is always "agent" or "code" (never null). When run_with="agent" and
+code_version >= 1, the code_version fallback still applies (workflow intended code mode).
"""
from datetime import datetime, timezone
@@ -21,7 +20,7 @@ from skyvern.forge.sdk.workflow.models.workflow import (
def _make_workflow(
- run_with: str | None = None,
+ run_with: str = "agent",
adaptive_caching: bool = False,
code_version: int | None = None,
) -> Workflow:
@@ -41,7 +40,7 @@ def _make_workflow(
)
-def _make_run(run_with: str | None = None) -> WorkflowRun:
+def _make_run(run_with: str = "agent") -> WorkflowRun:
return WorkflowRun(
workflow_run_id="wr_test",
workflow_id="wf_test",
@@ -76,56 +75,67 @@ class TestShouldRunScript:
def test_run_agent_overrides_code_version(self, service):
"""Explicit run-level agent overrides code_version fallback."""
- wf = _make_workflow(run_with=None, code_version=2)
+ wf = _make_workflow(run_with="agent", code_version=2)
wr = _make_run(run_with="agent")
assert service.should_run_script(wf, wr) is False
- def test_workflow_code_with_null_run(self, service):
+ def test_workflow_code_with_agent_run(self, service):
+ """Workflow says code, run says agent → run wins."""
wf = _make_workflow(run_with="code")
- wr = _make_run(run_with=None)
- assert service.should_run_script(wf, wr) is True
+ wr = _make_run(run_with="agent")
+ assert service.should_run_script(wf, wr) is False
- def test_workflow_agent_with_null_run(self, service):
+ def test_workflow_agent_with_agent_run(self, service):
wf = _make_workflow(run_with="agent")
- wr = _make_run(run_with=None)
+ wr = _make_run(run_with="agent")
assert service.should_run_script(wf, wr) is False
def test_workflow_agent_overrides_code_version(self, service):
"""Explicit workflow-level agent takes priority over code_version."""
wf = _make_workflow(run_with="agent", code_version=2)
- wr = _make_run(run_with=None)
+ wr = _make_run(run_with="agent")
assert service.should_run_script(wf, wr) is False
- def test_both_null_defaults_to_agent(self, service):
- """When neither workflow nor run specifies run_with and no code_version, default to agent."""
- wf = _make_workflow(run_with=None)
- wr = _make_run(run_with=None)
+ def test_both_agent_defaults_to_agent(self, service):
+ """When both workflow and run are agent, default to agent."""
+ wf = _make_workflow(run_with="agent")
+ wr = _make_run(run_with="agent")
assert service.should_run_script(wf, wr) is False
- def test_code_version_defaults_to_code(self, service):
- """code_version >= 1 with run_with=null should default to code mode."""
- wf = _make_workflow(run_with=None, code_version=2)
- wr = _make_run(run_with=None)
- assert service.should_run_script(wf, wr) is True
+ def test_code_version_with_agent_run_with(self, service):
+ """code_version >= 1 with run_with=agent should still check code_version fallback."""
+ wf = _make_workflow(run_with="agent", code_version=2)
+ wr = _make_run(run_with="agent")
+ # run_with=agent on both sides → agent wins, code_version ignored
+ assert service.should_run_script(wf, wr) is False
- def test_code_version_1_defaults_to_code(self, service):
- """code_version=1 with run_with=null should also run code."""
- wf = _make_workflow(run_with=None, code_version=1)
- wr = _make_run(run_with=None)
- assert service.should_run_script(wf, wr) is True
+ def test_code_version_with_code_run_with(self, service):
+ """code_version >= 1 with explicit run_with=code should run code."""
+ wf = _make_workflow(run_with="code", code_version=2)
+ wr = _make_run(run_with="agent")
+ # run-level agent overrides workflow code
+ assert service.should_run_script(wf, wr) is False
- def test_code_version_with_workflow_code_runs_code(self, service):
- """code_version=2 with run_with=code should run code."""
+ def test_workflow_code_run_code(self, service):
+ """Both workflow and run say code → code."""
wf = _make_workflow(run_with="code", code_version=2)
- wr = _make_run(run_with=None)
+ wr = _make_run(run_with="code")
assert service.should_run_script(wf, wr) is True
- def test_legacy_adaptive_caching_fallback(self, service):
- """Legacy adaptive_caching=True with no code_version should still default to code."""
- wf = _make_workflow(run_with=None, adaptive_caching=True)
- wr = _make_run(run_with=None)
+ def test_workflow_code_no_code_version(self, service):
+ """Workflow says code, no code_version → should still run code."""
+ wf = _make_workflow(run_with="code")
+ wr = _make_run(run_with="code")
assert service.should_run_script(wf, wr) is True
+ def test_legacy_adaptive_caching_does_not_override_agent(self, service):
+ """Legacy adaptive_caching=True does NOT override explicit run_with=agent."""
+ wf = _make_workflow(run_with="agent", adaptive_caching=True)
+ wr = _make_run(run_with="agent")
+ # Explicit agent wins — adaptive_caching is a legacy fallback
+ # that only applied when run_with was null (no longer possible).
+ assert service.should_run_script(wf, wr) is False
+
class TestScriptReviewerGate:
"""The script reviewer should only fire when the script was actually executed.
@@ -135,26 +145,26 @@ class TestScriptReviewerGate:
"""
@pytest.mark.parametrize(
- "run_with,code_version,expect_reviewer",
+ "wf_run_with,run_run_with,code_version,expect_reviewer",
[
- ("code", 2, True), # code + code_version=2 → adaptive caching on
- ("code", 1, False), # code + code_version=1 → adaptive caching off
- (None, 2, True), # code_version=2 defaults to code mode, adaptive
- (None, None, False), # no code_version, no run_with → agent
- ("agent", 2, False), # agent overrides everything
- ("agent", None, False),
- ("code", None, False), # code without code_version → not adaptive
+ ("code", "code", 2, True), # code + code_version=2 → adaptive caching on
+ ("code", "code", 1, False), # code + code_version=1 → adaptive caching off
+ ("agent", "agent", 2, False), # agent overrides everything
+ ("agent", "agent", None, False), # agent, no code_version
+ ("code", "agent", 2, False), # run-level agent overrides
+ ("agent", "code", None, False), # code without code_version → not adaptive
+ ("agent", "code", 2, True), # run-level code + code_version=2 → adaptive
],
)
- def test_reviewer_gate(self, service, run_with, code_version, expect_reviewer):
- wf = _make_workflow(run_with=None, code_version=code_version)
- wr = _make_run(run_with=run_with)
+ def test_reviewer_gate(self, service, wf_run_with, run_run_with, code_version, expect_reviewer):
+ wf = _make_workflow(run_with=wf_run_with, code_version=code_version)
+ wr = _make_run(run_with=run_run_with)
should_review = is_adaptive_caching(wf, wr) and service.should_run_script(wf, wr)
assert should_review is expect_reviewer
def test_legacy_adaptive_caching_backward_compat(self, service):
"""Legacy adaptive_caching=True with code_version=None still enables reviewer."""
- wf = _make_workflow(run_with=None, adaptive_caching=True, code_version=None)
+ wf = _make_workflow(run_with="agent", adaptive_caching=True, code_version=None)
wr = _make_run(run_with="code")
should_review = is_adaptive_caching(wf, wr) and service.should_run_script(wf, wr)
assert should_review is True