Automate browser based workflows with AI
Python aiapiautomationbrowserbrowser-automationcomputergptllmplaywrightpowerautomatepuppeteerpythonrpaseleniumvisionworkflow
Keep the copilot Explore phase active while the scout is still logging in (#7999)
Celal Zamanoğlu39b9e2a0fe3c
diff --git a/skyvern-frontend/src/routes/workflows/copilot/NarrativeView.checklist.test.tsx b/skyvern-frontend/src/routes/workflows/copilot/NarrativeView.checklist.test.tsxindex 45d224d83..be6266111 100644--- a/skyvern-frontend/src/routes/workflows/copilot/NarrativeView.checklist.test.tsx+++ b/skyvern-frontend/src/routes/workflows/copilot/NarrativeView.checklist.test.tsx@@ -204,6 +204,44 @@ describe("NarrativeView — phase checklist (SKY-11970)", () => {expect(screen.queryByText(/revising after failed verify/)).toBeNull();});+ it("REGRESSION PIN (SKY-12969): a mid-login code-only offer render keeps Explore active — no premature done, no 'Writing the workflow code…'", () => {+ // The synthesis lane renders an offer (turn.draft) while the scout is still+ // filling credentials, with zero authoring tools. Explore must stay active+ // and Draft must not claim the phase.+ const codeOnlyMidScout: TurnNarrativeState = {+ ...EMPTY_NARRATIVE,+ turnId: "turn-1",+ turnIndex: 0,+ mode: "build",+ designStarted: true,+ terminal: null,+ draft: { blockCount: 1, blockLabels: ["block_1"], summary: null },+ designActivity: [+ activityEntry({+ id: "tc-1",+ kind: "tool_call",+ toolName: "navigate_browser",+ displayLabel: "Opening page",+ }),+ activityEntry({+ id: "tc-2",+ kind: "tool_call",+ toolName: "fill_credential_field",+ displayLabel: "Filling credentials",+ }),+ ],+ };+ render(<NarrativeView turn={codeOnlyMidScout} uxV1 />);+ const exploreLabel = screen.getByText("Explore site");+ // Active rows render inert (no toggle button) with a spinner + sr-only word;+ // a completed row would render neither.+ expect(exploreLabel.closest("button")).toBeNull();+ const exploreRow = exploreLabel.closest("div")!;+ expect(exploreRow.querySelector(".animate-spin")).toBeTruthy();+ expect(exploreRow.textContent).toContain("Active");+ expect(screen.queryByText("Writing the workflow code…")).toBeNull();+ });+it("REGRESSION PIN: Test-run stays expandable when blocks exist even with an empty test-activity bucket (Codex catch)", () => {const historyRowNoTestActivity: TurnNarrativeState = {...EMPTY_NARRATIVE,diff --git a/skyvern-frontend/src/routes/workflows/copilot/copilotPhases.test.ts b/skyvern-frontend/src/routes/workflows/copilot/copilotPhases.test.tsindex 72130d0c9..45cbc9d26 100644--- a/skyvern-frontend/src/routes/workflows/copilot/copilotPhases.test.ts+++ b/skyvern-frontend/src/routes/workflows/copilot/copilotPhases.test.ts@@ -238,11 +238,21 @@ describe("derivePhases — live progression", () => {expect(phase(derivePhases(t), "draft").status).toBe("pending");});- it("draft goes active once the drafting-gap client hint fires, before any block runs", () => {- const t = turn({ draftingSignaledAt: 1000 });+ it("REGRESSION PIN (SKY-12969): the drafting-gap silence hint alone never completes Explore mid-scout", () => {+ // The 8s drafting-gap heuristic fires on any tool-call silence — including a+ // scout thinking-pause during login/2FA before the synthesis lane sets+ // turn.draft. A phase claim must derive from recorded authoring activity,+ // not the absence of frames, so a bare draftingSignaledAt leaves Explore+ // active and Draft pending.+ const t = turn({+ draftingSignaledAt: 1000,+ designActivity: [+ entry({ id: "1", kind: "tool_call", toolName: "navigate_browser" }),+ ],+ });const rows = derivePhases(t);- expect(phase(rows, "explore").status).toBe("done");- expect(phase(rows, "draft").status).toBe("active");+ expect(phase(rows, "explore").status).toBe("active");+ expect(phase(rows, "draft").status).toBe("pending");expect(phase(rows, "test").status).toBe("pending");});@@ -322,6 +332,176 @@ describe("derivePhases — terminal", () => {});});+describe("derivePhases — SKY-12969 code-only incremental build (concurrent draft)", () => {+ // Mirrors the production session: scout tool completions interleaved with the+ // synthesis lane's offer renders (turn.draft) at trajectory 1 and 4, zero+ // AUTHORING_TOOLS entries, user-cancel terminal.+ const OFFER = { blockCount: 1, blockLabels: ["block_1"], summary: null };+ const scoutTools = [+ "navigate_browser",+ "evaluate",+ "evaluate",+ "take_screenshot",+ "evaluate",+ "fill_credential_field",+ "fill_credential_field",+ "evaluate",+ "click",+ "fill_credential_field",+ "click",+ ];+ const scout = (n: number): ActivityEntry[] =>+ scoutTools+ .slice(0, n)+ .map((toolName, i) =>+ entry({ id: `s${i}`, kind: "tool_call", toolName }),+ );++ it("AC1: Explore stays active (never done) while the scout is mid-login and an offer has already rendered", () => {+ // Screenshot-1 instant: 10 scout completions, offer rendered (turn.draft set+ // by the synthesis lane), no authoring tool, live browser still on 2FA.+ const midScout = turn({+ terminal: null,+ draft: OFFER,+ designActivity: scout(10),+ });+ const rows = derivePhases(midScout);+ expect(phase(rows, "explore").status).toBe("active");+ expect(phase(rows, "draft").status).toBe("pending");+ // An active Explore row shows no done-stub — its count cannot be claimed+ // complete while it is still growing.+ expect(phase(rows, "explore").stub).toBeNull();+ });++ it("AC1: the growing step count never lands under a completed row", () => {+ const at10 = derivePhases(+ turn({ terminal: null, draft: OFFER, designActivity: scout(10) }),+ );+ const at11 = derivePhases(+ turn({ terminal: null, draft: OFFER, designActivity: scout(11) }),+ );+ expect(phase(at10, "explore").status).toBe("active");+ expect(phase(at11, "explore").status).toBe("active");+ expect(phase(at11, "explore").entries.length).toBeGreaterThan(+ phase(at10, "explore").entries.length,+ );+ });++ it("AC1: a user-cancel mid-login marks Explore stopped (not done); Draft stays pending", () => {+ const cancelled = turn({+ terminal: "response",+ cancelled: true,+ designEnded: true,+ draft: OFFER,+ designActivity: scout(11),+ });+ const rows = derivePhases(cancelled);+ expect(phase(rows, "explore").status).toBe("stopped");+ expect(phase(rows, "draft").status).toBe("pending");+ expect(phase(rows, "done").status).toBe("stopped");+ });++ it("AC1/ruling: a healthy (non-cancelled) response terminal carrying the proposal resolves the phases done, count frozen", () => {+ // The user let the same turn finish: scout completed, proposal offered, no+ // authoring tool, no run. The turn is over — Explore genuinely ended, so the+ // row completes WITH its final count (count-immutability holds).+ const healthy = turn({+ terminal: "response",+ cancelled: false,+ designEnded: true,+ draft: OFFER,+ designActivity: scout(11),+ });+ const rows = derivePhases(healthy);+ expect(phase(rows, "explore").status).toBe("done");+ expect(phase(rows, "draft").status).toBe("done");+ expect(phase(rows, "test").status).toBe("notrun");+ expect(phase(rows, "done").status).toBe("done");+ expect(phase(rows, "explore").stub).toBe("11 steps");+ });++ it("AC1: hydration parity — a draft-only authoring turn resolves identically live and after reload", () => {+ // authoringCount is client-only and resets to 0 on a history reload; the+ // hydrated designActivity still carries the update_workflow entry, so+ // authoringSeen keeps Explore/Draft resolved to done both ways (no jump).+ const authored = [+ entry({ id: "1", kind: "tool_call", toolName: "navigate_browser" }),+ entry({ id: "2", kind: "tool_call", toolName: "update_workflow" }),+ ];+ const live = turn({+ terminal: "response",+ designEnded: true,+ authoringCount: 1,+ draft: OFFER,+ designActivity: authored,+ });+ const hydrated = turn({+ terminal: "response",+ designEnded: true,+ authoringCount: 0,+ draft: OFFER,+ designActivity: authored,+ });+ expect(derivePhases(hydrated).map((r) => r.status)).toEqual(+ derivePhases(live).map((r) => r.status),+ );+ expect(phase(derivePhases(hydrated), "explore").status).toBe("done");+ expect(phase(derivePhases(hydrated), "draft").status).toBe("done");+ });++ it("AC2 regression: a failed-verify redraft still re-activates Draft exactly as today", () => {+ // The 11970 redraft beat re-activates Draft from activitySeq vs the+ // verdict snapshot, independent of any draft artifact.+ const t = turn({+ terminal: null,+ designEnded: true,+ authoringCount: 1,+ activitySeq: 3,+ draft: OFFER,+ blocks: [block({ state: "completed" })],+ lastRunOutcome: {+ verdict: "not_demonstrated",+ displayReason: "outcome not confirmed",+ activitySeqAtVerdict: 2,+ },+ designActivity: [+ entry({ id: "1", kind: "tool_call", toolName: "navigate_browser" }),+ entry({+ id: "2",+ kind: "tool_call",+ toolName: "update_and_run_blocks",+ }),+ entry({+ id: "3",+ kind: "tool_call",+ toolName: "inspect_current_workflow",+ }),+ ],+ });+ const rows = derivePhases(t);+ expect(phase(rows, "draft").status).toBe("active");+ expect(phase(rows, "test").status).toBe("done");+ });++ it("AC1/parity: a cancelled terminal with authoring evidence but an aged-out activity list still resolves Explore done, Draft stopped", () => {+ // The reducer grafts the uncapped authoringCount across the terminal swap;+ // the derivation must honor it so an authoring turn whose sole authoring+ // entry evicted from the 50-capped activity list doesn't flip Explore back+ // to stopped after the swap (SKY-11970 live/terminal parity).+ const cancelledEvicted = turn({+ terminal: "response",+ cancelled: true,+ designEnded: true,+ authoringCount: 1,+ draft: OFFER,+ designActivity: [],+ });+ const rows = derivePhases(cancelledEvicted);+ expect(phase(rows, "explore").status).toBe("done");+ expect(phase(rows, "draft").status).toBe("stopped");+ });+});+describe("showPhaseChecklist", () => {it("false for a clarify terminal turn with no draft and no blocks", () => {expect(diff --git a/skyvern-frontend/src/routes/workflows/copilot/copilotPhases.ts b/skyvern-frontend/src/routes/workflows/copilot/copilotPhases.tsindex 7c2a5e04c..67df75772 100644--- a/skyvern-frontend/src/routes/workflows/copilot/copilotPhases.ts+++ b/skyvern-frontend/src/routes/workflows/copilot/copilotPhases.ts@@ -99,6 +99,7 @@ function bucketActivity(designActivity: ActivityEntry[]): {explore: ActivityEntry[];draft: ActivityEntry[];test: ActivityEntry[];+ authoringSeen: boolean;} {const explore: ActivityEntry[] = [];const draft: ActivityEntry[] = [];@@ -118,7 +119,7 @@ function bucketActivity(designActivity: ActivityEntry[]): {}(authoringSeen ? draft : explore).push(entry);}- return { explore, draft, test };+ return { explore, draft, test, authoringSeen };}function lastAuthoringToolName(@@ -193,6 +194,7 @@ export function derivePhases(turn: TurnNarrativeState): PhaseRowModel[] {explore,draft: draftEntries,test,+ authoringSeen,} = bucketActivity(turn.designActivity);const lastAuthoring = lastAuthoringToolName(turn.designActivity);const latestBlocks = latestBlocksByLabel(turn.blocks).filter(@@ -201,12 +203,18 @@ export function derivePhases(turn: TurnNarrativeState): PhaseRowModel[] {const testReached =latestBlocks.length > 0 ||(turn.designEnded && lastAuthoring === "update_and_run_blocks");+ // Explore completes only on recorded authoring (authoringCount live /+ // authoringSeen after hydration resets the client-only count) or a run.+ // draftingSignaledAt can fire on a mid-scout pause and designEnded is forced+ // true at every terminal, so neither completes Explore mid-turn; turn.draft+ // resolves the phases only at a healthy, non-cancelled response terminal.const draftReached =turn.authoringCount > 0 ||- turn.draft !== null ||- turn.designEnded ||- turn.draftingSignaledAt !== null ||- testReached;+ authoringSeen ||+ testReached ||+ (turn.terminal === "response" &&+ turn.cancelled !== true &&+ turn.draft !== null);const running = turn.blocks.some((b) => b.state === "running" || b.state === "queued",diff --git a/skyvern-frontend/src/routes/workflows/copilot/narrativeState.phaseHint.test.ts b/skyvern-frontend/src/routes/workflows/copilot/narrativeState.phaseHint.test.tsindex 9588704a7..0823ef36c 100644--- a/skyvern-frontend/src/routes/workflows/copilot/narrativeState.phaseHint.test.ts+++ b/skyvern-frontend/src/routes/workflows/copilot/narrativeState.phaseHint.test.ts@@ -329,7 +329,7 @@ describe("applyNarrativeEvent — response hydration resets phase-hint fields",expect(s.draftingSignaledAt).toBeNull();});- it("authoringCount and lastRunOutcome are NOT grafted — terminal checklist is stubs-only", () => {+ it("authoringCount is grafted across the terminal swap (SKY-12969 parity); lastRunOutcome/activitySeq are not", () => {let s: TurnNarrativeState = applyNarrativeEvent(EMPTY_NARRATIVE,turnStart(),@@ -361,7 +361,11 @@ describe("applyNarrativeEvent — response hydration resets phase-hint fields",},}),);- expect(s.authoringCount).toBe(0);+ // Grafted (same turnId): the uncapped counter survives even though the+ // payload's capped designActivity has aged out the authoring entry, so+ // Explore stays resolved at the swap rather than flipping back.+ expect(s.authoringCount).toBe(1);+ // Still not grafted — a cancel-mid-redraft marks Test stopped, not Draft.expect(s.lastRunOutcome).toBeNull();expect(s.activitySeq).toBe(0);});diff --git a/skyvern-frontend/src/routes/workflows/copilot/narrativeState.ts b/skyvern-frontend/src/routes/workflows/copilot/narrativeState.tsindex 2b9f8c3a4..9414cce87 100644--- a/skyvern-frontend/src/routes/workflows/copilot/narrativeState.ts+++ b/skyvern-frontend/src/routes/workflows/copilot/narrativeState.ts@@ -990,12 +990,17 @@ export function applyNarrativeEvent(...hydrated,blocks,// Graft across the terminal replacement so a cancel mid-silence- // doesn't visually un-check the Draft phase (hydrated payloads- // never carry this client-only field). authoringCount/lastRunOutcome- // are intentionally NOT grafted — a stubs-only terminal checklist is- // correct there.+ // doesn't visually un-check the Draft phase (hydrated payloads never+ // carry these client-only fields). authoringCount is grafted too so a+ // turn whose only authoring entry aged out of the capped activity+ // list still completes Explore at the swap; lastRunOutcome is not —+ // a cancel-mid-redraft marks Test stopped rather than Draft.draftingSignaledAt:hydrated.turnId === prev.turnId ? prev.draftingSignaledAt : null,+ authoringCount:+ hydrated.turnId === prev.turnId+ ? prev.authoringCount+ : hydrated.authoringCount,responseType: event.response_type ?? hydrated.responseType,cancelled: event.cancelled ?? hydrated.cancelled,proposalDisposition: