Automate browser based workflows with AI
Python aiapiautomationbrowserbrowser-automationcomputergptllmplaywrightpowerautomatepuppeteerpythonrpaseleniumvisionworkflow
feat(SKY-12766): surface run id on copilot block_progress frames (#7608)
Celal Zamanoğlua4652f559bac
diff --git a/skyvern/forge/sdk/copilot/narration.py b/skyvern/forge/sdk/copilot/narration.pyindex f10b9ceb0..52845ec90 100644--- a/skyvern/forge/sdk/copilot/narration.py+++ b/skyvern/forge/sdk/copilot/narration.py@@ -823,6 +823,7 @@ async def narrator_poll_tick(block_state_map: dict[str, str] | None = None,block_started_at_map: dict[str, str] | None = None,block_ended_at_map: dict[str, str] | None = None,+ workflow_run_id: str | None = None,) -> NarratorPollTickResult:"""Per-tick narrator bookkeeping; returns updated (prior_block_ts, last_block_fetch_monotonic).@@ -900,6 +901,7 @@ async def narrator_poll_tick(WorkflowCopilotBlockProgressUpdate(type=WorkflowCopilotStreamMessageType.BLOCK_PROGRESS,workflow_run_block_id=event.block_id,+ workflow_run_id=workflow_run_id,block_label=event.block_label,block_type=event.block_type,status=event.status,diff --git a/skyvern/forge/sdk/copilot/tools/run_execution.py b/skyvern/forge/sdk/copilot/tools/run_execution.pyindex 226e7e87d..9cc06fb42 100644--- a/skyvern/forge/sdk/copilot/tools/run_execution.py+++ b/skyvern/forge/sdk/copilot/tools/run_execution.py@@ -1879,6 +1879,7 @@ async def _run_blocks_and_collect_debug(block_state_map=ctx.block_state_map,block_started_at_map=ctx.block_started_at_map,block_ended_at_map=ctx.block_ended_at_map,+ workflow_run_id=workflow_run.workflow_run_id,)prior_block_ts = tick_result.prior_block_tslast_block_fetch_monotonic = tick_result.last_block_fetch_monotonicdiff --git a/skyvern/forge/sdk/schemas/workflow_copilot.py b/skyvern/forge/sdk/schemas/workflow_copilot.pyindex 9932db581..ba10f1060 100644--- a/skyvern/forge/sdk/schemas/workflow_copilot.py+++ b/skyvern/forge/sdk/schemas/workflow_copilot.py@@ -364,6 +364,11 @@ class WorkflowCopilotBlockProgressUpdate(BaseModel):WorkflowCopilotStreamMessageType.BLOCK_PROGRESS, description="Message type")workflow_run_block_id: str = Field(..., description="Stable per-block id; used as the row key in the activity pane")+ workflow_run_id: str | None = Field(+ None,+ description="Dispatched run id for this block; lets the FE fetch recorded actions live during execution. "+ "Optional for backward compatibility with clients that only read the run id from run_outcome.",+ )block_label: str = Field(..., description="Workflow block label (e.g. 'enter_name')")block_type: str = Field(..., description="Workflow block type (e.g. 'navigation', 'extraction')")status: str = Field(diff --git a/tests/unit/test_copilot_narration.py b/tests/unit/test_copilot_narration.pyindex 8c8bef1c6..bcf4bccf2 100644--- a/tests/unit/test_copilot_narration.py+++ b/tests/unit/test_copilot_narration.py@@ -1149,6 +1149,43 @@ async def test_poll_tick_emits_block_progress_for_each_new_transition() -> None:pass+async def test_poll_tick_stamps_workflow_run_id_on_block_progress() -> None:+ """The run id threaded from the watchdog rides every block_progress frame so the+ FE can fetch recorded actions live during execution; it defaults to None for+ callers/paths that don't pass one (backward-compatible with run_outcome-only clients)."""+ from skyvern.forge.sdk.schemas.workflow_copilot import WorkflowCopilotBlockProgressUpdate++ async def fetch() -> list[_StubBlock]:+ return [_StubBlock("b0", "running", label="step_navigate", block_type="navigation")]++ async def run_once(run_id: str | None) -> WorkflowCopilotBlockProgressUpdate:+ state = NarratorState()+ stream = _StubStream()+ await narrator_poll_tick(+ state,+ current_block_ts=_ts(2.0),+ prior_block_ts=_ts(1.0),+ last_block_fetch_monotonic=0.0,+ seen_block_states={},+ fetch_block_statuses=fetch,+ stream=stream, # type: ignore[arg-type]+ workflow_run_id=run_id,+ )+ if state.in_flight_task is not None:+ state.in_flight_task.cancel()+ try:+ await state.in_flight_task+ except (asyncio.CancelledError, Exception):+ pass+ payloads = [p for p in stream.sent if isinstance(p, WorkflowCopilotBlockProgressUpdate)]+ assert len(payloads) == 1+ return payloads[0]++ assert (await run_once("wr_live_123")).workflow_run_id == "wr_live_123"+ assert (await run_once(None)).workflow_run_id is None++@pytest.mark.asyncioasync def test_poll_tick_does_not_emit_block_progress_for_unchanged_blocks() -> None:from skyvern.forge.sdk.schemas.workflow_copilot import WorkflowCopilotBlockProgressUpdate