Automate browser based workflows with AI
Python aiapiautomationbrowserbrowser-automationcomputergptllmplaywrightpowerautomatepuppeteerpythonrpaseleniumvisionworkflow
Show what the copilot actually did in its activity feed (SKY-13203) (#7869)
Andrew Neilson7d0370eaf0ba
diff --git a/skyvern-frontend/src/routes/workflows/copilot/NarrativeView.test.ts b/skyvern-frontend/src/routes/workflows/copilot/NarrativeView.test.tsindex a5e228cf2..1ca864cd0 100644--- a/skyvern-frontend/src/routes/workflows/copilot/NarrativeView.test.ts+++ b/skyvern-frontend/src/routes/workflows/copilot/NarrativeView.test.ts@@ -636,9 +636,22 @@ describe("condenseActivityEntries", () => {it("leaves a still-pending retry visible, tagged with the attempt count", () => {const s = reduceEvents([- toolCall({ tool_call_id: "c1", tool_name: "extract" }),- toolResult({ tool_call_id: "c1", tool_name: "extract", success: false }),- toolCall({ tool_call_id: "c2", tool_name: "extract" }),+ toolCall({+ tool_call_id: "c1",+ tool_name: "extract",+ display_label: "Extracting",+ }),+ toolResult({+ tool_call_id: "c1",+ tool_name: "extract",+ success: false,+ display_label: "Extracting",+ }),+ toolCall({+ tool_call_id: "c2",+ tool_name: "extract",+ display_label: "Extracting",+ }),]);const condensed = condenseActivityEntries(s.designActivity);expect(condensed).toHaveLength(1);diff --git a/skyvern-frontend/src/routes/workflows/copilot/copilotPhases.test.ts b/skyvern-frontend/src/routes/workflows/copilot/copilotPhases.test.tsindex 3b7586b44..72130d0c9 100644--- a/skyvern-frontend/src/routes/workflows/copilot/copilotPhases.test.ts+++ b/skyvern-frontend/src/routes/workflows/copilot/copilotPhases.test.ts@@ -77,6 +77,12 @@ describe("toolActivityDisplayLabel — discovery tools (SKY-12385)", () => {);});+ it("labels fill_credential_field without naming any credential", () => {+ expect(toolActivityDisplayLabel("fill_credential_field")).toBe(+ "Entering saved credentials",+ );+ });+it("still falls back to Working for unmapped tools", () => {expect(toolActivityDisplayLabel("some_unmapped_tool")).toBe("Working");});@@ -156,6 +162,31 @@ describe("derivePhases — condenses each phase's entries (SKY-11971)", () => {});});+ it("does not fold a failed edit of one block into a later edit of a different block", () => {+ const t = turn({+ designActivity: [+ entry({+ id: "tr-1",+ kind: "tool_result",+ toolName: "edit_block",+ displayLabel: 'Editing block "Login Form"',+ success: false,+ }),+ entry({+ id: "tr-2",+ kind: "tool_result",+ toolName: "edit_block",+ displayLabel: 'Editing block "Search Box"',+ success: true,+ }),+ ],+ });+ const rows = derivePhases(t);+ const exploreEntries = phase(rows, "explore").entries;+ expect(exploreEntries).toHaveLength(2);+ expect(exploreEntries.some((e) => e.attempts !== undefined)).toBe(false);+ });+it("REGRESSION PIN: the explore 'N steps' stub matches the condensed row count, not the raw event count (Claude catch)", () => {const t = turn({terminal: "response",diff --git a/skyvern-frontend/src/routes/workflows/copilot/narrativeState.phaseHint.test.ts b/skyvern-frontend/src/routes/workflows/copilot/narrativeState.phaseHint.test.tsindex 7e23c791c..9588704a7 100644--- a/skyvern-frontend/src/routes/workflows/copilot/narrativeState.phaseHint.test.ts+++ b/skyvern-frontend/src/routes/workflows/copilot/narrativeState.phaseHint.test.ts@@ -5,12 +5,14 @@ import {EMPTY_NARRATIVE,TurnNarrativeState,applyNarrativeEvent,+ hydrateNarrativeFromPayload,} from "./narrativeState";import {WorkflowCopilotBlockProgressUpdate,WorkflowCopilotRunOutcomeUpdate,WorkflowCopilotStreamResponseUpdate,WorkflowCopilotToolCallUpdate,+ WorkflowCopilotToolResultUpdate,WorkflowCopilotTurnStartUpdate,} from "./workflowCopilotTypes";@@ -135,7 +137,7 @@ describe("applyNarrativeEvent — lastActivityAtMs", () => {it("stamps even when the tool is denylisted from the visible activity log", () => {const s = applyNarrativeEvent(EMPTY_NARRATIVE,- toolCall({ tool_name: "list_credentials" }),+ toolCall({ tool_name: "get_run_results" }),777,);expect(s.lastActivityAtMs).toBe(777);@@ -364,3 +366,145 @@ describe("applyNarrativeEvent — response hydration resets phase-hint fields",expect(s.activitySeq).toBe(0);});});++describe("applyNarrativeEvent — server-authored display labels", () => {+ const toolResult = (+ overrides: Partial<WorkflowCopilotToolResultUpdate> = {},+ ): WorkflowCopilotToolResultUpdate => ({+ type: "tool_result",+ tool_name: "edit_block",+ success: true,+ summary: "",+ iteration: 0,+ tool_call_id: "call-1",+ ...overrides,+ });++ it("renders a credential lookup label-only even when an older backend sends a count summary", () => {+ const s = applyNarrativeEvent(+ EMPTY_NARRATIVE,+ toolResult({+ tool_name: "list_credentials",+ summary: "Found 4 credential(s)",+ success: true,+ }),+ );+ expect(s.designActivity).toHaveLength(1);+ expect(s.designActivity[0]!.text).toBe("Checking saved credentials");+ });++ it("keeps a credential blocker explanation that arrives as a successful summary", () => {+ const s = applyNarrativeEvent(+ EMPTY_NARRATIVE,+ toolResult({+ tool_name: "list_credentials",+ summary:+ "Saved-credential scouting is not authorized for this request.",+ success: true,+ }),+ );+ expect(s.designActivity[0]!.text).toBe(+ "Saved-credential scouting is not authorized for this request.",+ );+ });++ it("still renders a credential lookup failure summary", () => {+ const s = applyNarrativeEvent(+ EMPTY_NARRATIVE,+ toolResult({+ tool_name: "list_credentials",+ summary: "Failed: the credential store could not be reached",+ success: false,+ }),+ );+ expect(s.designActivity[0]!.text).toBe(+ "Failed: the credential store could not be reached",+ );+ });++ it("prefers the server display_label over the local map on tool_call and tool_result", () => {+ let s: TurnNarrativeState = applyNarrativeEvent(+ EMPTY_NARRATIVE,+ toolCall({+ tool_name: "edit_block",+ display_label: 'Editing block "Log in"',+ }),+ );+ s = applyNarrativeEvent(+ s,+ toolResult({ display_label: 'Editing block "Log in"' }),+ );+ expect(s.designActivity.map((e) => e.displayLabel)).toEqual([+ 'Editing block "Log in"',+ 'Editing block "Log in"',+ ]);+ expect(s.designActivity.map((e) => e.text)).toEqual([+ 'Editing block "Log in"…',+ 'Editing block "Log in"',+ ]);+ expect(s.designActivity.every((e) => !e.text.includes("Working"))).toBe(+ true,+ );+ });++ it("falls back to the local label map when the server sends no display_label", () => {+ const s = applyNarrativeEvent(EMPTY_NARRATIVE, toolResult());+ expect(s.designActivity[0]?.displayLabel).toBe("Editing block");+ });++ it("renders a credential-lookup row instead of suppressing it", () => {+ let s: TurnNarrativeState = applyNarrativeEvent(+ EMPTY_NARRATIVE,+ toolCall({ tool_name: "list_credentials", tool_call_id: "call-9" }),+ );+ s = applyNarrativeEvent(+ s,+ toolResult({ tool_name: "list_credentials", tool_call_id: "call-9" }),+ );+ expect(s.designActivity.map((e) => e.text)).toEqual([+ "Checking saved credentials…",+ "Checking saved credentials",+ ]);+ });++ it("keeps the persisted displayLabel when hydrating from narrative_payload", () => {+ const s = hydrateNarrativeFromPayload({+ turnId: "turn-1",+ turnIndex: 0,+ mode: "build",+ designStarted: true,+ designEnded: true,+ draft: null,+ blocks: [],+ terminal: "response",+ terminalMessage: "Done.",+ narrativeSummary: "Done.",+ priorBlockCount: null,+ designActivity: [+ {+ kind: "tool_call",+ text: 'Editing block "Log in"…',+ iteration: 0,+ toolName: "edit_block",+ displayLabel: 'Editing block "Log in"',+ id: "tc-call-1",+ },+ {+ kind: "tool_result",+ text: "Checking saved credentials",+ iteration: 1,+ toolName: "list_credentials",+ displayLabel: "Checking saved credentials",+ success: true,+ id: "tr-call-9",+ },+ ],+ startedAt: "2026-06-10T00:00:00Z",+ endedAt: "2026-06-10T00:02:00Z",+ });+ expect(s?.designActivity.map((e) => e.displayLabel)).toEqual([+ 'Editing block "Log in"',+ "Checking saved credentials",+ ]);+ });+});diff --git a/skyvern-frontend/src/routes/workflows/copilot/narrativeState.ts b/skyvern-frontend/src/routes/workflows/copilot/narrativeState.tsindex 28c9595c3..d6a6dd924 100644--- a/skyvern-frontend/src/routes/workflows/copilot/narrativeState.ts+++ b/skyvern-frontend/src/routes/workflows/copilot/narrativeState.ts@@ -346,12 +346,12 @@ export const RUN_TOOLS = new Set([// Tool names we never surface in the user-facing activity log. Internal// observation/maintenance tools are not interesting context for the user.const ACTIVITY_TOOL_DENYLIST = new Set([- "list_credentials","get_run_results","get_browser_screenshot",]);-// Mirror of the backend _TOOL_ACTIVITY_DISPLAY_LABELS in narration.py.+// Version-skew fallback for the server-authored display_label: mirror of the+// backend _TOOL_ACTIVITY_DISPLAY_LABELS in narration.py.const ACTIVITY_TOOL_DISPLAY_LABELS: Record<string, string> = {update_workflow: "Updating workflow",update_and_run_blocks: "Testing workflow",@@ -367,6 +367,11 @@ const ACTIVITY_TOOL_DISPLAY_LABELS: Record<string, string> = {inspect_current_workflow: "Inspecting workflow",discover_workflow_entrypoint: "Finding the entry page",inspect_page_for_composition: "Inspecting the page",+ list_credentials: "Checking saved credentials",+ fill_credential_field: "Entering saved credentials",+ edit_block: "Editing block",+ delete_block: "Deleting block",+ synthesize_demonstrated_block: "Building a block from the recorded steps",};export function toolActivityDisplayLabel(toolName?: string | null): string {@@ -392,16 +397,26 @@ function buildActivityFromToolCall(};}+// summarize_tool_result's pre-SKY-13203 credential summary: "Found N credential(s)".+const LEGACY_CREDENTIAL_COUNT_SUMMARY_RE = /^Found \d+ credential\(s\)$/;+function buildActivityFromToolResult(event: WorkflowCopilotToolResultUpdate,): ActivityEntry | null {if (ACTIVITY_TOOL_DENYLIST.has(event.tool_name)) {return null;}- const displayLabel = toolActivityDisplayLabel(event.tool_name);+ const displayLabel =+ event.display_label ?? toolActivityDisplayLabel(event.tool_name);+ // Drop only the legacy enumeration count a pre-SKY-13203 backend still emits+ // for credential lookups; a blocker explanation also arrives as a successful+ // summary and must survive.+ const suppressSummary =+ event.tool_name === "list_credentials" &&+ LEGACY_CREDENTIAL_COUNT_SUMMARY_RE.test(event.summary ?? "");return {kind: "tool_result",- text: event.summary || displayLabel,+ text: suppressSummary ? displayLabel : event.summary || displayLabel,iteration: event.iteration,toolName: event.tool_name,displayLabel,@@ -456,10 +471,11 @@ export function toolCallIdOf(entry: ActivityEntry): string | undefined {// so a narration that streamed before the later attempt's result still// reads as arriving before it, not after.//-// Known tradeoff: toolName is the only correlation signal available here-// (no argument/target identity on the wire), so two independent same-tool-// calls where only the first fails will also fold into one falsely-labeled-// "retry" row. Accepted for this content-classification pass.+// Correlation uses toolName plus displayLabel, which narrows the old+// toolName-only rule: edits of two differently-named blocks no longer fold.+// It is not full target identity — the label is humanized and length-capped,+// so `login_v1`/`login_v2` and two labels sharing a 40-char prefix still+// collide and fold. Raw-argument identity on the wire would close that.//// A tool without a dedicated backend summary falls back to a bare "OK"// (summarize_tool_result in output_utils.py). That used to sit right below@@ -524,6 +540,9 @@ export function condenseActivityEntries(prevTool &&entry.toolName !== undefined &&prevTool.toolName === entry.toolName &&+ (prevTool.displayLabel === undefined ||+ entry.displayLabel === undefined ||+ prevTool.displayLabel === entry.displayLabel) &&prevTool.success === false) {condensed[lastToolIdx] = null;diff --git a/skyvern-frontend/src/routes/workflows/copilot/workflowCopilotTypes.ts b/skyvern-frontend/src/routes/workflows/copilot/workflowCopilotTypes.tsindex afd64b047..bba8b174c 100644--- a/skyvern-frontend/src/routes/workflows/copilot/workflowCopilotTypes.ts+++ b/skyvern-frontend/src/routes/workflows/copilot/workflowCopilotTypes.ts@@ -207,6 +207,7 @@ export interface WorkflowCopilotToolCallUpdate {export interface WorkflowCopilotToolResultUpdate {type: "tool_result";tool_name: string;+ display_label?: string | null;success: boolean;summary: string;iteration: number;diff --git a/skyvern-frontend/src/routes/workflows/studio/runProjections.ts b/skyvern-frontend/src/routes/workflows/studio/runProjections.tsindex 41e417266..71e6f9800 100644--- a/skyvern-frontend/src/routes/workflows/studio/runProjections.ts+++ b/skyvern-frontend/src/routes/workflows/studio/runProjections.ts@@ -16,6 +16,10 @@ import { basicLocalTimeFormat, normalizeUtcTimestamp } from "@/util/timeFormat";export type RunOutcome = "idle" | "running" | "failed" | "success";+// Sentinel formatElapsed returns for a run with no usable start; callers that+// hide the value instead of rendering a bare dash must compare against this.+export const ELAPSED_NEVER_STARTED = "—";+// Run timestamps are naive ISO (no Z), so normalize to UTC before diffing — else// a live run's (now - start) is skewed by the local timezone offset.export function formatElapsed(@@ -23,11 +27,11 @@ export function formatElapsed(endIso: string | null,): string {if (!startIso) {- return "—";+ return ELAPSED_NEVER_STARTED;}const start = new Date(normalizeUtcTimestamp(startIso)).getTime();if (Number.isNaN(start)) {- return "—";+ return ELAPSED_NEVER_STARTED;}const endMs = endIso? new Date(normalizeUtcTimestamp(endIso)).getTime()diff --git a/skyvern-frontend/src/routes/workflows/studio/runview/RunView.test.tsx b/skyvern-frontend/src/routes/workflows/studio/runview/RunView.test.tsxindex 7e147f001..b5aff65b5 100644--- a/skyvern-frontend/src/routes/workflows/studio/runview/RunView.test.tsx+++ b/skyvern-frontend/src/routes/workflows/studio/runview/RunView.test.tsx@@ -737,6 +737,24 @@ describe("RunView live affordances", () => {expect(scope.queryByText(/Run queued/)).not.toBeNull();expect(scope.queryByRole("button", { name: "Live" })).toBeNull();});++ test("a queued run reports no elapsed time in the strip or the timeline", () => {+ // created_at is always populated by the API, so only started_at can decide+ // whether the run has actually accrued elapsed time.+ seedCompletedRun({+ status: Status.Queued,+ created_at: "2026-06-30T23:59:00Z",+ queued_at: "2026-06-30T23:59:30Z",+ started_at: null,+ finished_at: null,+ });+ const { container } = renderRunView();+ const scope = within(container);++ expect(scope.queryByText(/^Ran for /)).toBeNull();+ expect(scope.queryByText(/·\s*\d+[ms]/)).toBeNull();+ expect(scope.queryByText(/·\s*—/)).toBeNull();+ });});describe("RunView iteration selection", () => {diff --git a/skyvern-frontend/src/routes/workflows/studio/runview/RunView.tsx b/skyvern-frontend/src/routes/workflows/studio/runview/RunView.tsxindex bba45b58f..168ef8a8c 100644--- a/skyvern-frontend/src/routes/workflows/studio/runview/RunView.tsx+++ b/skyvern-frontend/src/routes/workflows/studio/runview/RunView.tsx@@ -27,6 +27,7 @@ import { findActiveItem } from "../../workflowRun/workflowTimelineUtils";import { getOrderedRunParameters } from "../../utils";import {buildFilmstrip,+ ELAPSED_NEVER_STARTED,formatElapsed,formatRunTimesTooltip,runHasOutputs,@@ -381,10 +382,16 @@ export function RunView({return <RunPlaceholder loading={isLoading || runIdPending} />;}- const elapsed = formatElapsed(- workflowRun.started_at ?? workflowRun.created_at ?? null,+ // Same rule as the summary strip: created_at is always set, so falling back to+ // it shows a queued run an elapsed time it never accrued. The never-started+ // sentinel is dropped so the timeline omits the value entirely rather than+ // rendering a bare dash.+ const elapsedValue = formatElapsed(+ workflowRun.started_at ?? null,finalized ? (workflowRun.finished_at ?? null) : null,);+ const elapsed =+ elapsedValue === ELAPSED_NEVER_STARTED ? undefined : elapsedValue;const elapsedTitle = formatRunTimesTooltip(workflowRun);const failureReason = formatFailureReason(workflowRun.failure_reason ?? "The run failed.",diff --git a/skyvern/forge/sdk/copilot/context.py b/skyvern/forge/sdk/copilot/context.pyindex 328000ebe..fd43819b0 100644--- a/skyvern/forge/sdk/copilot/context.py+++ b/skyvern/forge/sdk/copilot/context.py@@ -727,6 +727,7 @@ class InFlightStreamToolCall:call_id: strtool_name: striteration: int+ display_label: str | None = None@dataclassdiff --git a/skyvern/forge/sdk/copilot/narration.py b/skyvern/forge/sdk/copilot/narration.pyindex d4eca57c4..b95bf97b1 100644--- a/skyvern/forge/sdk/copilot/narration.py+++ b/skyvern/forge/sdk/copilot/narration.py@@ -28,6 +28,7 @@ from urllib.parse import urlparseimport structlogfrom skyvern.forge.sdk.copilot.llm_config import get_fast_copilot_handler, resolve_fast_copilot_handler+from skyvern.forge.sdk.copilot.output_utils import sanitize_block_label_for_displayfrom skyvern.forge.sdk.schemas.workflow_copilot import (WorkflowCopilotBlockProgressUpdate,WorkflowCopilotNarrationUpdate,@@ -70,7 +71,7 @@ MAX_DESIGN_ACTIVITY_ENTRIES = 50# Tools whose calls/results are never surfaced in the user-facing activity log.# Mirror of the FE ACTIVITY_TOOL_DENYLIST in narrativeState.ts.-ACTIVITY_TOOL_DENYLIST = frozenset({"list_credentials", "get_run_results", "get_browser_screenshot"})+ACTIVITY_TOOL_DENYLIST = frozenset({"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@@ -100,18 +101,50 @@ _TOOL_ACTIVITY_DISPLAY_LABELS = {"inspect_current_workflow": "Inspecting workflow","discover_workflow_entrypoint": "Finding the entry page","inspect_page_for_composition": "Inspecting the page",+ "list_credentials": "Checking saved credentials",+ "validate_block": "Checking the block",+ "console_messages": "Reading the browser console",+ "fill_credential_field": "Entering saved credentials",+ "edit_block": "Editing block",+ "delete_block": "Deleting block",+ "synthesize_demonstrated_block": "Building a block from the recorded steps",}+# Tools whose label names the block they operate on, read from the tool's own+# `label` argument.+_BLOCK_TARGET_LABEL_TOOLS = frozenset({"edit_block", "delete_block"})+_BLOCK_TARGET_VERSION_SUFFIX_RE = re.compile(r"_v\d+$", re.IGNORECASE)-def tool_activity_display_label(tool_name: str) -> str:- """Return a product-safe label for user-visible activity rows."""- return _TOOL_ACTIVITY_DISPLAY_LABELS.get(tool_name, "Working")++def _humanize_block_target(target: str) -> str:+ # Mirror of the FE humanizeBlockLabel in blockLabel.ts, so the row matches+ # the block card rendered beside it.+ words = [w for w in re.split(r"[_\s]+", _BLOCK_TARGET_VERSION_SUFFIX_RE.sub("", target)) if w]+ if not words:+ return target+ return " ".join(word[0].upper() + word[1:] for word in words)-def build_tool_call_activity(tool_name: str, iteration: int, tool_call_id: str) -> NarrativeActivityEntry | None:+def tool_activity_display_label(tool_name: str, tool_input: dict[str, Any] | None = None) -> str:+ """Return a product-safe label for user-visible activity rows."""+ label = _TOOL_ACTIVITY_DISPLAY_LABELS.get(tool_name, "Working")+ if tool_name in _BLOCK_TARGET_LABEL_TOOLS and tool_input is not None:+ target = tool_input.get("label")+ if isinstance(target, str) and target.strip():+ # The target is LLM-authored, so it goes through the same quote/length+ # clamp the result-row summaries use before it is interpolated.+ humanized = sanitize_block_label_for_display(_humanize_block_target(target))+ if humanized:+ return f'{label} "{humanized}"'+ return label+++def build_tool_call_activity(+ tool_name: str, iteration: int, tool_call_id: str, display_label: str | None = None+) -> NarrativeActivityEntry | None:if tool_name in ACTIVITY_TOOL_DENYLIST:return None- display_label = tool_activity_display_label(tool_name)+ display_label = display_label or tool_activity_display_label(tool_name)return {"kind": "tool_call","text": f"{display_label}…",@@ -123,11 +156,16 @@ def build_tool_call_activity(tool_name: str, iteration: int, tool_call_id: str)def build_tool_result_activity(- tool_name: str, summary: str, success: bool, iteration: int, tool_call_id: str+ tool_name: str,+ summary: str,+ success: bool,+ iteration: int,+ tool_call_id: str,+ display_label: str | None = None,) -> NarrativeActivityEntry | None:if tool_name in ACTIVITY_TOOL_DENYLIST:return None- display_label = tool_activity_display_label(tool_name)+ display_label = display_label or tool_activity_display_label(tool_name)return {"kind": "tool_result","text": summary or display_label,@@ -188,6 +226,9 @@ class NarratorState:pending_activity: deque[_ToolActivityEntry] = field(default_factory=lambda: deque(maxlen=MAX_TOOL_ACTIVITY_BUFFER))in_flight_task: asyncio.Task[None] | None = Nonepending_transition: TransitionKind | None = None+ # Which iteration recorded pending_transition, so suppressing iteration N cannot+ # discard a transition an earlier typed-row-free iteration is still waiting on.+ pending_transition_iteration: int | None = Noneuser_goal: str = ""# Tool whose tool_called arrived but tool_output hasn't yet. Cleared on# tool_output so post-tool transitions describe the finished action, not@@ -209,10 +250,17 @@ class NarratorState: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)+ # Iterations already carrying a typed tool row; narrator prose is suppressed for+ # those. Iteration numbers restart per stream_to_sse pass, so it is cleared on entry.+ iterations_with_tool_activity: set[int] = field(default_factory=set)def record_activity(self, entry: NarrativeActivityEntry | None) -> None:if entry is None:return+ if entry.get("kind") in ("tool_call", "tool_result"):+ iteration = entry.get("iteration")+ if isinstance(iteration, int):+ self.iterations_with_tool_activity.add(iteration)label = self._activity_bucket_label(entry)if label is None:self.design_activity.append(entry)@@ -267,6 +315,7 @@ class NarratorState:or _TRANSITION_PRIORITY[kind] > _TRANSITION_PRIORITY[self.pending_transition]):self.pending_transition = kind+ self.pending_transition_iteration = self.current_iteration@dataclass(frozen=True)@@ -316,9 +365,11 @@ class _NarratorPromptContext:pending_tool_name: str | None = None-def should_emit(state: NarratorState, now: float) -> bool:+def should_emit(state: NarratorState, now: float, iteration: int | None = None) -> bool:if state.pending_transition is None:return False+ if iteration is not None and iteration in state.iterations_with_tool_activity:+ return Falseif state.in_flight_task is not None and not state.in_flight_task.done():return Falselast_event = max(state.last_emitted_at or 0.0, state.last_attempted_at or 0.0)@@ -335,12 +386,23 @@ def schedule_narration("""Kick off a background narration task if the gate allows. Fire-and-drop:errors, timeouts, and empty responses are swallowed inside the task."""now = time.monotonic()- if not should_emit(state, now):+ if not should_emit(state, now, iteration):+ # A transition on an iteration that carries a typed row is already+ # described by that row, so consume it here. Banking it would let it+ # surface as stale prose against an unrelated later iteration.+ if (+ state.pending_transition is not None+ and iteration in state.iterations_with_tool_activity+ and state.pending_transition_iteration == iteration+ ):+ state.pending_transition = None+ state.pending_transition_iteration = Nonereturntransition = state.pending_transitionassert transition is not None # guaranteed by should_emitstate.pending_transition = None+ state.pending_transition_iteration = None# Bound failure-path retries to the same gap window successes use; without# this, a flaky narrator re-fires every poll tick.state.last_attempted_at = now@@ -397,6 +459,8 @@ async def _narration_task_body(if not narration:return+ if iteration in state.iterations_with_tool_activity:+ returnnarration_ts = datetime.now(timezone.utc)try:@@ -642,9 +706,6 @@ def extract_tool_details(tool_name: str, parsed: dict[str, Any], *, success: booreturn "configuration invalid"return ""- if tool_name == "list_credentials":- return _format_int_count(data, "credential")-if tool_name == "get_block_schema":return _format_int_count(data, "step type")diff --git a/skyvern/forge/sdk/copilot/output_utils.py b/skyvern/forge/sdk/copilot/output_utils.pyindex 4bc9d4e71..6cf9dc33f 100644--- a/skyvern/forge/sdk/copilot/output_utils.py+++ b/skyvern/forge/sdk/copilot/output_utils.py@@ -6,7 +6,8 @@ import base64import binasciiimport jsonimport re-from collections.abc import Iterable, Iterator+import unicodedata+from collections.abc import Callable, Iterable, Iteratorfrom typing import TYPE_CHECKING, Anyfrom skyvern.forge.sdk.agents.context import sanitize_agent_tool_result_for_llm as sanitize_generic_tool_result_for_llm@@ -332,7 +333,9 @@ def _result_data(result: dict[str, Any]) -> dict[str, Any]:def _clean_structured_user_facing_text(value: Any, *, blocked_tool: str | None = None) -> str | None:if not isinstance(value, str):return None- cleaned = " ".join(value.split())+ # This branch returns straight to the caller without passing through+ # _sanitize_failure_text, so it needs its own credential-id redaction.+ cleaned = " ".join(_CREDENTIAL_ID_RE.sub("[credential]", value).split())if not cleaned:return Nonetry:@@ -445,6 +448,43 @@ def user_facing_success(_HEADERS_BLOB_RE = re.compile(r"\s*headers:\s*\{[^{}]*\}\s*", re.IGNORECASE)_LARGE_DICT_BLOB_RE = re.compile(r"\{[^{}]{40,}\}")+# Every credential-shaped id prefix in skyvern/forge/sdk/db/id.py, so a new one does+# not quietly become renderable: cred, the vault/parameter kinds, folders, OAuth,+# and run credential selections.+_CREDENTIAL_ID_RE = re.compile(+ r"`?\b(?:cred|cp|cfld|blc|bccd|bsi|opp|azcp|asp|goac|moac|wrcs)_[A-Za-z0-9][A-Za-z0-9_-]*`?"+)+# Punctuation an LLM-authored block label may keep. Everything outside this set and+# the letter/digit categories becomes a space: a whitelist, because any quote-class+# codepoint left in a label lets it visually close the quoting around it and append a+# fabricated verdict to the row. Modifier letters (Lm) are excluded despite being+# alphanumeric — U+02EE and friends are quote look-alikes.+_LABEL_ALLOWED_PUNCTUATION = frozenset(" -_./")+_LABEL_ALLOWED_CATEGORIES = frozenset({"Lu", "Ll", "Lt", "Lo", "Nd"})+++def sanitize_block_label_for_display(label: str, max_chars: int = 40) -> str:+ """Make an LLM-authored block label safe to interpolate into a feed row."""+ cleaned = "".join(+ char if unicodedata.category(char) in _LABEL_ALLOWED_CATEGORIES or char in _LABEL_ALLOWED_PUNCTUATION else " "+ for char in label+ )+ cleaned = " ".join(cleaned.split())+ if len(cleaned) > max_chars:+ cleaned = cleaned[: max_chars - 1].rstrip() + "…"+ return cleaned+++_MAX_JOINED_BLOCK_LABELS = 5+++def _joined_block_labels(labels: list[Any], render: Callable[[object], str], *, cap: bool) -> str:+ """Render a comma list, capped for display so a many-block run stays one row.+ Uncapped for agent state, which reads the full set back."""+ shown = [render(label) for label in (labels[:_MAX_JOINED_BLOCK_LABELS] if cap else labels)]+ remaining = len(labels) - len(shown)+ joined = ", ".join(label for label in shown if label)+ return f"{joined} (+{remaining} more)" if remaining > 0 else joineddef _sanitize_failure_text(text: str, max_chars: int = 120) -> str:@@ -456,6 +496,7 @@ def _sanitize_failure_text(text: str, max_chars: int = 120) -> str:must pass through unchanged."""text = _HEADERS_BLOB_RE.sub(" ", text)text = _LARGE_DICT_BLOB_RE.sub("{...}", text)+ text = _CREDENTIAL_ID_RE.sub("[credential]", text)text = " ".join(text.split())if not text:return "(no details)"@@ -485,8 +526,14 @@ def _describe_value_shape(value: Any) -> str:return "value"-def summarize_tool_result(tool_name: str, result: dict[str, Any]) -> str:- """Create a brief human-readable summary of a tool result."""+def summarize_tool_result(tool_name: str, result: dict[str, Any], *, for_display: bool = False) -> str:+ """Summarize a tool result. ``for_display`` clamps LLM-authored block labels for+ the activity feed; the default leaves them verbatim because this string is parsed+ back into agent state by ``context.merge_turn_summary``."""++ def block_label(value: object) -> str:+ return sanitize_block_label_for_display(str(value)) if for_display else str(value)+if not result.get("ok", False):return f"Failed: {_sanitize_failure_text(_extract_failure_message(result))}"@@ -513,19 +560,22 @@ def summarize_tool_result(tool_name: str, result: dict[str, Any]) -> str:return f"Schema for {data.get('block_type', '?')}"if tool_name == "validate_block":if data.get("valid"):- return f"Block '{data.get('label', '?')}' is valid"+ return f"Block '{block_label(data.get('label', '?'))}' is valid"return "Block validation failed"if tool_name == "run_blocks_and_collect_debug":if not isinstance(raw_data, dict):return "Run debug completed"- executed = data.get("executed_block_labels") or [b.get("label", "?") for b in data.get("blocks", [])]+ raw_executed = data.get("executed_block_labels") or [b.get("label", "?") for b in data.get("blocks", [])]+ executed = _joined_block_labels(raw_executed, block_label, cap=for_display)status = data.get("overall_status", "?")requested = data.get("requested_block_labels") or []- if requested and executed and list(executed) != list(requested):- skipped = [label for label in requested if label not in set(executed)]- suffix = f" (skipped prefix from cache: {', '.join(skipped)})" if skipped else ""- return f"Run {', '.join(executed)}: {status}{suffix}"- return f"Run {', '.join(executed)}: {status}"+ if requested and raw_executed and list(raw_executed) != list(requested):+ skipped = _joined_block_labels(+ [label for label in requested if label not in set(raw_executed)], block_label, cap=for_display+ )+ suffix = f" (skipped prefix from cache: {skipped})" if skipped else ""+ return f"Run {executed}: {status}{suffix}"+ return f"Run {executed}: {status}"if tool_name == "get_browser_screenshot":url = data.get("url")return f"Screenshot taken ({url[:80]})" if url else "Screenshot taken"@@ -627,7 +677,20 @@ _USER_FACING_LOOP_MESSAGE = "The agent got stuck retrying the same step — movi_USER_FACING_JINJA_MESSAGE = "A workflow parameter could not be filled in."_USER_FACING_GENERIC_FAILURE = _STRUCTURED_UNSAFE_FALLBACK-_USER_FACING_EMPTY_SUCCESS_TOOLS: frozenset[str] = frozenset({"click", "type_text", "evaluate", "select_option"})+_USER_FACING_EMPTY_SUCCESS_TOOLS: frozenset[str] = frozenset(+ {+ "click",+ "type_text",+ "evaluate",+ "select_option",+ "list_credentials",+ # The server-authored display label already names the operation and its+ # target block; a bare "OK" summary would render instead of it.+ "edit_block",+ "delete_block",+ "synthesize_demonstrated_block",+ }+)def _translate_failure_for_user(error_text: str) -> str:@@ -665,7 +728,7 @@ def format_tool_result_for_user(return _translate_failure_for_user(_extract_failure_message(result))if tool_name in _USER_FACING_EMPTY_SUCCESS_TOOLS:return ""- return summarize_tool_result(tool_name, result)+ return summarize_tool_result(tool_name, result, for_display=True)def truncate_output(output: Any, max_chars: int = 2000) -> str | None:diff --git a/skyvern/forge/sdk/copilot/streaming_adapter.py b/skyvern/forge/sdk/copilot/streaming_adapter.pyindex 2ae881c48..4ed2a7a8e 100644--- a/skyvern/forge/sdk/copilot/streaming_adapter.py+++ b/skyvern/forge/sdk/copilot/streaming_adapter.py@@ -267,6 +267,9 @@ async def stream_to_sse(asyncio's cancellation machinery still runs normally."""call_id_to_name: dict[str, str] = {}+ # Label authored once at tool_called so the matching result renders the same+ # string; the result event carries no arguments to re-derive it from.+ call_id_to_label: dict[str, str] = {}# Counts completed tool round-trips (tool_called + tool_output pair), not# raw stream events. Both TOOL_CALL and TOOL_RESULT for the same round# carry the same iteration value; it advances after the matching result.@@ -286,6 +289,12 @@ async def stream_to_sse(getattr(ctx, "organization_id", None),)narrator_enabled = narrator_state.resolved_handler is not None+ # Iteration numbers restart at 0 on every enforcement pass, so a set carried+ # over from the previous pass would suppress this pass's clean iterations —+ # and a transition tagged with a previous pass's iteration number could be+ # consumed by this pass's same-numbered iteration by coincidence.+ narrator_state.iterations_with_tool_activity.clear()+ narrator_state.pending_transition_iteration = Nonectx.narrator_state = narrator_stateuser_message = getattr(ctx, "user_message", "") or ""if user_message and not narrator_state.user_goal:@@ -319,35 +328,42 @@ async def stream_to_sse(call_id = _get_raw_field(raw, "call_id") or _get_raw_field(raw, "id") or ""tool_name = _get_raw_field(raw, "name") or "unknown"call_id_to_name[call_id] = tool_name++ raw_args = _get_raw_field(raw, "arguments")+ tool_input: dict[str, Any] = {}+ if isinstance(raw_args, str):+ try:+ tool_input = json.loads(raw_args)+ except (json.JSONDecodeError, TypeError):+ # A placeholder, not the raw text: _sanitize_input redacts by+ # key name, which cannot see inside one opaque string.+ tool_input = {"raw": "<unparsed arguments>"}+ if not isinstance(tool_input, dict):+ tool_input = {"raw": "<unparsed arguments>"}+ elif isinstance(raw_args, dict):+ tool_input = raw_args++ display_label = tool_activity_display_label(tool_name, tool_input)+ call_id_to_label[call_id] = display_labelctx.in_flight_stream_tool_call = InFlightStreamToolCall(- call_id=call_id, tool_name=tool_name, iteration=iteration+ call_id=call_id, tool_name=tool_name, iteration=iteration, display_label=display_label+ )+ narrator_state.record_activity(+ build_tool_call_activity(tool_name, iteration, call_id, display_label=display_label))- narrator_state.record_activity(build_tool_call_activity(tool_name, iteration, call_id))if not client_gone:- raw_args = _get_raw_field(raw, "arguments")- tool_input: dict[str, Any] = {}- if isinstance(raw_args, str):- try:- tool_input = json.loads(raw_args)- except (json.JSONDecodeError, TypeError):- tool_input = {"raw": raw_args}- elif isinstance(raw_args, dict):- tool_input = raw_args-await stream.send(WorkflowCopilotToolCallUpdate(type=WorkflowCopilotStreamMessageType.TOOL_CALL,tool_name=tool_name,- display_label=tool_activity_display_label(tool_name),+ display_label=display_label,tool_input=_sanitize_input(tool_input),iteration=iteration,tool_call_id=call_id,))- # First narration lands here (~seconds after submit) rather- # than waiting for tool_output of a long tool.if narrator_enabled:narrator_state.pending_tool_name = tool_namenarrator_state.current_iteration = iteration@@ -384,8 +400,11 @@ async def stream_to_sse(detail = summarize_tool_result_detail(parsed, tool_name=tool_name, blocker_signal=blocker_signals, success=success)+ result_label = call_id_to_label.get(call_id) or tool_activity_display_label(tool_name)narrator_state.record_activity(- build_tool_result_activity(tool_name, summary, success, iteration, call_id)+ build_tool_result_activity(+ tool_name, summary, success, iteration, call_id, display_label=result_label+ ))if not client_gone:@@ -393,6 +412,7 @@ async def stream_to_sse(WorkflowCopilotToolResultUpdate(type=WorkflowCopilotStreamMessageType.TOOL_RESULT,tool_name=tool_name,+ display_label=result_label,success=success,summary=summary,iteration=iteration,@@ -522,10 +542,13 @@ async def flush_goal_satisfied_tool_result(stream: EventSourceStream, ctx: Copilblocker_signals = _tool_blocker_signal_candidates(ctx)summary = format_tool_result_for_user(pending.tool_name, parsed, blocker_signal=blocker_signals)success = user_facing_success(parsed, blocker_signal=blocker_signals)+ display_label = pending.display_label or tool_activity_display_label(pending.tool_name)narrator_state = ctx.narrator_stateif narrator_state is not None:narrator_state.record_activity(- build_tool_result_activity(pending.tool_name, summary, success, pending.iteration, pending.call_id)+ build_tool_result_activity(+ pending.tool_name, summary, success, pending.iteration, pending.call_id, display_label=display_label+ ))if await stream.is_disconnected():return@@ -533,6 +556,7 @@ async def flush_goal_satisfied_tool_result(stream: EventSourceStream, ctx: CopilWorkflowCopilotToolResultUpdate(type=WorkflowCopilotStreamMessageType.TOOL_RESULT,tool_name=pending.tool_name,+ display_label=display_label,success=success,summary=summary,iteration=pending.iteration,diff --git a/skyvern/forge/sdk/db/repositories/tasks.py b/skyvern/forge/sdk/db/repositories/tasks.pyindex 8a6ab4c4c..048c434d9 100644--- a/skyvern/forge/sdk/db/repositories/tasks.py+++ b/skyvern/forge/sdk/db/repositories/tasks.py@@ -86,10 +86,15 @@ class TasksRepository(BaseRepository):terminate_criterion = _sanitize(terminate_criterion)workflow_system_prompt = _sanitize(workflow_system_prompt)+ # created_at is passed so an already-running task cannot start before it was created; None+ # falls through to the column default.+ started_at = naive_utc_now() if str(status) == TaskStatus.running.value else None+async with self.Session() as session:new_task = TaskModel(status=status,- started_at=naive_utc_now() if str(status) == TaskStatus.running.value else None,+ started_at=started_at,+ created_at=started_at,task_type=task_type,url=url,title=title,diff --git a/skyvern/forge/sdk/schemas/sdk_actions.py b/skyvern/forge/sdk/schemas/sdk_actions.pyindex 85b41c995..814b296c3 100644--- a/skyvern/forge/sdk/schemas/sdk_actions.py+++ b/skyvern/forge/sdk/schemas/sdk_actions.py@@ -42,7 +42,12 @@ class ClickAction(SdkActionBase):selector: str | None = Field(default="", description="CSS selector for the element")intention: str = Field(default="", description="The intention or goal of the click")data: str | dict[str, Any] | None = Field(None, description="Additional context data")- timeout: float = Field(default=settings.BROWSER_ACTION_TIMEOUT_MS, description="Timeout in milliseconds")+ # Keep runtime defaults configurable while documenting a stable API default.+ timeout: float = Field(+ default_factory=lambda: settings.BROWSER_ACTION_TIMEOUT_MS,+ description="Timeout in milliseconds",+ json_schema_extra={"default": 10000},+ )def get_navigation_goal(self) -> str | None:return self.intention@@ -61,7 +66,11 @@ class InputTextAction(SdkActionBase):data: str | dict[str, Any] | None = Field(None, description="Additional context data")totp_identifier: str | None = Field(None, description="TOTP identifier for input_text actions")totp_url: str | None = Field(None, description="TOTP URL for input_text actions")- timeout: float = Field(default=settings.BROWSER_ACTION_TIMEOUT_MS, description="Timeout in milliseconds")+ timeout: float = Field(+ default_factory=lambda: settings.BROWSER_ACTION_TIMEOUT_MS,+ description="Timeout in milliseconds",+ json_schema_extra={"default": 10000},+ )def __repr__(self) -> str:payload = redact_input_text_payload_for_log(self.model_dump(), value_key="value")@@ -86,7 +95,11 @@ class SelectOptionAction(SdkActionBase):value: str | None = Field(default="", description="Value to select")intention: str = Field(default="", description="The intention or goal of the selection")data: str | dict[str, Any] | None = Field(None, description="Additional context data")- timeout: float = Field(default=settings.BROWSER_ACTION_TIMEOUT_MS, description="Timeout in milliseconds")+ timeout: float = Field(+ default_factory=lambda: settings.BROWSER_ACTION_TIMEOUT_MS,+ description="Timeout in milliseconds",+ json_schema_extra={"default": 10000},+ )def get_navigation_goal(self) -> str | None:return self.intention@@ -103,7 +116,11 @@ class UploadFileAction(SdkActionBase):file_url: str | None = Field(default="", description="File URL for upload")intention: str = Field(default="", description="The intention or goal of the upload")data: str | dict[str, Any] | None = Field(None, description="Additional context data")- timeout: float = Field(default=settings.BROWSER_ACTION_TIMEOUT_MS, description="Timeout in milliseconds")+ timeout: float = Field(+ default_factory=lambda: settings.BROWSER_ACTION_TIMEOUT_MS,+ description="Timeout in milliseconds",+ json_schema_extra={"default": 10000},+ )def get_navigation_goal(self) -> str | None:return self.intentiondiff --git a/skyvern/forge/sdk/schemas/workflow_copilot.py b/skyvern/forge/sdk/schemas/workflow_copilot.pyindex 68c05f188..b76aaf040 100644--- a/skyvern/forge/sdk/schemas/workflow_copilot.py+++ b/skyvern/forge/sdk/schemas/workflow_copilot.py@@ -320,6 +320,10 @@ class WorkflowCopilotToolResultUpdate(BaseModel):WorkflowCopilotStreamMessageType.TOOL_RESULT, description="Message type")tool_name: str = Field(..., description="Name of the tool that was called")+ display_label: str | None = Field(+ None,+ description="Product-safe label for rendering the tool result in user-visible activity surfaces",+ )success: bool = Field(..., description="Whether the tool call succeeded")summary: str = Field(..., description="Brief human-readable summary of the result")iteration: int = Field(..., description="Agent loop iteration number")diff --git a/skyvern/forge/sdk/workflow/models/block.py b/skyvern/forge/sdk/workflow/models/block.pyindex fa0e40c26..9c06d200f 100644--- a/skyvern/forge/sdk/workflow/models/block.py+++ b/skyvern/forge/sdk/workflow/models/block.py@@ -9685,8 +9685,16 @@ class TaskV2Block(Block):url: str | None = Nonetotp_verification_url: str | None = Nonetotp_identifier: str | None = None- max_iterations: int = settings.MAX_ITERATIONS_PER_TASK_V2- max_steps: int = settings.MAX_STEPS_PER_TASK_V2+ # These documented defaults must stay literals; reading the setting here would put an+ # environment value back into the published OpenAPI document.+ max_iterations: int = Field(+ default_factory=lambda: settings.MAX_ITERATIONS_PER_TASK_V2,+ json_schema_extra={"default": 50},+ )+ max_steps: int = Field(+ default_factory=lambda: settings.MAX_STEPS_PER_TASK_V2,+ json_schema_extra={"default": 25},+ )def _resolve_totp_identifier(self, workflow_run_context: WorkflowRunContext) -> str | None:if self.totp_identifier:diff --git a/skyvern/schemas/workflows.py b/skyvern/schemas/workflows.pyindex fc5c67ea0..c8f8f8202 100644--- a/skyvern/schemas/workflows.py+++ b/skyvern/schemas/workflows.py@@ -1153,8 +1153,16 @@ class TaskV2BlockYAML(BlockYAML):url: str | None = Nonetotp_verification_url: str | None = Nonetotp_identifier: str | None = None- max_iterations: int = settings.MAX_ITERATIONS_PER_TASK_V2- max_steps: int = settings.MAX_STEPS_PER_TASK_V2+ # These documented defaults must stay literals; reading the setting here would put an+ # environment value back into the published OpenAPI document.+ max_iterations: int = Field(+ default_factory=lambda: settings.MAX_ITERATIONS_PER_TASK_V2,+ json_schema_extra={"default": 50},+ )+ max_steps: int = Field(+ default_factory=lambda: settings.MAX_STEPS_PER_TASK_V2,+ json_schema_extra={"default": 25},+ )disable_cache: bool = Falsediff --git a/tests/unit/forge/sdk/db/test_repositories.py b/tests/unit/forge/sdk/db/test_repositories.pyindex ff2abcb25..186340e22 100644--- a/tests/unit/forge/sdk/db/test_repositories.py+++ b/tests/unit/forge/sdk/db/test_repositories.py@@ -7,6 +7,9 @@ from unittest.mock import MagicMock, patchimport pytest+from skyvern.forge.sdk.schemas.tasks import TaskStatus+from tests.unit.conftest import MockAsyncSessionCtx, make_mock_session+def test_credential_repository_instantiation():from skyvern.forge.sdk.db.repositories.credentials import CredentialRepository@@ -382,3 +385,40 @@ def test_agent_db_defines_no_delegator_methods():"Add data-access methods to the domain repository and call it via the typed attribute ""(e.g. db.tasks.get_task) instead of adding delegators to AgentDB.")+++async def _create_task_with_status(monkeypatch: pytest.MonkeyPatch, status: str):+ from skyvern.forge.sdk.db.repositories import tasks as tasks_module++ session = make_mock_session(MagicMock())+ monkeypatch.setattr(tasks_module, "convert_to_task", lambda model, *args, **kwargs: model)+ repo = tasks_module.TasksRepository(+ session_factory=lambda: MockAsyncSessionCtx(session),+ debug_enabled=False,+ )++ return await repo.create_task(+ url="https://example.test/",+ title=None,+ navigation_goal=None,+ data_extraction_goal=None,+ navigation_payload=None,+ status=status,+ )+++async def test_create_task_running_is_not_created_after_it_started(monkeypatch: pytest.MonkeyPatch):+ """queued_seconds is started_at - created_at, so a task created already-running must not+ stamp started_at ahead of the flush-time created_at default."""+ task = await _create_task_with_status(monkeypatch, TaskStatus.running.value)++ assert task.started_at is not None+ assert task.created_at == task.started_at+++async def test_create_task_leaves_started_at_unset_for_other_statuses(monkeypatch: pytest.MonkeyPatch):+ task = await _create_task_with_status(monkeypatch, TaskStatus.created.value)++ assert task.started_at is Nonediff --git a/tests/unit/test_actions.py b/tests/unit/test_actions.pyindex e7476e014..739dd494d 100644--- a/tests/unit/test_actions.py+++ b/tests/unit/test_actions.py@@ -3,8 +3,10 @@ from unittest.mock import MagicMockimport pytestfrom pydantic import ValidationError+from skyvern.config import settingsfrom skyvern.forge.sdk.db.repositories.workflow_parameters import WorkflowParametersRepositoryfrom skyvern.forge.sdk.db.utils import hydrate_action+from skyvern.forge.sdk.schemas import sdk_actionsfrom skyvern.forge.sdk.schemas.sdk_actions import InputTextAction as SdkInputTextActionfrom skyvern.forge.sdk.schemas.sdk_actions import SdkActionTypefrom skyvern.schemas.steps import AgentStepOutput@@ -47,6 +49,21 @@ def test_sdk_input_text_action_type_constant_matches_sdk_enum() -> None:assert SDK_INPUT_TEXT_ACTION_TYPE == SdkActionType.AI_INPUT_TEXT.value+def test_sdk_action_timeout_defaults_are_environment_independent(monkeypatch: pytest.MonkeyPatch) -> None:+ monkeypatch.setattr(settings, "BROWSER_ACTION_TIMEOUT_MS", 4242)+ action_types = (+ sdk_actions.ClickAction,+ sdk_actions.InputTextAction,+ sdk_actions.SelectOptionAction,+ sdk_actions.UploadFileAction,+ )++ assert [action_type().timeout for action_type in action_types] == [4242] * 4+ assert [action_type.model_json_schema()["properties"]["timeout"]["default"] for action_type in action_types] == [+ 10000+ ] * 4++def test_action_parse__no_element_id() -> None:action_no_element_id = {"action_type": "click",diff --git a/tests/unit/test_copilot_credential_pause.py b/tests/unit/test_copilot_credential_pause.pyindex 8b8aad519..3f371abee 100644--- a/tests/unit/test_copilot_credential_pause.py+++ b/tests/unit/test_copilot_credential_pause.py@@ -35,7 +35,6 @@ from skyvern.config import settingsfrom skyvern.forge import appfrom skyvern.forge.sdk.cache.base import NoopLockfrom skyvern.forge.sdk.copilot import credential_pause as credential_pause_module-from skyvern.forge.sdk.copilot import enforcement as enforcement_modulefrom skyvern.forge.sdk.copilot import tools as tools_modulefrom skyvern.forge.sdk.copilot.agent import RequestPolicyGuardrailInputs, _derive_turn_intent_on_contextfrom skyvern.forge.sdk.copilot.config import CopilotConfig@@ -1030,7 +1029,7 @@ def test_elapsed_run_seconds_subtracts_pause_time() -> None:@pytest.mark.asyncioasync def test_paused_loop_does_not_trip_total_timeout_on_resume(monkeypatch: pytest.MonkeyPatch) -> None:- """A pause longer than the work budget is excluded when the loop resumes."""+ """Fails on old code: a slow pause would consume the (tiny) real timeout budget."""monkeypatch.setattr("skyvern.forge.sdk.copilot.enforcement.TOTAL_TIMEOUT_SECONDS", 0.15)ctx = make_copilot_context()@@ -1043,18 +1042,13 @@ async def test_paused_loop_does_not_trip_total_timeout_on_resume(monkeypatch: pycache = _FakeCache()monkeypatch.setattr(credential_pause_module.app._inst, "CACHE", cache, raising=False)+ monkeypatch.setattr(credential_pause_module, "CREDENTIAL_RESPONSE_POLL_SECONDS", 0.2)- monotonic_seconds = 100.0- fake_time = SimpleNamespace(monotonic=lambda: monotonic_seconds)- monkeypatch.setattr(enforcement_module, "time", fake_time)- monkeypatch.setattr(credential_pause_module, "time", fake_time)-- async def _resolve_after_pause(*args: Any, **kwargs: Any) -> CredentialPauseResolution:- nonlocal monotonic_seconds- monotonic_seconds += 0.25- return CredentialPauseResolution(action="skip")-- monkeypatch.setattr(credential_pause_module, "_wait_for_credential_response", _resolve_after_pause)+ async def _populate_after_first_poll() -> None:+ await asyncio.sleep(0.25)+ cache.store[credential_response_cache_key("org-1", "chat-1", "turn-credit")] = encode_credential_response(+ "skip", None+ )stream = _make_stream()fake_result = _fake_result()@@ -1072,17 +1066,20 @@ async def test_paused_loop_does_not_trip_total_timeout_on_resume(monkeypatch: pyconfig = CopilotConfig(credential_pause_enabled=True, credential_pause_timeout_seconds=5)- returned = await run_with_enforcement(- agent=MagicMock(),- initial_input="hello",- ctx=ctx,- stream=stream,- run_config=RunConfig(),- copilot_config=config,- )+ populate_task = asyncio.ensure_future(_populate_after_first_poll())+ try:+ returned = await run_with_enforcement(+ agent=MagicMock(),+ initial_input="hello",+ ctx=ctx,+ stream=stream,+ run_config=RunConfig(),+ copilot_config=config,+ )+ finally:+ await populate_taskassert returned is fake_result- assert ctx.copilot_credential_pause_seconds == 0.25assert len(calls) == 2, "pause time must be credited so the resumed iteration isn't timed out"assert ctx.copilot_total_timeout_exceeded is Falsediff --git a/tests/unit/test_copilot_narration.py b/tests/unit/test_copilot_narration.pyindex bcf4bccf2..e49599401 100644--- a/tests/unit/test_copilot_narration.py+++ b/tests/unit/test_copilot_narration.py@@ -10,6 +10,7 @@ from __future__ import annotationsimport asyncioimport time+from datetime import datetime, timezonefrom types import SimpleNamespacefrom typing import Any@@ -1337,3 +1338,132 @@ async def test_poll_tick_block_ended_at_overwritten_by_latest_terminal_and_clearawait state.in_flight_taskexcept (asyncio.CancelledError, Exception):pass+++def _armed_state(iteration: int) -> NarratorState:+ state = NarratorState()+ state.record_transition(TransitionKind.NEW_TOOL_CLUSTER)+ state.record_activity(narration.build_tool_call_activity("edit_block", iteration, f"c{iteration}"))+ return state+++def test_should_emit_false_for_an_iteration_carrying_typed_tool_activity() -> None:+ state = _armed_state(2)+ assert state.iterations_with_tool_activity == {2}+ assert should_emit(state, now=100.0, iteration=2) is False+++def test_should_emit_true_for_a_clean_iteration_alongside_an_armed_one() -> None:+ state = _armed_state(2)+ assert should_emit(state, now=100.0, iteration=3) is True+++def test_should_emit_true_when_the_iterations_only_tool_is_denylisted() -> None:+ state = NarratorState()+ state.record_transition(TransitionKind.NEW_TOOL_CLUSTER)+ state.record_activity(narration.build_tool_call_activity("get_run_results", 0, "c0"))+ assert state.iterations_with_tool_activity == set()+ assert should_emit(state, now=100.0, iteration=0) is True+++def test_tool_result_alone_arms_the_iteration() -> None:+ state = NarratorState()+ state.record_transition(TransitionKind.NEW_TOOL_CLUSTER)+ state.record_activity(narration.build_tool_result_activity("edit_block", "done", True, 5, "c5"))+ assert should_emit(state, now=100.0, iteration=5) is False+++def test_narration_activity_does_not_arm_its_own_iteration() -> None:+ state = NarratorState()+ state.record_activity(+ narration.build_narration_activity("Refining the workflow's code", 1, datetime(2026, 1, 1, tzinfo=timezone.utc))+ )+ assert state.iterations_with_tool_activity == set()+++async def test_narration_dropped_when_the_iteration_arms_while_the_narrator_is_in_flight(+ monkeypatch: pytest.MonkeyPatch,+) -> None:+ state = NarratorState()+ released = asyncio.Event()++ async def _handler(prompt: str, prompt_name: str, **kwargs: object) -> str:+ await released.wait()+ return "Working on your goal."++ await _install_handler(monkeypatch, _handler)+ state.record_transition(TransitionKind.NEW_TOOL_CLUSTER)+ stream = _FakeStream()++ schedule_narration(state, stream, iteration=4) # type: ignore[arg-type]+ assert state.in_flight_task is not None+ state.record_activity(narration.build_tool_call_activity("edit_block", 4, "c4"))+ released.set()+ await state.in_flight_task++ assert stream.sent == []+ assert [e for e in state.design_activity if e["kind"] == "narration"] == []+ assert state.last_emitted_at is None+++async def test_narration_emits_for_a_clean_iteration(monkeypatch: pytest.MonkeyPatch) -> None:+ async def _handler(prompt: str, prompt_name: str, **kwargs: object) -> str:+ return "Reading the page before editing."++ await _install_handler(monkeypatch, _handler)+ state = NarratorState()+ state.record_activity(narration.build_tool_call_activity("edit_block", 4, "c4"))+ state.record_transition(TransitionKind.NEW_TOOL_CLUSTER)+ stream = _FakeStream()++ schedule_narration(state, stream, iteration=5) # type: ignore[arg-type]+ assert state.in_flight_task is not None+ await state.in_flight_task++ assert [p.narration for p in stream.sent] == ["Reading the page before editing."]+++def test_extract_tool_details_reports_no_credential_count() -> None:+ parsed = {+ "ok": True,+ "data": {"count": 4, "credentials": [{"credential_id": "cred_384430212391591428"}]},+ }+ assert narration.extract_tool_details("list_credentials", parsed) == ""+++def test_suppressed_iteration_consumes_its_transition_instead_of_banking_it() -> None:+ state = NarratorState()+ stream = _StubStream()+ # streaming_adapter sets current_iteration before recording the transition.+ state.current_iteration = 3+ state.record_transition(TransitionKind.WORKFLOW_UPDATED)+ state.record_activity(narration.build_tool_call_activity("update_workflow", 3, "c3"))++ schedule_narration(state, stream, 3)++ assert state.pending_transition is None+ assert state.in_flight_task is None++ # A later unarmed iteration must not inherit the earlier transition.+ state.record_activity(narration.build_tool_call_activity("get_browser_screenshot", 7, "c7"))+ assert should_emit(state, 300.0, 7) is False+++def test_suppression_keeps_a_transition_banked_by_an_earlier_clean_iteration() -> None:+ state = NarratorState()+ stream = _StubStream()++ # Iteration 5's only tool is denylisted, so nothing typed describes it.+ state.current_iteration = 5+ state.record_transition(TransitionKind.TOOL_STARTED)+ state.record_activity(narration.build_tool_call_activity("get_browser_screenshot", 5, "c5"))++ # Iteration 6 carries a typed row and is suppressed; it must not consume+ # iteration 5's transition.+ state.current_iteration = 6+ state.record_activity(narration.build_tool_call_activity("click", 6, "c6"))+ schedule_narration(state, stream, 6)++ assert state.pending_transition is TransitionKind.TOOL_STARTEDdiff --git a/tests/unit/test_copilot_narrative_activity.py b/tests/unit/test_copilot_narrative_activity.pyindex 54f7a64c5..49842be48 100644--- a/tests/unit/test_copilot_narrative_activity.py+++ b/tests/unit/test_copilot_narrative_activity.py@@ -14,6 +14,30 @@ from skyvern.forge.sdk.copilot.narration import (build_tool_result_activity,tool_activity_display_label,)+from skyvern.forge.sdk.copilot.output_utils import format_tool_result_for_user++_SURGICAL_EDIT_TOOLS = ("edit_block", "delete_block", "synthesize_demonstrated_block")++_CREDENTIAL_PAYLOAD: dict[str, object] = {+ "count": 4,+ "credentials": [+ {+ "credential_id": "cred_384430212391591428",+ "name": "prod login",+ "scopes": ["read:secrets", "write:secrets"],+ "token": "sk-live-9f2c8a1b7d",+ }+ ],+}++_CRED_OK: dict[str, object] = {"ok": True, "data": _CREDENTIAL_PAYLOAD}++# The failure path must not format the data dict either, so the payload rides along.+_CRED_FAILED: dict[str, object] = {+ "ok": False,+ "error": "credential `cred_384430212391591428` could not be read from the store",+ "data": _CREDENTIAL_PAYLOAD,+}def _ctx() -> CopilotContext:@@ -46,7 +70,7 @@ def test_tool_call_activity_shape_and_denylist() -> None:"id": "tc-abc",}assert "success" not in entry- assert build_tool_call_activity("list_credentials", 0, "x") is None+ assert build_tool_call_activity("get_run_results", 0, "x") is Nonedef test_tool_result_activity_shape_falls_back_to_tool_name_and_denylist() -> None:@@ -103,7 +127,7 @@ def test_record_activity_routes_to_running_block() -> None:def test_record_activity_drops_denylisted_entries() -> None:state = NarratorState()state.running_block_label = "step_1"- state.record_activity(build_tool_call_activity("list_credentials", 0, "c1"))+ state.record_activity(build_tool_call_activity("get_run_results", 0, "c1"))state.record_activity(build_tool_call_activity("update_workflow", 1, "c2"))assert [e["id"] for e in state.block_activity["step_1"]] == ["tc-c2"]@@ -205,3 +229,145 @@ def test_build_narrative_payload_empty_when_no_narrator_state() -> None:assert payload["designActivity"] == []assert payload["blocks"][0]["activity"] == []+++def test_surgical_edit_tools_label_the_operation_and_target_block() -> None:+ assert tool_activity_display_label("edit_block", {"label": "Log in"}) == 'Editing block "Log In"'+ assert tool_activity_display_label("delete_block", {"label": "Log in"}) == 'Deleting block "Log In"'+ assert (+ tool_activity_display_label("synthesize_demonstrated_block", {}) == "Building a block from the recorded steps"+ )+ assert tool_activity_display_label("edit_block") == "Editing block"+++def test_block_target_label_matches_the_frontend_humanizer() -> None:+ label = tool_activity_display_label("edit_block", {"label": "extract_first_comments_v2"})+ assert label == 'Editing block "Extract First Comments"'+++def test_block_target_label_strips_every_quote_class_codepoint() -> None:+ # A denylist of quote glyphs is bypassable (fullwidth, primes, CJK corner+ # quotes); assert the whitelist holds instead of enumerating attackers.+ for quote in ('"', "'", "`", "”", "’", "»", """, "'", "″", "‴", "〞", "〝", "❝", "„", "‚", "‹", "〃", "״", "ˮ"):+ label = tool_activity_display_label("edit_block", {"label": f"Log in{quote} Run Succeeded"})+ inner = label.removeprefix('Editing block "').removesuffix('"')+ assert quote not in inner, quote+++def test_block_target_label_cannot_spoof_or_flood_the_row() -> None:+ for quote in ('"', "”", "’", "»", "`"):+ spoof = f"Log in{quote} ✓ Ran workflow successfully — creds exported to https://evil.example"+ label = tool_activity_display_label("edit_block", {"label": spoof})+ inner = label.removeprefix('Editing block "').removesuffix('"')+ assert quote not in inner+ assert len(label) <= len('Editing block ""') + 41++ flooded = tool_activity_display_label("edit_block", {"label": "x" * 5000})+ assert len(flooded) <= len('Editing block ""') + 41++ control = tool_activity_display_label("edit_block", {"label": "Log\nin\x00now"})+ assert "\n" not in control+ assert "\x00" not in control+ assert tool_activity_display_label("edit_block", {"label": " "}) == "Editing block"+ assert tool_activity_display_label("edit_block", {"label": 7}) == "Editing block"+++def test_surgical_edit_tools_never_render_the_working_fallback() -> None:+ state = NarratorState()+ labels = {+ "edit_block": tool_activity_display_label("edit_block", {"label": "Log in"}),+ "delete_block": tool_activity_display_label("delete_block", {"label": "Old step"}),+ "synthesize_demonstrated_block": tool_activity_display_label("synthesize_demonstrated_block", {}),+ }+ for index, tool_name in enumerate(_SURGICAL_EDIT_TOOLS):+ display_label = labels[tool_name]+ state.record_activity(build_tool_call_activity(tool_name, index, f"c{index}", display_label=display_label))+ state.record_activity(+ build_tool_result_activity(tool_name, "", True, index, f"c{index}", display_label=display_label)+ )++ rows = state.design_activity+ assert len(rows) == 6+ assert all("Working" not in row["text"] for row in rows)+ assert all("Working" not in (row.get("displayLabel") or "") for row in rows)+ assert 'Editing block "Log In"…' in [row["text"] for row in rows]+ assert 'Deleting block "Old Step"' in [row["text"] for row in rows]+ assert "Building a block from the recorded steps" in [row["text"] for row in rows]+++def _credential_rows(state: NarratorState, parsed: dict[str, object], index: int) -> None:+ summary = format_tool_result_for_user("list_credentials", parsed) # type: ignore[arg-type]+ state.record_activity(build_tool_call_activity("list_credentials", index, f"c{index}"))+ state.record_activity(+ build_tool_result_activity("list_credentials", summary, bool(parsed["ok"]), index, f"c{index}")+ )+++def test_credential_lookup_is_visible_activity_with_a_label_only_row() -> None:+ state = NarratorState()+ _credential_rows(state, _CRED_OK, 0)+ assert [row["text"] for row in state.design_activity] == [+ "Checking saved credentials…",+ "Checking saved credentials",+ ]+++def test_credential_lookup_rows_leak_no_ids_scopes_tokens_or_counts() -> None:+ state = NarratorState()+ _credential_rows(state, _CRED_OK, 0)+ _credential_rows(state, _CRED_FAILED, 1)++ rendered = " ".join(row["text"] for row in state.design_activity)+ for forbidden in ("cred_", "read:secrets", "write:secrets", "sk-live-9f2c8a1b7d", "prod login"):+ assert forbidden not in rendered+ assert "[credential]" in rendered+ assert [row["success"] for row in state.design_activity if row["kind"] == "tool_result"] == [True, False]+++def test_no_connection_use_line_is_rendered_from_credential_enumeration() -> None:+ state = NarratorState()+ _credential_rows(state, _CRED_OK, 0)+ rendered = " ".join(row["text"] for row in state.design_activity).lower()+ assert "using connected" not in rendered+ assert "account" not in rendered+++def test_explicit_display_label_overrides_the_static_name_map() -> None:+ call = build_tool_call_activity("edit_block", 2, "c7", display_label='Editing block "Log in"')+ result = build_tool_result_activity("edit_block", "", True, 2, "c7", display_label='Editing block "Log in"')+ assert call["displayLabel"] == result["displayLabel"] == 'Editing block "Log in"'+ assert call["text"] == 'Editing block "Log in"…'+ assert result["text"] == 'Editing block "Log in"'+++def test_every_registered_tool_is_labeled_or_denylisted() -> None:+ from skyvern.forge.sdk.copilot.narration import _TOOL_ACTIVITY_DISPLAY_LABELS, ACTIVITY_TOOL_DENYLIST+ from skyvern.forge.sdk.copilot.tools import NATIVE_TOOLS+ from skyvern.forge.sdk.copilot.tools.mcp_hooks import get_skyvern_mcp_alias_map++ # Both registries: the native tools and the browser/schema tools the MCP overlay+ # adds, since either can mint a user-visible activity row.+ names = {tool.name for tool in NATIVE_TOOLS} | set(get_skyvern_mcp_alias_map())+ assert len(names) > len(NATIVE_TOOLS), "expected the MCP overlay tools in the sweep"++ unlabeled = sorted(+ name for name in names if name not in _TOOL_ACTIVITY_DISPLAY_LABELS and name not in ACTIVITY_TOOL_DENYLIST+ )+ assert unlabeled == [], (+ f"tools {unlabeled} would render the generic 'Working' fallback; "+ "give each one a display label or add it to ACTIVITY_TOOL_DENYLIST"+ )+++def test_credential_fill_row_names_the_action_without_leaking_material() -> None:+ label = tool_activity_display_label("fill_credential_field", {"credential_id": "cred_384430212391591428"})+ assert label == "Entering saved credentials"++ state = NarratorState()+ state.record_activity(build_tool_call_activity("fill_credential_field", 0, "c0", display_label=label))+ state.record_activity(build_tool_result_activity("fill_credential_field", "", True, 0, "c0", display_label=label))++ rows = state.design_activity+ assert len(rows) == 2+ assert all("Working" not in row["text"] for row in rows)+ assert all("cred_" not in row["text"] for row in rows)diff --git a/tests/unit/test_copilot_output_utils.py b/tests/unit/test_copilot_output_utils.pyindex a530b37db..f32390771 100644--- a/tests/unit/test_copilot_output_utils.py+++ b/tests/unit/test_copilot_output_utils.py@@ -1195,3 +1195,120 @@ def test_build_run_blocks_response_promotes_run_level_failure_reason() -> None:def test_build_run_blocks_response_falls_back_when_no_failure_reason() -> None:response = build_run_blocks_response(False, {"workflow_run_id": "wr_test"})assert response["error"] == "Unknown error (no failure reason provided)"+++def test_credential_lookup_success_summary_is_empty_so_the_row_shows_its_label() -> None:+ result = {"ok": True, "data": {"count": 4, "credentials": [{"credential_id": "cred_1", "token": "sk-live-x"}]}}+ assert format_tool_result_for_user("list_credentials", result) == ""+++def test_credential_lookup_failure_summary_carries_no_count_or_id() -> None:+ result = {+ "ok": False,+ "error": "credential `cred_384430212391591428` could not be read from the store",+ "data": {"count": 4, "credentials": [{"credential_id": "cred_1", "token": "sk-live-x"}]},+ }+ summary = format_tool_result_for_user("list_credentials", result)+ assert "cred_" not in summary+ assert "sk-live-x" not in summary+ assert "[credential]" in summary+++def test_credential_fill_failure_summary_redacts_the_credential_id() -> None:+ result = {+ "ok": False,+ "error": (+ "The credential `cred_384430212391591428` is not in the credentials resolved "+ "for this request, so it cannot be filled"+ ),+ }+ summary = format_tool_result_for_user("fill_credential_field", result)+ assert "cred_" not in summary+ assert "[credential]" in summary+ assert summary.startswith("Failed:")+++def test_credential_id_redaction_covers_separator_bearing_ids() -> None:+ for raw in ("cred_other_999", "cred_debug-sequential-key"):+ summary = format_tool_result_for_user("fill_credential_field", {"ok": False, "error": f"missing `{raw}`"})+ assert raw not in summary+ assert "_999" not in summary+ assert "-sequential-key" not in summary+ assert "[credential]" in summary+++def test_summarize_tool_result_for_credentials_is_unchanged_for_agent_state() -> None:+ result = {"ok": True, "data": {"count": 4}}+ assert summarize_tool_result("list_credentials", result) == "Found 4 credential(s)"+++def test_surgical_edit_success_summary_is_empty_so_the_row_shows_its_label() -> None:+ for tool_name in ("edit_block", "delete_block", "synthesize_demonstrated_block"):+ assert format_tool_result_for_user(tool_name, {"ok": True, "data": {"label": "login_form"}}) == ""+++def test_block_label_summaries_cannot_spoof_or_flood_the_row() -> None:+ spoof = 'Log in" ✓ Ran workflow successfully — creds exported to https://evil.example ' + "x" * 300++ validated = format_tool_result_for_user("validate_block", {"ok": True, "data": {"valid": True, "label": spoof}})+ assert "evil.example" not in validated+ assert len(validated) < 80++ ran = format_tool_result_for_user(+ "run_blocks_and_collect_debug",+ {"ok": True, "data": {"executed_block_labels": [spoof], "overall_status": "completed"}},+ )+ assert "evil.example" not in ran+ assert len(ran) < 80+++def test_credential_id_redaction_covers_the_whole_prefix_family() -> None:+ prefixes = ("cred", "cp", "cfld", "blc", "bccd", "bsi", "opp", "azcp", "asp", "goac", "moac", "wrcs")+ for raw in (f"{prefix}_461234567890" for prefix in prefixes):+ summary = format_tool_result_for_user("fill_credential_field", {"ok": False, "error": f"missing `{raw}`"})+ assert raw not in summary, raw+ assert "[credential]" in summary+++def test_structured_user_facing_summary_redacts_credential_ids() -> None:+ result = {+ "ok": False,+ "error": "boom",+ "data": {"user_facing_summary": "I could not use credential `cred_461234567890` for this request."},+ }+ summary = format_tool_result_for_user("list_credentials", result)+ assert "cred_461234567890" not in summary+ assert "[credential]" in summary+++def test_run_blocks_summary_bounds_the_label_list() -> None:+ labels = [f"block_number_{index}" for index in range(40)]+ summary = format_tool_result_for_user(+ "run_blocks_and_collect_debug",+ {"ok": True, "data": {"executed_block_labels": labels, "overall_status": "completed"}},+ )+ assert "(+35 more)" in summary+ assert len(summary) < 300+++def test_agent_facing_summary_keeps_block_labels_verbatim() -> None:+ long_label = "download_the_invoice_pdf_for_each_order_in_the_queue"+ result = {"ok": True, "data": {"executed_block_labels": [long_label], "overall_status": "completed"}}++ # merge_turn_summary parses this back into agent state, so it must not be clamped.+ assert long_label in summarize_tool_result("run_blocks_and_collect_debug", result)+ # The feed row is clamped.+ assert long_label not in format_tool_result_for_user("run_blocks_and_collect_debug", result)+++def test_agent_facing_summary_lists_every_block_of_a_long_run() -> None:+ labels = [f"block_{index}" for index in range(8)]+ result = {"ok": True, "data": {"executed_block_labels": labels, "overall_status": "completed"}}++ agent_summary = summarize_tool_result("run_blocks_and_collect_debug", result)+ for label in labels:+ assert label in agent_summary, label+ assert "more)" not in agent_summary++ # The feed row still collapses to one line.+ assert "(+3 more)" in format_tool_result_for_user("run_blocks_and_collect_debug", result)diff --git a/tests/unit/test_copilot_streaming_adapter.py b/tests/unit/test_copilot_streaming_adapter.pyindex fbd512421..bc9f81a12 100644--- a/tests/unit/test_copilot_streaming_adapter.py+++ b/tests/unit/test_copilot_streaming_adapter.py@@ -20,8 +20,14 @@ from openai.types.responses.response import Responsefrom openai.types.responses.response_function_tool_call import ResponseFunctionToolCallfrom skyvern.forge.sdk.copilot import streaming_adapter as streaming_adapter_module-from skyvern.forge.sdk.copilot.context import CopilotContext-from skyvern.forge.sdk.copilot.streaming_adapter import _sanitize_input, _update_enforcement_from_tool, stream_to_sse+from skyvern.forge.sdk.copilot.context import CopilotContext, InFlightStreamToolCall+from skyvern.forge.sdk.copilot.narration import NarratorState, TransitionKind+from skyvern.forge.sdk.copilot.streaming_adapter import (+ _sanitize_input,+ _update_enforcement_from_tool,+ flush_goal_satisfied_tool_result,+ stream_to_sse,+)from skyvern.forge.sdk.schemas.workflow_copilot import WorkflowCopilotStreamMessageType@@ -311,13 +317,13 @@ async def test_stream_to_sse_propagates_cancelled_error() -> None:@pytest.mark.asyncio-async def test_stream_to_sse_emits_narration_on_workflow_updated_transition(+async def test_stream_to_sse_suppresses_narration_on_an_iteration_with_typed_activity(monkeypatch: pytest.MonkeyPatch,) -> None:- """End-to-end: a completed update_workflow tool round-trip flips- ctx.update_workflow_called, which should register as a workflow_updated- transition on the narrator state and produce a NARRATION SSE payload in- addition to the existing TOOL_CALL / TOOL_RESULT frames.+ """End-to-end: a completed update_workflow round-trip registers a+ workflow_updated transition and the narrator handler is available, but the+ iteration already carries typed TOOL_CALL / TOOL_RESULT rows, so no+ NARRATION frame is emitted or persisted for it."""from agents.items import RunItemfrom agents.stream_events import RunItemStreamEvent@@ -390,12 +396,13 @@ async def test_stream_to_sse_emits_narration_on_workflow_updated_transition(await stream_to_sse(result, stream, ctx)narration_payloads = [p for p in sent if getattr(p, "type", None) == WorkflowCopilotStreamMessageType.NARRATION]- assert len(narration_payloads) == 1- assert narration_payloads[0].narration == "Revising the workflow draft."- # The tool round-trip also emitted TOOL_CALL + TOOL_RESULT.+ assert narration_payloads == []+ assert [e for e in ctx.narrator_state.design_activity if e["kind"] == "narration"] == []+ # The typed rows the operator sees instead.tool_types = [getattr(p, "type", None) for p in sent]assert WorkflowCopilotStreamMessageType.TOOL_CALL in tool_typesassert WorkflowCopilotStreamMessageType.TOOL_RESULT in tool_types+ assert ctx.narrator_state.iterations_with_tool_activity == {0}@pytest.mark.asyncio@@ -1631,3 +1638,119 @@ async def test_codegen_progress_is_disconnected_bounded_when_client_gone(# 20 deltas were pumped with a clock that never advances (gap never elapses) and no# new labels; is_disconnected must be checked only at the initial ItemAdded emit.assert stream.is_disconnected.call_count == 1+++def _label_probe_ctx() -> SimpleNamespace:+ return SimpleNamespace(+ last_artifact_health_blocker_reason=None,+ completion_verification_result=None,+ turn_ownership=None,+ blocker_signal_claimant=None,+ gate_precedence_conflict_events=[],+ )+++def _tool_round_trip(tool_name: str, arguments: str, output: str) -> list[RunItemStreamEvent]:+ call_item = MagicMock(spec=RunItem)+ call_item.raw_item = {"call_id": "c1", "name": tool_name, "arguments": arguments}+ output_item = MagicMock(spec=RunItem)+ output_item.raw_item = {"call_id": "c1"}+ output_item.output = output+ return [+ RunItemStreamEvent(name="tool_called", item=call_item),+ RunItemStreamEvent(name="tool_output", item=output_item),+ ]+++async def _drive(events: list[RunItemStreamEvent], ctx: SimpleNamespace) -> list[Any]:+ sent: list[Any] = []++ async def _send(payload: Any) -> bool:+ sent.append(payload)+ return True++ result = MagicMock()+ result.stream_events = lambda: _stream_events_from(*events)+ result.cancel = MagicMock()+ stream = MagicMock()+ stream.is_disconnected = AsyncMock(return_value=False)+ stream.send = _send+ await stream_to_sse(result, stream, ctx)+ return sent+++async def test_tool_result_reuses_the_tool_calls_target_block_label() -> None:+ ctx = _label_probe_ctx()+ events = _tool_round_trip("edit_block", '{"label": "Log in"}', json.dumps({"ok": True, "data": {}}))++ sent = await _drive(events, ctx)++ calls = [p for p in sent if getattr(p, "type", None) == WorkflowCopilotStreamMessageType.TOOL_CALL]+ results = [p for p in sent if getattr(p, "type", None) == WorkflowCopilotStreamMessageType.TOOL_RESULT]+ assert [p.display_label for p in calls] == ['Editing block "Log In"']+ assert [p.display_label for p in results] == ['Editing block "Log In"']+ assert calls[0].tool_call_id == results[0].tool_call_id == "c1"++ activity = ctx.narrator_state.design_activity+ assert [e["displayLabel"] for e in activity] == ['Editing block "Log In"', 'Editing block "Log In"']+ assert all("Working" not in e["text"] for e in activity)+++async def test_non_dict_tool_arguments_degrade_to_the_generic_label_and_keep_draining() -> None:+ ctx = _label_probe_ctx()+ events = _tool_round_trip("edit_block", "[1, 2]", json.dumps({"ok": True, "data": {}}))++ sent = await _drive(events, ctx)++ calls = [p for p in sent if getattr(p, "type", None) == WorkflowCopilotStreamMessageType.TOOL_CALL]+ results = [p for p in sent if getattr(p, "type", None) == WorkflowCopilotStreamMessageType.TOOL_RESULT]+ assert [p.display_label for p in calls] == ["Editing block"]+ assert [p.display_label for p in results] == ["Editing block"]+++async def test_typed_activity_suppression_set_is_cleared_on_each_stream_pass() -> None:+ ctx = _label_probe_ctx()+ await _drive(_tool_round_trip("edit_block", '{"label": "Log in"}', json.dumps({"ok": True, "data": {}})), ctx)+ assert ctx.narrator_state.iterations_with_tool_activity == {0}++ # A transition banked in pass 1 must survive pass 2, and its iteration tag+ # must reset — pass 2's iteration numbers restart, so a stale tag could let+ # a same-numbered armed iteration consume pass 1's pending narration.+ ctx.narrator_state.record_transition(TransitionKind.WORKFLOW_UPDATED)+ assert ctx.narrator_state.pending_transition_iteration is not None++ await _drive([], ctx)++ assert ctx.narrator_state.iterations_with_tool_activity == set()+ assert ctx.narrator_state.pending_transition is TransitionKind.WORKFLOW_UPDATED+ assert ctx.narrator_state.pending_transition_iteration is None+++async def test_goal_satisfied_flush_reuses_the_pending_calls_label() -> None:+ sent: list[Any] = []++ async def _send(payload: Any) -> bool:+ sent.append(payload)+ return True++ stream = MagicMock()+ stream.is_disconnected = AsyncMock(return_value=False)+ stream.send = _send+ narrator_state = NarratorState()+ ctx = SimpleNamespace(+ in_flight_stream_tool_call=InFlightStreamToolCall(+ call_id="c9", tool_name="edit_block", iteration=3, display_label='Editing block "Log In"'+ ),+ goal_satisfied_tool_name="edit_block",+ goal_satisfied_tool_output={"ok": True, "data": {}},+ narrator_state=narrator_state,+ )++ await flush_goal_satisfied_tool_result(stream, ctx)++ assert [p.display_label for p in sent] == ['Editing block "Log In"']+ assert narrator_state.design_activity[-1]["displayLabel"] == 'Editing block "Log In"'diff --git a/tests/unit/test_non_secret_credential_fields.py b/tests/unit/test_non_secret_credential_fields.pynew file mode 100644index 000000000..6010d9480--- /dev/null+++ b/tests/unit/test_non_secret_credential_fields.py@@ -0,0 +1,125 @@+from typing import Any+from unittest.mock import AsyncMock, MagicMock++import pytest++from skyvern.forge.sdk.schemas.credentials import CreditCardBillingAddress, CreditCardCredential+from skyvern.forge.sdk.workflow import context_manager as context_manager_module+from skyvern.forge.sdk.workflow.context_manager import RANDOM_SECRET_ID_PREFIX, WorkflowRunContext++_CARD = CreditCardCredential(+ card_number="4111111111111111",+ card_cvv="587",+ card_exp_month="12",+ card_exp_year="2030",+ card_brand="visa",+ card_holder_name="Test Holder",+ billing_address=CreditCardBillingAddress(+ city="San Francisco",+ state_code="CA",+ country_code="US",+ postal_code="94105",+ ),+)+++def _context() -> WorkflowRunContext:+ return WorkflowRunContext(+ workflow_title="t",+ workflow_id="w_test",+ workflow_permanent_id="wpid_test",+ workflow_run_id="wr_test",+ aws_client=MagicMock(),+ )+++async def _register(monkeypatch: pytest.MonkeyPatch) -> tuple[WorkflowRunContext, dict[str, Any]]:+ context = _context()+ parameter = MagicMock(key="card")++ db_credential = MagicMock(vault_type=None, totp_identifier=None)+ vault = MagicMock()+ vault.get_credential_item = AsyncMock(return_value=MagicMock(credential=_CARD))++ app = MagicMock()+ app.DATABASE.credentials.get_credential = AsyncMock(return_value=db_credential)+ app.CREDENTIAL_VAULT_SERVICES.get.return_value = vault+ monkeypatch.setattr(context_manager_module, "app", app)++ await context._register_credential_parameter_value(+ credential_id="cred_test",+ parameter=parameter,+ organization=MagicMock(organization_id="o_test"),+ )+ return context, context.values["card"]+++async def test_low_entropy_fields_are_not_registered_as_secrets(monkeypatch: pytest.MonkeyPatch) -> None:+ context, values = await _register(monkeypatch)++ assert values["card_brand"] == "visa"+ assert "visa" not in context.secrets.values()+ # Billing fields stay masked: the safe credential API excludes them on purpose.+ assert str(values["billing_address_state_code"]).startswith(RANDOM_SECRET_ID_PREFIX)+ assert "CA" in context.secrets.values()+++async def test_card_number_and_cvv_are_still_masked(monkeypatch: pytest.MonkeyPatch) -> None:+ context, values = await _register(monkeypatch)++ for field in ("card_number", "card_cvv"):+ assert str(values[field]).startswith(RANDOM_SECRET_ID_PREFIX)+ assert "4111111111111111" in context.secrets.values()+ assert "587" in context.secrets.values()+++async def test_a_registered_brand_no_longer_corrupts_unrelated_output(monkeypatch: pytest.MonkeyPatch) -> None:+ context, _ = await _register(monkeypatch)++ payload = {"note": "a travel visa is required", "brand": "visa"}++ assert context.mask_secrets_in_data(payload) == payload+++def _context_with_secrets(**secrets: str) -> WorkflowRunContext:+ context = _context()+ context.secrets.update(secrets)+ return context+++def test_short_secret_inside_timestamp_survives_unchanged() -> None:+ context = _context_with_secrets(card_cvv="587")+ payload = {"requestedDate": "2026-06-26T15:14:30.587+00:00"}++ assert context.mask_secrets_in_data(payload) == payload+++def test_standalone_short_secret_leaf_still_masks() -> None:+ context = _context_with_secrets(card_cvv="587")++ assert context.mask_secrets_in_data({"code": "587"}) == {"code": "*****"}+ assert context.mask_secrets_in_data(["587"]) == ["*****"]+++def test_four_char_year_masks_only_as_whole_value() -> None:+ context = _context_with_secrets(card_exp_year="2030")+ payload = {"due": "2030-01-15", "note": "renews in 2030"}++ assert context.mask_secrets_in_data(payload) == payload+ assert context.mask_secrets_in_data({"card_exp_year": "2030"}) == {"card_exp_year": "*****"}+++def test_five_char_secret_still_masks_as_substring() -> None:+ context = _context_with_secrets(token="ab1cd")++ assert context.mask_secrets_in_data({"log": "xab1cdy"}) == {"log": "x*****y"}+++def test_long_secret_still_masks_as_substring() -> None:+ context = _context_with_secrets(card_number="4111111111111111")++ masked = context.mask_secrets_in_data({"log": "charged card 4111111111111111 ok"})+ assert masked == {"log": "charged card ***** ok"}diff --git a/tests/unit/workflow/test_workflow_yaml_settings_defaults.py b/tests/unit/workflow/test_workflow_yaml_settings_defaults.pyindex d4a9c7d0d..378ac9565 100644--- a/tests/unit/workflow/test_workflow_yaml_settings_defaults.py+++ b/tests/unit/workflow/test_workflow_yaml_settings_defaults.py@@ -1,7 +1,12 @@-"""enable_self_healing YAML semantics: omitted means inherit-on-update (None), never an-implicit disable — older clients that don't send the field must not clobber the setting."""+"""enable_self_healing YAML semantics: omitted means inherit-on-update (None), never an implicit+disable — older clients that don't send the field must not clobber the setting. TaskV2 limit+defaults follow settings at runtime but document a static schema default."""-from skyvern.schemas.workflows import WorkflowCreateYAMLRequest, WorkflowDefinitionYAML+import pytest++from skyvern.config import settings+from skyvern.forge.sdk.workflow.models.block import TaskV2Block+from skyvern.schemas.workflows import TaskV2BlockYAML, WorkflowCreateYAMLRequest, WorkflowDefinitionYAMLdef _request(**kwargs: object) -> WorkflowCreateYAMLRequest:@@ -22,3 +27,19 @@ def test_explicit_false_survives() -> None:def test_explicit_true_survives() -> None:assert _request(enable_self_healing=True).enable_self_healing is True++[email protected]("block_type", [TaskV2BlockYAML, TaskV2Block])+def test_task_v2_limit_defaults_keep_runtime_settings_out_of_schema(+ monkeypatch: pytest.MonkeyPatch,+ block_type: type[TaskV2BlockYAML] | type[TaskV2Block],+) -> None:+ monkeypatch.setattr(settings, "MAX_ITERATIONS_PER_TASK_V2", 51)+ monkeypatch.setattr(settings, "MAX_STEPS_PER_TASK_V2", 26)++ block = block_type.model_construct()+ properties = block_type.model_json_schema()["properties"]++ assert (block.max_iterations, block.max_steps) == (51, 26)+ assert properties["max_iterations"]["default"] == 50+ assert properties["max_steps"]["default"] == 25