Automate browser based workflows with AI
Python aiapiautomationbrowserbrowser-automationcomputergptllmplaywrightpowerautomatepuppeteerpythonrpaseleniumvisionworkflow
Append a minimum-age default to Task V3 job-application task messages unless the payload has an age or birth-date field (#8724)
pedrohsdb7c800bced5bb
diff --git a/skyvern-frontend/src/routes/workflows/RunWorkflowForm.test.tsx b/skyvern-frontend/src/routes/workflows/RunWorkflowForm.test.tsxindex def6de3b5..6ab085ff5 100644--- a/skyvern-frontend/src/routes/workflows/RunWorkflowForm.test.tsx+++ b/skyvern-frontend/src/routes/workflows/RunWorkflowForm.test.tsx@@ -97,6 +97,7 @@ vi.mock("@/hooks/useFeatureFlag", () => ({}));vi.mock("posthog-js/react", () => ({useFeatureFlagVariantKey: () => undefined,+ usePostHog: () => ({ capture: vi.fn() }),}));vi.mock("@/store/onboarding/useOnboardingState", () => ({useOnboardingStateOptional: () => null,diff --git a/skyvern-frontend/src/routes/workflows/RunWorkflowForm.tsx b/skyvern-frontend/src/routes/workflows/RunWorkflowForm.tsxindex 8ef926002..60d7b7213 100644--- a/skyvern-frontend/src/routes/workflows/RunWorkflowForm.tsx+++ b/skyvern-frontend/src/routes/workflows/RunWorkflowForm.tsx@@ -50,7 +50,7 @@ import { useWorkflowQuery } from "@/routes/workflows/hooks/useWorkflowQuery";import { useWorkflowStudioEnabled } from "@/hooks/useWorkflowStudioEnabled";import { workflowEditorPath } from "./studioNavigation";import { CredentialSetupPrompt } from "@/components/onboarding/CredentialSetupPrompt";-import { useFeatureFlagVariantKey } from "posthog-js/react";+import { useFeatureFlagVariantKey, usePostHog } from "posthog-js/react";import { useFeatureFlag } from "@/hooks/useFeatureFlag";import { CREDENTIAL_FALLBACK_RETRY_FLAG } from "@/util/featureFlags";import { EXPERIMENT } from "@/util/onboarding/experimentConfig";@@ -568,6 +568,7 @@ function RunWorkflowForm({const location = useLocation();const studioEnabled = useWorkflowStudioEnabled();const queryClient = useQueryClient();+ const postHog = usePostHog();const apiCredential = useApiCredential();const recoveryGuidanceRetryContext = getRecoveryGuidanceRetryContext(location.state,@@ -678,6 +679,7 @@ function RunWorkflowForm({);const runWorkflowMutation = useMutation({+ mutationKey: ["runWorkflow"],mutationFn: async (values: RunWorkflowFormType) => {const client = await getClient(credentialGetter);const body = getRunWorkflowRequestBody(@@ -692,6 +694,10 @@ function RunWorkflowForm({>(`/workflows/${workflowPermanentId}/run`, body);},onSuccess: (response) => {+ postHog.capture("workflow.run.started", {+ org_id: workflow?.organization_id,+ workflow_permanent_id: workflowPermanentId,+ });handleRunWorkflowSuccess(response.data?.workflow_run_id,recoveryGuidanceRetryContext,diff --git a/skyvern-frontend/src/routes/workflows/copilot/NarrativeView.checklist.test.tsx b/skyvern-frontend/src/routes/workflows/copilot/NarrativeView.checklist.test.tsxindex 0bc9a143a..468e6d2c0 100644--- a/skyvern-frontend/src/routes/workflows/copilot/NarrativeView.checklist.test.tsx+++ b/skyvern-frontend/src/routes/workflows/copilot/NarrativeView.checklist.test.tsx@@ -6,6 +6,7 @@ import {render,screen,waitFor,+ within,} from "@testing-library/react";import { afterEach, describe, expect, it } from "vitest";@@ -214,18 +215,164 @@ describe("NarrativeView — activity log", () => {expect(screen.getByText(error).className).toContain("rose");});- it("a block inside a step wears the shared row treatment", () => {- render(<NarrativeView turn={repairLoopTurn()} />);- openFold();- fireEvent.click(stepLines()[1]!);- const blockRow = screen.getByTitle(/Highlight block_1/);-- // The block used to lead with a 24px status puck and a bold label while- // the steps beside it led with a 16px glyph, so the column never lined up.- expect(blockRow.querySelector(".rounded-full")).toBeNull();- expect(blockRow.className).toContain("grid-cols-[18px_1fr_auto]");- expect(visibleText(blockRow)).not.toContain("code");- expect(visibleText(blockRow)).not.toContain("done");+ it("a live test reads as one card per block run, in place of its call", () => {+ const turn = testActiveTurn();+ turn.designActivity = [+ activityEntry({+ id: "tc-2",+ kind: "tool_call",+ toolName: "update_and_run_blocks",+ displayLabel: 'Editing and testing block "block_1"',+ timestamp: "2026-06-10T00:00:01Z",+ codeDiffs: [+ { label: "block_1", added: 3, removed: 2, patch: "-old\n+new" },+ ],+ }),+ ];+ turn.blocks = [+ runningBlock({+ recordedActions: [+ {+ actionId: "a1",+ label: "Goto URL",+ summary: "Open the sign-in page",+ durationMs: 800,+ failed: false,+ codeLine: null,+ response: null,+ },+ ],+ recordedActionsAt: 0,+ }),+ ];+ render(<NarrativeView turn={turn} />);++ const card = screen.getByTestId("copilot-test-card");+ expect(card.dataset.tone).toBe("running");+ expect(visibleText(card)).toContain("Testing Block 1");+ expect(visibleText(card)).toContain("Open the sign-in page");+ expect(visibleText(card)).toContain("0.8s");+ // The card replaces the call row, the diff row and the flat block line.+ expect(screen.queryByText(/Editing and testing block/)).toBeNull();+ expect(screen.queryByText("Active in Live Browser")).toBeNull();+ expect(screen.queryByText("Working…")).toBeNull();+ expect(+ screen.queryByRole("button", { name: /Expand code changes/ }),+ ).toBeNull();+ // Its spinner is the one loader; the step line above does not repeat it.+ expect(screen.queryByText("in progress")).toBeNull();++ expect(screen.queryByText("+new")).toBeNull();+ fireEvent.click(screen.getByRole("button", { name: /Code change/ }));+ expect(screen.getByText("+new")).toBeTruthy();+ });++ it("a retried test reads one card per attempt, the fix in the attempt that ran it", () => {+ const turn = repairLoopTurn();+ const firstAttempt = activityEntry({+ id: "tr-1",+ kind: "tool_result",+ toolName: "update_and_run_blocks",+ text: "Failed: the page never loaded",+ success: false,+ timestamp: "2026-06-10T00:00:08Z",+ codeDiffs: [{ label: "block_1", added: 4, removed: 0, patch: "+old" }],+ });+ const failedBlock = runningBlock({+ workflowRunBlockId: "wrb_1",+ state: "failed",+ // First polled already failed, so it has no start of its own.+ startedAt: null,+ endedAt: "2026-06-10T00:00:07Z",+ });++ // Until the retry reaches the patched block, its new patch stays off the+ // failed card, even while it runs another block first.+ render(+ <NarrativeView+ turn={{+ ...turn,+ terminal: null,+ blocks: [+ failedBlock,+ runningBlock({+ workflowRunBlockId: "wrb_0",+ label: "block_0",+ startedAt: "2026-06-10T00:00:10Z",+ }),+ ],+ designActivity: [+ activityEntry({+ id: "tc-2",+ kind: "tool_call",+ toolName: "update_and_run_blocks",+ attempts: 2,+ priorFailures: [firstAttempt],+ timestamp: "2026-06-10T00:00:09Z",+ codeDiffs: [+ { label: "block_1", added: 2, removed: 0, patch: "+new" },+ ],+ }),+ ],+ }}+ />,+ );+ const pendingCards = screen.getAllByTestId("copilot-test-card");+ expect(pendingCards).toHaveLength(2);+ for (const card of pendingCards) {+ expect(within(card).queryByText("Code change")).toBeNull();+ }+ expect(+ screen.getByRole("button", { name: /Expand code changes/ }),+ ).toBeTruthy();+ cleanup();++ turn.designActivity = [+ activityEntry({+ id: "tr-2",+ kind: "tool_result",+ toolName: "update_and_run_blocks",+ text: "Ran 1 block",+ success: true,+ attempts: 2,+ priorFailures: [firstAttempt],+ timestamp: "2026-06-10T00:00:23Z",+ codeDiffs: [+ { label: "block_1", added: 10, removed: 0, patchDropped: true },+ ],+ }),+ ];+ turn.blocks = [+ failedBlock,+ runningBlock({+ workflowRunBlockId: "wrb_2",+ state: "completed",+ outcome: "demonstrated",+ startedAt: "2026-06-10T00:00:10Z",+ endedAt: "2026-06-10T00:00:22Z",+ }),+ ];+ render(<NarrativeView turn={turn} />);+ fireEvent.click(stepLines()[0]!);++ const [failedCard, passedCard] = screen.getAllByTestId("copilot-test-card");+ expect(failedCard!.getAttribute("data-tone")).toBe("failed");+ expect(+ within(failedCard!).getByText("Failed: the page never loaded"),+ ).toBeTruthy();+ expect(within(failedCard!).queryByText("Code change")).toBeNull();++ const header = within(passedCard!).getByRole("button", {+ name: /Passed Block 1/,+ });+ expect(header.getAttribute("aria-expanded")).toBe("false");+ expect(visibleText(header)).not.toContain("attempts");+ fireEvent.click(header);+ // The patch was dropped, so the change reads as counts with nothing to open.+ expect(within(passedCard!).getByText("Code change")).toBeTruthy();+ expect(+ within(passedCard!).queryByRole("button", { name: /Code change/ }),+ ).toBeNull();});it("a run row still calling claims no result", () => {@@ -806,6 +953,7 @@ describe("NarrativeView — activity log", () => {workflowRunBlockId: id,label,state: "completed",+ outcome: "demonstrated",startedAt: null,});const turn: TurnNarrativeState = {@@ -853,38 +1001,41 @@ describe("NarrativeView — activity log", () => {]);});- it("does not call a run passed when a block went unevaluated", () => {- const turn: TurnNarrativeState = {- ...EMPTY_NARRATIVE,- turnId: "turn-1",- turnIndex: 0,- designStarted: true,- designEnded: true,- terminal: "response",- blocks: [- runningBlock({- workflowRunBlockId: "wrb_a",- label: "open_statement",- state: "completed",- startedAt: null,- outcome: "not_evaluated",- }),- ],- designActivity: [- activityEntry({- id: "tr-1",- kind: "tool_result",- toolName: "update_and_run_blocks",- text: "Ran the draft",- success: true,- }),- ],- };- render(<NarrativeView turn={turn} />);+ it.each([["not_evaluated" as const], [undefined]])(+ "does not call a run passed when its block's verdict is %s",+ (outcome) => {+ const turn: TurnNarrativeState = {+ ...EMPTY_NARRATIVE,+ turnId: "turn-1",+ turnIndex: 0,+ designStarted: true,+ designEnded: true,+ terminal: "response",+ blocks: [+ runningBlock({+ workflowRunBlockId: "wrb_a",+ label: "open_statement",+ state: "completed",+ startedAt: null,+ outcome,+ }),+ ],+ designActivity: [+ activityEntry({+ id: "tr-1",+ kind: "tool_result",+ toolName: "update_and_run_blocks",+ text: "Ran the draft",+ success: true,+ }),+ ],+ };+ render(<NarrativeView turn={turn} />);- const lines = stepLines().map(visibleText);- expect(lines).toEqual(["Tested the workflow"]);- });+ const lines = stepLines().map(visibleText);+ expect(lines).toEqual(["Tested the workflow"]);+ },+ );it("a block whose run row was evicted still renders inside a row at Done", () => {const turn: TurnNarrativeState = {@@ -1243,7 +1394,7 @@ describe("NarrativeView — code write diffs", () => {).not.toContain("opacity-50");});- it("shows an active repair's code before its tool result arrives", () => {+ it("keeps an active repair's code in its block's card before its tool result arrives", () => {render(<NarrativeViewturn={{@@ -1278,11 +1429,7 @@ describe("NarrativeView — code write diffs", () => {/>,);- expect(- screen.getByRole("button", {- name: "Expand code changes for add_to_cart",- }),- ).toBeTruthy();+ fireEvent.click(screen.getByRole("button", { name: /Code change/ }));expect(screen.getByText("+new line")).toBeTruthy();});diff --git a/skyvern-frontend/src/routes/workflows/copilot/NarrativeView.presentation.test.tsx b/skyvern-frontend/src/routes/workflows/copilot/NarrativeView.presentation.test.tsxindex 604958766..2718bb1d8 100644--- a/skyvern-frontend/src/routes/workflows/copilot/NarrativeView.presentation.test.tsx+++ b/skyvern-frontend/src/routes/workflows/copilot/NarrativeView.presentation.test.tsx@@ -1,6 +1,6 @@// @vitest-environment jsdom-import { cleanup, fireEvent, render, screen } from "@testing-library/react";+import { cleanup, render, screen } from "@testing-library/react";import { afterEach, describe, expect, it } from "vitest";import { NarrativeView } from "./NarrativeView";@@ -88,8 +88,10 @@ describe("NarrativeView structured turn presentation", () => {);expect(screen.queryByText("Outcome not confirmed")).toBeNull();- const activityRow = screen.getByRole("button", { name: /Open Site.*ran/ });- fireEvent.click(activityRow);+ // The warning is the card's line, not a preview behind a click.+ expect(+ screen.getByRole("button", { name: /Not confirmed Open Site/ }),+ ).toBeTruthy();expect(screen.getByText(reason)).toBeTruthy();});@@ -109,13 +111,12 @@ describe("NarrativeView structured turn presentation", () => {);expect(screen.queryByText("Outcome not confirmed")).toBeNull();- const activityRow = screen.getByRole("button", {- name: /Open Site.*stopped/,- });+ expect(+ screen.getByRole("button", { name: /Stopped Open Site/ }),+ ).toBeTruthy();expect(screen.getByText(/The expected destination was not observed/),).toBeTruthy();- expect(activityRow.getAttribute("aria-expanded")).toBe("false");});it("shows a failed row's run-level reason while the row is collapsed", () => {@@ -133,13 +134,12 @@ describe("NarrativeView structured turn presentation", () => {/>,);- const activityRow = screen.getByRole("button", {- name: /Open Site.*halted/,- });+ expect(+ screen.getByRole("button", { name: /Failed Open Site/ }),+ ).toBeTruthy();expect(screen.getByText(/The expected destination was not observed/),).toBeTruthy();- expect(activityRow.getAttribute("aria-expanded")).toBe("false");});it("does not make a reasonless stopped owner expandable", () => {@@ -156,10 +156,8 @@ describe("NarrativeView structured turn presentation", () => {/>,);- const activityRow = screen.getByRole("button", {- name: /Open Site.*stopped/,- });- expect(activityRow.getAttribute("aria-expanded")).toBeNull();+ const card = screen.getByRole("button", { name: /Stopped Open Site/ });+ expect(card.getAttribute("aria-expanded")).toBeNull();});});diff --git a/skyvern-frontend/src/routes/workflows/copilot/NarrativeView.reveal.test.tsx b/skyvern-frontend/src/routes/workflows/copilot/NarrativeView.reveal.test.tsxindex 080352769..6dccf40ba 100644--- a/skyvern-frontend/src/routes/workflows/copilot/NarrativeView.reveal.test.tsx+++ b/skyvern-frontend/src/routes/workflows/copilot/NarrativeView.reveal.test.tsx@@ -23,6 +23,8 @@ const action = (summary: null,durationMs: 200,failed: false,+ codeLine: null,+ response: null,...overrides,});diff --git a/skyvern-frontend/src/routes/workflows/copilot/NarrativeView.tsx b/skyvern-frontend/src/routes/workflows/copilot/NarrativeView.tsxindex 9aff3a33f..c1191bb79 100644--- a/skyvern-frontend/src/routes/workflows/copilot/NarrativeView.tsx+++ b/skyvern-frontend/src/routes/workflows/copilot/NarrativeView.tsx@@ -1,5 +1,6 @@import { useCallback, useEffect, useMemo, useRef, useState } from "react";import {+ CheckIcon,ChevronRightIcon,CodeIcon,Cross2Icon,@@ -24,6 +25,7 @@ import {ActivityLog,ActivityRow as ActivityRowModel,FinishedTurnSummary,+ blocksByRunCall,callLabel,callRollup,condenseCalls,@@ -43,6 +45,7 @@ import {RecordedActionSummary,ToolCallKind,TurnNarrativeState,+ blockPassed,formatElapsed,humanizeJudgeText,hasObservedBlockEvidence,@@ -305,62 +308,6 @@ function AttemptsBadge({ attempts }: { attempts?: number }) {);}-// A block's line inside the activity log: a gutter glyph, the block's name, and-// a trailing disclosure. Status rides inline at the end of the name.-function FLogLine({- glyph,- children,- trailing,- onClick,- expanded,- title,-}: {- glyph: React.ReactNode;- children: React.ReactNode;- trailing?: React.ReactNode;- onClick?: () => void;- expanded?: boolean;- title?: string;-}) {- const body = (- <>- <span- // Baseline-aligned, per the design canvas — but these glyphs do not fill- // their box the way letters fill theirs, so sharing a baseline leaves- // their ink centre ~1.5px below the sentence's and they read as sloppy.- // Centring the box does not move ink; only a transform does. The offset- // is measured, not eyeballed: render the row and compare the ink bands- // of the two columns, and re-derive it if the type changes.- className="inline-block -translate-y-[1.5px] text-center font-mono text-[11px] text-muted-foreground dark:text-slate-500"- aria-hidden="true"- >- {glyph}- </span>- <span className="min-w-0 text-left text-[12.5px] leading-[1.5] text-muted-foreground dark:text-slate-400">- {children}- </span>- <span className="whitespace-nowrap font-mono text-[10.5px] tabular-nums text-muted-foreground dark:text-slate-500">- {trailing}- </span>- </>- );- const shape =- "grid w-full grid-cols-[18px_1fr_auto] items-baseline gap-x-2.5 py-[3px]";- return onClick === undefined ? (- <div className={shape}>{body}</div>- ) : (- <button- type="button"- className={`${shape} cursor-pointer text-left`}- aria-expanded={expanded}- onClick={onClick}- title={title}- >- {body}- </button>- );-}-function ActivityRow({ entry }: { entry: ActivityEntry }) {if (entry.kind === "narration") {return (@@ -469,6 +416,10 @@ function FRecordedActionRow({? "animate-copilot-row-flash-error": "animate-copilot-row-flash-success": "";+ const detail = [+ action.codeLine !== null ? `line ${action.codeLine}` : action.summary,+ action.response,+ ].filter((part): part is string => Boolean(part));return (<FSubRowglyph={action.failed ? "✕" : "✓"}@@ -483,31 +434,61 @@ function FRecordedActionRow({>{action.label}</span>- {action.summary ? (+ {detail.length > 0 ? (<span className="text-muted-foreground dark:text-slate-500">{" "}- · {action.summary}+ · {detail.join(SEP)}</span>) : null}</FSubRow>);}+interface ActionReveal {+ // Recorded actions shown so far, oldest first.+ visible: RecordedActionSummary[];+ total: number;+ // Index into `visible` of the action still replaying, or -1.+ revealingIndex: number;+ flashing: (index: number) => boolean;+}++// Time-derived, not timer-chained: recomputed from wall-clock time on every+// render/tick so collapse, remount, and StrictMode double-invoke can never+// restart or duplicate the reveal.+function useActionReveal(block: BlockState): ActionReveal {+ const recordedActions = block.recordedActions;+ const total = recordedActions?.length ?? 0;+ const durations = useMemo(+ () => (recordedActions ?? []).map((a) => a.durationMs),+ [recordedActions],+ );+ const offsets = useMemo(() => buildRevealOffsets(durations), [durations]);+ const totalMs = offsets.length > 0 ? offsets[offsets.length - 1]! : 0;+ const elapsedReveal =+ total > 0 ? Date.now() - (block.recordedActionsAt ?? 0) : 0;+ const revealedCount = total > 0 ? revealedCountAt(offsets, elapsedReveal) : 0;+ const replaying = total > 0 && elapsedReveal >= 0 && revealedCount < total;+ const visibleCount =+ total === 0 || elapsedReveal < 0+ ? 0+ : Math.min(revealedCount + (replaying ? 1 : 0), total);+ useFrameTick(total > 0 && (replaying || elapsedReveal < totalMs));+ return {+ visible: (recordedActions ?? []).slice(0, visibleCount),+ total,+ revealingIndex: replaying ? revealedCount : -1,+ flashing: (i) =>+ i < revealedCount && elapsedReveal - offsets[i]! < FLASH_WINDOW_MS,+ };+}+interface FBlockRunProps {block: BlockState;turnEnded: boolean;onSelect?: (label: string) => void;outcomeReasonFallback?: string | null;ownsOutcomeNotConfirmed?: boolean;- // Inside the activity log the card sheds its puck for the shared row grid,- // so a block does not read as a different species from the steps around it.- flat?: boolean;- // When the activity log owns this card's row, open/closed comes from there- // so the row and the card never disagree about a single click.- expansion?: { open: boolean; onToggle: () => void };- // Historical failed attempts stay quiet in the collapsed timeline. Their- // full failure treatment remains available in the expanded evidence.- quietFailure?: boolean;}function FBlockRun({@@ -516,9 +497,6 @@ function FBlockRun({onSelect,outcomeReasonFallback,ownsOutcomeNotConfirmed,- flat,- expansion,- quietFailure,}: FBlockRunProps) {const displayLabel = humanizeBlockLabel(block.label);const palette = paletteFor(block.blockType);@@ -539,7 +517,6 @@ function FBlockRun({!isInterimNotDemonstrated;const isOk = isBlockOk(block);const isFail = block.state === "failed";- const prominentFailure = isFail && !quietFailure;const isStopped = block.state === "stopped";const isDraft = block.state === "drafted";const collapsedOutcomeReason =@@ -555,7 +532,7 @@ function FBlockRun({? "border-emerald-400/60": isOutcomeNotShown? "border-amber-400/60"- : prominentFailure+ : isFail? "border-rose-400/60": "border-slate-500/60";const accentText = isRunning@@ -564,7 +541,7 @@ function FBlockRun({? "text-emerald-700 dark:text-emerald-300": isOutcomeNotShown? "text-amber-700 dark:text-amber-300"- : prominentFailure+ : isFail? "text-rose-700 dark:text-rose-300": isVerifying || isRanNeutral? "text-tertiary-foreground"@@ -575,50 +552,18 @@ function FBlockRun({? "bg-emerald-500/15": isOutcomeNotShown? "bg-amber-500/15"- : prominentFailure+ : isFail? "bg-rose-500/15": "bg-slate-elevation3";- const recordedActions = block.recordedActions;- const hasActions =- recordedActions !== undefined && recordedActions.length > 0;- const durations = useMemo(- () => (recordedActions ?? []).map((a) => a.durationMs),- [recordedActions],- );- const offsets = useMemo(() => buildRevealOffsets(durations), [durations]);- const totalMs = offsets.length > 0 ? offsets[offsets.length - 1]! : 0;- // Time-derived, not timer-chained: recomputed from wall-clock time on- // every render/tick so collapse, remount, and StrictMode double-invoke- // can never restart or duplicate the reveal.- const elapsedReveal = hasActions- ? Date.now() - (block.recordedActionsAt ?? 0)- : 0;- const revealedCount = hasActions- ? revealedCountAt(offsets, elapsedReveal)- : 0;- const replayingAction =- hasActions && elapsedReveal >= 0 && revealedCount < recordedActions!.length;- const visibleActionCount = !hasActions- ? 0- : elapsedReveal < 0- ? 0- : Math.min(- revealedCount + (replayingAction ? 1 : 0),- recordedActions!.length,- );+ const reveal = useActionReveal(block);+ const hasActions = reveal.total > 0;const [userOpen, setUserOpen] = useState<boolean | null>(null);const defaultOpen = isRunning || isFail || (hasActions && !turnEnded);- const open = expansion- ? expansion.open- : userOpen === null- ? defaultOpen- : userOpen;+ const open = userOpen === null ? defaultOpen : userOpen;// A stop stays inspectable but not self-opening: the user knows why it- // stopped, so it should not demand attention the way a failure does. Under- // the activity log `expansion` supplies the open state and none of this- // applies — there, every finished row folds, a failure included.+ // stopped, so it should not demand attention the way a failure does.const hasExpandableDetail =isRunning ||block.activity.length > 0 ||@@ -628,15 +573,13 @@ function FBlockRun({ownsOutcomeReason;const toggleable =hasExpandableDetail &&- (expansion !== undefined ||- isOk ||+ (isOk ||isOutcomeNotShown ||ownsOutcomeReason ||isVerifying ||isRanNeutral ||isStopped);useTick(isRunning);- useFrameTick(hasActions && (replayingAction || elapsedReveal < totalMs));const elapsed = formatElapsed(block.startedAt, block.endedAt);const live = isRunning ? liveElapsed(block.startedAt) : null;const statusText = isOk@@ -654,24 +597,6 @@ function FBlockRun({: isDraft? "drafted": "queued";- // The visible mark carries the state for sighted readers; this is the same- // state as a word, without the duration statusText folds in — the row- // already has an elapsed column.- const stateWord = isOk- ? "done"- : isRunning- ? "working"- : isVerifying- ? "verifying outcome"- : isRanNeutral || isOutcomeNotShown- ? "ran"- : isFail- ? "halted"- : isStopped- ? "stopped"- : isDraft- ? "drafted"- : "queued";const stateGlyph = isOk ? ("✓") : isOutcomeNotShown ? (@@ -700,20 +625,16 @@ function FBlockRun({const onHeaderClick = () => {onSelect?.(block.label);if (!toggleable) return;- if (expansion) {- expansion.onToggle();- } else {- setUserOpen((v) => !(v === null ? defaultOpen : v));- }+ setUserOpen((v) => !(v === null ? defaultOpen : v));};const collapsedExtras = (<>- {!open && !expansion && isOk && block.activity.length > 0 ? (+ {!open && isOk && block.activity.length > 0 ? (<div className="mt-0.5 text-[12px] leading-[1.5] text-muted-foreground">{block.activity[block.activity.length - 1]!.text}</div>) : null}- {!open && !expansion && isOutcomeNotShown ? (+ {!open && isOutcomeNotShown ? (<div className="mt-0.5 text-[12px] leading-[1.5] text-amber-700 dark:text-amber-200/80">{`Outcome not confirmed — ${OUTCOME_NOT_CONFIRMED_REASON}`}{collapsedOutcomeReason@@ -749,21 +670,14 @@ function FBlockRun({{block.activity.map((entry) => (<ActivityRow key={entry.id} entry={entry} />))}- {hasActions- ? recordedActions!- .slice(0, visibleActionCount)- .map((action, i) => (- <FRecordedActionRow- key={action.actionId}- action={action}- revealing={replayingAction && i === revealedCount}- flash={- i < revealedCount &&- elapsedReveal - offsets[i]! < FLASH_WINDOW_MS- }- />- ))- : null}+ {reveal.visible.map((action, i) => (+ <FRecordedActionRow+ key={action.actionId}+ action={action}+ revealing={i === reveal.revealingIndex}+ flash={reveal.flashing(i)}+ />+ ))}{isFail ? (<div className="mt-1 flex items-start gap-2 rounded-md border border-rose-400/30 bg-rose-500/10 px-2.5 py-1.5"><span className="text-[11px] font-bold text-rose-700 dark:text-rose-300">@@ -791,27 +705,6 @@ function FBlockRun({</div>);- if (flat) {- return (- <div className="flex flex-col">- <FLogLine- glyph={<span className={accentText}>{stateGlyph}</span>}- trailing={toggleable ? <Chevron open={open} /> : null}- onClick={onHeaderClick}- expanded={toggleable && expansion ? open : undefined}- title={`Highlight ${block.label} on canvas`}- >- {displayLabel}- <span className="sr-only">{` · ${stateWord}`}</span>- </FLogLine>- <div className="pl-[28px]">{collapsedExtras}</div>- {open && hasExpandableDetail ? (- <div className="pl-[28px]">{blockDetail}</div>- ) : null}- </div>- );- }-return (<div className="flex flex-col"><button@@ -819,7 +712,7 @@ function FBlockRun({className={`flex w-full items-start gap-3 px-1 py-1 text-left ${toggleable ? "cursor-pointer" : "cursor-default"}`}- aria-expanded={toggleable && expansion ? expansion.open : undefined}+ aria-expanded={toggleable ? open : undefined}onClick={onHeaderClick}title={`Highlight ${block.label} on canvas`}>@@ -973,6 +866,44 @@ interface FActivityLogProps {anchoredBeforeRows?: AnchoredTurnItem[];}+// Unified-diff lines keep their +/- colors; a muted peek greys them out.+function renderPatchLine(line: string, i: number, muted: boolean) {+ return (+ <span+ key={`${i}-${line}`}+ className={[+ "block",+ line.startsWith("+")+ ? "text-emerald-700 dark:text-emerald-300"+ : line.startsWith("-")+ ? "text-rose-700 dark:text-rose-300"+ : "text-muted-foreground",+ muted ? "!text-muted-foreground" : "",+ ]+ .filter(Boolean)+ .join(" ")}+ >+ {line}+ </span>+ );+}++function DiffPatch({+ patch,+ className,+}: {+ patch: string;+ className?: string;+}) {+ return (+ <pre+ className={`overflow-x-auto whitespace-pre rounded border border-border/60 bg-muted/40 p-2 text-[11px] leading-[1.5] ${className ?? ""}`}+ >+ {patch.split("\n").map((line, i) => renderPatchLine(line, i, false))}+ </pre>+ );+}+// The kind gutter sits to the left of ActivityRow's own status column, so a// row reads <kind> <status> <text> and neither signal displaces the other.// The counts line sits outside the row's own expand button, so its `view diff`@@ -996,24 +927,6 @@ function FCodeWriteDiff({restoreFocusAfterPeek.current = false;}, [open]);const patchLines = diff.patch?.split("\n") ?? [];- const renderLine = (line: string, i: number, muted: boolean) => (- <span- key={`${i}-${line}`}- className={[- "block",- line.startsWith("+")- ? "text-emerald-700 dark:text-emerald-300"- : line.startsWith("-")- ? "text-rose-700 dark:text-rose-300"- : "text-muted-foreground",- muted ? "!text-muted-foreground" : "",- ]- .filter(Boolean)- .join(" ")}- >- {line}- </span>- );return (<div className="flex flex-col"><FSubRow glyph="±" glyphClass="text-sky-700 dark:text-sky-300">@@ -1050,9 +963,7 @@ function FCodeWriteDiff({)}</FSubRow>{open && diff.patch !== undefined ? (- <pre className="ml-5 overflow-x-auto whitespace-pre rounded border border-border/60 bg-muted/40 p-2 text-[11px] leading-[1.5]">- {patchLines.map((line, i) => renderLine(line, i, false))}- </pre>+ <DiffPatch patch={diff.patch} className="ml-5" />) : peek && diff.patch !== undefined ? (<buttontype="button"@@ -1066,7 +977,9 @@ function FCodeWriteDiff({}}><code className="block whitespace-pre">- {patchLines.slice(0, 2).map((line, i) => renderLine(line, i, true))}+ {patchLines+ .slice(0, 2)+ .map((line, i) => renderPatchLine(line, i, true))}</code><spanaria-hidden="true"@@ -1092,11 +1005,17 @@ const STEP_TEXT = "text-foreground/75";// The no-break space binds each "·" to the item before it, so a wrapped tail never starts a line with one.const SEP = "\u00a0· ";-function Chevron({ open }: { open: boolean }) {+function Chevron({+ open,+ className = "text-muted-foreground",+}: {+ open: boolean;+ className?: string;+}) {return (<ChevronRightIconaria-hidden="true"- className={`size-3 shrink-0 text-muted-foreground transition-transform motion-reduce:transition-none ${+ className={`size-3 shrink-0 transition-transform motion-reduce:transition-none ${className} ${open ? "rotate-90" : ""}`}/>@@ -1135,6 +1054,468 @@ function FFailurePin({ block }: { block: BlockState }) {);}+type TestCardTone =+ | "running"+ | "failed"+ | "notConfirmed"+ | "passed"+ | "neutral";++const TEST_CARD_TONE: Record<+ TestCardTone,+ { card: string; word: string; glyph: string }+> = {+ running: {+ card: "border-blue-400/40 bg-blue-400/[0.06]",+ word: "text-blue-700 dark:text-blue-300",+ glyph: "text-blue-600 dark:text-blue-400",+ },+ failed: {+ card: "border-rose-500/40 bg-rose-500/[0.06]",+ word: "text-rose-700 dark:text-rose-300",+ glyph: "text-rose-600 dark:text-rose-500",+ },+ notConfirmed: {+ card: "border-amber-500/40 bg-amber-500/[0.06]",+ word: "text-amber-700 dark:text-amber-300",+ glyph: "text-amber-600 dark:text-amber-300",+ },+ passed: {+ card: "border-emerald-500/40 bg-emerald-500/[0.06]",+ word: "text-emerald-700 dark:text-emerald-300",+ glyph: "text-emerald-600 dark:text-emerald-500",+ },+ neutral: {+ card: "border-slate-500/40 bg-slate-500/[0.06]",+ word: "text-slate-700 dark:text-slate-300",+ glyph: "text-slate-500 dark:text-slate-400",+ },+};++interface TestCardStatus {+ tone: TestCardTone;+ word: string;+ // Muted words after the status, for a state the word alone does not name.+ note: string | null;+ glyph: React.ReactNode;+}++function testCardStatus(block: BlockState, turnEnded: boolean): TestCardStatus {+ const glyphClass = "size-3.5";+ switch (block.state) {+ case "running":+ return {+ tone: "running",+ word: "Testing",+ note: null,+ glyph: <Spinner />,+ };+ case "failed":+ return {+ tone: "failed",+ word: "Failed",+ note: null,+ glyph: <Cross2Icon aria-hidden="true" className={glyphClass} />,+ };+ case "stopped":+ return {+ tone: "neutral",+ word: "Stopped",+ note: null,+ glyph: <StopIcon aria-hidden="true" className="size-3" />,+ };+ case "skipped":+ return { tone: "neutral", word: "Skipped", note: null, glyph: "–" };+ case "queued":+ return { tone: "neutral", word: "Queued", note: null, glyph: "·" };+ case "drafted":+ return { tone: "neutral", word: "Drafted", note: null, glyph: "·" };+ case "completed":+ break;+ }+ if (blockPassed(block)) {+ return {+ tone: "passed",+ word: "Passed",+ note: null,+ glyph: <CheckIcon aria-hidden="true" className={glyphClass} />,+ };+ }+ if (+ block.outcome === "not_demonstrated" &&+ !isInterimOutcome(block.outcomeRole)+ ) {+ return {+ tone: "notConfirmed",+ word: "Not confirmed",+ note: null,+ glyph: "!",+ };+ }+ // A verdict still pending at turn end (dropped stream) reads as ran, never+ // as the live verifying beat.+ if (block.outcome === "evaluating" && !turnEnded) {+ return {+ tone: "neutral",+ word: "Ran",+ note: "verifying outcome…",+ glyph: "…",+ };+ }+ return { tone: "neutral", word: "Ran", note: null, glyph: "•" };+}++function formatActionDuration(ms: number | null): string | null {+ if (ms === null) return null;+ if (ms < 60_000) return `${(ms / 1000).toFixed(1)}s`;+ const secs = Math.round(ms / 1000);+ return `${Math.floor(secs / 60)}:${(secs % 60).toString().padStart(2, "0")}`;+}++// A failure's first line reads under its row in full; the rest of the recorded+// text opens below it. The split is display-only: no meaning is read from it.+function FFailureText({ text }: { text: string }) {+ const [open, setOpen] = useState(false);+ const [firstLine = "", ...rest] = text.split("\n");+ const more = rest.join("\n").trim();+ const hasMore = more.length > 0;+ return (+ <div className="ml-[22px] flex flex-col gap-1.5">+ <p className="whitespace-pre-wrap break-words text-[12.5px] leading-[1.5] text-rose-800 [overflow-wrap:anywhere] dark:text-rose-100">+ {firstLine}+ </p>+ {hasMore && open ? (+ <pre className="whitespace-pre-wrap break-words rounded-md border border-rose-500/30 bg-background p-2 font-mono text-[11px] leading-[1.5] text-foreground/80 [overflow-wrap:anywhere]">+ {more}+ </pre>+ ) : null}+ {hasMore ? (+ <button+ type="button"+ aria-expanded={open}+ onClick={() => setOpen(!open)}+ className="flex w-fit items-center gap-1 text-[11.5px] text-muted-foreground hover:text-foreground"+ >+ <Chevron open={open} />+ {open ? "Hide details" : "Show details"}+ </button>+ ) : null}+ </div>+ );+}++function FCardActionRow({+ action,+ revealing,+ flash,+ failureText,+}: {+ action: RecordedActionSummary;+ revealing: boolean;+ flash: boolean;+ failureText: string | null;+}) {+ const shimmerRef = useShimmerText<HTMLSpanElement>(revealing);+ const failed = !revealing && action.failed;+ const duration = revealing ? null : formatActionDuration(action.durationMs);+ const flashClass = flash+ ? failed+ ? "animate-copilot-row-flash-error"+ : "animate-copilot-row-flash-success"+ : "";+ const row = (+ <div className="flex items-start gap-2 text-[12px] leading-[1.5]">+ <span className="flex h-[18px] w-3.5 shrink-0 items-center justify-center">+ {revealing ? (+ <Spinner small />+ ) : failed ? (+ <Cross2Icon+ aria-hidden="true"+ className="size-[13px] text-rose-600 dark:text-rose-500"+ />+ ) : (+ <CheckIcon+ aria-hidden="true"+ className="size-[13px] text-emerald-600 dark:text-emerald-500"+ />+ )}+ </span>+ <span+ ref={shimmerRef}+ className={`shrink-0 ${+ failed+ ? "font-semibold text-rose-700 dark:text-rose-300"+ : "text-foreground"+ } ${flashClass}`}+ >+ {action.label}+ </span>+ <span+ className={`min-w-0 flex-1 break-words [overflow-wrap:anywhere] ${+ failed && action.codeLine !== null+ ? "text-rose-700 dark:text-rose-300"+ : "text-muted-foreground"+ }`}+ >+ {failed && action.codeLine !== null+ ? `line ${action.codeLine}`+ : action.summary}+ </span>+ {duration === null ? null : (+ <span className="shrink-0 text-[11px] tabular-nums text-muted-foreground">+ {duration}+ </span>+ )}+ <span className="sr-only">{failed ? " · failed" : ""}</span>+ </div>+ );+ if (!failed) return row;+ return (+ <div className="-mx-1.5 flex flex-col gap-1.5 rounded-md bg-rose-500/[0.08] px-1.5 py-2">+ {row}+ {failureText === null ? null : <FFailureText text={failureText} />}+ </div>+ );+}++// One card per block run of a test. The header says where the block stands;+// the body holds the code change that block got and the steps its run took.+function FTestRunCard({+ block,+ diff,+ diffOpen,+ onDiffToggle,+ callFailure,+ outcomeReason,+ ownsVerdict,+ turnEnded,+ open,+ onToggle,+ onSelect,+}: {+ block: BlockState;+ diff: CodeWriteDiff | null;+ diffOpen: boolean;+ onDiffToggle: () => void;+ // The failed run call's error, for a failure that recorded no text of its own.+ callFailure: string | null;+ // Why the run did not confirm the block's outcome, when it says.+ outcomeReason: string | null;+ // This block holds the turn's unconfirmed verdict, so its card is where the+ // reason reads; the turn card stands down for it.+ ownsVerdict: boolean;+ turnEnded: boolean;+ open: boolean;+ onToggle: () => void;+ onSelect?: (label: string) => void;+}) {+ const status = testCardStatus(block, turnEnded);+ const tone = TEST_CARD_TONE[status.tone];+ const isRunning = block.state === "running";+ useTick(isRunning);+ const reveal = useActionReveal(block);+ const elapsed = isRunning+ ? liveElapsed(block.startedAt)+ : formatElapsed(block.startedAt, block.endedAt);++ const actions = reveal.visible;+ let lastFailed = -1;+ actions.forEach((action, i) => {+ if (action.failed && i !== reveal.revealingIndex) lastFailed = i;+ });+ const failureOf = (action: RecordedActionSummary, i: number) =>+ action.response ?? (i === lastFailed ? callFailure : null);+ // A failed block whose run recorded no failed step still says why. It stays+ // put while actions replay above it, then moves onto the step that failed.+ const recordedFailure = (block.recordedActions ?? []).some((a) => a.failed);+ const blockFailure =+ block.state === "failed" && lastFailed === -1+ ? (callFailure ?? (recordedFailure ? null : "Halted — see run details."))+ : null;+ const reason =+ status.tone === "notConfirmed"+ ? (outcomeReason ??+ "The step ran, but the run did not demonstrate the goal was met.")+ : ownsVerdict && outcomeReason !== null+ ? `Outcome not confirmed — ${outcomeReason}`+ : null;++ const hasBody =+ diff !== null ||+ actions.length > 0 ||+ blockFailure !== null ||+ block.activity.length > 0;+ const expanded = hasBody && open;+ const summary = [+ reveal.total > 0+ ? `${reveal.total} ${reveal.total === 1 ? "action" : "actions"}`+ : null,+ elapsed,+ ]+ .filter((part) => part !== null)+ .join(" · ");++ const header = (+ <>+ <span+ className={`flex h-5 w-3.5 shrink-0 items-center justify-center text-[12px] font-bold ${tone.glyph}`}+ aria-hidden="true"+ >+ {hasBody && !expanded ? (+ <Chevron open={false} className={tone.word} />+ ) : (+ status.glyph+ )}+ </span>+ <span className="min-w-0 flex-1 break-words">+ <span className={`font-semibold ${tone.word}`}>{status.word}</span>{" "}+ <span className="text-foreground">+ {humanizeBlockLabel(block.label)}+ </span>+ {status.note === null ? null : (+ <span className="text-muted-foreground">{`${SEP}${status.note}`}</span>+ )}+ </span>+ {(expanded ? elapsed : summary) ? (+ <span className="shrink-0 whitespace-nowrap text-[11.5px] tabular-nums text-muted-foreground">+ {expanded ? elapsed : summary}+ </span>+ ) : null}+ </>+ );+ const headerClass = `flex w-full min-w-0 items-start gap-2 px-3 text-left text-[12.5px] leading-5 ${+ reason === null ? "py-[11px]" : "pb-1 pt-[11px]"+ }`;++ return (+ <div+ data-testid="copilot-test-card"+ data-tone={status.tone}+ className={`overflow-hidden rounded-lg border ${tone.card}`}+ >+ <button+ type="button"+ className={headerClass}+ aria-expanded={hasBody ? expanded : undefined}+ title={`Highlight ${block.label} on canvas`}+ onClick={() => {+ onSelect?.(block.label);+ if (hasBody) onToggle();+ }}+ >+ {header}+ </button>+ {reason === null ? null : (+ <p className="px-3 pb-[11px] pl-[34px] text-[12px] leading-[1.5] text-muted-foreground">+ {reason}+ </p>+ )}+ {expanded ? (+ <div className="flex flex-col gap-2 border-t border-border bg-slate-elevation2 px-3 py-2.5">+ {diff === null ? null : (+ <FCardCodeChange+ diff={diff}+ open={diffOpen}+ onToggle={onDiffToggle}+ />+ )}+ {diff !== null &&+ (actions.length > 0 ||+ blockFailure !== null ||+ block.activity.length > 0) ? (+ <div aria-hidden="true" className="h-px bg-border" />+ ) : null}+ {actions.map((action, i) => (+ <FCardActionRow+ key={action.actionId}+ action={action}+ revealing={i === reveal.revealingIndex}+ flash={reveal.flashing(i)}+ failureText={failureOf(action, i)}+ />+ ))}+ {blockFailure === null ? null : (+ <div className="-mx-1.5 flex flex-col gap-1.5 rounded-md bg-rose-500/[0.08] px-1.5 py-2">+ <div className="flex items-start gap-2 text-[12px] leading-[1.5]">+ <span className="flex h-[18px] w-3.5 shrink-0 items-center justify-center">+ <Cross2Icon+ aria-hidden="true"+ className="size-[13px] text-rose-600 dark:text-rose-500"+ />+ </span>+ <span className="font-semibold text-rose-700 dark:text-rose-300">+ Error+ </span>+ </div>+ <FFailureText text={blockFailure} />+ </div>+ )}+ {block.activity.map((entry) => (+ <ActivityRow key={entry.id} entry={entry} />+ ))}+ </div>+ ) : null}+ </div>+ );+}++// A failed call's error: the sanitized detail when the stream carried it, else+// its saved result line.+function callFailureText(entry: ActivityEntry): string | null {+ if (entry.kind !== "tool_result" || entry.success !== false) return null;+ return entry.detail ?? (entry.text !== callLabel(entry) ? entry.text : null);+}++function FCardCodeChange({+ diff,+ open,+ onToggle,+}: {+ diff: CodeWriteDiff;+ open: boolean;+ onToggle: () => void;+}) {+ const counts = (+ <span className="font-mono text-[11px] tabular-nums">+ <span className="text-emerald-700 dark:text-emerald-500">{`+${diff.added}`}</span>{" "}+ <span className="text-rose-700 dark:text-rose-500">{`−${diff.removed}`}</span>+ </span>+ );+ const lineClass =+ "flex w-fit items-center gap-1.5 text-[12px] leading-[1.5] text-muted-foreground";+ // A patch dropped for size keeps its counts; there is nothing to open.+ if (diff.patch === undefined) {+ return (+ <div+ className={`${lineClass} pl-[18px]`}+ title={+ diff.patchDropped+ ? "The diff was too large to keep, so only its line counts were saved."+ : undefined+ }+ >+ <span>Code change</span>+ {counts}+ </div>+ );+ }+ return (+ <div className="flex flex-col gap-1.5">+ <button+ type="button"+ aria-expanded={open}+ onClick={onToggle}+ className={`${lineClass} hover:text-foreground`}+ >+ <Chevron open={open} />+ <span>Code change</span>+ {counts}+ </button>+ {open ? <DiffPatch patch={diff.patch} /> : null}+ </div>+ );+}+// One call in an expanded step. A result reads inline beside the call and// opens to its full text; an error opens as its own box.function FCallItem({@@ -1239,6 +1620,8 @@ function FActivityLogRow({diffOpen,diffPeek,onDiffToggle,+ cardOpen,+ onCardToggle,turnEnded,onBlockSelect,outcomeReasonFallback,@@ -1250,6 +1633,8 @@ function FActivityLogRow({diffOpen: (label: string) => boolean;diffPeek: (label: string) => boolean;onDiffToggle: (label: string) => void;+ cardOpen: (blockKey: string, fallback: boolean) => boolean;+ onCardToggle: (blockKey: string, open: boolean) => void;turnEnded: boolean;onBlockSelect?: (label: string) => void;outcomeReasonFallback?: string | null;@@ -1286,43 +1671,104 @@ function FActivityLogRow({</p>);- const diffNodes = row.codeDiffs.map((diff) => (- <FCodeWriteDiff- key={diff.label}- diff={diff}- open={diffOpen(diff.label)}- peek={diffPeek(diff.label)}- onToggle={() => onDiffToggle(diff.label)}- />- ));- const blockNodes = row.blocks.map((b) => (- <FBlockRun- key={b.workflowRunBlockId || b.label}- block={b}- turnEnded={turnEnded}- onSelect={onBlockSelect}- outcomeReasonFallback={outcomeReasonFallback}- ownsOutcomeNotConfirmed={blockIdentity(b) === outcomeOwnerKey}- flat- quietFailure- expansion={- row.entries.length === 0 && row.blocks.length === 1- ? { open, onToggle }- : undefined+ // A block its run call ran reads as one card in that call's place, and the+ // row's newest code change moves into the card of the newest run of its label:+ // its first card there, since loop iterations share one.+ const blocksByCall = blocksByRunCall(row);+ const diffCardKey = new Map<string, string>();+ const claimDiffs = (blocks: BlockState[]) => {+ const claimed = new Set<string>();+ for (const block of blocks) {+ if (+ !claimed.has(block.label) &&+ row.codeDiffs.some((diff) => diff.label === block.label)+ ) {+ claimed.add(block.label);+ diffCardKey.set(block.label, blockIdentity(block));}- />- ));+ }+ };+ if (blocksByCall.size === 0) claimDiffs(row.blocks);+ // A retry whose patched block has not started yet keeps its new patch on the+ // row, not in the earlier attempt's card.+ for (const entry of row.entries) {+ for (const diff of entry.codeDiffs ?? []) diffCardKey.delete(diff.label);+ const hosted = blocksByCall.get(toolCallIdOf(entry) ?? "");+ if (hosted !== undefined) claimDiffs(hosted);+ }+ const isCardOpen = (block: BlockState) =>+ cardOpen(+ blockIdentity(block),+ block.state === "running" || block.state === "failed",+ );+ // A run call's error reads once: on the last card whose block failed.+ const cardNode = (+ block: BlockState,+ host: ActivityEntry | undefined,+ carriesCallFailure: boolean,+ ) => {+ const key = blockIdentity(block);+ const diff =+ diffCardKey.get(block.label) === key+ ? (row.codeDiffs.find((d) => d.label === block.label) ?? null)+ : null;+ const reasonFallback =+ key === outcomeOwnerKey || block.outcome === "not_demonstrated"+ ? outcomeReasonFallback+ : null;+ const cardIsOpen = isCardOpen(block);+ return (+ <FTestRunCard+ key={key}+ block={block}+ diff={diff}+ diffOpen={diffOpen(block.label)}+ onDiffToggle={() => onDiffToggle(block.label)}+ callFailure={+ host !== undefined && carriesCallFailure+ ? callFailureText(host)+ : null+ }+ outcomeReason={normalizeOutcomeReason(+ block.outcomeReason ?? reasonFallback,+ )}+ ownsVerdict={key === outcomeOwnerKey}+ turnEnded={turnEnded}+ open={cardIsOpen}+ onToggle={() => onCardToggle(key, cardIsOpen)}+ onSelect={onBlockSelect}+ />+ );+ };+ const diffNodes = row.codeDiffs+ .filter((diff) => !diffCardKey.has(diff.label))+ .map((diff) => (+ <FCodeWriteDiff+ key={diff.label}+ diff={diff}+ open={diffOpen(diff.label)}+ peek={diffPeek(diff.label)}+ onToggle={() => onDiffToggle(diff.label)}+ />+ ));const diffEvidence = (<div className="mb-1 ml-[18px] mt-0.5 flex flex-col gap-1">{diffNodes}</div>);+ const cardStack = (cards: React.ReactNode[], key?: string) => (+ <div key={key} className="my-1 flex flex-col gap-1.5">+ {cards}+ </div>+ );// A block observed with no step of its own keeps its card as the line.if (row.entries.length === 0 && row.draftingLabels === undefined) {return (<div className="flex flex-col">{reasonNode}- {blockNodes}+ {cardStack(+ row.blocks.map((block) => cardNode(block, undefined, false)),+ )}{open && diffNodes.length > 0 ? diffEvidence : null}</div>);@@ -1397,12 +1843,16 @@ function FActivityLogRow({)}</span>);+ // An open row's running card already carries the loader.+ const cardShowsLive =+ open &&+ row.blocks.some((block) => block.state === "running" && isCardOpen(block));const line = (<><span className="flex h-[19px] w-3 shrink-0 items-center">{hasDetail ? <Chevron open={open} /> : null}</span>- {row.live ? (+ {row.live && !cardShowsLive ? (<span className="flex h-[19px] shrink-0 items-center"><Spinner small /><span className="sr-only">in progress</span>@@ -1424,61 +1874,94 @@ function FActivityLogRow({row.blocks.length > 1,);- const lastIndexWhere = (predicate: (entry: ActivityEntry) => boolean) => {- for (let i = calls.length - 1; i >= 0; i -= 1) {- if (predicate(calls[i]!.entry)) return i;- }- return -1;+ const hostedBlocks = (entry: ActivityEntry) =>+ blocksByCall.get(toolCallIdOf(entry) ?? "") ?? [];+ let diffHost = -1;+ if (diffNodes.length > 0) {+ calls.forEach(({ entry }, i) => {+ if (+ (entry.codeDiffs?.length ?? 0) > 0 &&+ hostedBlocks(entry).length === 0+ ) {+ diffHost = i;+ }+ });+ }++ // Calls read as one bordered list; a card breaks the list where its call+ // was, so the log keeps the order things happened in.+ const listClass =+ "mb-1 ml-[18px] mt-0.5 flex list-none flex-col gap-px border-l border-border pl-2";+ const segments: React.ReactNode[] = [];+ let items: React.ReactNode[] = [];+ const flushItems = () => {+ if (items.length === 0) return;+ segments.push(+ <ul key={`calls-${segments.length}`} className={listClass}>+ {items}+ </ul>,+ );+ items = [];};- const diffHost =- diffNodes.length === 0- ? -1- : lastIndexWhere((entry) => (entry.codeDiffs?.length ?? 0) > 0);- const blockHost =- blockNodes.length === 0- ? -1- : lastIndexWhere(- (entry) =>- entry.toolName !== undefined &&- toolCallKind(entry.toolName) === "run",- );- const blockEvidence = <FDetailBox>{blockNodes}</FDetailBox>;-- const body = (- <ul className="mb-1 ml-[18px] mt-0.5 flex list-none flex-col gap-px border-l border-border pl-2">- {diffNodes.length > 0 && diffHost === -1 ? <li>{diffEvidence}</li> : null}- {calls.map(({ entry, count }, i) => {- const failed = entry.kind === "tool_result" && entry.success === false;- const result =- failed && resultShown(entry) ? (- <pre className="whitespace-pre-wrap break-words font-mono text-[11.5px] leading-[1.5] text-rose-700 dark:text-rose-300">- {entry.text}- </pre>- ) : null;- return (- <FCallItem- key={toolCallIdOf(entry) ?? entry.id}- entry={entry}- turnEnded={turnEnded}- count={count}- detail={result}- inlineResult={!failed && resultShown(entry) ? entry.text : null}- // The exact server error is the evidence a failed step owes.- defaultOpen={failed}- evidence={- <>- {i === diffHost ? diffEvidence : null}- {i === blockHost ? blockEvidence : null}- </>- }- />- );- })}- {blockNodes.length > 0 && blockHost === -1 ? (- <li>{blockEvidence}</li>- ) : null}- </ul>- );+ if (diffNodes.length > 0 && diffHost === -1) {+ items.push(<li key="diffs">{diffEvidence}</li>);+ }+ const carded = new Set<BlockState>();+ calls.forEach(({ entry, count }, i) => {+ const hosted = hostedBlocks(entry);+ const failed = entry.kind === "tool_result" && entry.success === false;+ const result =+ failed && resultShown(entry) ? (+ <pre className="whitespace-pre-wrap break-words font-mono text-[11.5px] leading-[1.5] text-rose-700 dark:text-rose-300">+ {entry.text}+ </pre>+ ) : null;+ const callItem = (+ <FCallItem+ key={toolCallIdOf(entry) ?? entry.id}+ entry={entry}+ turnEnded={turnEnded}+ count={count}+ detail={result}+ inlineResult={!failed && resultShown(entry) ? entry.text : null}+ // The exact server error is the evidence a failed step owes.+ defaultOpen={failed}+ evidence={i === diffHost ? diffEvidence : null}+ />+ );+ if (hosted.length > 0) {+ // A failed card carries its call's error; with none to carry it, the+ // call keeps its own row above the cards.+ if (result !== null && !hosted.some((b) => b.state === "failed")) {+ items.push(callItem);+ }+ flushItems();+ hosted.forEach((block) => carded.add(block));+ const lastFailedHosted = hosted.map((b) => b.state).lastIndexOf("failed");+ segments.push(+ cardStack(+ hosted.map((block, blockIndex) =>+ cardNode(block, entry, blockIndex === lastFailedHosted),+ ),+ `cards-${toolCallIdOf(entry) ?? entry.id}`,+ ),+ );+ return;+ }+ items.push(callItem);+ });+ flushItems();+ // A block whose call was condensed into an identical sibling still shows.+ const uncarded = row.blocks.filter((block) => !carded.has(block));+ if (uncarded.length > 0) {+ segments.push(+ cardStack(+ uncarded.map((block) => cardNode(block, undefined, false)),+ "cards-rest",+ ),+ );+ }+ const body = <>{segments}</>;return (<div className="flex flex-col">@@ -1626,12 +2109,13 @@ function FActivityLog({},[lastInteractedRow],);- const toggleDiff = useCallback(- (rowId: string, label: string, open: boolean) => {+ // A diff or a test card inside a row, keyed `<kind>:<row id>:<id>`.+ const toggleEvidence = useCallback(+ (rowId: string, key: string, open: boolean) => {lastInteractedRow.current = rowId;setOverride((prev) => {const next = new Map(prev);- next.set(`diff:${rowId}:${label}`, !open);+ next.set(key, !open);// Expanding evidence is also an explicit request to keep its parent// visible when the automatic frontier advances.if (!open) next.set(rowId, true);@@ -1718,7 +2202,21 @@ function FActivityLog({diffOpen={diffOpen}diffPeek={diffPeek}onDiffToggle={(label) =>- toggleDiff(row.id, label, diffOpen(label))+ toggleEvidence(+ row.id,+ `diff:${row.id}:${label}`,+ diffOpen(label),+ )+ }+ cardOpen={(blockKey, fallback) =>+ override.get(`card:${row.id}:${blockKey}`) ?? fallback+ }+ onCardToggle={(blockKey, cardIsOpen) =>+ toggleEvidence(+ row.id,+ `card:${row.id}:${blockKey}`,+ cardIsOpen,+ )}turnEnded={turnEnded}onBlockSelect={onBlockSelect}diff --git a/skyvern-frontend/src/routes/workflows/copilot/WorkflowCopilotChat.blockActions.test.tsx b/skyvern-frontend/src/routes/workflows/copilot/WorkflowCopilotChat.blockActions.test.tsxindex 5f2e90d0f..38bf6e538 100644--- a/skyvern-frontend/src/routes/workflows/copilot/WorkflowCopilotChat.blockActions.test.tsx+++ b/skyvern-frontend/src/routes/workflows/copilot/WorkflowCopilotChat.blockActions.test.tsx@@ -428,6 +428,86 @@ describe("WorkflowCopilotChat — recorded-action live poll wiring", () => {await waitFor(() => expect(screen.getByText("Wobble Gizmo")).toBeTruthy());});+ it("names a code block's raised error by its line and keeps its full text one click deep", async () => {+ const failure =+ "Locator.fill: Timeout 30000ms exceeded.\nCall log:\n - waiting for the email field";+ timelineGet.mockResolvedValue({+ data: [+ {+ type: "block",+ block: {+ workflow_run_block_id: "wrb_1",+ actions: [+ {+ action_id: "a2",+ action_type: "null_action",+ status: "failed",+ task_id: null,+ step_id: null,+ step_order: null,+ action_order: 1,+ confidence_float: null,+ description: "code error at line 8",+ reasoning: null,+ intention: null,+ response: failure,+ created_by: null,+ text: null,+ output: { code_line: 8 },+ },+ ],+ },+ children: [],+ thought: null,+ created_at: "2026-06-10T00:00:00Z",+ modified_at: "2026-06-10T00:00:00Z",+ },+ ],+ });++ await renderChat();+ await submit("build a workflow");+ streamCalls[0]!.onMessage({+ type: "turn_start",+ turn_id: "turn-1",+ turn_index: 0,+ mode: "build",+ timestamp: "2026-06-10T00:00:00Z",+ });+ streamCalls[0]!.onMessage({+ type: "design_start",+ timestamp: "2026-06-10T00:00:00Z",+ });+ for (const [status, timestamp] of [+ ["running", "2026-06-10T00:00:00Z"],+ ["failed", "2026-06-10T00:00:31Z"],+ ]) {+ streamCalls[0]!.onMessage({+ type: "block_progress",+ workflow_run_id: "wr_1",+ workflow_run_block_id: "wrb_1",+ block_label: "block_1",+ block_type: "code",+ status,+ iteration: 0,+ timestamp,+ });+ }++ // The recorded step replays before it settles into its failure.+ await waitFor(() => expect(screen.getByText("line 8")).toBeTruthy(), {+ timeout: 3000,+ });+ expect(screen.getByText("Code error")).toBeTruthy();+ expect(screen.queryByText("Screenshot")).toBeNull();+ expect(+ screen.getByText("Locator.fill: Timeout 30000ms exceeded."),+ ).toBeTruthy();+ expect(screen.queryByText(/waiting for the email field/)).toBeNull();+ fireEvent.click(screen.getByRole("button", { name: "Show details" }));+ expect(screen.getByText(/waiting for the email field/)).toBeTruthy();+ });+it("patches an already-frozen AI message when the timeline fetch resolves after the terminal response", async () => {let resolveTimeline!: (value: { data: unknown[] }) => void;timelineGet.mockImplementation(diff --git a/skyvern-frontend/src/routes/workflows/copilot/WorkflowCopilotChat.tsx b/skyvern-frontend/src/routes/workflows/copilot/WorkflowCopilotChat.tsxindex bf7b5c995..cd4ef5b2b 100644--- a/skyvern-frontend/src/routes/workflows/copilot/WorkflowCopilotChat.tsx+++ b/skyvern-frontend/src/routes/workflows/copilot/WorkflowCopilotChat.tsx@@ -38,8 +38,10 @@ import { getClient, deleteUploadedFileOnPageExit } from "@/api/AxiosClient";import { queryClient } from "@/api/QueryClient";import {ActionsApiResponse,+ ActionTypes,type CredentialApiResponse,getReadableActionType,+ Status,} from "@/api/types";import { useCredentialGetter } from "@/hooks/useCredentialGetter";import { CredentialsModal } from "@/routes/credentials/CredentialsModal";@@ -445,26 +447,56 @@ type ArmedProductAction =// they land without hammering the timeline endpoint.const RECORDED_ACTIONS_POLL_INTERVAL_MS = 2500;-function recordedActionDurationMs(action: ActionsApiResponse): number | null {+function recordedActionOutput(+ action: ActionsApiResponse,+): Record<string, unknown> | null {const output = action.output;if (!output || typeof output !== "object" || Array.isArray(output)) {return null;}- const durationMs = (output as Record<string, unknown>).duration_ms;- return typeof durationMs === "number" ? durationMs : null;+ return output as Record<string, unknown>;+}++// A code block records an error raised outside any page call as a failed+// null_action whose output carries `code_line`, even when the line is unknown.+function isCodeErrorAction(action: ActionsApiResponse): boolean {+ const output = recordedActionOutput(action);+ return (+ action.action_type === ActionTypes.NullAction &&+ action.status === Status.Failed &&+ output !== null &&+ "code_line" in output+ );}function toRecordedActionSummary(action: ActionsApiResponse,): RecordedActionSummary {+ const output = recordedActionOutput(action);+ const codeError = isCodeErrorAction(action);+ const codeLine = codeError ? output?.code_line : null;+ const durationMs = output?.duration_ms;+ const failed = action.status === Status.Failed;return {actionId: action.action_id,- label: getReadableActionType(action.action_type),+ label: getReadableActionType(+ action.action_type,+ codeError ? { nullActionLabel: "Code error" } : {},+ ),// The chat has no workflow definition in scope, so rows resolve from the action// itself; the run-view timeline additionally matches the definition's step text.- summary: describeRecordedAction(action, null),- durationMs: recordedActionDurationMs(action),- failed: action.status === "failed",+ // A code error's description only restates its line, and a failure's+ // response is shown in full under the row, so neither repeats as the summary.+ summary: codeError+ ? null+ : describeRecordedAction(+ failed ? { ...action, response: null } : action,+ null,+ ),+ durationMs: typeof durationMs === "number" ? durationMs : null,+ failed,+ codeLine: typeof codeLine === "number" ? codeLine : null,+ response: failed ? action.response?.trim() || null : null,};}diff --git a/skyvern-frontend/src/routes/workflows/copilot/copilotActivityLog.ts b/skyvern-frontend/src/routes/workflows/copilot/copilotActivityLog.tsindex 63f73bb9c..1d4625803 100644--- a/skyvern-frontend/src/routes/workflows/copilot/copilotActivityLog.ts+++ b/skyvern-frontend/src/routes/workflows/copilot/copilotActivityLog.ts@@ -7,10 +7,10 @@ import {ToolCallKind,TurnFacts,TurnNarrativeState,+ blockPassed,condenseActivityEntries,hasObservedBlockEvidence,hasPendingToolCall,- isBlockOk,parseUtcIsoMs,ranCleanOnCurrentSource,toolActivityDisplayLabel,@@ -799,22 +799,48 @@ export function callRollup(return text.charAt(0).toUpperCase() + text.slice(1);}+// The row's blocks keyed by the tool call id of the run call that ran them: the+// first run call, in row order, still running when the block was first seen (its+// start, else its end, since a short block can be first polled finished). A+// block with neither, or seen after every dated call returned, goes to the row's+// last run call. Empty when the row made no run call.+export function blocksByRunCall(row: ActivityRow): Map<string, BlockState[]> {+ const runCalls = row.entries.filter(+ (entry) =>+ entry.toolName !== undefined && toolCallKind(entry.toolName) === "run",+ );+ const byCall = new Map<string, BlockState[]>();+ const lastRun = runCalls[runCalls.length - 1];+ const lastId = lastRun === undefined ? undefined : toolCallIdOf(lastRun);+ if (lastId === undefined) return byCall;+ for (const block of row.blocks) {+ const seenMs = parseUtcIsoMs(block.startedAt ?? block.endedAt);+ const host =+ seenMs === null+ ? undefined+ : runCalls.find((entry) => {+ if (entry.kind === "tool_call") return true;+ const endedMs = parseUtcIsoMs(entry.timestamp);+ return endedMs !== null && endedMs >= seenMs;+ });+ const id = (host && toolCallIdOf(host)) || lastId;+ byCall.set(id, [...(byCall.get(id) ?? []), block]);+ }+ return byCall;+}+export function failedRowBlocks(row: ActivityRow): BlockState[] {return row.blocks.filter((block) => block.state === "failed");}-// A run row whose every block the run recorded as ok and evaluated; null otherwise.+// A run row whose every block passed, by the same rule its cards use; null otherwise.export function passedBlockCount(row: ActivityRow): number | null {if (row.kind !== "run" || row.pending || row.blocks.length === 0) {return null;}const last = row.entries[row.entries.length - 1];if (last?.kind === "tool_result" && last.success === false) return null;- return row.blocks.every(- (block) => isBlockOk(block) && block.outcome !== "not_evaluated",- )- ? row.blocks.length- : null;+ return row.blocks.every(blockPassed) ? row.blocks.length : null;}function isFailedTest(row: ActivityRow): boolean {diff --git a/skyvern-frontend/src/routes/workflows/copilot/narrativeState.blockActions.test.ts b/skyvern-frontend/src/routes/workflows/copilot/narrativeState.blockActions.test.tsindex ec71589f4..17997878f 100644--- a/skyvern-frontend/src/routes/workflows/copilot/narrativeState.blockActions.test.ts+++ b/skyvern-frontend/src/routes/workflows/copilot/narrativeState.blockActions.test.ts@@ -41,6 +41,8 @@ const recordedAction = (summary: null,durationMs: 200,failed: false,+ codeLine: null,+ response: null,...overrides,});diff --git a/skyvern-frontend/src/routes/workflows/copilot/narrativeState.ts b/skyvern-frontend/src/routes/workflows/copilot/narrativeState.tsindex 3956b73f7..8c676055a 100644--- a/skyvern-frontend/src/routes/workflows/copilot/narrativeState.ts+++ b/skyvern-frontend/src/routes/workflows/copilot/narrativeState.ts@@ -85,6 +85,11 @@ export interface RecordedActionSummary {summary: string | null;durationMs: number | null;failed: boolean;+ // The failing line of a code error; null for every other action, and when+ // the line is unknown.+ codeLine: number | null;+ // A failed action's full recorded failure text; the secure runner records none.+ response: string | null;}// Client-synthesized event (never sent by the backend) that carries the@@ -333,6 +338,9 @@ export interface ActivityEntry {activeLabel?: string;// Result success when kind is tool_result.success?: boolean;+ // A failed tool_result's sanitized failure text. Live-only: saved turns+ // do not carry it.+ detail?: string;// Server-computed line delta per code block this write changed. Absent on// every other row and on payloads from a backend that predates it.codeDiffs?: CodeWriteDiff[];@@ -858,6 +866,7 @@ function buildActivityFromToolResult(toolName: event.tool_name,displayLabel,success: event.success,+ detail: event.detail || undefined,codeDiffs: parseCodeDiffs(event.code_diffs),id: `tr-${event.tool_call_id}`,timestamp: event.timestamp ?? undefined,@@ -1210,6 +1219,13 @@ export function isBlockOk();}+// Stricter than isBlockOk: a block passed only when its run demonstrated it.+export function blockPassed(+ block: Pick<BlockState, "state" | "outcome">,+): boolean {+ return block.state === "completed" && block.outcome === "demonstrated";+}+// Labels that occur exactly once in the given set — the only labels safe to key// recorded actions on when the run-block id is missing (a block that never// reported progress, or an older backend). Loop iterations reuse a label, so andiff --git a/skyvern-frontend/src/routes/workflows/editor/FlowRenderer.tsx b/skyvern-frontend/src/routes/workflows/editor/FlowRenderer.tsxindex 1902c4602..264b2e4d4 100644--- a/skyvern-frontend/src/routes/workflows/editor/FlowRenderer.tsx+++ b/skyvern-frontend/src/routes/workflows/editor/FlowRenderer.tsx@@ -792,6 +792,27 @@ function FlowRenderer({);});const blockerExit = useBlockerExit(blocker);+ const unsavedResolutionCapturedRef = useRef(false);++ useEffect(() => {+ if (blocker.state === "blocked") {+ unsavedResolutionCapturedRef.current = false;+ }+ }, [blocker.state]);++ const captureUnsavedResolution = (+ choice: "stay" | "discard" | "save" | "apply_goal",+ ) => {+ if (unsavedResolutionCapturedRef.current) {+ return;+ }+ unsavedResolutionCapturedRef.current = true;+ postHog.capture("builder.unsaved_changes.resolved", {+ org_id: workflow.organization_id,+ workflow_permanent_id: workflow.workflow_permanent_id,+ choice,+ });+ };const applyPendingGoalChanges = useCopilotActionStore((state) => state.applyPendingGoalChanges,);@@ -1403,6 +1424,7 @@ function FlowRenderer({workflowChangesStore.setHasChanges(true);postHog.capture("builder.block.duplicated", {org_id: workflow.organization_id,+ workflow_permanent_id: workflow.workflow_permanent_id,position: result.position,source_block_id: id,});@@ -1418,6 +1440,7 @@ function FlowRenderer({workflowChangesStore,postHog,workflow.organization_id,+ workflow.workflow_permanent_id,],);@@ -2419,6 +2442,7 @@ function FlowRenderer({open={blocker.state === "blocked"}onOpenChange={(open) => {if (!open) {+ captureUnsavedResolution("stay");blockerExit.reset();}}}@@ -2449,6 +2473,7 @@ function FlowRenderer({<Buttonvariant="secondary"onClick={() => {+ captureUnsavedResolution("discard");useWorkflowTitleStore.getState().clearCopilotMetadata(workflow.workflow_permanent_id);@@ -2460,6 +2485,7 @@ function FlowRenderer({{pendingGoalChanges.length > 0 ? (<ButtononClick={() => {+ captureUnsavedResolution("apply_goal");blockerExit.reset();applyPendingGoalChanges();}}@@ -2473,6 +2499,7 @@ function FlowRenderer({onClick={() => {handleSave().then((ok) => {if (ok) {+ captureUnsavedResolution("save");blockerExit.proceed();}});diff --git a/skyvern-frontend/src/routes/workflows/editor/Workspace.tsx b/skyvern-frontend/src/routes/workflows/editor/Workspace.tsxindex 829414cd4..1cbd6c7d4 100644--- a/skyvern-frontend/src/routes/workflows/editor/Workspace.tsx+++ b/skyvern-frontend/src/routes/workflows/editor/Workspace.tsx@@ -663,7 +663,14 @@ function Workspace({canUndo: canUndoWorkflowEdit,canRedo: canRedoWorkflowEdit,historyApplyTrigger,- } = useWorkflowHistory({ nodes, edges, setNodes, setEdges });+ } = useWorkflowHistory({+ nodes,+ edges,+ setNodes,+ setEdges,+ organizationId: workflow.organization_id,+ workflowPermanentId: workflow.workflow_permanent_id,+ });const [restoreApplyTrigger, setRestoreApplyTrigger] = useState(0);const captureLiveEditorState = (): EditorStateSnapshot => {const titles = useWorkflowTitleStore.getState();@@ -1516,6 +1523,7 @@ function Workspace({};const cycleBrowser = useMutation({+ mutationKey: ["cycleBrowser"],mutationFn: async (id: string) => {const client = await getClient(credentialGetter, "sans-api-v1");return client.post<DebugSessionApiResponse>(`/debug-session/${id}/new`);@@ -1997,6 +2005,7 @@ function Workspace({workflowChangesStore.setHasChanges(true);postHog.capture("builder.block.added", {org_id: workflow.organization_id,+ workflow_permanent_id: workflow.workflow_permanent_id,block_type: blockTypeFromNode(node) ?? nodeType,position: previousNodeIndex + 1,});diff --git a/skyvern-frontend/src/routes/workflows/editor/hooks/useWorkflowHistory.test.ts b/skyvern-frontend/src/routes/workflows/editor/hooks/useWorkflowHistory.test.tsindex fd20568f6..ff5342fff 100644--- a/skyvern-frontend/src/routes/workflows/editor/hooks/useWorkflowHistory.test.ts+++ b/skyvern-frontend/src/routes/workflows/editor/hooks/useWorkflowHistory.test.ts@@ -59,7 +59,14 @@ describe("useWorkflowHistory hook", () => {const hook = renderHook(({ n, e }: { n: AppNode[]; e: Edge[] }) =>- useWorkflowHistory({ nodes: n, edges: e, setNodes, setEdges }),+ useWorkflowHistory({+ nodes: n,+ edges: e,+ setNodes,+ setEdges,+ organizationId: "org_1",+ workflowPermanentId: "wpid_1",+ }),{ initialProps: { n: nodes, e: edges } },);diff --git a/skyvern-frontend/src/routes/workflows/editor/hooks/useWorkflowHistory.ts b/skyvern-frontend/src/routes/workflows/editor/hooks/useWorkflowHistory.tsindex c49230833..73feaebe8 100644--- a/skyvern-frontend/src/routes/workflows/editor/hooks/useWorkflowHistory.ts+++ b/skyvern-frontend/src/routes/workflows/editor/hooks/useWorkflowHistory.ts@@ -37,6 +37,8 @@ const CAPTURE_DEBOUNCE_MS = 300;type UseWorkflowHistoryParams = {nodes: AppNode[];edges: Edge[];+ organizationId: string;+ workflowPermanentId: string;// Match React Flow's useNodesState / useEdgesState signatures so// callers can pass the setter dispatcher straight through (and use// the updater-function form elsewhere if they want).@@ -84,6 +86,8 @@ type UseWorkflowHistoryResult = {export function useWorkflowHistory({nodes,edges,+ organizationId,+ workflowPermanentId,setNodes,setEdges,}: UseWorkflowHistoryParams): UseWorkflowHistoryResult {@@ -407,13 +411,22 @@ export function useWorkflowHistory({nodesBeforeUndo - result.applied.nodes.length,);posthog.capture("builder.undo_redo.used", {+ org_id: organizationId,+ workflow_permanent_id: workflowPermanentId,action: "undo",node_count: result.applied.nodes.length,edge_count: result.applied.edges.length,history_depth: result.state.past.length,cap_reached: result.state.past.length >= MAX_HISTORY_ENTRIES,});- }, [applySnapshot, flushPendingCapture, refreshFlags, posthog]);+ }, [+ applySnapshot,+ flushPendingCapture,+ refreshFlags,+ posthog,+ organizationId,+ workflowPermanentId,+ ]);const redo = useCallback(() => {if (useWorkflowHasChangesStore.getState().internalUpdateCount > 0) return;@@ -426,13 +439,22 @@ export function useWorkflowHistory({applySnapshot(result.applied.nodes, result.applied.edges);refreshFlags();posthog.capture("builder.undo_redo.used", {+ org_id: organizationId,+ workflow_permanent_id: workflowPermanentId,action: "redo",node_count: result.applied.nodes.length,edge_count: result.applied.edges.length,history_depth: result.state.past.length,cap_reached: result.state.past.length >= MAX_HISTORY_ENTRIES,});- }, [applySnapshot, flushPendingCapture, refreshFlags, posthog]);+ }, [+ applySnapshot,+ flushPendingCapture,+ refreshFlags,+ posthog,+ organizationId,+ workflowPermanentId,+ ]);return useMemo(() => ({diff --git a/skyvern-frontend/src/routes/workflows/editor/nodes/components/NodeHeader.tsx b/skyvern-frontend/src/routes/workflows/editor/nodes/components/NodeHeader.tsxindex 38854847d..eed1413e5 100644--- a/skyvern-frontend/src/routes/workflows/editor/nodes/components/NodeHeader.tsx+++ b/skyvern-frontend/src/routes/workflows/editor/nodes/components/NodeHeader.tsx@@ -25,6 +25,7 @@ import { useLocation, useNavigate } from "react-router-dom";import { useWorkflowPermanentId } from "@/routes/workflows/WorkflowPermanentIdContext";import { useMutation, useQueryClient } from "@tanstack/react-query";import { useReactFlow } from "@xyflow/react";+import { usePostHog } from "posthog-js/react";import { getClient } from "@/api/AxiosClient";import {@@ -269,6 +270,7 @@ function NodeHeader({type,}: Props) {const log = useLogging();+ const postHog = usePostHog();const mode = useWorkflowEditorMode();const workflowPermanentId = useWorkflowPermanentId();const { workflowRunId: activeWorkflowRunId, blockLabel: targetBlockLabel } =@@ -399,6 +401,7 @@ function NodeHeader({});const runBlock = useMutation({+ mutationKey: ["runBlock"],mutationFn: async (opts?: {codeGen: boolean;parameterOverrides?: Record<string, unknown>;@@ -547,7 +550,12 @@ function NodeHeader({"/run/workflows/blocks",body,);- return { response, mergedParameters };+ return {+ response,+ mergedParameters,+ organizationId: workflow.organization_id,+ blockType: type,+ };},onSuccess: (result) => {if (!result?.response) {@@ -565,7 +573,13 @@ function NodeHeader({return;}- const { response, mergedParameters } = result;+ const { response, mergedParameters, organizationId, blockType } = result;++ postHog.capture("builder.block.run", {+ org_id: organizationId,+ workflow_permanent_id: workflowPermanentId,+ block_type: blockType,+ });if (workflowPermanentId) {useDebuggerLastRunValuesStore@@ -644,6 +658,7 @@ function NodeHeader({});const cancelBlock = useMutation({+ mutationKey: ["cancelBlock"],mutationFn: async () => {if (!debugSession) {log.error("Cancel block: missing debug session", {diff --git a/skyvern-frontend/src/routes/workflows/studio/BrowserPaneHeader.tsx b/skyvern-frontend/src/routes/workflows/studio/BrowserPaneHeader.tsxindex 6af30f55b..f4f622601 100644--- a/skyvern-frontend/src/routes/workflows/studio/BrowserPaneHeader.tsx+++ b/skyvern-frontend/src/routes/workflows/studio/BrowserPaneHeader.tsx@@ -252,6 +252,7 @@ export function BrowserPaneActions() {const moreActionsRef = useRef<HTMLButtonElement>(null);const cycleBrowser = useMutation({+ mutationKey: ["cycleBrowser"],mutationFn: async (workflowId: string) => {const client = await getClient(credentialGetter, "sans-api-v1");return client.post<DebugSessionApiResponse>(diff --git a/skyvern-frontend/src/routes/workflows/studio/BrowserTab.tsx b/skyvern-frontend/src/routes/workflows/studio/BrowserTab.tsxindex d3ce93afe..c53f824dc 100644--- a/skyvern-frontend/src/routes/workflows/studio/BrowserTab.tsx+++ b/skyvern-frontend/src/routes/workflows/studio/BrowserTab.tsx@@ -49,6 +49,7 @@ export function BrowserTab() {}postHog.capture("run.recording.viewed", {org_id: workflowRun.workflow?.organization_id,+ workflow_permanent_id: workflowRun.workflow?.workflow_permanent_id,run_id: workflowRun.workflow_run_id,recording_index: index,recording_count: recordingUrls.length,diff --git a/skyvern-frontend/src/routes/workflows/studio/StudioTopBar.tsx b/skyvern-frontend/src/routes/workflows/studio/StudioTopBar.tsxindex 24baaf6df..d40bdaf71 100644--- a/skyvern-frontend/src/routes/workflows/studio/StudioTopBar.tsx+++ b/skyvern-frontend/src/routes/workflows/studio/StudioTopBar.tsx@@ -20,6 +20,7 @@ import {} from "@radix-ui/react-icons";import { useMutation, useQueryClient } from "@tanstack/react-query";import { Link, useNavigate, useSearchParams } from "react-router-dom";+import { usePostHog } from "posthog-js/react";import { useWorkflowPermanentId } from "@/routes/workflows/WorkflowPermanentIdContext";import { getClient } from "@/api/AxiosClient";@@ -376,6 +377,7 @@ export function RunStopButton({ stopOnly = false }: { stopOnly?: boolean }) {const runId = useStudioRunId();const [searchParams] = useSearchParams();const queryClient = useQueryClient();+ const postHog = usePostHog();const credentialGetter = useCredentialGetter();const isRecording = useRecordingStore((s) => s.isRecording);const {@@ -406,6 +408,7 @@ export function RunStopButton({ stopOnly = false }: { stopOnly?: boolean }) {);const cancelRun = useMutation({+ mutationKey: ["cancelRun"],mutationFn: async () => {const client = await getClient(credentialGetter);return client@@ -413,6 +416,12 @@ export function RunStopButton({ stopOnly = false }: { stopOnly?: boolean }) {.then((response) => response.data);},onSuccess: () => {+ if (!isBlockRun) {+ postHog.capture("studio.run.cancelled", {+ org_id: workflowRun?.workflow?.organization_id,+ workflow_permanent_id: workflowPermanentId,+ });+ }queryClient.invalidateQueries({ queryKey: ["workflowRun", activeRunId] });queryClient.invalidateQueries({queryKey: ["workflowRun", workflowPermanentId, activeRunId],diff --git a/skyvern/forge/agent_functions.py b/skyvern/forge/agent_functions.pyindex 0fe78daf9..fa5d9838e 100644--- a/skyvern/forge/agent_functions.py+++ b/skyvern/forge/agent_functions.py@@ -944,10 +944,26 @@ class RecordingVideoSizeResolution:raw_output_bound: dict[str, int] | None+@dataclass(frozen=True)+class DownloadRecoveryRemap:+ """Bounded outcome of a download-recovery ``remap``.++ ``locator`` is the retry target on the pinned page, or ``None`` when recovery must not click.+ ``resolution`` names how the locator was found (``cached_css`` or ``fresh_scrape``) and is set only+ when ``locator`` is present. ``reason`` is a bounded, non-sensitive rejection code when ``locator``+ is ``None`` so the single structured log line can distinguish sub-outcomes without leaking URLs,+ query parameters, or customer data.+ """++ locator: Locator | None+ resolution: str | None = None+ reason: str | None = None++class DownloadRecoveryHook(Protocol):def matches_failure(self, response: Response) -> bool: ...- async def remap(self, page: Page) -> Locator | None: ...+ async def remap(self, page: Page) -> DownloadRecoveryRemap: ...class AgentFunction:@@ -979,6 +995,11 @@ class AgentFunction:def task_v3_required_field_answers_text(self) -> tuple[str, str] | None:return None+ # (text appended to a page-aware v3 run's task message or None, reason logged on the loop-finished line), given+ # the run's payload. OSS supplies no default.+ def task_v3_age_default(self, parameters: dict[str, Any] | None) -> tuple[str | None, str] | None:+ return None+# The v3 code tool, or None when this deployment cannot run model-authored code under a sandbox.# Uncalled while frame perception withholds the code tool on every run; it stays as the seam for# when the action ledger records code-driven work. OSS ships no runner and always returns None.diff --git a/skyvern/forge/sdk/copilot/tools/run_execution.py b/skyvern/forge/sdk/copilot/tools/run_execution.pyindex 5da8ffe1e..96dc97de8 100644--- a/skyvern/forge/sdk/copilot/tools/run_execution.py+++ b/skyvern/forge/sdk/copilot/tools/run_execution.py@@ -3697,6 +3697,7 @@ async def _run_blocks_and_collect_debug(sensitive_run_custody_lock: asyncio.Lock | None = Nonesensitive_run_session_id: str | None = Noneinterim_run_id: str | None = None+ current_context = skyvern_context.current()# Set only where the run may already be executing, so an unwind before either executor call# can still retract the run-start record.run_submission_attempted = False@@ -3710,7 +3711,7 @@ async def _run_blocks_and_collect_debug(# select a newer proposal while this run still carries the previous definition.resolved_workflow_id=snapshot.workflow.workflow_id,max_steps=None,- request_id=None,+ request_id=current_context.request_id if current_context is not None else None,# The trigger type (and the -ui queue routing it implies) is a cloud contract; ask the# AgentFunction for it rather than hardcoding "manual == -ui pool" in OSS. OSS base# returns None (no routing hint); cloud returns the value its executor routes to -ui.diff --git a/skyvern/forge/sdk/routes/agent_protocol.py b/skyvern/forge/sdk/routes/agent_protocol.pyindex 553839f0d..891bdaadb 100644--- a/skyvern/forge/sdk/routes/agent_protocol.py+++ b/skyvern/forge/sdk/routes/agent_protocol.py@@ -1362,11 +1362,21 @@ async def update_workflow_legacy(user_id: str | None = Depends(org_auth_service.get_current_user_id_or_none),) -> Workflow:analytics.capture("skyvern-oss-agent-workflow-update")++ def log_save_rejected(error: Exception) -> None:+ LOG.info(+ "Workflow save rejected",+ organization_id=current_org.organization_id,+ workflow_permanent_id=workflow_id,+ error_type=type(error).__name__,+ )+# validate the workflowraw_yaml = await request.body()try:workflow_yaml = safe_load_no_dates(raw_yaml)except yaml.YAMLError as exc:+ log_save_rejected(exc)raise HTTPException(status_code=422, detail=format_yaml_error(exc))try:@@ -1379,10 +1389,16 @@ async def update_workflow_legacy(edited_by=user_id,)except WorkflowDefinitionValidationException as e:- raise e- except (SkyvernHTTPException, ValidationError) as e:+ log_save_rejected(e)+ raise+ except ValidationError as e:+ log_save_rejected(e)+ raise+ except SkyvernHTTPException as e:# Bubble up well-formed client errors so they are not converted to 500s- raise e+ if 400 <= e.status_code < 500:+ log_save_rejected(e)+ raiseexcept Exception as e:LOG.exception("Failed to update workflow",@@ -3573,6 +3589,7 @@ async def run_block(organization=organization,user_id=user_id,browser_session_id=browser_session_id,+ debug_session_id=block_run_request.debug_session_id,block_outputs=block_run_request.block_outputs,)except SkyvernHTTPException:@@ -3582,6 +3599,8 @@ async def run_block("Unexpected error running blocks",workflow_id=block_run_request.workflow_id,organization_id=organization.organization_id,+ debug_session_id=block_run_request.debug_session_id,+ block_label_count=len(block_run_request.block_labels),)raisediff --git a/skyvern/forge/sdk/routes/debug_sessions.py b/skyvern/forge/sdk/routes/debug_sessions.pyindex 9ac666039..31dc5d5b0 100644--- a/skyvern/forge/sdk/routes/debug_sessions.py+++ b/skyvern/forge/sdk/routes/debug_sessions.py@@ -1,5 +1,6 @@import asyncioimport hashlib+import timeimport typing as tfrom datetime import datetime, timedelta, timezonefrom functools import partial@@ -437,7 +438,7 @@ async def get_or_create_debug_session_by_user_and_workflow_permanent_id(if claimed_prewarm:return debug_session- LOG.info(+ LOG.debug("Existing debug session found",debug_session_id=debug_session.debug_session_id,browser_session_id=debug_session.browser_session_id,@@ -550,7 +551,7 @@ async def new_debug_session()if completed_debug_sessions and settings.ENV != "local":- closeable_browser_sessions: list[PersistentBrowserSession] = []+ closeable_browser_sessions: list[tuple[PersistentBrowserSession, str]] = []for debug_session in completed_debug_sessions:try:@@ -562,7 +563,7 @@ async def new_debug_session(browser_session = Noneif browser_session and browser_session.completed_at is None:- closeable_browser_sessions.append(browser_session)+ closeable_browser_sessions.append((browser_session, debug_session.debug_session_id))LOG.info(f"Closing browser {len(closeable_browser_sessions)} browser session(s)",@@ -573,17 +574,21 @@ async def new_debug_session(def handle_close_browser_session_error(browser_session_id: str,+ debug_session_id: str,organization_id: str,task: asyncio.Task,) -> None:if task.exception():LOG.error(- f"Failed to close session: {task.exception()}",+ "Failed to close browser session for debug session",browser_session_id=browser_session_id,+ debug_session_id=debug_session_id,organization_id=organization_id,+ workflow_permanent_id=workflow_permanent_id,+ error=str(task.exception()),)- for browser_session in closeable_browser_sessions:+ for browser_session, debug_session_id in closeable_browser_sessions:LOG.info("Closing existing browser session for debug session",browser_session_id=browser_session.persistent_browser_session_id,@@ -604,6 +609,7 @@ async def new_debug_session(partial(handle_close_browser_session_error,browser_session.persistent_browser_session_id,+ debug_session_id,current_org.organization_id,))@@ -624,13 +630,29 @@ async def new_debug_session()proxy_location = runtime_proxy_location(workflow.proxy_location)- new_browser_session = await app.PERSISTENT_SESSIONS_MANAGER.create_session(+ browser_start_started_at = time.monotonic()+ try:+ new_browser_session = await app.PERSISTENT_SESSIONS_MANAGER.create_session(+ organization_id=current_org.organization_id,+ timeout_minutes=settings.DEBUG_SESSION_TIMEOUT_MINUTES,+ proxy_location=proxy_location,+ wait_for_startup=settings.ENV != "local",+ needs_live_view=True,+ created_by=current_user_id,+ )+ except Exception:+ LOG.exception(+ "Debug session browser startup failed",+ organization_id=current_org.organization_id,+ workflow_permanent_id=workflow_permanent_id,+ )+ raise+ LOG.info(+ "Debug session browser ready",organization_id=current_org.organization_id,- timeout_minutes=settings.DEBUG_SESSION_TIMEOUT_MINUTES,- proxy_location=proxy_location,- wait_for_startup=settings.ENV != "local",- needs_live_view=True,- created_by=current_user_id,+ workflow_permanent_id=workflow_permanent_id,+ browser_session_id=new_browser_session.persistent_browser_session_id,+ duration_seconds=time.monotonic() - browser_start_started_at,)debug_session = await app.DATABASE.debug.create_debug_session(diff --git a/skyvern/forge/sdk/routes/workflow_copilot.py b/skyvern/forge/sdk/routes/workflow_copilot.pyindex 6a84a67e5..3022de41c 100644--- a/skyvern/forge/sdk/routes/workflow_copilot.py+++ b/skyvern/forge/sdk/routes/workflow_copilot.py@@ -5,11 +5,12 @@ import hashlibimport hmacimport jsonimport re+import timeimport uuidfrom collections.abc import Iteratorfrom contextlib import contextmanagerfrom datetime import UTC, datetime, timedelta-from typing import Any, cast, get_args+from typing import Any, Literal, cast, get_argsfrom urllib.parse import urlparseimport structlog@@ -640,10 +641,38 @@ async def _watch_for_cancel(return+RouteExit = Literal["completed", "error", "cancelled", "duplicate"]+++class _FirstEventTimingStream:+ def __init__(self, stream: EventSourceStream, started_at: float) -> None:+ self._stream = stream+ self._started_at = started_at+ self.first_event_seconds: float | None = None++ async def send(self, data: Any) -> bool:+ is_status_ack = isinstance(data, WorkflowCopilotProcessingUpdate) and data.status in {+ "Processing...",+ "Thinking...",+ }+ if self.first_event_seconds is None and not is_status_ack:+ self.first_event_seconds = time.monotonic() - self._started_at+ return await self._stream.send(data)++ async def is_disconnected(self) -> bool:+ return await self._stream.is_disconnected()++ async def close(self) -> None:+ await self._stream.close()++async def _ensure_terminal_frame(stream: EventSourceStream,already_emitted: bool,turn_id: str | None = None,+ organization_id: str | None = None,+ workflow_permanent_id: str | None = None,+ workflow_copilot_chat_id: str | None = None,) -> None:"""Emit a fallback ERROR frame if the turn hasn't sent a terminal one.@@ -652,6 +681,13 @@ async def _ensure_terminal_frame("""if already_emitted:return+ LOG.warning(+ "Copilot turn ended without terminal frame",+ organization_id=organization_id,+ workflow_permanent_id=workflow_permanent_id,+ workflow_copilot_chat_id=workflow_copilot_chat_id,+ turn_id=turn_id,+ )try:await asyncio.shield(stream.send(@@ -665,7 +701,14 @@ async def _ensure_terminal_frame())except BaseException:- pass+ LOG.debug(+ "Copilot fallback terminal frame send failed",+ organization_id=organization_id,+ workflow_permanent_id=workflow_permanent_id,+ workflow_copilot_chat_id=workflow_copilot_chat_id,+ turn_id=turn_id,+ exc_info=True,+ )_KNOWN_PROPOSAL_DISPOSITIONS: frozenset[str] = frozenset(get_args(ProposalDisposition))@@ -2123,6 +2166,8 @@ async def _new_copilot_chat_post(``original_workflow`` via ``_restore_workflow_definition`` to avoid leavinga half-persisted draft."""+ request_started_at = time.monotonic()+# Captured before any await, since stopping the recording drops the live session while this turn loads.# The request wpid is safe here: the registry matches org and wpid, and the chat lookup rejects a mismatch.live_recording_evidence = _live_recording_evidence(@@ -2131,10 +2176,12 @@ async def _new_copilot_chat_post(workflow_permanent_id=chat_request.workflow_permanent_id,)- async def stream_handler(stream: EventSourceStream) -> None:+ async def stream_handler(raw_stream: EventSourceStream) -> None:+ stream = _FirstEventTimingStream(raw_stream, request_started_at)LOG.info("Workflow copilot agent chat request",workflow_copilot_chat_id=chat_request.workflow_copilot_chat_id,+ workflow_permanent_id=chat_request.workflow_permanent_id,workflow_run_id=chat_request.workflow_run_id,**_workflow_copilot_ingress_log_fields(chat_request.message),workflow_yaml_length=len(chat_request.workflow_yaml or ""),@@ -2151,6 +2198,10 @@ async def _new_copilot_chat_post(# try-block so route-level error paths and the agent's TURN_START# envelope all carry the same identifier.turn_id = uuid.uuid4().hex+ turn_id_for_log = turn_id+ route_exit: RouteExit = "error"+ turn_outcome_for_log: TurnOutcome | None = None+ failure_kind_for_log: str | None = Noneoriginal_workflow: Workflow | None = Nonechat = None@@ -2205,7 +2256,9 @@ async def _new_copilot_chat_post(``exc_info`` is the writer's failure; the ``diagnosed_`` fields name what failed the turn."""- nonlocal terminal_frame_emitted+ nonlocal failure_kind_for_log, route_exit, terminal_frame_emitted+ route_exit = "error"+ failure_kind_for_log = failure.failure_kindLOG.exception("Workflow copilot could not persist this turn's terminal row",organization_id=organization.organization_id,@@ -2237,7 +2290,9 @@ async def _new_copilot_chat_post() -> None:"""Shared by the LLMProviderError and generic Exception handlers below —only their log/user-facing strings and failure kind differ."""- nonlocal terminal_frame_emitted+ nonlocal failure_kind_for_log, route_exit, terminal_frame_emitted, turn_outcome_for_log+ route_exit = "error"+ failure_kind_for_log = failure_kindif any(isinstance(item, DatabaseConnectionUnavailableError) for item in iter_exception_chain(exc)):# Rolling the workflow back and writing the reply are both database work, against a# database that just exhausted a full reconnection budget. Report what is already@@ -2259,8 +2314,12 @@ async def _new_copilot_chat_post(persisted_directly = (agent_result is not None and agent_result.workflow_was_persisted and not rolled_back)+ failure = build_recoverable_failure(+ exc,+ workflow_modified=committed_staged or persisted_directly,+ )await _emit_unpersisted_failure(- build_recoverable_failure(exc, workflow_modified=committed_staged or persisted_directly),+ failure,failure_kind=failure_kind,writer_exc=exc,)@@ -2318,6 +2377,8 @@ async def _new_copilot_chat_post(code_available=current_code_available,turn_id=turn_id,)+ failure_kind_for_log = failure.failure_kind+ turn_outcome_for_log = recovered_result.turn_outcomeif agent_result is not None:# Without this turn's candidate token the recovered result reads as owning whatever# the row holds now, so its clear would take a candidate another turn published.@@ -2554,6 +2615,7 @@ async def _new_copilot_chat_post(api_key = await app.AGENT_FUNCTION.resolve_org_api_key(organization.organization_id)if not api_key:+ failure_kind_for_log = "configuration"LOG.warning("Copilot cannot resolve an org API token; refusing to start the agent",organization_id=organization.organization_id,@@ -2619,7 +2681,16 @@ async def _new_copilot_chat_post(sender=_turn_opener_sender(chat_request),)except DuplicateCopilotTurnError as exc:+ route_exit = "duplicate"+ turn_id_for_log = exc.turn_idterminal_frame_emitted = True+ LOG.info(+ "Copilot duplicate turn rejected",+ organization_id=organization.organization_id,+ workflow_permanent_id=chat_request.workflow_permanent_id,+ workflow_copilot_chat_id=chat.workflow_copilot_chat_id,+ turn_id=exc.turn_id,+ )await stream.send(WorkflowCopilotStreamErrorUpdate(type=WorkflowCopilotStreamMessageType.ERROR,@@ -2728,8 +2799,10 @@ async def _new_copilot_chat_post(code_available=current_code_available,turn_id=turn_id,)+ turn_outcome_for_log = agent_result.turn_outcomeif getattr(agent_result, "cancelled", False):+ route_exit = "cancelled"# The agent absorbed the CancelledError and returned a result# carrying ``workflow_was_persisted`` so rollback proceeds normally.# Nobody pressed Stop on a cancellation the user never asked for, so@@ -2757,6 +2830,8 @@ async def _new_copilot_chat_post(LOG.info("Workflow copilot agent turn cancelled",workflow_copilot_chat_id=chat_request.workflow_copilot_chat_id,+ workflow_permanent_id=chat_request.workflow_permanent_id,+ turn_id=turn_id,user_cancel_observed=user_cancel_observed[0],cancel_source=user_cancel_source[0],)@@ -2780,7 +2855,22 @@ async def _new_copilot_chat_post()terminal_frame_emitted = Truecapture_code_mode_opt_out_after_persist()+ route_exit = "completed"except HTTPException as exc:+ failure_kind_for_log = _http_exception_failure_kind(exc)+ http_exception_log = LOG.error if exc.status_code >= 500 else LOG.warning+ http_exception_log(+ "Copilot turn failed with HTTPException",+ status_code=exc.status_code,+ detail=exc.detail,+ organization_id=organization.organization_id,+ workflow_copilot_chat_id=(+ chat.workflow_copilot_chat_id if chat is not None else chat_request.workflow_copilot_chat_id+ ),+ turn_id=turn_id,+ workflow_permanent_id=chat_request.workflow_permanent_id,+ exc_info=exc.status_code >= 500,+ )if chat is not None and _should_restore_persisted_workflow(chat.auto_accept,agent_result,@@ -2798,7 +2888,7 @@ async def _new_copilot_chat_post(WorkflowCopilotStreamErrorUpdate(type=WorkflowCopilotStreamMessageType.ERROR,error=exc.detail,- failure_kind=_http_exception_failure_kind(exc),+ failure_kind=failure_kind_for_log,turn_id=turn_id,narrative_summary=None,)@@ -2813,6 +2903,8 @@ async def _new_copilot_chat_post(failure_kind="provider",)except asyncio.CancelledError:+ route_exit = "cancelled"+ turn_outcome_for_log = agent_result.turn_outcome if agent_result is not None else Noneif chat is not None and _should_restore_persisted_workflow(chat.auto_accept,agent_result,@@ -2863,6 +2955,8 @@ async def _new_copilot_chat_post(LOG.info("Workflow copilot agent cancelled by user during pre-agent setup",workflow_copilot_chat_id=chat_request.workflow_copilot_chat_id,+ workflow_permanent_id=chat_request.workflow_permanent_id,+ turn_id=turn_id,cancel_source=user_cancel_source[0],)return@@ -2875,6 +2969,8 @@ async def _new_copilot_chat_post(LOG.info("Workflow copilot agent task cancelled (operational or post-finalisation)",workflow_copilot_chat_id=chat_request.workflow_copilot_chat_id,+ workflow_permanent_id=chat_request.workflow_permanent_id,+ turn_id=turn_id,user_cancel_observed=user_cancel_observed[0],finalise_started=finalise_started,)@@ -2917,19 +3013,55 @@ async def _new_copilot_chat_post(failure_kind="server",)finally:- if cancel_watcher is not None and not cancel_watcher.done():- cancel_watcher.cancel()- with contextlib.suppress(asyncio.CancelledError, Exception):- await cancel_watcher- await _ensure_terminal_frame(stream, terminal_frame_emitted, turn_id=turn_id)- if eval_mode == CopilotEvalMode.BROWSER_ABLATION and agent_result is not None:- metadata = agent_result.browser_ablation_metadata- browser_session_id = metadata.get("browser_session_id") if isinstance(metadata, dict) else None- if isinstance(browser_session_id, str) and browser_session_id:- await close_browser_session_quietly(- organization.organization_id,- browser_session_id,- reason=BrowserSessionCloseReason.user_requested,+ try:+ if cancel_watcher is not None and not cancel_watcher.done():+ cancel_watcher.cancel()+ with contextlib.suppress(asyncio.CancelledError, Exception):+ await cancel_watcher+ await _ensure_terminal_frame(+ stream,+ terminal_frame_emitted,+ turn_id=turn_id,+ organization_id=organization.organization_id,+ workflow_permanent_id=chat_request.workflow_permanent_id,+ workflow_copilot_chat_id=(+ chat.workflow_copilot_chat_id if chat is not None else chat_request.workflow_copilot_chat_id+ ),+ )+ if eval_mode == CopilotEvalMode.BROWSER_ABLATION and agent_result is not None:+ metadata = agent_result.browser_ablation_metadata+ browser_session_id = metadata.get("browser_session_id") if isinstance(metadata, dict) else None+ if isinstance(browser_session_id, str) and browser_session_id:+ await close_browser_session_quietly(+ organization.organization_id,+ browser_session_id,+ reason=BrowserSessionCloseReason.user_requested,+ )+ finally:+ with contained_effect("copilot turn outcome log"):+ LOG.info(+ "Copilot turn outcome",+ organization_id=organization.organization_id,+ workflow_permanent_id=chat_request.workflow_permanent_id,+ workflow_copilot_chat_id=(+ chat.workflow_copilot_chat_id if chat is not None else chat_request.workflow_copilot_chat_id+ ),+ turn_id=turn_id_for_log,+ route_exit=route_exit,+ terminal_reason=(+ turn_outcome_for_log.terminal_reason if turn_outcome_for_log is not None else None+ ),+ response_kind=(+ turn_outcome_for_log.response_kind if turn_outcome_for_log is not None else None+ ),+ failure_kind=failure_kind_for_log,+ proposal_disposition=(+ _proposal_disposition(agent_result)+ if route_exit == "completed" and agent_result is not None+ else None+ ),+ duration_seconds=time.monotonic() - request_started_at,+ first_event_seconds=stream.first_event_seconds,)return FastAPIEventSourceStream.create(request, stream_handler)@@ -3923,7 +4055,7 @@ async def workflow_copilot_clear_proposed_workflow(expected_owner_turn_id = stored.owner_turn_idexpected_revision = stored.revisiontry:- await app.DATABASE.workflow_params.clear_workflow_copilot_candidate(+ cleared_chat = await app.DATABASE.workflow_params.clear_workflow_copilot_candidate(organization_id=organization.organization_id,workflow_copilot_chat_id=clear_request.workflow_copilot_chat_id,expected_owner_turn_id=expected_owner_turn_id,@@ -3934,6 +4066,12 @@ async def workflow_copilot_clear_proposed_workflow(raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail="Chat not found")except CopilotProposalConflictError:raise HTTPException(status_code=status.HTTP_409_CONFLICT, detail="Copilot proposal changed; reload required")+ LOG.info(+ "Copilot proposal rejected",+ organization_id=organization.organization_id,+ workflow_permanent_id=cleared_chat.workflow_permanent_id,+ workflow_copilot_chat_id=clear_request.workflow_copilot_chat_id,+ )@base_router.post(@@ -3984,12 +4122,23 @@ async def workflow_copilot_apply_proposed_workflow(if chat is None:raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail="Chat not found")+ def log_accept_refused(status_code: int) -> None:+ LOG.info(+ "Copilot proposal accept refused",+ organization_id=organization.organization_id,+ workflow_permanent_id=chat.workflow_permanent_id,+ workflow_copilot_chat_id=chat.workflow_copilot_chat_id,+ status_code=status_code,+ )+proposal = chat.proposed_workflowif not proposal:+ log_accept_refused(status.HTTP_400_BAD_REQUEST)raise HTTPException(status_code=status.HTTP_400_BAD_REQUEST, detail="No proposed workflow to apply")metadata = copilot_proposal_metadata(proposal)if isinstance(proposal, dict) and COPILOT_PROPOSAL_METADATA_KEY in proposal and metadata is None:+ log_accept_refused(status.HTTP_409_CONFLICT)raise HTTPException(status_code=status.HTTP_409_CONFLICT,detail="Copilot proposal metadata is invalid; reload required",@@ -4000,6 +4149,7 @@ async def workflow_copilot_apply_proposed_workflow(if not untokenized_client and (apply_request.owner_turn_id != metadata.owner_turn_id or apply_request.revision != metadata.revision):+ log_accept_refused(status.HTTP_409_CONFLICT)raise HTTPException(status_code=status.HTTP_409_CONFLICT, detail="Copilot proposal changed; reload required")@@ -4011,8 +4161,10 @@ async def workflow_copilot_apply_proposed_workflow()if metadata is not None:if canonical is None or not proposal_workflow_fingerprint_matches(canonical, metadata.canonical_fingerprint):+ log_accept_refused(status.HTTP_409_CONFLICT)raise HTTPException(status_code=status.HTTP_409_CONFLICT, detail="Workflow changed after this proposal")if metadata.claim_is_live(datetime.now(UTC)):+ log_accept_refused(status.HTTP_409_CONFLICT)raise HTTPException(status_code=status.HTTP_409_CONFLICT, detail="Copilot proposal is already being accepted")@@ -4026,6 +4178,7 @@ async def workflow_copilot_apply_proposed_workflow(copilot_yaml = proposal.get("_copilot_yaml") if isinstance(proposal, dict) else Noneif not copilot_yaml:+ log_accept_refused(status.HTTP_400_BAD_REQUEST)raise HTTPException(status_code=status.HTTP_400_BAD_REQUEST,detail="Proposed workflow has no copilot YAML to apply",@@ -4045,6 +4198,7 @@ async def workflow_copilot_apply_proposed_workflow(yaml_request.title = live_titleexcept (yaml.YAMLError, ValidationError) as e:+ log_accept_refused(status.HTTP_400_BAD_REQUEST)raise HTTPException(status_code=status.HTTP_400_BAD_REQUEST,detail=f"Proposed copilot YAML is invalid: {e}",@@ -4062,6 +4216,7 @@ async def workflow_copilot_apply_proposed_workflow(claimed_metadata = copilot_proposal_metadata(claimed.proposed_workflow)claimed_at = claimed_metadata.claimed_at if claimed_metadata is not None else Noneexcept CopilotProposalConflictError:+ log_accept_refused(status.HTTP_409_CONFLICT)raise HTTPException(status_code=status.HTTP_409_CONFLICT, detail="Copilot proposal changed; reload required")@@ -4134,6 +4289,12 @@ async def workflow_copilot_apply_proposed_workflow(exc_info=True,)+ LOG.info(+ "Copilot proposal accepted",+ organization_id=organization.organization_id,+ workflow_permanent_id=chat.workflow_permanent_id,+ workflow_copilot_chat_id=chat.workflow_copilot_chat_id,+ )return new_workflowdiff --git a/skyvern/forge/sdk/workflow/service.py b/skyvern/forge/sdk/workflow/service.pyindex 3fb3c97ed..fda8c219f 100644--- a/skyvern/forge/sdk/workflow/service.py+++ b/skyvern/forge/sdk/workflow/service.py@@ -12906,6 +12906,8 @@ class WorkflowService:else latest_attempt is not None and is_retry_pending(status, now, latest_attempt)),organization_id=workflow_run.organization_id,+ debug_session_id=workflow_run.debug_session_id,+ copilot_session_id=workflow_run.copilot_session_id,start_hold=_start_hold(workflow_run),backup_queue=app.AGENT_FUNCTION.is_backup_queue_organization(workflow_run.organization_id),run_with=workflow_run.run_with,@@ -16297,6 +16299,7 @@ class WorkflowService:LOG.info("Creating workflow from request",organization_id=organization_id,+ workflow_permanent_id=workflow_permanent_id or new_workflow_permanent_id,title=title,)if new_workflow_permanent_id:@@ -16558,7 +16561,7 @@ class WorkflowService:if new_workflow_id:await self.delete_workflow_by_id(workflow_id=new_workflow_id, organization_id=organization_id)raise- except Exception as e:+ except Exception:if attached_recording_to_new_version and new_workflow_id and recording_id_to_attach:await app.DATABASE.browser_recordings.detach_from_workflow_version(recording_id=recording_id_to_attach,@@ -16567,13 +16570,20 @@ class WorkflowService:)if new_workflow_id:LOG.error(- f"Failed to create workflow from request, deleting workflow {new_workflow_id}",+ "Failed to create workflow from request, deleting workflow",organization_id=organization_id,+ workflow_permanent_id=workflow_permanent_id,+ workflow_id=new_workflow_id,)await self.delete_workflow_by_id(workflow_id=new_workflow_id, organization_id=organization_id)else:- LOG.exception(f"Failed to create workflow from request, title: {title}")- raise e+ LOG.exception(+ "Failed to create workflow from request",+ organization_id=organization_id,+ workflow_permanent_id=workflow_permanent_id,+ title=title,+ )+ raiseasync def _refresh_workflow_schedule_runtime_limits(self,diff --git a/skyvern/forge/taskv3/engine.py b/skyvern/forge/taskv3/engine.pyindex 4c519b0eb..7419869d8 100644--- a/skyvern/forge/taskv3/engine.py+++ b/skyvern/forge/taskv3/engine.py@@ -595,11 +595,17 @@ async def run_task_v3_agent_loop()if refs.refs:system_prompt += OPAQUE_URL_GUIDANCE+ age_default = None if page_free else app.AGENT_FUNCTION.task_v3_age_default(parameters)+ age_default_text, age_default_reason = age_default or (None, None)+ user_prompt = build_user_prompt(model_goal, refs.masked, model_starting_url)+ # After the data, never in the system prompt: the data and the task's own instructions outrank the default.+ if age_default_text:+ user_prompt += f"\n\n{age_default_text}"try:outcome = await run_agent_tool_loop(llm_caller=llm_caller,system_prompt=system_prompt,- user_prompt=build_user_prompt(model_goal, refs.masked, model_starting_url),+ user_prompt=user_prompt,tools=tools,max_turns=max_turns,max_tool_calls=max_tool_calls,@@ -715,6 +721,8 @@ async def run_task_v3_agent_loop(perceptions_at_hold_gate=activity.perceptions_at_hold_gate,status_at_hold_gate=activity.status_at_hold_gate,has_navigation_goal=has_navigation_goal,+ age_default_rendered=bool(age_default_text),+ age_default_reason=age_default_reason,# The run's model, so exposure rates on this line split per model like the re-ask line's.llm_key=llm_caller.llm_key,unlisted_reask=outcome.unlisted_reask,diff --git a/skyvern/services/block_service.py b/skyvern/services/block_service.pyindex 140ab140b..19bfe46da 100644--- a/skyvern/services/block_service.py+++ b/skyvern/services/block_service.py@@ -111,6 +111,7 @@ async def execute_blocks(organization: Organization,user_id: str,browser_session_id: str | None = None,+ debug_session_id: str | None = None,block_outputs: dict[str, t.Any] | None = None,) -> None:"""@@ -148,8 +149,10 @@ async def execute_blocks("Executing block(s)",organization_id=organization.organization_id,workflow_run_id=workflow_run_id,+ workflow_permanent_id=workflow_permanent_id,+ debug_session_id=debug_session_id,block_labels=block_labels,- block_outputs=block_outputs,+ block_output_count=len(block_outputs or {}),)await AsyncExecutorFactory.get_executor().execute_workflow(diff --git a/skyvern/webeye/actions/handler.py b/skyvern/webeye/actions/handler.pyindex 7dbd16429..752de9f49 100644--- a/skyvern/webeye/actions/handler.py+++ b/skyvern/webeye/actions/handler.py@@ -395,6 +395,10 @@ class CustomSelectFamilyOutcome(StrEnum):DOWNLOAD_EVENT_ACTIVE_DIR_GRACE_SECONDS = 60DOWNLOAD_IN_FLIGHT_EXTENSION_MAX_SECONDS = 120DOWNLOAD_IN_FLIGHT_POLL_INTERVAL_SECONDS = 1.0+# Fire the one-shot download-recovery retry this many seconds before the no-signal grace expires, so a+# slow-but-real download has the whole grace to arrive on its own before we spend the single retry.+# Clamped to the grace, so a short grace still fires the retry inside the existing wait.+DOWNLOAD_RECOVERY_LATE_FIRE_LEAD_SECONDS = 15.0# Synchronous FileDownloadBlock false-click start-signal detection window: how long to wait for a first local# download signal (a new .crdownload/final file) before giving up, so a legitimate non-download popup is not# held for the whole download budget. Widened by an operator-set popup grace (up to its 60s setting cap); the@@ -4443,6 +4447,12 @@ class ScopedXhrDownloadCapture:def resume_in_flight_requests(self) -> None:self._accept_new_requests = True+ # Reopen the status-observation window for the one resumed retry so its own request (and the+ # retry's exact 500/200-class response) is observable again. The window was sealed after the+ # original action; without this the late retry's requests would start past the deadline and be+ # dropped. The window is re-sealed by the caller's seal_in_flight_requests() after the retry+ # click, still bounded by the original download-wait hard deadline.+ self._status_observation_deadline = Nonedef _is_xhr_download(self, headers: dict[str, str], status: int) -> bool:"""Check if an XHR response carries a downloadable file body.@@ -5387,6 +5397,10 @@ class ActionHandler:download_wait_hard_timeout_seconds = no_signal_grace_seconds + DOWNLOAD_IN_FLIGHT_EXTENSION_MAX_SECONDSdownload_wait_started_at = time.monotonic()download_wait_deadline = download_wait_started_at + download_wait_hard_timeout_seconds+ # Late-fire the one-shot recovery retry near the end of the no-signal grace (clamped to the+ # grace so a short timeout still fires inside the existing wait), giving a slow real download+ # the whole grace to land on its own before the single retry is spent.+ recovery_fire_after_seconds = max(0.0, no_signal_grace_seconds - DOWNLOAD_RECOVERY_LATE_FIRE_LEAD_SECONDS)def _remaining_download_wait_seconds() -> float:return max(0.0, download_wait_deadline - time.monotonic())@@ -5601,37 +5615,105 @@ class ActionHandler:)download_event_fallback_failed = Truebreak- if recovery_hook is not None and xhr_capture.recovery_requested:+ recovery_elapsed_seconds = time.monotonic() - download_wait_started_at+ if (+ recovery_hook is not None+ and xhr_capture.recovery_requested+ and recovery_elapsed_seconds >= recovery_fire_after_seconds+ ):+ # Consume the one-shot only now that a real attempt is about to begin: an+ # earlier poll where the fire time had not arrived leaves the still-eligible+ # hook untouched. Every branch below emits exactly one structured+ # "Download recovery click" receipt with a bounded sub-outcome.hook, recovery_hook = recovery_hook, None- if (- not download_event.done()- and not any(staging_dir.iterdir())- and _remaining_download_wait_seconds() > 0- ):+ if download_event.done():+ LOG.info(+ "Download recovery click",+ attempt=1,+ result="not_attempted",+ reason="event_done",+ elapsed_seconds=recovery_elapsed_seconds,+ )+ elif any(staging_dir.iterdir()):+ LOG.info(+ "Download recovery click",+ attempt=1,+ result="not_attempted",+ reason="staging_nonempty",+ elapsed_seconds=recovery_elapsed_seconds,+ )+ elif _remaining_download_wait_seconds() <= 0:+ LOG.info(+ "Download recovery click",+ attempt=1,+ result="not_attempted",+ reason="budget_exhausted",+ elapsed_seconds=recovery_elapsed_seconds,+ )+ else:+ phase = "remap"try:- locator = await hook.remap(page)- files = await _list_download_signal_files()- if (- locator is not None- and not download_event.done()- and not any(staging_dir.iterdir())- and not (- {_download_signal_identity(file) for file in files}- - signal_file_identities_before+ remap = await hook.remap(page)+ if remap.locator is None:+ LOG.info(+ "Download recovery click",+ attempt=1,+ result="remap_none",+ reason=remap.reason,+ elapsed_seconds=recovery_elapsed_seconds,)- ):- remaining = _remaining_download_wait_seconds()- if remaining > 0:+ else:+ phase = "recheck"+ files = await _list_download_signal_files()+ if (+ download_event.done()+ or any(staging_dir.iterdir())+ or (+ {_download_signal_identity(file) for file in files}+ - signal_file_identities_before+ )+ ):+ LOG.info(+ "Download recovery click",+ attempt=1,+ result="stale_signal",+ resolution=remap.resolution,+ elapsed_seconds=recovery_elapsed_seconds,+ )+ elif _remaining_download_wait_seconds() <= 0:+ LOG.info(+ "Download recovery click",+ attempt=1,+ result="no_budget_at_click",+ resolution=remap.resolution,+ elapsed_seconds=recovery_elapsed_seconds,+ )+ else:+ phase = "click"+ remaining = _remaining_download_wait_seconds()xhr_capture.resume_in_flight_requests()try:- await locator.click(timeout=remaining * 1000)- LOG.info("Download recovery click", attempt=1, result="clicked")+ await remap.locator.click(timeout=remaining * 1000)+ LOG.info(+ "Download recovery click",+ attempt=1,+ result="clicked",+ resolution=remap.resolution,+ elapsed_seconds=recovery_elapsed_seconds,+ )await asyncio.sleep(0)finally:xhr_capture.seal_in_flight_requests()continue- except Exception:- LOG.info("Download recovery click", attempt=1, result="failed")+ except Exception as recovery_exc:+ LOG.info(+ "Download recovery click",+ attempt=1,+ result="failed",+ phase=phase,+ error_type=type(recovery_exc).__name__,+ elapsed_seconds=recovery_elapsed_seconds,+ )elapsed_since_action = time.monotonic() - download_wait_started_atif elapsed_since_action >= download_wait_hard_timeout_seconds:diff --git a/skyvern/webeye/scraper/scraper.py b/skyvern/webeye/scraper/scraper.pyindex 972b78122..70c452d53 100644--- a/skyvern/webeye/scraper/scraper.py+++ b/skyvern/webeye/scraper/scraper.py@@ -552,6 +552,7 @@ async def scrape_web_unsafe(wait_seconds: float = 0,must_included_tags: list[str] | None = None,allow_transient_ui_suppression: bool = False,+ page: Page | None = None,) -> ScrapedPage:"""Asynchronous function that performs web scraping without any built-in error handling. This function is intended@@ -560,13 +561,15 @@ async def scrape_web_unsafe(:param browser_context: BrowserContext instance used for scraping.:param url: URL of the web page to be scraped. Used only when creating a new page.- :param page: Optional Page instance for scraping, a new page is created if None.+ :param page: Optional Page instance to scrape directly. When provided, the global working page is NOT+ reacquired, so a page opened concurrently (e.g. a popup) cannot become the scrape target.:return: Tuple containing Page instance, base64 encoded screenshot, and page elements.:note: This function does not handle exceptions. Ensure proper error handling in the calling context."""# browser state must have the page instance, otherwise we should not do scraping- page = await browser_state.must_get_working_page()+ if page is None:+ page = await browser_state.must_get_working_page()# Take screenshots of the page with the bounding boxes. We will remove the bounding boxes later.# Scroll to the top of the page and take a screenshot.# Scroll to the next page and take a screenshot until we reach the end of the page.diff --git a/tests/unit/force_stub_app.py b/tests/unit/force_stub_app.pyindex 5df81abcc..f9b1f36be 100644--- a/tests/unit/force_stub_app.py+++ b/tests/unit/force_stub_app.py@@ -69,6 +69,7 @@ def create_forge_stub_app() -> ForgeApp:fake_app_module.AGENT_FUNCTION.task_v3_required_field_answers_text = (base_agent_function.task_v3_required_field_answers_text)+ fake_app_module.AGENT_FUNCTION.task_v3_age_default = base_agent_function.task_v3_age_defaultfake_app_module.AGENT_FUNCTION.serialize_codeblock_parameters = base_agent_function.serialize_codeblock_parametersfake_app_module.AGENT_FUNCTION.redact_codeblock_parameter_values = (base_agent_function.redact_codeblock_parameter_valuesdiff --git a/tests/unit/test_taskv3_engine.py b/tests/unit/test_taskv3_engine.pyindex e6bc4a2e9..983d6f084 100644--- a/tests/unit/test_taskv3_engine.py+++ b/tests/unit/test_taskv3_engine.py@@ -1510,6 +1510,34 @@ async def test_terminal_log_carries_the_guard_class_that_ended_the_run() -> Noneassert terminal[0]["guard"] is None+async def test_age_default_rides_the_task_message_only_and_leaves_the_system_prompt_alone(+ monkeypatch: pytest.MonkeyPatch,+) -> None:+ async def run(hook_result: tuple[str | None, str] | None) -> tuple[str, str, dict[str, Any]]:+ monkeypatch.setattr(app.AGENT_FUNCTION, "task_v3_age_default", lambda parameters: hook_result)+ with capture_logs() as logs:+ outcome = await run_task_v3_agent_loop(+ page_provider=_fixed_page_provider(_FakePage()),+ llm_caller=_ScriptedCaller([[("finish", {"status": "completed", "reason": "ok"})]]),+ goal="Apply.",+ parameters={"resume": "text"},+ )+ by_role = {m["role"]: m["content"] for m in outcome.messages if m.get("role") in ("system", "user")}+ terminal = next(e for e in logs if e.get("event") == "taskv3 engine loop finished")+ return by_role["system"], by_role["user"], terminal++ base_system, base_user, base_log = await run(None)+ withheld_system, withheld_user, withheld_log = await run((None, "age_field_present"))+ rendered_system, rendered_user, rendered_log = await run(("AGE DEFAULT TEXT", "rendered"))++ assert base_system.startswith(SYSTEM_PROMPT) and base_system == withheld_system == rendered_system+ assert base_user == withheld_user and rendered_user == base_user + "\n\nAGE DEFAULT TEXT"+ assert (base_log["age_default_rendered"], base_log["age_default_reason"]) == (False, None)+ assert (withheld_log["age_default_rendered"], withheld_log["age_default_reason"]) == (False, "age_field_present")+ assert (rendered_log["age_default_rendered"], rendered_log["age_default_reason"]) == (True, "rendered")++@pytest.mark.asyncioasync def test_terminal_log_carries_duration_and_block_type() -> None:# The v1-vs-v3 wall-time dashboard reads this log line; it needs the loop's own wall-clock anddiff --git a/tests/unit/test_workflow_copilot_route.py b/tests/unit/test_workflow_copilot_route.pyindex 7bea28799..9f16ff942 100644--- a/tests/unit/test_workflow_copilot_route.py+++ b/tests/unit/test_workflow_copilot_route.py@@ -22,6 +22,7 @@ import yamlfrom fastapi import FastAPI, HTTPExceptionfrom httpx import ASGITransport, AsyncClientfrom sqlalchemy.ext.asyncio import AsyncEngine+from structlog.testing import capture_logsfrom skyvern.config import settingsfrom skyvern.forge import app@@ -2056,7 +2057,12 @@ async def test_flag_on_pre_agent_failure_persists_recoverable_reply(handler = captured["handler"]assert callable(handler)- await handler(copilot_stream)+ with capture_logs() as logs:+ await handler(copilot_stream)++ outcome_logs = [log for log in logs if log["event"] == "Copilot turn outcome"]+ assert len(outcome_logs) == 1+ assert outcome_logs[0]["route_exit"] == "error"contents = [call.kwargs.get("content") for call in workflow_params.create_workflow_copilot_chat_message.await_args_listdiff --git a/tests/unit/test_workflow_run_minutes_gate.py b/tests/unit/test_workflow_run_minutes_gate.pyindex 32d7bf360..3820119a8 100644--- a/tests/unit/test_workflow_run_minutes_gate.py+++ b/tests/unit/test_workflow_run_minutes_gate.py@@ -321,6 +321,8 @@ async def test_finally_block_re_finalization_records_only_the_minutes_it_added(task_queue=None,browser_session_id=None,browser_profile_id=None,+ debug_session_id=None,+ copilot_session_id=None,browser_address=None,start_fresh_browser=None,reuse_browser_session=None,