Automate browser based workflows with AI
Python aiapiautomationbrowserbrowser-automationcomputergptllmplaywrightpowerautomatepuppeteerpythonrpaseleniumvisionworkflow
fix(SKY-11217): restore parameter-value search on the v2 runs list (#6796)
Aaron Perez842905a7f472
diff --git a/skyvern/forge/sdk/db/repositories/workflow_runs.py b/skyvern/forge/sdk/db/repositories/workflow_runs.pyindex 22993aa96..e33117abd 100644--- a/skyvern/forge/sdk/db/repositories/workflow_runs.py+++ b/skyvern/forge/sdk/db/repositories/workflow_runs.py@@ -624,6 +624,13 @@ class WorkflowRunsRepository(BaseRepository):TaskRunModel.searchable_text.icontains(search_key, autoescape=True),TaskRunModel.run_id.icontains(search_key, autoescape=True),effective_wpid.icontains(search_key, autoescape=True),+ # task_runs.searchable_text is only title+url, so agent inputs are matched via+ # workflow_run_parameters / extra_http_headers correlated on this run's run_id.+ *self._run_input_search_clauses(+ search_key,+ TaskRunModel.run_id,+ WorkflowRunModel.extra_http_headers,+ ),))@@ -903,20 +910,17 @@ class WorkflowRunsRepository(BaseRepository):return [convert_to_workflow_run(workflow_run) for workflow_run in workflow_runs]@staticmethod- def _apply_workflow_run_search_key_filter(query, search_key: str | None): # type: ignore[no-untyped-def]- if not search_key:- return query- # Call only on WorkflowRunModel queries that already join WorkflowModel. The TaskRunModel query in- # get_all_runs_v2 uses its own filter so workflow-title search cannot add an implicit workflows FROM.- # Match workflow_run_id directly- id_matches = WorkflowRunModel.workflow_run_id.icontains(search_key, autoescape=True)- workflow_title_matches = WorkflowModel.title.icontains(search_key, autoescape=True)- workflow_permanent_id_matches = WorkflowRunModel.workflow_permanent_id.icontains(- search_key,- autoescape=True,- )- # Match parameter key or description (only for non-deleted parameter definitions)- # Use EXISTS to avoid duplicate rows and to keep pagination correct+ def _run_input_search_clauses(+ search_key: str,+ workflow_run_id_col: ColumnElement[Any],+ extra_http_headers_col: ColumnElement[Any],+ ) -> list[ColumnElement[bool]]:+ """Clauses matching a run's agent inputs: workflow_run_parameters (key/description/value)+ and extra_http_headers, correlated on the given workflow_run_id column. Self-contained+ subqueries, so they OR into either the task_runs or workflow_runs search without adding an+ implicit FROM."""+ # Match parameter key or description (only for non-deleted parameter definitions).+ # Use EXISTS to avoid duplicate rows and to keep pagination correct.param_key_desc_exists = exists(select(1).select_from(WorkflowRunParameterModel)@@ -924,7 +928,7 @@ class WorkflowRunsRepository(BaseRepository):WorkflowParameterModel,WorkflowParameterModel.workflow_parameter_id == WorkflowRunParameterModel.workflow_parameter_id,)- .where(WorkflowRunParameterModel.workflow_run_id == WorkflowRunModel.workflow_run_id)+ .where(WorkflowRunParameterModel.workflow_run_id == workflow_run_id_col).where(WorkflowParameterModel.deleted_at.is_(None)).where(or_(@@ -933,26 +937,42 @@ class WorkflowRunsRepository(BaseRepository):)))- # Match run parameter value directly (searches all values regardless of parameter definition status)+ # Match run parameter value directly (searches all values regardless of parameter definition status).param_value_exists = exists(select(1).select_from(WorkflowRunParameterModel)- .where(WorkflowRunParameterModel.workflow_run_id == WorkflowRunModel.workflow_run_id)+ .where(WorkflowRunParameterModel.workflow_run_id == workflow_run_id_col).where(WorkflowRunParameterModel.value.icontains(search_key, autoescape=True)))- # Match extra HTTP headers (cast JSON to text for search, skip NULLs)+ # Match extra HTTP headers (cast JSON to text for search, skip NULLs).extra_headers_match = and_(- WorkflowRunModel.extra_http_headers.isnot(None),- func.cast(WorkflowRunModel.extra_http_headers, Text()).icontains(search_key, autoescape=True),+ extra_http_headers_col.isnot(None),+ func.cast(extra_http_headers_col, Text()).icontains(search_key, autoescape=True),+ )+ return [param_key_desc_exists, param_value_exists, extra_headers_match]++ @staticmethod+ def _apply_workflow_run_search_key_filter(query, search_key: str | None): # type: ignore[no-untyped-def]+ if not search_key:+ return query+ # Call only on WorkflowRunModel queries that already join WorkflowModel. The TaskRunModel query in+ # get_all_runs_v2 uses its own filter so workflow-title search cannot add an implicit workflows FROM.+ id_matches = WorkflowRunModel.workflow_run_id.icontains(search_key, autoescape=True)+ workflow_title_matches = WorkflowModel.title.icontains(search_key, autoescape=True)+ workflow_permanent_id_matches = WorkflowRunModel.workflow_permanent_id.icontains(+ search_key,+ autoescape=True,)return query.where(or_(id_matches,workflow_title_matches,workflow_permanent_id_matches,- param_key_desc_exists,- param_value_exists,- extra_headers_match,+ *WorkflowRunsRepository._run_input_search_clauses(+ search_key,+ WorkflowRunModel.workflow_run_id,+ WorkflowRunModel.extra_http_headers,+ ),))diff --git a/tests/unit/forge/sdk/db/test_workflow_runs_repository.py b/tests/unit/forge/sdk/db/test_workflow_runs_repository.pyindex 0d83169fb..7759d45c2 100644--- a/tests/unit/forge/sdk/db/test_workflow_runs_repository.py+++ b/tests/unit/forge/sdk/db/test_workflow_runs_repository.py@@ -228,6 +228,38 @@ async def test_get_all_runs_v2_search_key_matches_run_id_and_workflow_permanent_assert f"LIMIT {MAX_SEARCH_FETCH_LIMIT}" in _query_sql(query)+async def test_get_all_runs_v2_search_key_matches_parameter_inputs() -> None:+ """Regression test for SKY-11217: Run History search must match agent input values+ (workflow_run_parameters key/description/value + extra_http_headers) on the primary+ task_runs query — not only searchable_text/run_id/wpid. The SKY-7600 unified task_runs+ migration repointed the runs list to the v2 path and dropped parameter-value search for+ runs that have a task_runs row (the common case); the fallback query only covers orphan+ workflow_runs, so param search must live on the primary query too."""+ captured_queries: list[Any] = []++ async def _execute(query):+ captured_queries.append(query)+ return _EmptyExecuteResult()++ session = MagicMock()+ session.execute = AsyncMock(side_effect=_execute)++ repo = WorkflowRunsRepository(session_factory=lambda: _SessionContext(session), debug_enabled=False)++ await repo.get_all_runs_v2(organization_id="o_test", search_key="Paris")++ primary_where = _where_clause_sql(captured_queries[0])+ # Parameter EXISTS subqueries correlate on the run_id of the primary task_runs row.+ assert "workflow_run_parameters.workflow_run_id = task_runs.run_id" in primary_where+ assert "workflow_run_parameters.value" in primary_where+ assert "workflow_parameters.key" in primary_where+ assert "workflow_parameters.description" in primary_where+ assert "extra_http_headers" in primary_where+ # Param search must not drag workflows.title into the primary query (no implicit FROM workflows).+ assert ".".join(("workflows", "title")) not in primary_where++@pytest.mark.asyncioasync def test_get_all_runs_v2_selects_workflow_deleted_flag() -> None:captured: dict[str, Any] = {}