Automate browser based workflows with AI
Python aiapiautomationbrowserbrowser-automationcomputergptllmplaywrightpowerautomatepuppeteerpythonrpaseleniumvisionworkflow
fix(SKY-12831): co-locate copilot run-tool narration + name unmapped tools (SKY-12385) (#7660)
Celal Zamanoğlub1a907e61100
diff --git a/skyvern-frontend/src/routes/workflows/copilot/NarrativeView.test.ts b/skyvern-frontend/src/routes/workflows/copilot/NarrativeView.test.tsindex 80ec5c75e..7213ffe8d 100644--- a/skyvern-frontend/src/routes/workflows/copilot/NarrativeView.test.ts+++ b/skyvern-frontend/src/routes/workflows/copilot/NarrativeView.test.ts@@ -376,6 +376,33 @@ describe("applyNarrativeEvent — activity", () => {});expect(s.designActivity[0]?.text).not.toContain("update_and_run_blocks");});++ it("co-locates a run tool's result with its call after a block starts running (SKY-12831)", () => {+ // The call lands in designActivity (no block running yet); the run then+ // flips a block to running. The result must rejoin the call in+ // designActivity so the pair folds — not land in the block card.+ const afterCall = applyNarrativeEvent(+ EMPTY_NARRATIVE,+ toolCall({ tool_call_id: "call-1" }),+ );+ const afterBlock = applyNarrativeEvent(+ afterCall,+ blockProgress({ block_label: "step_1", status: "running" }),+ );+ const s = applyNarrativeEvent(+ afterBlock,+ toolResult({ tool_call_id: "call-1" }),+ );++ expect(s.designActivity.map((e) => e.id)).toEqual([+ "tc-call-1",+ "tr-call-1",+ ]);+ expect(+ s.blocks.find((b) => b.label === "step_1")?.activity ?? [],+ ).toHaveLength(0);+ expect(condenseActivityEntries(s.designActivity)).toHaveLength(1);+ });});describe("condenseActivityEntries", () => {diff --git a/skyvern-frontend/src/routes/workflows/copilot/copilotPhases.test.ts b/skyvern-frontend/src/routes/workflows/copilot/copilotPhases.test.tsindex 6d6aae453..3b7586b44 100644--- a/skyvern-frontend/src/routes/workflows/copilot/copilotPhases.test.ts+++ b/skyvern-frontend/src/routes/workflows/copilot/copilotPhases.test.ts@@ -12,6 +12,7 @@ import {BlockState,EMPTY_NARRATIVE,TurnNarrativeState,+ toolActivityDisplayLabel,} from "./narrativeState";const entry = (@@ -66,6 +67,21 @@ describe("AUTHORING_TOOLS / RUN_TOOLS", () => {});});+describe("toolActivityDisplayLabel — discovery tools (SKY-12385)", () => {+ it("labels discover_workflow_entrypoint and inspect_page_for_composition", () => {+ expect(toolActivityDisplayLabel("discover_workflow_entrypoint")).toBe(+ "Finding the entry page",+ );+ expect(toolActivityDisplayLabel("inspect_page_for_composition")).toBe(+ "Inspecting the page",+ );+ });++ it("still falls back to Working for unmapped tools", () => {+ expect(toolActivityDisplayLabel("some_unmapped_tool")).toBe("Working");+ });+});+describe("derivePhases — bucket split keeps update_workflow in Draft (Codex catch)", () => {it("an update_workflow tool_call on a draft-only turn lands in the Draft bucket, not Test", () => {const t = turn({diff --git a/skyvern-frontend/src/routes/workflows/copilot/narrativeState.ts b/skyvern-frontend/src/routes/workflows/copilot/narrativeState.tsindex 3143de2a2..ef1a15541 100644--- a/skyvern-frontend/src/routes/workflows/copilot/narrativeState.ts+++ b/skyvern-frontend/src/routes/workflows/copilot/narrativeState.ts@@ -334,6 +334,8 @@ const ACTIVITY_TOOL_DISPLAY_LABELS: Record<string, string> = {navigate_browser: "Opening page",get_block_schema: "Checking workflow block options",inspect_current_workflow: "Inspecting workflow",+ discover_workflow_entrypoint: "Finding the entry page",+ inspect_page_for_composition: "Inspecting the page",};export function toolActivityDisplayLabel(toolName?: string | null): string {@@ -521,6 +523,39 @@ function appendActivity(designActivity: ActivityEntry[],entry: ActivityEntry,): { blocks: BlockState[]; designActivity: ActivityEntry[] } {+ // A run tool's result must rejoin its call's bucket. The run flips the active+ // block between the call and the result, so routing the result to the live+ // active block would split the call/result pair across buckets and it could+ // never fold (mirrors the backend NarratorState._activity_bucket_label fix).+ if (+ entry.kind === "tool_result" &&+ entry.toolName !== undefined &&+ RUN_TOOLS.has(entry.toolName)+ ) {+ const callId = `tc-${toolCallIdOf(entry) ?? ""}`;+ if (designActivity.some((e) => e.id === callId)) {+ return {+ blocks,+ designActivity: appendCapped(+ designActivity,+ entry,+ MAX_DESIGN_ACTIVITY_ENTRIES,+ ),+ };+ }+ const callBlockIdx = blocks.findIndex((b) =>+ b.activity.some((e) => e.id === callId),+ );+ if (callBlockIdx !== -1) {+ const nextBlocks = blocks.slice();+ const callBlock = nextBlocks[callBlockIdx]!;+ nextBlocks[callBlockIdx] = {+ ...callBlock,+ activity: appendCapped(callBlock.activity, entry, MAX_ACTIVITY_ENTRIES),+ };+ return { blocks: nextBlocks, designActivity };+ }+ }const activeIdx = blocks.findIndex((b) => b.state === "running");if (activeIdx === -1) {return {diff --git a/skyvern/forge/sdk/copilot/narration.py b/skyvern/forge/sdk/copilot/narration.pyindex 52845ec90..d4eca57c4 100644--- a/skyvern/forge/sdk/copilot/narration.py+++ b/skyvern/forge/sdk/copilot/narration.py@@ -72,6 +72,12 @@ MAX_DESIGN_ACTIVITY_ENTRIES = 50# Mirror of the FE ACTIVITY_TOOL_DENYLIST in narrativeState.ts.ACTIVITY_TOOL_DENYLIST = frozenset({"list_credentials", "get_run_results", "get_browser_screenshot"})+# Tools that kick off a block run. Mirror of the FE RUN_TOOLS in narrativeState.ts.+# Their tool_call is recorded before the run flips running_block_label to the+# running block, so the matching tool_result is pinned to the call's bucket (see+# NarratorState._activity_bucket_label) rather than routed live.+_RUN_ACTIVITY_TOOLS = frozenset({"update_and_run_blocks", "run_blocks_and_collect_debug"})+# Shared classification for a code-authoring reject the streaming adapter renders# as quiet de-duplicated progress. Tagged on the reject (workflow_update) and# consumed by the SSE layer (streaming_adapter) — one source of truth for both.@@ -92,6 +98,8 @@ _TOOL_ACTIVITY_DISPLAY_LABELS = {"navigate_browser": "Opening page","get_block_schema": "Checking workflow block options","inspect_current_workflow": "Inspecting workflow",+ "discover_workflow_entrypoint": "Finding the entry page",+ "inspect_page_for_composition": "Inspecting the page",}@@ -195,13 +203,17 @@ class NarratorState:block_activity: dict[str, list[NarrativeActivityEntry]] = field(default_factory=dict)design_activity: list[NarrativeActivityEntry] = field(default_factory=list)running_block_label: str | None = None+ # tool_call_id -> the bucket its tool_call landed in, tracked for+ # _RUN_ACTIVITY_TOOLS only so the later tool_result rejoins the call's bucket.+ # An unmatched call (result never arrives) is bounded by this state's one-turn lifetime.+ run_tool_call_buckets: dict[str, str | None] = field(default_factory=dict)# Per-turn (NarratorState lives one turn); collapses repeated code-repair progress to one entry.emitted_progress_texts: set[str] = field(default_factory=set)def record_activity(self, entry: NarrativeActivityEntry | None) -> None:if entry is None:return- label = self.running_block_label+ label = self._activity_bucket_label(entry)if label is None:self.design_activity.append(entry)if len(self.design_activity) > MAX_DESIGN_ACTIVITY_ENTRIES:@@ -212,6 +224,25 @@ class NarratorState:if len(bucket) > MAX_BLOCK_ACTIVITY_ENTRIES:del bucket[:-MAX_BLOCK_ACTIVITY_ENTRIES]+ def _activity_bucket_label(self, entry: NarrativeActivityEntry) -> str | None:+ """Bucket an entry to a running block (its label) or design (None).++ A run tool's call is recorded before the run it triggers flips+ running_block_label, so routing its result live would split the+ call/result pair across buckets and the FE could never fold it. Pin the+ result to the call's bucket by tool_call_id; everything else routes live.+ """+ entry_id = entry.get("id") or ""+ if entry.get("kind") == "tool_call" and entry.get("toolName") in _RUN_ACTIVITY_TOOLS:+ bucket = self.running_block_label+ self.run_tool_call_buckets[entry_id.removeprefix("tc-")] = bucket+ return bucket+ if entry.get("kind") == "tool_result":+ call_id = entry_id.removeprefix("tr-")+ if call_id in self.run_tool_call_buckets:+ return self.run_tool_call_buckets.pop(call_id)+ return self.running_block_label+def record_tool(self,tool_name: str,diff --git a/skyvern/forge/sdk/copilot/output_utils.py b/skyvern/forge/sdk/copilot/output_utils.pyindex 37aa8eb97..4b5df4f4f 100644--- a/skyvern/forge/sdk/copilot/output_utils.py+++ b/skyvern/forge/sdk/copilot/output_utils.py@@ -499,8 +499,16 @@ def summarize_tool_result(tool_name: str, result: dict[str, Any]) -> str:if tool_name == "update_workflow":return f"Workflow updated ({data.get('block_count', '?')} blocks)"- if tool_name == "update_and_run_blocks" and data.get("skipped_run"):- return f"Workflow updated ({data.get('block_count', '?')} blocks); browser run skipped"+ if tool_name == "update_and_run_blocks":+ if not isinstance(raw_data, dict):+ return "OK"+ if data.get("skipped_run"):+ return f"Workflow updated ({data.get('block_count', '?')} blocks); browser run skipped"+ # Non-skip result is run-blocks-shaped (overall_status, no block_count).+ status = data.get("overall_status") or data.get("status")+ if status:+ return f"Updated the workflow and ran it: {status}"+ return "Updated the workflow and ran it"if tool_name == "list_credentials":return f"Found {data.get('count', 0)} credential(s)"if tool_name == "get_block_schema":@@ -548,6 +556,18 @@ def summarize_tool_result(tool_name: str, result: dict[str, Any]) -> str:return f"Selected '{data.get('value', '?')}'"if tool_name == "press_key":return f"Pressed '{data.get('key', '?')}'"+ if tool_name == "discover_workflow_entrypoint":+ candidate_url = data.get("candidate_url")+ if isinstance(candidate_url, str) and candidate_url:+ return f"Found the entry page: {candidate_url[:80]}"+ return "No entry page found"+ if tool_name == "inspect_page_for_composition":+ raw_forms = data.get("forms")+ forms = raw_forms if isinstance(raw_forms, list) else []+ field_count = sum(len(f.get("fields") or []) for f in forms if isinstance(f, dict))+ if field_count:+ return f"Inspected the page ({field_count} form field(s))"+ return "Inspected the page"return "OK"diff --git a/tests/unit/test_copilot_narrative_activity.py b/tests/unit/test_copilot_narrative_activity.pyindex 6f7a49447..54f7a64c5 100644--- a/tests/unit/test_copilot_narrative_activity.py+++ b/tests/unit/test_copilot_narrative_activity.py@@ -12,6 +12,7 @@ from skyvern.forge.sdk.copilot.narration import (build_narration_activity,build_tool_call_activity,build_tool_result_activity,+ tool_activity_display_label,)@@ -124,6 +125,39 @@ def test_record_activity_caps_keep_most_recent() -> None:assert design_state.design_activity[0]["text"] == "n5"+def test_record_activity_pins_run_tool_result_to_its_call_bucket() -> None:+ # A run tool's call is recorded before the run it triggers flips+ # running_block_label; its result must rejoin the call's bucket so the FE+ # folds the pair instead of stranding the call row "calling…".+ state = NarratorState()+ state.record_activity(build_tool_call_activity("update_and_run_blocks", 0, "c1"))+ assert [e["id"] for e in state.design_activity] == ["tc-c1"]++ state.running_block_label = "step_1"+ state.record_activity(build_tool_result_activity("update_and_run_blocks", "Workflow updated", True, 1, "c1"))++ assert [e["id"] for e in state.design_activity] == ["tc-c1", "tr-c1"]+ assert state.block_activity == {}+++def test_record_activity_non_run_tool_result_routes_live_not_pinned() -> None:+ # The pin is scoped to run tools; other tools keep live running_block_label routing.+ state = NarratorState()+ state.record_activity(build_tool_call_activity("evaluate", 0, "c9"))+ assert [e["id"] for e in state.design_activity] == ["tc-c9"]++ state.running_block_label = "step_2"+ state.record_activity(build_tool_result_activity("evaluate", "Inspecting page", True, 1, "c9"))++ assert [e["id"] for e in state.block_activity["step_2"]] == ["tr-c9"]+ assert [e["id"] for e in state.design_activity] == ["tc-c9"]+++def test_tool_activity_display_label_covers_discovery_tools() -> None:+ assert tool_activity_display_label("discover_workflow_entrypoint") == "Finding the entry page"+ assert tool_activity_display_label("inspect_page_for_composition") == "Inspecting the page"++def test_build_narrative_payload_serializes_block_and_design_activity() -> None:ctx = _ctx()ctx.staged_workflow = _staged("step_1", "step_2") # type: ignore[assignment]diff --git a/tests/unit/test_copilot_output_utils.py b/tests/unit/test_copilot_output_utils.pyindex faeebaa1b..2eefc0b66 100644--- a/tests/unit/test_copilot_output_utils.py+++ b/tests/unit/test_copilot_output_utils.py@@ -357,6 +357,57 @@ class TestSummarizeToolResult:summary = self._summarize("unknown_tool", {"ok": True})assert summary == "OK"+ def test_update_and_run_blocks_success_reports_run_status(self) -> None:+ # The non-skip result is run-blocks-shaped (overall_status, executed_block_labels);+ # it never carries block_count, so the summary must not fabricate a count.+ summary = self._summarize(+ "update_and_run_blocks",+ {"ok": True, "data": {"overall_status": "completed", "executed_block_labels": ["step_1"]}},+ )+ assert summary == "Updated the workflow and ran it: completed"++ def test_update_and_run_blocks_success_without_status(self) -> None:+ summary = self._summarize(+ "update_and_run_blocks",+ {"ok": True, "data": {"executed_block_labels": ["step_1"]}},+ )+ assert summary == "Updated the workflow and ran it"++ def test_update_and_run_blocks_skipped_run_still_reported(self) -> None:+ summary = self._summarize(+ "update_and_run_blocks",+ {"ok": True, "data": {"block_count": 3, "skipped_run": True}},+ )+ assert summary == "Workflow updated (3 blocks); browser run skipped"++ def test_discover_workflow_entrypoint_found(self) -> None:+ summary = self._summarize(+ "discover_workflow_entrypoint",+ {"ok": True, "data": {"candidate_url": "https://example.com/apply"}},+ )+ assert summary == "Found the entry page: https://example.com/apply"++ def test_discover_workflow_entrypoint_not_found(self) -> None:+ summary = self._summarize(+ "discover_workflow_entrypoint",+ {"ok": True, "data": {"candidate_url": None, "failure_reason": "no_candidate"}},+ )+ assert summary == "No entry page found"++ def test_inspect_page_for_composition_reports_field_count(self) -> None:+ summary = self._summarize(+ "inspect_page_for_composition",+ {"ok": True, "data": {"forms": [{"fields": [{}, {}]}, {"fields": [{}]}]}},+ )+ assert summary == "Inspected the page (3 form field(s))"++ def test_inspect_page_for_composition_no_forms(self) -> None:+ summary = self._summarize(+ "inspect_page_for_composition",+ {"ok": True, "data": {"forms": []}},+ )+ assert summary == "Inspected the page"+def test_evaluate_does_not_dump_raw_list(self) -> None:# The activity bullet must describe shape only — JS return values# (which are page-controlled) must never reach the SSE payload.