Skip to content

Automate browser based workflows with AI

Cap sweep-finalized run minutes at the run type's compute budget (#8292)

Shuchang Zhengd1cfc46ddfda
diff --git a/docs/api-reference/openapi.json b/docs/api-reference/openapi.json
index 9582729e9..593374080 100644
--- a/docs/api-reference/openapi.json
+++ b/docs/api-reference/openapi.json
@@ -19458,9 +19458,9 @@
"properties": {
"password": {
"type": "string",
- "minLength": 1,
"title": "Password",
- "description": "The password value (must not be empty)",
+ "description": "The password value; may be empty or omitted for logins that have no password",
+ "default": "",
"examples": [
"securepassword123"
]
@@ -19531,11 +19531,10 @@
},
"type": "object",
"required": [
- "password",
"username"
],
"title": "NonEmptyPasswordCredential",
- "description": "Password credential model that requires non-empty values."
+ "description": "Password credential model for API writes: non-empty username, optionally empty password."
},
"OTPType": {
"type": "string",
diff --git a/skyvern-frontend/src/api/types.ts b/skyvern-frontend/src/api/types.ts
index 56a07cee2..ca484ed13 100644
--- a/skyvern-frontend/src/api/types.ts
+++ b/skyvern-frontend/src/api/types.ts
@@ -1112,7 +1112,8 @@ export type CreateCredentialRequest = {
export type PasswordCredential = {
username: string;
- password: string;
+ /** Omit on an overwrite to keep the stored password; "" blanks it. */
+ password?: string;
totp: string | null;
totp_type: "authenticator" | "email" | "text" | "passkey" | "none";
totp_identifier?: string | null;
diff --git a/skyvern-frontend/src/components/BrowserStream.test.tsx b/skyvern-frontend/src/components/BrowserStream.test.tsx
index d9ba8b3ed..c5e121f3b 100644
--- a/skyvern-frontend/src/components/BrowserStream.test.tsx
+++ b/skyvern-frontend/src/components/BrowserStream.test.tsx
@@ -624,6 +624,45 @@ describe("BrowserStream", () => {
});
});
+ it("backs off VNC reconnects and stops after the cap", async () => {
+ vi.useFakeTimers();
+ try {
+ renderBrowserStream();
+ await vi.advanceTimersByTimeAsync(1000);
+ expect(mocks.rfbInstances).toHaveLength(1);
+ mocks.autoConnect.value = false;
+
+ // Each disconnect schedules exactly one delayed redial, up to the cap.
+ for (let attempt = 0; attempt < 8; attempt++) {
+ const instanceCount = mocks.rfbInstances.length;
+ const rfb = mocks.rfbInstances[
+ mocks.rfbInstances.length - 1
+ ] as unknown as {
+ emit: (type: string, detail?: unknown) => void;
+ };
+ rfb.emit("disconnect", { clean: false });
+ // No immediate redial: the retry waits out its backoff delay.
+ await vi.advanceTimersByTimeAsync(0);
+ expect(mocks.rfbInstances).toHaveLength(instanceCount);
+ // Max delay 15s plus up to 50% jitter.
+ await vi.advanceTimersByTimeAsync(30000);
+ expect(mocks.rfbInstances).toHaveLength(instanceCount + 1);
+ }
+
+ const instanceCount = mocks.rfbInstances.length;
+ const rfb = mocks.rfbInstances[
+ mocks.rfbInstances.length - 1
+ ] as unknown as {
+ emit: (type: string, detail?: unknown) => void;
+ };
+ rfb.emit("disconnect", { clean: false });
+ await vi.advanceTimersByTimeAsync(120000);
+ expect(mocks.rfbInstances).toHaveLength(instanceCount);
+ } finally {
+ vi.useRealTimers();
+ }
+ });
+
it("shows a two-sentence message on an unclean VNC disconnect", async () => {
renderBrowserStream();
diff --git a/skyvern-frontend/src/components/BrowserStream.tsx b/skyvern-frontend/src/components/BrowserStream.tsx
index 9e34a41ad..6ec59e4cd 100644
--- a/skyvern-frontend/src/components/BrowserStream.tsx
+++ b/skyvern-frontend/src/components/BrowserStream.tsx
@@ -5,9 +5,8 @@ import _RFB, { type RfbEvent } from "@novnc/novnc/lib/rfb.js";
type RFB = _RFB;
const RFB = (_RFB as typeof _RFB & { default?: typeof _RFB }).default ?? _RFB;
import { ExitIcon, HandIcon, InfoCircledIcon } from "@radix-ui/react-icons";
-import { useEffect, useMemo, useState, useRef, useCallback } from "react";
+import { useEffect, useState, useRef, useCallback } from "react";
import { useQuery } from "@tanstack/react-query";
-import { useShallow } from "zustand/react/shallow";
import { getClient } from "@/api/AxiosClient";
import {
@@ -15,25 +14,22 @@ import {
type TaskApiResponse,
type WorkflowRunStatusApiResponse,
} from "@/api/types";
+import { RecordingPill } from "@/components/RecordingPill";
import { Tip } from "@/components/Tip";
import { Button } from "@/components/ui/button";
import { toast } from "@/components/ui/use-toast";
import { useCredentialGetter } from "@/hooks/useCredentialGetter";
-import { useRecordingElapsedSeconds } from "@/hooks/useRecordingElapsedSeconds";
import { statusIsNotFinalized } from "@/routes/tasks/types";
-import {
- useRecordingStore,
- countVisibleDraftSteps,
-} from "@/store/useRecordingStore";
+import { useRecordingStore } from "@/store/useRecordingStore";
import { useSettingsStore } from "@/store/SettingsStore";
import { wssBaseUrl, newWssBaseUrl } from "@/util/env";
-import { formatRecordingClock } from "@/util/recordingClock";
import { installNoVncGestureCrashGuard } from "@/util/novncGestureCrashGuard";
import { cn } from "@/util/utils";
import {
StreamStatusPanel,
type StreamDiagnostic,
} from "@/routes/streaming/StreamDiagnostics";
+import { streamReconnectDelayMs } from "@/routes/streaming/streamLifecycle";
import {
handleVncClipboardPasteShortcut,
type HeldMetaSides,
@@ -47,6 +43,7 @@ installNoVncGestureCrashGuard();
const MESSAGE_RECONNECT_DELAY_MS = 1000;
const MESSAGE_MAX_RECONNECT_ATTEMPTS = 20;
+const VNC_MAX_RECONNECT_ATTEMPTS = 8;
const STREAM_GAVE_UP_DIAGNOSTIC: StreamDiagnostic = {
title: "Browser stream connection lost",
detail:
@@ -107,68 +104,6 @@ function applyVncStreamProfile(
rfb.qualityLevel = 6;
}
-function RecordingPill() {
- const {
- finishRequested,
- manualCapturePaused,
- draftSteps,
- deletedStepIds,
- exposedEventCount,
- optimisticStepCount,
- interpretationEnabled,
- } = useRecordingStore(
- useShallow((state) => ({
- finishRequested: state.finishRequested,
- manualCapturePaused: state.manualCapturePaused,
- draftSteps: state.draftSteps,
- deletedStepIds: state.deletedStepIds,
- exposedEventCount: state.exposedEventCount,
- optimisticStepCount: state.optimisticSteps.length,
- interpretationEnabled: state.workflowPermanentId !== null,
- })),
- );
-
- const interpretedStepCount = useMemo(
- () => countVisibleDraftSteps(draftSteps, deletedStepIds),
- [draftSteps, deletedStepIds],
- );
- const elapsedSeconds = useRecordingElapsedSeconds();
- // Show interpreted + optimistic steps whenever interpretation is enabled, not
- // just after the first snapshot arrives — otherwise the first step waits a
- // backend round-trip even though the optimistic placeholder is already local.
- const count = interpretationEnabled
- ? interpretedStepCount + optimisticStepCount
- : exposedEventCount;
-
- const paused = manualCapturePaused && !finishRequested;
-
- return (
- <div
- className={cn(
- "inline-flex h-6 items-center gap-2 rounded-full border px-3 text-xs font-semibold tabular-nums",
- paused
- ? "border-amber-500/50 bg-amber-950 text-amber-200"
- : "border-red-500/50 bg-red-950 text-red-200",
- )}
- >
- <span
- className={cn("h-2 w-2 rounded-full", {
- "bg-amber-500": paused,
- "bg-red-500": !paused,
- "animate-pulse": !finishRequested && !paused,
- "opacity-50": finishRequested,
- })}
- />
- {finishRequested ? "FINISHING" : paused ? "PAUSED" : "REC"}{" "}
- {formatRecordingClock(elapsedSeconds)}
- <span className={paused ? "text-amber-400/80" : "text-red-400/80"}>
- ·
- </span>
- {count}
- </div>
- );
-}
-
function BrowserStream({
browserSessionId = undefined,
exfiltrate = false,
@@ -267,6 +202,10 @@ function BrowserStream({
right: false,
});
const observerRef = useRef<MutationObserver | null>(null);
+ const vncReconnectAttemptsRef = useRef(0);
+ const vncReconnectTimerRef = useRef<ReturnType<typeof setTimeout> | null>(
+ null,
+ );
const messageReconnectAttemptsRef = useRef(0);
const messageReconnectTimerRef = useRef<ReturnType<typeof setTimeout> | null>(
null,
@@ -352,6 +291,11 @@ function BrowserStream({
clearTimeout(messageReconnectTimerRef.current);
messageReconnectTimerRef.current = null;
}
+ vncReconnectAttemptsRef.current = 0;
+ if (vncReconnectTimerRef.current) {
+ clearTimeout(vncReconnectTimerRef.current);
+ vncReconnectTimerRef.current = null;
+ }
if (rfbRef.current) {
rfbRef.current.disconnect();
rfbRef.current = null;
@@ -549,6 +493,7 @@ function BrowserStream({
setIsVncConnected(true);
setTerminalDiagnostic(null);
messageReconnectAttemptsRef.current = 0;
+ vncReconnectAttemptsRef.current = 0;
});
rfb.addEventListener("disconnect", (e: RfbEvent) => {
@@ -556,7 +501,22 @@ function BrowserStream({
didDisconnect = true;
setIsVncConnected(false);
setIsCanvasReady(false);
- setVncDisconnectedTrigger((x) => x + 1);
+ // Exponential backoff with jitter, capped attempts: a session with no
+ // reachable VNC endpoint dies in ~150ms per dial, and an immediate
+ // retrigger hammered the API at ~4 dials/second.
+ if (vncReconnectAttemptsRef.current < VNC_MAX_RECONNECT_ATTEMPTS) {
+ const delay = streamReconnectDelayMs(
+ vncReconnectAttemptsRef.current,
+ );
+ vncReconnectAttemptsRef.current += 1;
+ vncReconnectTimerRef.current = setTimeout(
+ () => {
+ vncReconnectTimerRef.current = null;
+ setVncDisconnectedTrigger((x) => x + 1);
+ },
+ delay + Math.random() * delay * 0.5,
+ );
+ }
onClose?.();
const clean = Boolean(e.detail?.clean);
setTerminalDiagnostic(
@@ -579,6 +539,11 @@ function BrowserStream({
return () => {
cancelled = true;
+ // Every re-run redials via setupVnc, so a pending retry is redundant.
+ if (vncReconnectTimerRef.current) {
+ clearTimeout(vncReconnectTimerRef.current);
+ vncReconnectTimerRef.current = null;
+ }
if (observerRef.current) {
observerRef.current.disconnect();
observerRef.current = null;
diff --git a/skyvern-frontend/src/components/RecordingPill.tsx b/skyvern-frontend/src/components/RecordingPill.tsx
new file mode 100644
index 000000000..caced38a5
--- /dev/null
+++ b/skyvern-frontend/src/components/RecordingPill.tsx
@@ -0,0 +1,73 @@
+import { useMemo } from "react";
+import { useShallow } from "zustand/react/shallow";
+
+import { useRecordingElapsedSeconds } from "@/hooks/useRecordingElapsedSeconds";
+import {
+ useRecordingStore,
+ countVisibleDraftSteps,
+} from "@/store/useRecordingStore";
+import { formatRecordingClock } from "@/util/recordingClock";
+import { cn } from "@/util/utils";
+
+export function RecordingPill() {
+ const {
+ finishRequested,
+ manualCapturePaused,
+ draftSteps,
+ deletedStepIds,
+ exposedEventCount,
+ optimisticStepCount,
+ interpretationEnabled,
+ } = useRecordingStore(
+ useShallow((state) => ({
+ finishRequested: state.finishRequested,
+ manualCapturePaused: state.manualCapturePaused,
+ draftSteps: state.draftSteps,
+ deletedStepIds: state.deletedStepIds,
+ exposedEventCount: state.exposedEventCount,
+ optimisticStepCount: state.optimisticSteps.length,
+ interpretationEnabled: state.workflowPermanentId !== null,
+ })),
+ );
+
+ const interpretedStepCount = useMemo(
+ () => countVisibleDraftSteps(draftSteps, deletedStepIds),
+ [draftSteps, deletedStepIds],
+ );
+ const elapsedSeconds = useRecordingElapsedSeconds();
+ // Show interpreted + optimistic steps whenever interpretation is enabled, not
+ // just after the first snapshot arrives — otherwise the first step waits a
+ // backend round-trip even though the optimistic placeholder is already local.
+ const count = interpretationEnabled
+ ? interpretedStepCount + optimisticStepCount
+ : exposedEventCount;
+
+ const paused = manualCapturePaused && !finishRequested;
+
+ return (
+ <div
+ data-testid="recording-pill"
+ className={cn(
+ "inline-flex h-6 items-center gap-2 rounded-full border px-3 text-xs font-semibold tabular-nums",
+ paused
+ ? "border-amber-500/50 bg-amber-950 text-amber-200"
+ : "border-red-500/50 bg-red-950 text-red-200",
+ )}
+ >
+ <span
+ className={cn("h-2 w-2 rounded-full", {
+ "bg-amber-500": paused,
+ "bg-red-500": !paused,
+ "animate-pulse": !finishRequested && !paused,
+ "opacity-50": finishRequested,
+ })}
+ />
+ {finishRequested ? "FINISHING" : paused ? "PAUSED" : "REC"}{" "}
+ {formatRecordingClock(elapsedSeconds)}
+ <span className={paused ? "text-amber-400/80" : "text-red-400/80"}>
+ ·
+ </span>
+ {count}
+ </div>
+ );
+}
diff --git a/skyvern-frontend/src/routes/credentials/CredentialsModal.test.tsx b/skyvern-frontend/src/routes/credentials/CredentialsModal.test.tsx
index 5ca672671..2550dad37 100644
--- a/skyvern-frontend/src/routes/credentials/CredentialsModal.test.tsx
+++ b/skyvern-frontend/src/routes/credentials/CredentialsModal.test.tsx
@@ -723,6 +723,172 @@ describe("CredentialsModal edit-mode inline test", () => {
}, 15_000);
});
+describe("CredentialsModal edit-mode password preservation", () => {
+ const noPasswordLabel = "This login has no password";
+
+ it("omits password from the overwrite payload when the field is left untouched", async () => {
+ postMock.mockResolvedValueOnce({
+ data: { credential_id: "real-cred-id", name: "Acme Login" },
+ });
+ patchMock.mockResolvedValue({ data: {} });
+ renderEditPasswordCredentialsModal();
+
+ fireEvent.click(screen.getAllByLabelText("Edit credential values")[0]!);
+ const usernameInput = screen.getByDisplayValue("[email protected]");
+ fireEvent.change(usernameInput, {
+ target: { value: "[email protected]" },
+ });
+ fireEvent.click(screen.getByRole("button", { name: "Update" }));
+
+ await waitFor(() => {
+ expect(postMock).toHaveBeenCalledWith(
+ "/credentials/real-cred-id/update",
+ expect.objectContaining({
+ credential: expect.objectContaining({
+ username: "[email protected]",
+ }),
+ }),
+ );
+ });
+ const submitted = postMock.mock.calls[0]?.[1] as {
+ credential: Record<string, unknown>;
+ };
+ expect(submitted.credential).not.toHaveProperty("password");
+ }, 10_000);
+
+ it("sends an empty password only when the no-password box is checked", async () => {
+ postMock.mockResolvedValueOnce({
+ data: { credential_id: "real-cred-id", name: "Acme Login" },
+ });
+ patchMock.mockResolvedValue({ data: {} });
+ renderEditPasswordCredentialsModal();
+
+ fireEvent.click(screen.getAllByLabelText("Edit credential values")[0]!);
+ fireEvent.click(screen.getByRole("checkbox", { name: noPasswordLabel }));
+ fireEvent.click(screen.getByRole("button", { name: "Update" }));
+
+ await waitFor(() => {
+ expect(postMock).toHaveBeenCalledWith(
+ "/credentials/real-cred-id/update",
+ expect.objectContaining({
+ credential: expect.objectContaining({ password: "" }),
+ }),
+ );
+ });
+ }, 10_000);
+
+ it("still sends a re-entered password on the overwrite", async () => {
+ postMock.mockResolvedValueOnce({
+ data: { credential_id: "real-cred-id", name: "Acme Login" },
+ });
+ patchMock.mockResolvedValue({ data: {} });
+ renderEditPasswordCredentialsModal();
+
+ fireEvent.click(screen.getAllByLabelText("Edit credential values")[0]!);
+ fireEvent.change(screen.getByPlaceholderText("••••••••"), {
+ target: { value: "rotated-password" },
+ });
+ fireEvent.click(screen.getByRole("button", { name: "Update" }));
+
+ await waitFor(() => {
+ expect(postMock).toHaveBeenCalledWith(
+ "/credentials/real-cred-id/update",
+ expect.objectContaining({
+ credential: expect.objectContaining({
+ password: "rotated-password",
+ }),
+ }),
+ );
+ });
+ }, 10_000);
+
+ it("hides the no-password box until the values group is opened", () => {
+ renderEditPasswordCredentialsModal();
+
+ expect(
+ screen.queryByRole("checkbox", { name: noPasswordLabel }),
+ ).toBeNull();
+ fireEvent.click(screen.getAllByLabelText("Edit credential values")[0]!);
+ expect(
+ screen.getByRole("checkbox", { name: noPasswordLabel }),
+ ).toBeTruthy();
+ });
+
+ it("does not offer the no-password box on create, where a blank field already means none", async () => {
+ renderPasswordCredentialsModal();
+
+ await waitFor(() => {
+ expect(screen.getByDisplayValue("credentials")).toBeTruthy();
+ });
+ expect(
+ screen.queryByRole("checkbox", { name: noPasswordLabel }),
+ ).toBeNull();
+ });
+});
+
+describe("CredentialsModal password-less inline test", () => {
+ it("enables Test on a create-mode credential with no password", async () => {
+ renderPasswordCredentialsModal();
+
+ await waitFor(() => {
+ expect(screen.getByDisplayValue("credentials")).toBeTruthy();
+ });
+ const usernameInput = Array.from(
+ document.querySelectorAll<HTMLInputElement>("input"),
+ ).find(
+ (input) =>
+ input.type === "text" && input.value === "" && input.placeholder === "",
+ );
+ fireEvent.change(usernameInput as HTMLInputElement, {
+ target: { value: "[email protected]" },
+ });
+ fireEvent.click(
+ screen.getByLabelText("Save browser session for future logins"),
+ );
+ fireEvent.change(screen.getByPlaceholderText("https://example.com/login"), {
+ target: { value: "https://example.com/login" },
+ });
+
+ const testButton = screen.getByRole("button", {
+ name: "Test",
+ }) as HTMLButtonElement;
+ expect(testButton.disabled).toBe(false);
+
+ postMock.mockResolvedValueOnce({
+ data: { credential_id: "temp-cred-id", workflow_run_id: "wr-1" },
+ });
+ fireEvent.click(testButton);
+ await waitFor(() => {
+ expect(postMock).toHaveBeenCalledWith(
+ "/credentials/test-login",
+ expect.objectContaining({
+ username: "[email protected]",
+ password: "",
+ }),
+ );
+ });
+ }, 10_000);
+
+ it("keeps Test disabled in edit mode until the password is entered or declared absent", async () => {
+ renderEditPasswordCredentialsModal();
+
+ fireEvent.click(screen.getAllByLabelText("Edit credential values")[0]!);
+ const testButton = screen.getByRole("button", {
+ name: "Test",
+ }) as HTMLButtonElement;
+ // Blank here means "keep the stored password", which the inline test cannot read.
+ expect(testButton.disabled).toBe(true);
+
+ fireEvent.click(
+ screen.getByRole("checkbox", { name: "This login has no password" }),
+ );
+ expect(
+ (screen.getByRole("button", { name: "Test" }) as HTMLButtonElement)
+ .disabled,
+ ).toBe(false);
+ });
+});
+
describe("CredentialsModal browser-memory profile section (flag on)", () => {
beforeEach(() => {
useFeatureFlagMock.mockImplementation(
@@ -1033,7 +1199,7 @@ describe("CredentialsModal copilot-context tested_url default", () => {
);
}
- async function fillUsernameAndPassword() {
+ async function fillUsername() {
await waitFor(() => {
expect(screen.getByDisplayValue("credentials")).toBeTruthy();
});
@@ -1047,6 +1213,10 @@ describe("CredentialsModal copilot-context tested_url default", () => {
fireEvent.change(usernameInput as HTMLInputElement, {
target: { value: "[email protected]" },
});
+ }
+
+ async function fillUsernameAndPassword() {
+ await fillUsername();
const passwordInput = document.querySelector('input[type="password"]');
expect(passwordInput).toBeTruthy();
fireEvent.change(passwordInput as HTMLInputElement, {
@@ -1080,6 +1250,28 @@ describe("CredentialsModal copilot-context tested_url default", () => {
expect(onCredentialCreated).toHaveBeenCalledWith("cred-x", "credentials");
}, 10_000);
+ it("saves a password-less credential when the password is left empty", async () => {
+ postMock.mockResolvedValueOnce({
+ data: { credential_id: "cred-z", name: "credentials" },
+ });
+ const onCredentialCreated = vi.fn();
+ renderCopilotPasswordModal({ onCredentialCreated });
+ await fillUsername();
+ fireEvent.click(screen.getByRole("button", { name: "Save" }));
+ await waitFor(() =>
+ expect(postMock).toHaveBeenCalledWith(
+ "/credentials",
+ expect.objectContaining({
+ credential: expect.objectContaining({
+ username: "[email protected]",
+ password: "",
+ }),
+ }),
+ ),
+ );
+ expect(onCredentialCreated).toHaveBeenCalledWith("cred-z", "credentials");
+ }, 10_000);
+
it("sends no tested_url when defaultTestUrl is absent (modal from elsewhere)", async () => {
postMock.mockResolvedValueOnce({
data: { credential_id: "cred-y", name: "credentials" },
diff --git a/skyvern-frontend/src/routes/credentials/CredentialsModal.tsx b/skyvern-frontend/src/routes/credentials/CredentialsModal.tsx
index 8e386faa6..9504e9a79 100644
--- a/skyvern-frontend/src/routes/credentials/CredentialsModal.tsx
+++ b/skyvern-frontend/src/routes/credentials/CredentialsModal.tsx
@@ -336,6 +336,7 @@ function CredentialsModal({
name: false,
values: false,
});
+ const [noPassword, setNoPassword] = useState(false);
// Inline authenticator setup error returned by the backend when it rejects a
// decoded QR value or pasted key. Cleared whenever the user edits the key.
const [authenticatorSaveError, setAuthenticatorSaveError] =
@@ -353,12 +354,29 @@ function CredentialsModal({
if (next.totp !== prev.totp || next.totp_type !== prev.totp_type) {
setAuthenticatorSaveError(null);
}
+ if (next.password !== "") {
+ setNoPassword(false);
+ }
return next;
});
},
[],
);
+ const handleNoPasswordChange = useCallback((checked: boolean) => {
+ setNoPassword(checked);
+ if (checked) {
+ setPasswordCredentialValues((prev) => ({ ...prev, password: "" }));
+ }
+ }, []);
+
+ // Edit mode never prefills the stored password, so a blank field means "keep what is stored" and
+ // the payload omits password entirely; only the no-password checkbox sends "" to blank it.
+ const preservesStoredPassword =
+ isEditMode &&
+ !noPassword &&
+ passwordCredentialValues.password.trim() === "";
+
const editingPasswordCredentialData =
editingCredential && isPasswordCredential(editingCredential.credential)
? editingCredential.credential
@@ -710,6 +728,7 @@ function CredentialsModal({
setCreditCardCredentialValues(createCreditCardCredentialInitialValues());
setSecretCredentialValues(SECRET_CREDENTIAL_INITIAL_VALUES);
setEditingGroups({ name: false, values: false });
+ setNoPassword(false);
setAuthenticatorSaveError(null);
setRemovalConfirmationMessage(null);
removalConfirmedRef.current = false;
@@ -1317,10 +1336,10 @@ function CredentialsModal({
const totp = passwordCredentialValues.totp.trim();
const totpIdentifier = passwordCredentialValues.totp_identifier.trim();
- if (username === "" || password === "") {
+ if (username === "") {
toast({
title: "Error",
- description: "Username and password are required",
+ description: "Username is required",
variant: "destructive",
});
return;
@@ -1456,7 +1475,7 @@ function CredentialsModal({
credential_type: "password",
credential: {
username,
- password,
+ ...(preservesStoredPassword ? {} : { password }),
totp: selectedAdditionalTwoFactorMethod || totp === "" ? null : totp,
// When newly selecting an additional method, stage "none" so the dedicated endpoint sets type
// and material atomically; a rejection then can't leave a 2FA type with no material behind.
@@ -1903,7 +1922,20 @@ function CredentialsModal({
authenticatorSaveError={authenticatorSaveError}
beforeCredentialFields={customVaultCheckbox}
afterPassword={
- browserMemoryEnabled ? browserProfileModalSection : null
+ <>
+ {isEditMode && editingGroups.values && (
+ <label className="flex cursor-pointer items-center gap-2 text-sm">
+ <Checkbox
+ checked={noPassword}
+ onCheckedChange={(checked) =>
+ handleNoPasswordChange(checked === true)
+ }
+ />
+ <span>This login has no password</span>
+ </label>
+ )}
+ {browserMemoryEnabled ? browserProfileModalSection : null}
+ </>
}
afterUrl={
browserMemoryEnabled ? null : (
@@ -2066,11 +2098,19 @@ function CredentialsModal({
}
const username = passwordCredentialValues.username.trim();
- const password = passwordCredentialValues.password.trim();
- if (username === "" || password === "") {
+ if (username === "") {
+ toast({
+ title: "Error",
+ description: "Username is required to test",
+ variant: "destructive",
+ });
+ return;
+ }
+ if (preservesStoredPassword) {
toast({
title: "Error",
- description: "Username and password are required to test",
+ description:
+ 'Enter the password, or check "This login has no password", to run a test',
variant: "destructive",
});
return;
@@ -2138,7 +2178,7 @@ function CredentialsModal({
showTestButton &&
testUrl.trim() !== "" &&
passwordCredentialValues.username.trim() !== "" &&
- passwordCredentialValues.password.trim() !== "" &&
+ !preservesStoredPassword &&
!authenticatorKeyError &&
!additionalTwoFactorError &&
!isTestInProgress;
@@ -2189,9 +2229,9 @@ function CredentialsModal({
<Alert variant="warning">
<ExclamationTriangleIcon className="size-4" />
<AlertDescription>
- For security, saved values are never retrieved. Changing any
- field other than the credential name requires re-entering all
- fields, including passwords and 2FA settings.
+ For security, saved values are never retrieved. Leave the
+ password blank to keep the saved one; every other field,
+ including 2FA settings, must be re-entered.
</AlertDescription>
</Alert>
)}
diff --git a/skyvern-frontend/src/routes/workflows/copilot/workingVerbs.test.ts b/skyvern-frontend/src/routes/workflows/copilot/workingVerbs.test.ts
index 26462f4d1..80dba68a3 100644
--- a/skyvern-frontend/src/routes/workflows/copilot/workingVerbs.test.ts
+++ b/skyvern-frontend/src/routes/workflows/copilot/workingVerbs.test.ts
@@ -1,6 +1,14 @@
import { describe, expect, it } from "vitest";
-import { COPILOT_WORKING_VERBS, pickWorkingVerb } from "./workingVerbs";
+import {
+ COPILOT_WORKING_VERBS,
+ pickWorkingVerb,
+ VERB_CYCLE_MS,
+} from "./workingVerbs";
+
+it("cycles working verbs every six seconds", () => {
+ expect(VERB_CYCLE_MS).toBe(6000);
+});
describe("pickWorkingVerb", () => {
it("never repeats the verb it just showed", () => {
diff --git a/skyvern-frontend/src/routes/workflows/copilot/workingVerbs.ts b/skyvern-frontend/src/routes/workflows/copilot/workingVerbs.ts
index e076dbc1e..b9d14d336 100644
--- a/skyvern-frontend/src/routes/workflows/copilot/workingVerbs.ts
+++ b/skyvern-frontend/src/routes/workflows/copilot/workingVerbs.ts
@@ -21,7 +21,7 @@ export const COPILOT_WORKING_VERBS = [
"Scanning the horizon",
];
-export const VERB_CYCLE_MS = 3000;
+export const VERB_CYCLE_MS = 6000;
export function pickWorkingVerb(previous?: string): string {
const pool = COPILOT_WORKING_VERBS.filter((verb) => verb !== previous);
diff --git a/skyvern-frontend/src/routes/workflows/studio/StreamPresenter.test.tsx b/skyvern-frontend/src/routes/workflows/studio/StreamPresenter.test.tsx
index a02aa90d0..bfe44ef6a 100644
--- a/skyvern-frontend/src/routes/workflows/studio/StreamPresenter.test.tsx
+++ b/skyvern-frontend/src/routes/workflows/studio/StreamPresenter.test.tsx
@@ -3,6 +3,8 @@
import { cleanup, render, screen } from "@testing-library/react";
import { afterEach, describe, expect, it, vi } from "vitest";
+import { useRecordingStore } from "@/store/useRecordingStore";
+
import { StreamPresenter } from "./StreamPresenter";
const runtimeConfigMock = vi.hoisted(() => ({
@@ -16,7 +18,14 @@ const browserStreamProps = vi.hoisted(
);
const cdpStreamProps = vi.hoisted(
- () => ({ last: null }) as { last: { enableUrlInput?: boolean } | null },
+ () =>
+ ({ last: null }) as {
+ last: {
+ enableUrlInput?: boolean;
+ exfiltrate?: boolean;
+ workflowPermanentId?: string | null;
+ } | null;
+ },
);
vi.mock("@/hooks/useRuntimeConfig", () => ({
@@ -38,7 +47,11 @@ vi.mock("@/components/BrowserStream", () => ({
}));
vi.mock("@/routes/browserSessions/BrowserSessionStream", () => ({
- BrowserSessionStream: (props: { enableUrlInput?: boolean }) => {
+ BrowserSessionStream: (props: {
+ enableUrlInput?: boolean;
+ exfiltrate?: boolean;
+ workflowPermanentId?: string | null;
+ }) => {
cdpStreamProps.last = props;
return <div data-testid="cdp-stream" />;
},
@@ -51,6 +64,7 @@ describe("StreamPresenter transport-swap recording", () => {
cdpStreamProps.last = null;
runtimeConfigMock.browserStreamingMode = "cdp";
runtimeConfigMock.transportPending = false;
+ useRecordingStore.getState().reset();
});
it("forwards the URL input opt-in to the CDP stream", () => {
@@ -81,14 +95,49 @@ describe("StreamPresenter transport-swap recording", () => {
expect(screen.queryByTestId("vnc-stream")).toBeNull();
});
- it("swaps to the VNC stream and opts it out of the unmount reset when recording starts", () => {
+ it("keeps the recording message channel closed on the non-recording CDP live view", () => {
+ // BrowserSessionStream opens its recording WebSocket whenever exfiltrate is
+ // defined, so the idle live view must pass undefined, not false.
+ render(<StreamPresenter browserSessionId="pbs_test" isRecording={false} />);
+ expect(cdpStreamProps.last?.exfiltrate).toBeUndefined();
+ });
+
+ it("keeps the CDP stream and drives exfiltration through it when recording starts on cdp transport", () => {
+ // A CDP-transport session has no reachable VNC endpoint: swapping to VNC on
+ // record killed the live view and hammered the API with reconnects.
+ useRecordingStore
+ .getState()
+ .setIsRecording(true, { workflowPermanentId: "wpid_test" });
const { rerender } = render(
<StreamPresenter browserSessionId="pbs_test" isRecording={false} />,
);
- expect(screen.queryByTestId("cdp-stream")).not.toBeNull();
+ expect(screen.queryByTestId("recording-pill")).toBeNull();
- // Recording forces VNC: the CDP stream unmounts, the fresh VNC stream mounts.
rerender(<StreamPresenter browserSessionId="pbs_test" isRecording />);
+ expect(screen.queryByTestId("cdp-stream")).not.toBeNull();
+ expect(screen.queryByTestId("vnc-stream")).toBeNull();
+ expect(cdpStreamProps.last?.exfiltrate).toBe(true);
+ expect(cdpStreamProps.last?.workflowPermanentId).toBe("wpid_test");
+ expect(screen.queryByTestId("recording-pill")).not.toBeNull();
+ });
+
+ it("hides the CDP recording pill when the caller shows its own indicator", () => {
+ useRecordingStore
+ .getState()
+ .setIsRecording(true, { workflowPermanentId: "wpid_test" });
+ render(
+ <StreamPresenter
+ browserSessionId="pbs_test"
+ isRecording
+ hideRecordingIndicator
+ />,
+ );
+ expect(screen.queryByTestId("recording-pill")).toBeNull();
+ });
+
+ it("records over the VNC stream, opted out of the unmount reset, on vnc transport", () => {
+ runtimeConfigMock.browserStreamingMode = "vnc";
+ render(<StreamPresenter browserSessionId="pbs_test" isRecording />);
expect(screen.queryByTestId("vnc-stream")).not.toBeNull();
expect(screen.queryByTestId("cdp-stream")).toBeNull();
expect(browserStreamProps.last?.resetRecordingOnUnmount).toBe(false);
diff --git a/skyvern-frontend/src/routes/workflows/studio/StreamPresenter.tsx b/skyvern-frontend/src/routes/workflows/studio/StreamPresenter.tsx
index 9c5f3aa83..d2d31415b 100644
--- a/skyvern-frontend/src/routes/workflows/studio/StreamPresenter.tsx
+++ b/skyvern-frontend/src/routes/workflows/studio/StreamPresenter.tsx
@@ -1,6 +1,10 @@
+import { useLayoutEffect } from "react";
+
import { BrowserStream } from "@/components/BrowserStream";
+import { RecordingPill } from "@/components/RecordingPill";
import { useStreamTransport } from "@/hooks/useRuntimeConfig";
import { BrowserSessionStream } from "@/routes/browserSessions/BrowserSessionStream";
+import { useRecordingStore } from "@/store/useRecordingStore";
type StreamPresenterProps = {
browserSessionId: string;
@@ -18,8 +22,10 @@ type StreamPresenterProps = {
};
/**
- * Transport-agnostic live browser stream: picks VNC vs CDP from runtime config,
- * honoring the recording override (recording requires VNC).
+ * Transport-agnostic live browser stream: picks VNC vs CDP from runtime config.
+ * Recording stays on the session's own transport — a CDP-transport session has
+ * no reachable VNC endpoint, so swapping to VNC for recording kills the view;
+ * exfiltration only needs the messages channel, which both transports carry.
*/
export function StreamPresenter({
browserSessionId,
@@ -32,25 +38,50 @@ export function StreamPresenter({
onActivity,
}: StreamPresenterProps) {
const { streamTransport } = useStreamTransport(browserSessionId);
- const useCdp = streamTransport === "cdp" && !isRecording;
+ const workflowPermanentId = useRecordingStore(
+ (state) => state.workflowPermanentId,
+ );
+ const finishRequested = useRecordingStore((state) => state.finishRequested);
+ const setRecordingTransport = useRecordingStore(
+ (state) => state.setRecordingTransport,
+ );
+
+ // Recording telemetry labels each recording with its transport; the store
+ // ignores this while a recording is live.
+ useLayoutEffect(() => {
+ if (streamTransport) {
+ setRecordingTransport(streamTransport);
+ }
+ }, [streamTransport, setRecordingTransport]);
if (!streamTransport) {
// Mounting either transport now would open a connection this session may not serve.
return null;
}
- if (useCdp) {
+ if (streamTransport === "cdp") {
// CDP frames must be explicitly centered; VNC handles this in its own CSS.
return (
- <BrowserSessionStream
- browserSessionId={browserSessionId}
- interactive={interactive}
- showControlButtons={showControlButtons}
- enableUrlInput={enableUrlInput}
- onUrlChange={onUrlChange}
- onActivity={onActivity}
- centered
- />
+ <div className="relative h-full w-full">
+ <BrowserSessionStream
+ browserSessionId={browserSessionId}
+ interactive={interactive}
+ showControlButtons={showControlButtons}
+ enableUrlInput={enableUrlInput}
+ // undefined keeps the recording message channel closed on the
+ // non-recording live view; a defined value opens it.
+ exfiltrate={isRecording ? !finishRequested : undefined}
+ workflowPermanentId={workflowPermanentId}
+ onUrlChange={onUrlChange}
+ onActivity={onActivity}
+ centered
+ />
+ {isRecording && !hideRecordingIndicator && (
+ <div className="pointer-events-none absolute left-3 top-3 z-10">
+ <RecordingPill />
+ </div>
+ )}
+ </div>
);
}
@@ -61,9 +92,8 @@ export function StreamPresenter({
showControlButtons={showControlButtons}
exfiltrate={isRecording}
hideRecordingIndicator={hideRecordingIndicator}
- // The studio swaps CDP<->VNC when recording toggles and StrictMode remounts
- // this component; the recording must survive those. StudioBrowserStream owns
- // the session-level reset instead.
+ // StrictMode remounts this component; the recording must survive those.
+ // StudioBrowserStream owns the session-level reset instead.
resetRecordingOnUnmount={false}
onActivity={onActivity}
/>
diff --git a/skyvern-frontend/src/routes/workflows/studio/StudioBrowserStream.tsx b/skyvern-frontend/src/routes/workflows/studio/StudioBrowserStream.tsx
index 12bcfc041..7ee10f5ac 100644
--- a/skyvern-frontend/src/routes/workflows/studio/StudioBrowserStream.tsx
+++ b/skyvern-frontend/src/routes/workflows/studio/StudioBrowserStream.tsx
@@ -84,8 +84,9 @@ export function StudioBrowserStream() {
enableUrlInput={true}
isRecording={isRecording}
// While recording, the Copilot pane hosts the live-drafts panel, whose
- // header already shows the timer + step count — the REC pill would
- // duplicate it. Closing that pane brings the pill back as the indicator.
+ // header already shows the timer + step count — an on-stream REC pill
+ // would duplicate it. Closing that pane brings the pill back on either
+ // transport (VNC renders it in BrowserStream, CDP in StreamPresenter).
hideRecordingIndicator={panes.includes("copilot")}
onUrlChange={handleUrlChange}
onActivity={handleActivity}
diff --git a/skyvern/cli/mcp_tools/credential.py b/skyvern/cli/mcp_tools/credential.py
index edeacce23..78865f96a 100644
--- a/skyvern/cli/mcp_tools/credential.py
+++ b/skyvern/cli/mcp_tools/credential.py
@@ -308,7 +308,10 @@ async def skyvern_credential_create(
Field(description="Type of credential: 'password', 'credit_card', or 'secret'"),
] = "password",
username: Annotated[str | None, Field(description="Username or email (required for password type)")] = None,
- password: Annotated[str | None, Field(description="Password (required for password type)")] = None,
+ password: Annotated[
+ str | None,
+ Field(description="Password (optional for password type; omit or leave empty for logins without a password)"),
+ ] = None,
totp: Annotated[str | None, Field(description="TOTP secret for 2FA (e.g., 'JBSWY3DPEHPK3PXP')")] = None,
card_number: Annotated[str | None, Field(description="Full card number (for credit_card type)")] = None,
card_cvv: Annotated[str | None, Field(description="Card CVV (for credit_card type)")] = None,
@@ -338,17 +341,17 @@ async def skyvern_credential_create(
# Build credential payload per type
credential_data: dict[str, Any]
if credential_type == "password":
- if not username or not password:
+ if not username:
return make_result(
"skyvern_credential_create",
ok=False,
error=make_error(
ErrorCode.INVALID_INPUT,
- "username and password are required for credential_type='password'",
- "Provide both username and password",
+ "username is required for credential_type='password'",
+ "Provide a username; password may be empty for logins without a password",
),
)
- credential_data = {"username": username, "password": password}
+ credential_data = {"username": username, "password": password or ""}
if totp:
credential_data["totp"] = totp
elif credential_type == "credit_card":
diff --git a/skyvern/exceptions.py b/skyvern/exceptions.py
index 11f1667e9..60679222e 100644
--- a/skyvern/exceptions.py
+++ b/skyvern/exceptions.py
@@ -1138,6 +1138,16 @@ class CredentialParameterNotFoundError(SkyvernException):
)
+class CredentialVaultShapeMismatchError(SkyvernHTTPException):
+ def __init__(self, credential_id: str, stored_credential_type: str) -> None:
+ super().__init__(
+ f"Credential {credential_id} is recorded as a password credential but the vault holds a "
+ f"{stored_credential_type}. Refusing to update it, because an omitted password would "
+ "overwrite the stored secret with an empty one.",
+ status_code=HTTPStatus.CONFLICT,
+ )
+
+
class CredentialVaultNotConfiguredError(SkyvernException):
def __init__(self, vault_type: str, credential_id: str) -> None:
super().__init__(
diff --git a/skyvern/forge/agent_functions.py b/skyvern/forge/agent_functions.py
index 60cd532ae..a85378390 100644
--- a/skyvern/forge/agent_functions.py
+++ b/skyvern/forge/agent_functions.py
@@ -887,6 +887,7 @@ class AgentFunction:
workflow_run_id: str | None = None,
organization_id: str | None = None,
excluded_reason: str | None = None,
+ finalized_by: str | None = None,
) -> None:
"""Cloud overrides this to emit run-duration telemetry; the OSS default is a no-op.
@@ -894,6 +895,8 @@ class AgentFunction:
workflow run that backs a task_v2) without the caller paying for the lookup.
excluded_reason marks a run whose duration must not count as compute (e.g.
it never started); the override records it as an exclusion, not as minutes.
+ finalized_by names the writer when it is not the run's own finalizer, so the
+ override can bound a duration that measures the row's age rather than compute.
"""
return None
diff --git a/skyvern/forge/sdk/schemas/credentials.py b/skyvern/forge/sdk/schemas/credentials.py
index 65c027d1c..9666aacd9 100644
--- a/skyvern/forge/sdk/schemas/credentials.py
+++ b/skyvern/forge/sdk/schemas/credentials.py
@@ -139,10 +139,12 @@ class PasswordCredential(BaseModel):
class NonEmptyPasswordCredential(PasswordCredential):
- """Password credential model that requires non-empty values."""
+ """Password credential model for API writes: non-empty username, optionally empty password."""
password: str = Field(
- ..., min_length=1, description="The password value (must not be empty)", examples=["securepassword123"]
+ default="",
+ description="The password value; may be empty or omitted for logins that have no password",
+ examples=["securepassword123"],
)
username: str = Field(
...,
@@ -579,9 +581,8 @@ class TestLoginRequest(BaseModel):
examples=["[email protected]"],
)
password: str = Field(
- ...,
- min_length=1,
- description="The password to test",
+ default="",
+ description="The password to test; may be empty for logins that have no password",
examples=["securepassword123"],
)
totp: str | None = Field(
diff --git a/skyvern/forge/sdk/services/credential/azure_credential_vault_service.py b/skyvern/forge/sdk/services/credential/azure_credential_vault_service.py
index 2eda4dea6..d77c4fd5f 100644
--- a/skyvern/forge/sdk/services/credential/azure_credential_vault_service.py
+++ b/skyvern/forge/sdk/services/credential/azure_credential_vault_service.py
@@ -75,7 +75,7 @@ class AzureCredentialVaultService(CredentialVaultService):
async def update_credential(self, credential: Credential, data: CreateCredentialRequest) -> Credential:
credential_data = data.credential
if data.credential_type == CredentialType.PASSWORD and isinstance(credential_data, PasswordCredential):
- credential_data = await self._preserve_omitted_password_metadata(
+ credential_data = await self._preserve_omitted_password_fields(
credential=credential,
updated_credential=credential_data,
)
diff --git a/skyvern/forge/sdk/services/credential/bitwarden_credential_service.py b/skyvern/forge/sdk/services/credential/bitwarden_credential_service.py
index 3ff901646..74fa7e2db 100644
--- a/skyvern/forge/sdk/services/credential/bitwarden_credential_service.py
+++ b/skyvern/forge/sdk/services/credential/bitwarden_credential_service.py
@@ -60,7 +60,7 @@ class BitwardenCredentialVaultService(CredentialVaultService):
credential_data = data.credential
if data.credential_type == CredentialType.PASSWORD and isinstance(credential_data, PasswordCredential):
- credential_data = await self._preserve_omitted_password_metadata(
+ credential_data = await self._preserve_omitted_password_fields(
credential=credential,
updated_credential=credential_data,
)
diff --git a/skyvern/forge/sdk/services/credential/credential_vault_service.py b/skyvern/forge/sdk/services/credential/credential_vault_service.py
index 4b9698e56..4cb258e91 100644
--- a/skyvern/forge/sdk/services/credential/credential_vault_service.py
+++ b/skyvern/forge/sdk/services/credential/credential_vault_service.py
@@ -4,6 +4,7 @@ from typing import Any, Awaitable, Callable
import structlog
+from skyvern.exceptions import CredentialVaultShapeMismatchError
from skyvern.forge import app
from skyvern.forge.sdk.schemas.credentials import (
CreateCredentialRequest,
@@ -189,19 +190,39 @@ class CredentialVaultService(ABC):
return updated_credential.model_copy(update=preserved_fields)
- async def _preserve_omitted_password_metadata(
+ async def _preserve_omitted_password_fields(
self,
credential: Credential,
updated_credential: PasswordCredential,
) -> PasswordCredential:
- if "metadata" in updated_credential.model_fields_set:
+ """Restore fields the overwrite request omitted.
+
+ `password` defaults to "" so a login with no password can be stored, which makes an omitted
+ password indistinguishable from an explicitly blanked one by value alone. Only an explicitly
+ set password may overwrite the stored one.
+ """
+ updated_fields = updated_credential.model_fields_set
+ if {"metadata", "password"}.issubset(updated_fields):
return updated_credential
existing_item = await self.get_credential_item(credential)
if not isinstance(existing_item.credential, PasswordCredential):
+ # Callers only reach this helper for CredentialType.PASSWORD, so a non-password item
+ # means the row and the vault disagree. There is nothing password-shaped to restore
+ # from, so continuing would write the defaulted "" over the stored secret.
+ if "password" not in updated_fields:
+ raise CredentialVaultShapeMismatchError(
+ credential_id=credential.credential_id,
+ stored_credential_type=type(existing_item.credential).__name__,
+ )
return updated_credential
- return updated_credential.model_copy(update={"metadata": existing_item.credential.metadata})
+ preserved_fields: dict[str, object] = {}
+ for field_name in ("metadata", "password"):
+ if field_name not in updated_fields:
+ preserved_fields[field_name] = getattr(existing_item.credential, field_name)
+
+ return updated_credential.model_copy(update=preserved_fields)
@staticmethod
def _preserve_omitted_billing_address_fields(
diff --git a/skyvern/forge/sdk/services/credential/custom_credential_vault_service.py b/skyvern/forge/sdk/services/credential/custom_credential_vault_service.py
index aaa48d0d9..d518fc0d7 100644
--- a/skyvern/forge/sdk/services/credential/custom_credential_vault_service.py
+++ b/skyvern/forge/sdk/services/credential/custom_credential_vault_service.py
@@ -212,7 +212,7 @@ class CustomCredentialVaultService(CredentialVaultService):
client = await self._get_client_for_organization(credential.organization_id)
credential_data = data.credential
if data.credential_type == CredentialType.PASSWORD and isinstance(credential_data, PasswordCredential):
- credential_data = await self._preserve_omitted_password_metadata(
+ credential_data = await self._preserve_omitted_password_fields(
credential=credential,
updated_credential=credential_data,
)
diff --git a/skyvern/forge/sdk/services/credential/gcp_credential_vault_service.py b/skyvern/forge/sdk/services/credential/gcp_credential_vault_service.py
index 385e80442..8c96e0ca3 100644
--- a/skyvern/forge/sdk/services/credential/gcp_credential_vault_service.py
+++ b/skyvern/forge/sdk/services/credential/gcp_credential_vault_service.py
@@ -85,7 +85,7 @@ class GcpCredentialVaultService(CredentialVaultService):
async def update_credential(self, credential: Credential, data: CreateCredentialRequest) -> Credential:
credential_data = data.credential
if data.credential_type == CredentialType.PASSWORD and isinstance(credential_data, PasswordCredential):
- credential_data = await self._preserve_omitted_password_metadata(
+ credential_data = await self._preserve_omitted_password_fields(
credential=credential,
updated_credential=credential_data,
)
diff --git a/skyvern/forge/sdk/services/credential/skyvern_credential_vault_service.py b/skyvern/forge/sdk/services/credential/skyvern_credential_vault_service.py
index 484b3aa63..408165f6d 100644
--- a/skyvern/forge/sdk/services/credential/skyvern_credential_vault_service.py
+++ b/skyvern/forge/sdk/services/credential/skyvern_credential_vault_service.py
@@ -63,7 +63,7 @@ class SkyvernCredentialVaultService(CredentialVaultService):
async def update_credential(self, credential: Credential, data: CreateCredentialRequest) -> Credential:
credential_data = data.credential
if data.credential_type == CredentialType.PASSWORD and isinstance(credential_data, PasswordCredential):
- credential_data = await self._preserve_omitted_password_metadata(
+ credential_data = await self._preserve_omitted_password_fields(
credential=credential,
updated_credential=credential_data,
)
diff --git a/skyvern/forge/sdk/workflow/context_manager.py b/skyvern/forge/sdk/workflow/context_manager.py
index 0b30df198..17258e084 100644
--- a/skyvern/forge/sdk/workflow/context_manager.py
+++ b/skyvern/forge/sdk/workflow/context_manager.py
@@ -471,7 +471,10 @@ class WorkflowRunContext:
value = self.values.get(key)
if not isinstance(value, dict) or "context" not in value:
continue
- has_password_shape = "username" in value and "password" in value
+ # A password-less credential registers "password" as a literal "" rather than a
+ # placeholder id, so username alone marks the password shape; the secrets lookup
+ # below misses on "" and falls back to "", which is the value it actually holds.
+ has_password_shape = "username" in value
if not has_password_shape and "secret_value" not in value:
continue
entries[f"{key}_real_username"] = self.secrets.get(value.get("username", ""), "")
@@ -840,6 +843,12 @@ class WorkflowRunContext:
if key in ("totp_type", "totp"):
continue
if not value:
+ # A password-less login stores password="". Blocks dereference `.password`
+ # directly, so the key has to exist or the namespace lookup raises instead of
+ # yielding the empty string the credential actually holds.
+ if key == "password" and isinstance(credential, PasswordCredential):
+ self.values[parameter.key][key] = ""
+ used_secret_field_keys.add(key)
continue
for field_key, field_value in self._flatten_credential_secret_field(key, value):
field_key = self._dedupe_secret_field_key(field_key, used_secret_field_keys)
diff --git a/skyvern/forge/sdk/workflow/service.py b/skyvern/forge/sdk/workflow/service.py
index 740a2856a..f59478861 100644
--- a/skyvern/forge/sdk/workflow/service.py
+++ b/skyvern/forge/sdk/workflow/service.py
@@ -9430,6 +9430,7 @@ class WorkflowService:
failure_reason: str | None = None,
run_with: str | None = None,
failure_category: list[dict] | None = None,
+ finalized_by: str | None = None,
run_minutes_recorded_through: datetime | None = None,
) -> WorkflowRun | None:
""":meth:`_update_workflow_run_status` for writers that must lose a race against the
@@ -9446,6 +9447,7 @@ class WorkflowService:
await self._after_workflow_run_status_write(
workflow_run,
status,
+ finalized_by=finalized_by,
run_minutes_recorded_through=run_minutes_recorded_through,
)
return workflow_run
@@ -9456,6 +9458,7 @@ class WorkflowService:
failure_reason: str | None = None,
run_with: str | None = None,
failure_category: list[dict] | None = None,
+ finalized_by: str | None = None,
) -> WorkflowRun | None:
workflow_run = await app.DATABASE.workflow_runs.finish_preexisting_timed_out_workflow_run(
workflow_run_id=workflow_run_id,
@@ -9467,7 +9470,9 @@ class WorkflowService:
return None
# Bulk stuck-run cleanup writes only the status. Complete that deferred
# terminal transition exactly once, when ``finished_at`` is still null.
- await self._after_workflow_run_status_write(workflow_run, WorkflowRunStatus.timed_out)
+ await self._after_workflow_run_status_write(
+ workflow_run, WorkflowRunStatus.timed_out, finalized_by=finalized_by
+ )
return workflow_run
async def _after_workflow_run_status_write(
@@ -9475,6 +9480,7 @@ class WorkflowService:
workflow_run: WorkflowRun,
status: WorkflowRunStatus,
emit_run_minutes: bool = True,
+ finalized_by: str | None = None,
run_minutes_recorded_through: datetime | None = None,
) -> None:
workflow_run_id = workflow_run.workflow_run_id
@@ -9524,6 +9530,7 @@ class WorkflowService:
workflow_run_id=workflow_run_id,
organization_id=workflow_run.organization_id,
excluded_reason=None if workflow_run.started_at else "never_started",
+ finalized_by=finalized_by,
)
await self._apply_completion_run_tags_best_effort(workflow_run)
self._schedule_workflow_run_terminal_hooks(
@@ -10067,6 +10074,7 @@ class WorkflowService:
failure_reason: str | None = None,
run_with: str | None = None,
fallback_workflow_run: WorkflowRun | None = None,
+ finalized_by: str | None = None,
) -> WorkflowRun:
LOG.info(
f"Marking workflow run {workflow_run_id} as timed out",
@@ -10093,6 +10101,7 @@ class WorkflowService:
failure_reason=failure_reason,
run_with=run_with,
failure_category=failure_category,
+ finalized_by=finalized_by,
)
if updated_workflow_run is None:
# The CAS lost to a terminal writer, so only a fresh row can identify
@@ -10108,6 +10117,7 @@ class WorkflowService:
failure_reason=failure_reason,
run_with=run_with,
failure_category=failure_category,
+ finalized_by=finalized_by,
)
if enriched_workflow_run is not None:
updated_workflow_run = enriched_workflow_run
diff --git a/skyvern/forge/taskv3/loop.py b/skyvern/forge/taskv3/loop.py
index 3b34010e3..6b979ca90 100644
--- a/skyvern/forge/taskv3/loop.py
+++ b/skyvern/forge/taskv3/loop.py
@@ -17,6 +17,7 @@ from __future__ import annotations
import asyncio
import hashlib
import json
+import re
import secrets
import time
from collections import deque
@@ -150,7 +151,7 @@ NO_TOOL_CALL_NUDGE = (
"finish(status, reason, extracted_output) if the goal is complete. Emit a tool call now."
)
-# Perception-stall policy: N consecutive byte-identical snapshots from the same (compactable) tool
+# Perception-stall policy: N consecutive identical (marker-canonicalized) snapshots from the same (compactable) tool
# AND from the same probe (that tool with the same arguments) mean the page has stopped changing in
# response to actions, and a page gated by something the run cannot perceive or operate otherwise
# burns the whole budget on identical re-observes. The per-probe term is what keeps two different
@@ -198,6 +199,24 @@ def telemetry_hash(salt: str, *parts: str) -> str:
return hashlib.sha256("\x1f".join((salt, *parts)).encode()).hexdigest()[:TELEMETRY_HASH_HEX_LEN]
+# The value shape observe()'s enrichment mints ('t' + monotonic counter, optional '-<n>'
+# disambiguator — tools._OBSERVE_JS): identity handles, not page semantics, and a node-replacing
+# framework re-mints them on every read, so hashed raw they hide a frozen page from the stall
+# guard. Page-authored data-tv3 values (any other shape) are page content and stay significant.
+_TV3_MARKER_VALUE_RE = re.compile(r'data-tv3="t\d+(?:-\d+)?"')
+
+# get_html truncates to a fixed budget before the loop ever sees the content, so a marker the cut
+# leaves open at the tail has no closing quote for the pattern above and its churning digits would
+# be the one leak that survives canonicalization. The lookahead assumes the truncation notice itself
+# carries no quote character, and this sub must run AFTER closed markers are rewritten to the
+# quote-bearing placeholder — either broken silently brings the leak back.
+_TV3_MARKER_CUT_RE = re.compile(r'data-tv3="t\d*(?:-\d*)?(?=[^"]*\Z)')
+
+
+def _canonical_perception_content(content: str) -> str:
+ return _TV3_MARKER_CUT_RE.sub('data-tv3="*', _TV3_MARKER_VALUE_RE.sub('data-tv3="*"', content))
+
+
# How many recent states a probe remembers. This length IS the longest oscillation period that can
# be recognised, so it is a detection limit and not a memory tuning knob.
PERCEPTION_RING = 8
@@ -436,9 +455,10 @@ def _unblocker_options(available_tools: set[str]) -> list[str]:
def _stall_nudge_text(stalled: list[tuple[str, int]], available_tools: set[str]) -> str:
"""One warning naming every stalled perception tool and the unblockers this run actually has —
a model that cannot see the gate won't reach for solve_captcha unless the symptom names it."""
- symptoms = "; ".join(f"{name} has returned byte-identical output {count} times in a row" for name, count in stalled)
+ symptoms = "; ".join(f"{name} has returned identical output {count} times in a row" for name, count in stalled)
return (
- f"The page is not changing: {symptoms}, despite your actions. Do not keep re-observing, "
+ f"The page is not changing: {symptoms}, despite your actions (transient element-marker ids are "
+ "ignored when comparing). Do not keep re-observing, "
"waiting, or repeating the same action. Your options: " + "; ".join(_unblocker_options(available_tools)) + "."
)
@@ -994,7 +1014,7 @@ async def run_agent_tool_loop(
attribution: dict[str, Any] = {"action_key_hash": telemetry_hash(telemetry_salt, *action_key)}
content_digest: str | None = None
if spec is not None and spec.compactable and result.status == "ok":
- content_digest = hashlib.sha256(result.content.encode()).hexdigest()
+ content_digest = hashlib.sha256(_canonical_perception_content(result.content).encode()).hexdigest()
attribution["snapshot_digest"] = telemetry_hash(telemetry_salt, content_digest)
attribution["probe_first_time"] = perception.first_time(action_key)
# The only per-tool-call timing the engine has: tool execution is the majority of a v3
@@ -1055,7 +1075,7 @@ async def run_agent_tool_loop(
)
outcome = LoopOutcome(
"terminated",
- f"{PERCEPTION_STALL_REASON_PREFIX} {snap.live} consecutive byte-identical snapshots from "
+ f"{PERCEPTION_STALL_REASON_PREFIX} {snap.live} consecutive identical snapshots from "
f"one {tool_name} probe — the page stopped changing in response to actions, so the goal cannot "
"progress (commonly a blocker the run cannot perceive or operate, e.g. inside a "
"cross-origin frame)",
diff --git a/tests/unit/test_context_manager.py b/tests/unit/test_context_manager.py
index 987957fbd..b47e0f999 100644
--- a/tests/unit/test_context_manager.py
+++ b/tests/unit/test_context_manager.py
@@ -9,6 +9,7 @@ from skyvern.forge.sdk.schemas.organizations import Organization
from skyvern.forge.sdk.workflow.context_manager import WorkflowRunContext
from skyvern.forge.sdk.workflow.models.parameter import WorkflowParameter, WorkflowParameterType
from skyvern.forge.sdk.workflow.models.workflow import Workflow, WorkflowDefinition, WorkflowRunParameter
+from tests.unit.fake_workflow_run_context import FakeWorkflowRunContext
def _make_workflow_parameter(
@@ -141,3 +142,74 @@ class TestAtWillCredentialBackfill:
)
assert not context.has_value("portal_cred")
+
+
+class TestCredentialTemplateEntriesShape:
+ """`credential_template_entries` decides which credential secrets reach block templates, and a
+ password-less credential registers no password placeholder — so the password shape is now keyed
+ on `username` alone. Pin that the widened check still scopes secrets to password credentials."""
+
+ def test_password_less_credential_exposes_username_and_empty_password(self) -> None:
+ context = FakeWorkflowRunContext(
+ values={
+ "portal_cred": {
+ "context": "credential",
+ "username": "secret_username_id",
+ },
+ },
+ secrets={"secret_username_id": "[email protected]"},
+ )
+
+ entries = context.credential_template_entries(["portal_cred"], resolve_credential_dicts=True)
+
+ assert entries["portal_cred_real_username"] == "[email protected]"
+ assert entries["portal_cred_real_password"] == ""
+ assert entries["portal_cred"] == {"username": "[email protected]"}
+
+ def test_password_credential_still_exposes_both_secrets(self) -> None:
+ context = FakeWorkflowRunContext(
+ values={
+ "portal_cred": {
+ "context": "credential",
+ "username": "secret_username_id",
+ "password": "secret_password_id",
+ },
+ },
+ secrets={"secret_username_id": "[email protected]", "secret_password_id": "hunter2"},
+ )
+
+ entries = context.credential_template_entries(["portal_cred"], resolve_credential_dicts=True)
+
+ assert entries["portal_cred_real_username"] == "[email protected]"
+ assert entries["portal_cred_real_password"] == "hunter2"
+
+ def test_credit_card_credential_registers_no_password_entries(self) -> None:
+ # Card credentials carry no `username`, so the widened check must not start emitting
+ # spurious _real_username/_real_password entries for them.
+ context = FakeWorkflowRunContext(
+ values={
+ "card_cred": {
+ "context": "credential",
+ "card_number": "secret_card_id",
+ "card_cvv": "secret_cvv_id",
+ },
+ },
+ secrets={"secret_card_id": "4111111111111111", "secret_cvv_id": "123"},
+ )
+
+ entries = context.credential_template_entries(["card_cred"], resolve_credential_dicts=True)
+
+ assert entries == {}
+
+ def test_undeclared_credential_is_never_exposed(self) -> None:
+ context = FakeWorkflowRunContext(
+ values={
+ "portal_cred": {
+ "context": "credential",
+ "username": "secret_username_id",
+ },
+ },
+ secrets={"secret_username_id": "[email protected]"},
+ )
+
+ assert context.credential_template_entries([], resolve_credential_dicts=True) == {}
diff --git a/tests/unit/test_credential_update_params.py b/tests/unit/test_credential_update_params.py
index cddc1bb7b..0e45681b9 100644
--- a/tests/unit/test_credential_update_params.py
+++ b/tests/unit/test_credential_update_params.py
@@ -7,17 +7,26 @@ from unittest.mock import AsyncMock, MagicMock, patch
import pytest
from fastapi import BackgroundTasks, HTTPException
+from pydantic import ValidationError
from skyvern.forge import app as forge_app
from skyvern.forge.agent_functions import AgentFunction
+from skyvern.forge.forge_app import ForgeApp
from skyvern.forge.sdk.db.repositories.browser_sessions import BrowserSessionsRepository
from skyvern.forge.sdk.db.repositories.credentials import CredentialRepository
from skyvern.forge.sdk.routes import credentials as credentials_routes
from skyvern.forge.sdk.schemas.credentials import (
CreateCredentialRequest,
Credential,
+ CredentialItem,
CredentialType,
CredentialVaultType,
+ NonEmptyCreditCardCredential,
+ NonEmptyPasswordCredential,
+ PasswordCredential,
+)
+from skyvern.forge.sdk.schemas.credentials import TestLoginRequest as LoginTestRequest
+from skyvern.forge.sdk.schemas.credentials import (
TotpType,
UpdateCredentialRequest,
)
@@ -1372,8 +1381,6 @@ async def test_repo_update_credential_clears_proxy_session_id_with_proxy_locatio
async def test_update_credential_route_applies_validated_browser_profile_and_pin(
monkeypatch: pytest.MonkeyPatch,
) -> None:
- from skyvern.forge.sdk.schemas.credentials import NonEmptyPasswordCredential
-
existing = _stored_credential()
monkeypatch.setattr(forge_app.DATABASE.credentials, "get_credential", AsyncMock(return_value=existing))
monkeypatch.setattr(
@@ -1386,8 +1393,6 @@ async def test_update_credential_route_applies_validated_browser_profile_and_pin
"get_credentials_by_browser_profile_id",
AsyncMock(return_value=[]),
)
- from skyvern.forge.forge_app import ForgeApp
-
vault_service = SimpleNamespace(
update_credential=AsyncMock(return_value=_stored_credential()),
post_delete_credential_item=AsyncMock(),
@@ -1637,3 +1642,192 @@ async def test_oss_route_allows_disabling_sequential_credential(monkeypatch: pyt
assert response.run_sequentially is False
assert update_credential.await_args.kwargs["run_sequentially"] is False
+
+
+def test_password_credential_accepts_empty_password() -> None:
+ credential = NonEmptyPasswordCredential(username="[email protected]", password="")
+ assert credential.password == ""
+
+ request = CreateCredentialRequest.model_validate(
+ {
+ "name": "passwordless login",
+ "credential_type": "password",
+ "credential": {"username": "[email protected]", "password": ""},
+ }
+ )
+ assert isinstance(request.credential, NonEmptyPasswordCredential)
+ assert request.credential.password == ""
+
+
+def test_password_credential_omitted_password_stored_as_empty() -> None:
+ request = CreateCredentialRequest.model_validate(
+ {
+ "name": "passwordless login",
+ "credential_type": "password",
+ "credential": {"username": "[email protected]"},
+ }
+ )
+ assert isinstance(request.credential, NonEmptyPasswordCredential)
+ assert request.credential.password == ""
+
+
+def test_password_credential_still_rejects_empty_username() -> None:
+ with pytest.raises(ValidationError):
+ NonEmptyPasswordCredential(username="", password="pw")
+ with pytest.raises(ValidationError):
+ CreateCredentialRequest.model_validate(
+ {
+ "name": "bad login",
+ "credential_type": "password",
+ "credential": {"username": "", "password": ""},
+ }
+ )
+
+
+def test_credit_card_and_secret_credentials_still_reject_empty_values() -> None:
+ with pytest.raises(ValidationError):
+ NonEmptyCreditCardCredential(
+ card_number="",
+ card_cvv="123",
+ card_exp_month="12",
+ card_exp_year="2030",
+ card_brand="visa",
+ card_holder_name="Jane Doe",
+ )
+ with pytest.raises(ValidationError):
+ CreateCredentialRequest.model_validate(
+ {
+ "name": "bad secret",
+ "credential_type": "secret",
+ "credential": {"secret_value": ""},
+ }
+ )
+
+
+async def test_update_credential_route_accepts_blanking_password(monkeypatch: pytest.MonkeyPatch) -> None:
+ existing = _stored_credential()
+ monkeypatch.setattr(forge_app.DATABASE.credentials, "get_credential", AsyncMock(return_value=existing))
+ vault_service = SimpleNamespace(
+ update_credential=AsyncMock(return_value=_stored_credential()),
+ post_delete_credential_item=AsyncMock(),
+ )
+ monkeypatch.setattr(ForgeApp, "CREDENTIAL_VAULT_SERVICES", {existing.vault_type: vault_service}, raising=False)
+ monkeypatch.setattr(credentials_routes, "_clear_cached_totp_code_preview", lambda **_kwargs: None)
+
+ data = CreateCredentialRequest.model_validate(
+ {
+ "name": "test",
+ "credential_type": "password",
+ "credential": {"username": "[email protected]", "password": ""},
+ }
+ )
+
+ response = await credentials_routes.update_credential(
+ background_tasks=BackgroundTasks(),
+ credential_id="cred_123",
+ data=data,
+ current_org=SimpleNamespace(organization_id="org_123"),
+ )
+
+ written = vault_service.update_credential.await_args.kwargs["data"]
+ assert isinstance(written.credential, NonEmptyPasswordCredential)
+ assert written.credential.password == ""
+ assert written.credential.username == "[email protected]"
+ assert response.credential_id == "cred_123"
+
+
+class _PreservingVaultService(CredentialVaultService):
+ """Vault stub that runs the real omitted-field preservation, like every concrete vault does."""
+
+ def __init__(self, stored: PasswordCredential) -> None:
+ self.stored = stored
+ self.written: PasswordCredential | None = None
+
+ async def create_credential(self, organization_id: str, data: CreateCredentialRequest) -> Credential:
+ raise NotImplementedError
+
+ async def update_credential(self, credential: Credential, data: CreateCredentialRequest) -> Credential:
+ assert isinstance(data.credential, PasswordCredential)
+ self.written = await self._preserve_omitted_password_fields(
+ credential=credential,
+ updated_credential=data.credential,
+ )
+ return credential
+
+ async def delete_credential(self, credential: Credential) -> None:
+ raise NotImplementedError
+
+ async def get_credential_item(self, db_credential: Credential) -> CredentialItem:
+ return CredentialItem(
+ item_id=db_credential.item_id,
+ name=db_credential.name,
+ credential_type=CredentialType.PASSWORD,
+ credential=self.stored,
+ )
+
+
+async def _update_password_credential_via_route(
+ monkeypatch: pytest.MonkeyPatch,
+ credential_payload: dict[str, object],
+) -> _PreservingVaultService:
+ existing = _stored_credential()
+ monkeypatch.setattr(forge_app.DATABASE.credentials, "get_credential", AsyncMock(return_value=existing))
+ vault_service = _PreservingVaultService(
+ PasswordCredential(
+ username="[email protected]",
+ password="stored-password",
+ metadata={"tenant": "north"},
+ )
+ )
+ monkeypatch.setattr(ForgeApp, "CREDENTIAL_VAULT_SERVICES", {existing.vault_type: vault_service}, raising=False)
+ monkeypatch.setattr(credentials_routes, "_clear_cached_totp_code_preview", lambda **_kwargs: None)
+
+ await credentials_routes.update_credential(
+ background_tasks=BackgroundTasks(),
+ credential_id="cred_123",
+ data=CreateCredentialRequest.model_validate(
+ {"name": "test", "credential_type": "password", "credential": credential_payload}
+ ),
+ current_org=SimpleNamespace(organization_id="org_123"),
+ )
+ return vault_service
+
+
+async def test_update_credential_route_preserves_omitted_password(monkeypatch: pytest.MonkeyPatch) -> None:
+ # An overwrite that only renames or re-sends the username must not destroy the stored password.
+ vault_service = await _update_password_credential_via_route(monkeypatch, {"username": "[email protected]"})
+
+ assert vault_service.written is not None
+ assert vault_service.written.password == "stored-password"
+ assert vault_service.written.username == "[email protected]"
+ assert vault_service.written.metadata == {"tenant": "north"}
+
+
+async def test_update_credential_route_blanks_explicitly_empty_password(monkeypatch: pytest.MonkeyPatch) -> None:
+ vault_service = await _update_password_credential_via_route(
+ monkeypatch, {"username": "[email protected]", "password": ""}
+ )
+
+ assert vault_service.written is not None
+ assert vault_service.written.password == ""
+
+
+async def test_update_credential_route_overwrites_supplied_password(monkeypatch: pytest.MonkeyPatch) -> None:
+ vault_service = await _update_password_credential_via_route(
+ monkeypatch, {"username": "[email protected]", "password": "rotated-password"}
+ )
+
+ assert vault_service.written is not None
+ assert vault_service.written.password == "rotated-password"
+
+
+def test_login_test_request_accepts_empty_password() -> None:
+ # The inline Test button must work for the password-less credentials this endpoint can now store.
+ assert LoginTestRequest(url="https://example.com/login", username="[email protected]", password="").password == ""
+ assert LoginTestRequest(url="https://example.com/login", username="[email protected]").password == ""
+ with pytest.raises(ValidationError):
+ LoginTestRequest(url="https://example.com/login", username="", password="")
diff --git a/tests/unit/test_local_browser_profile.py b/tests/unit/test_local_browser_profile.py
index 0739fb4b0..3876f18e4 100644
--- a/tests/unit/test_local_browser_profile.py
+++ b/tests/unit/test_local_browser_profile.py
@@ -147,15 +147,18 @@ def test_background_sweep_logs_failure_instead_of_killing_its_thread(monkeypatch
"sweep_local_browser_profiles_with_budget",
MagicMock(side_effect=OSError("cannot spawn sweep")),
)
- warning = MagicMock()
- monkeypatch.setattr(local_browser_profile.LOG, "warning", warning)
+ # Patch the module's LOG, not LOG.warning: monkeypatching an attribute on the
+ # BoundLoggerLazyProxy makes the undo re-install a bound method frozen to the
+ # current structlog config, permanently hiding this logger from capture_logs.
+ fake_log = MagicMock()
+ monkeypatch.setattr(local_browser_profile, "LOG", fake_log)
thread = local_browser_profile.sweep_local_browser_profiles_once_in_background()
assert thread is not None
thread.join(timeout=5)
assert not thread.is_alive()
- assert warning.call_args.args[0] == "local_browser_profile_background_sweep_failed"
+ assert fake_log.warning.call_args.args[0] == "local_browser_profile_background_sweep_failed"
@pytest.mark.skipif(os.name == "nt", reason="managed profile sweep is POSIX-only")
diff --git a/tests/unit/test_non_secret_credential_fields.py b/tests/unit/test_non_secret_credential_fields.py
index bfc62e545..7208630c1 100644
--- a/tests/unit/test_non_secret_credential_fields.py
+++ b/tests/unit/test_non_secret_credential_fields.py
@@ -3,7 +3,11 @@ from unittest.mock import AsyncMock, MagicMock
import pytest
-from skyvern.forge.sdk.schemas.credentials import CreditCardBillingAddress, CreditCardCredential
+from skyvern.forge.sdk.schemas.credentials import (
+ CreditCardBillingAddress,
+ CreditCardCredential,
+ PasswordCredential,
+)
from skyvern.forge.sdk.workflow import context_manager as context_manager_module
from skyvern.forge.sdk.workflow.context_manager import RANDOM_SECRET_ID_PREFIX, WorkflowRunContext
@@ -34,13 +38,17 @@ def _context(*, mask_secrets: bool = True) -> WorkflowRunContext:
)
-async def _register(monkeypatch: pytest.MonkeyPatch) -> tuple[WorkflowRunContext, dict[str, Any]]:
+async def _register(
+ monkeypatch: pytest.MonkeyPatch,
+ credential: Any = _CARD,
+ parameter_key: str = "card",
+) -> tuple[WorkflowRunContext, dict[str, Any]]:
context = _context()
- parameter = MagicMock(key="card")
+ parameter = MagicMock(key=parameter_key)
db_credential = MagicMock(vault_type=None, totp_identifier=None)
vault = MagicMock()
- vault.get_credential_item = AsyncMock(return_value=MagicMock(credential=_CARD))
+ vault.get_credential_item = AsyncMock(return_value=MagicMock(credential=credential))
app = MagicMock()
app.DATABASE.credentials.get_credential = AsyncMock(return_value=db_credential)
@@ -56,7 +64,7 @@ async def _register(monkeypatch: pytest.MonkeyPatch) -> tuple[WorkflowRunContext
parameter=parameter,
organization=MagicMock(organization_id="o_test"),
)
- return context, context.values["card"]
+ return context, context.values[parameter_key]
@pytest.mark.asyncio
@@ -145,3 +153,35 @@ def test_mask_secrets_in_data_masks_even_when_global_flag_disabled(
context.secrets["password"] = "secret-value"
assert context.mask_secrets_in_data({"password": "secret-value"}) == {"password": "*****"}
+
+
+async def test_password_less_credential_still_exposes_a_password_key(monkeypatch: pytest.MonkeyPatch) -> None:
+ """A login with no password must still register `password`, as the empty string.
+
+ Blocks (code blocks especially) dereference `.password` directly, so dropping the key for a
+ falsy value turns a valid password-less credential into a namespace lookup failure.
+ """
+ credential = PasswordCredential(username="[email protected]", password="")
+
+ context, values = await _register(monkeypatch, credential=credential, parameter_key="login")
+
+ assert values["password"] == ""
+ assert str(values["username"]).startswith(RANDOM_SECRET_ID_PREFIX)
+ # The empty password is not a secret to mask, so it must not enter the secrets map.
+ assert "" not in context.secrets
+
+
+async def test_password_less_credential_resolves_real_password_to_empty(
+ monkeypatch: pytest.MonkeyPatch,
+) -> None:
+ """The template entry for the real password resolves to "" rather than a placeholder id."""
+ credential = PasswordCredential(username="[email protected]", password="")
+
+ context, _ = await _register(monkeypatch, credential=credential, parameter_key="login")
+ entries = context.credential_template_entries(["login"], resolve_credential_dicts=True)
+
+ assert entries["login_real_password"] == ""
+ assert entries["login_real_username"] == "[email protected]"
+ assert entries["login"]["password"] == ""
diff --git a/tests/unit/test_quickstart_command.py b/tests/unit/test_quickstart_command.py
index 5dab89620..4ef9e11e3 100644
--- a/tests/unit/test_quickstart_command.py
+++ b/tests/unit/test_quickstart_command.py
@@ -43,8 +43,16 @@ def _structlog_config_capture_can_see(monkeypatch: pytest.MonkeyPatch) -> None:
cache_logger_on_first_use=False,
)
from skyvern.cli import run_commands
+ from skyvern.library import local_browser_profile
- monkeypatch.setattr(run_commands.LOG, "_logger", None, raising=False)
+ for log_proxy in (run_commands.LOG, local_browser_profile.LOG):
+ monkeypatch.setattr(log_proxy, "_logger", None, raising=False)
+ # Strip instance attrs shadowing the proxy's lazy dispatch: a stashed `bind`
+ # closure, or a bound method frozen onto the proxy by another test's
+ # monkeypatch undo (e.g. setattr(LOG, "warning", ...)). Either keeps routing
+ # through a logger built under an earlier config, bypassing capture_logs.
+ for attr in [a for a in vars(log_proxy) if not a.startswith("_")]:
+ monkeypatch.delattr(log_proxy, attr)
yield
structlog.configure(**saved)
@@ -91,6 +99,15 @@ def _patch_minimal_run_mcp_dependencies(monkeypatch, events: list[str], run_mcp_
fake_telemetry = types.ModuleType("skyvern.cli.mcp_tools.telemetry")
fake_telemetry.configure_mcp_telemetry_runtime = lambda **_kwargs: None
+ fake_instructions = types.ModuleType("skyvern.cli.mcp_tools.instructions")
+ fake_instructions.instructions_for_scope = lambda _scope: ""
+
+ fake_origin_middleware = types.ModuleType("skyvern.cli.mcp_tools.origin_middleware")
+ fake_origin_middleware.OriginValidationMiddleware = object
+
+ fake_scopes = types.ModuleType("skyvern.cli.mcp_tools.scopes")
+ fake_scopes.apply_scope = lambda _mcp, _scope: None
+
fake_mcp_tools = types.ModuleType("skyvern.cli.mcp_tools")
class FakeMCP:
@@ -118,6 +135,9 @@ def _patch_minimal_run_mcp_dependencies(monkeypatch, events: list[str], run_mcp_
monkeypatch.setitem(sys.modules, "skyvern.cli.core.session_manager", fake_session_manager)
monkeypatch.setitem(sys.modules, "skyvern.cli.mcp_tools", fake_mcp_tools)
monkeypatch.setitem(sys.modules, "skyvern.cli.mcp_tools.telemetry", fake_telemetry)
+ monkeypatch.setitem(sys.modules, "skyvern.cli.mcp_tools.instructions", fake_instructions)
+ monkeypatch.setitem(sys.modules, "skyvern.cli.mcp_tools.origin_middleware", fake_origin_middleware)
+ monkeypatch.setitem(sys.modules, "skyvern.cli.mcp_tools.scopes", fake_scopes)
return run_commands
@@ -376,6 +396,15 @@ def test_run_mcp_prepares_cloud_env_before_starting_mcp(tmp_path, monkeypatch) -
monkeypatch.setitem(sys.modules, "skyvern.cli.core.session_manager", fake_session_manager)
monkeypatch.setitem(sys.modules, "skyvern.cli.mcp_tools", fake_mcp_tools)
monkeypatch.setitem(sys.modules, "skyvern.cli.mcp_tools.telemetry", fake_telemetry)
+ fake_instructions = types.ModuleType("skyvern.cli.mcp_tools.instructions")
+ fake_instructions.instructions_for_scope = lambda _scope: ""
+ fake_origin_middleware = types.ModuleType("skyvern.cli.mcp_tools.origin_middleware")
+ fake_origin_middleware.OriginValidationMiddleware = object
+ fake_scopes = types.ModuleType("skyvern.cli.mcp_tools.scopes")
+ fake_scopes.apply_scope = lambda _mcp, _scope: None
+ monkeypatch.setitem(sys.modules, "skyvern.cli.mcp_tools.instructions", fake_instructions)
+ monkeypatch.setitem(sys.modules, "skyvern.cli.mcp_tools.origin_middleware", fake_origin_middleware)
+ monkeypatch.setitem(sys.modules, "skyvern.cli.mcp_tools.scopes", fake_scopes)
run_commands.run_mcp()
@@ -1056,7 +1085,7 @@ def test_quickstart_docker_compose_bypasses_server_extra_guard(monkeypatch) -> N
@pytest.mark.asyncio
async def test_start_services_without_frontend_runtime_starts_backend_only(monkeypatch) -> None:
- import skyvern.cli.utils as utils
+ from skyvern.cli import utils
commands = []
diff --git a/tests/unit/test_skyvern_credential_vault_service.py b/tests/unit/test_skyvern_credential_vault_service.py
index 5443e74a2..52332e6ae 100644
--- a/tests/unit/test_skyvern_credential_vault_service.py
+++ b/tests/unit/test_skyvern_credential_vault_service.py
@@ -8,12 +8,15 @@ from cryptography.fernet import Fernet
from fastapi import HTTPException
from skyvern.config import settings
+from skyvern.exceptions import CredentialVaultShapeMismatchError
from skyvern.forge import app
from skyvern.forge.sdk.schemas.credentials import (
CreateCredentialRequest,
Credential,
+ CredentialItem,
CredentialType,
CredentialVaultType,
+ CreditCardCredential,
NonEmptyPasswordCredential,
)
from skyvern.forge.sdk.services.credential.skyvern_credential_vault_service import (
@@ -114,13 +117,12 @@ class _CapturingCreateCredentialRepository(_FakeCredentialRepository):
def _password_request(
name: str = "Login",
- password: str = "secret-password",
+ password: str | object = "secret-password",
metadata: dict[str, str] | None | object = _UNSET,
) -> CreateCredentialRequest:
- credential_data: dict[str, object] = {
- "username": "[email protected]",
- "password": password,
- }
+ credential_data: dict[str, object] = {"username": "[email protected]"}
+ if password is not _UNSET:
+ credential_data["password"] = password
if metadata is not _UNSET:
credential_data["metadata"] = metadata
return CreateCredentialRequest(
@@ -207,6 +209,92 @@ async def test_skyvern_credential_vault_update_creates_new_item_and_cleans_old(t
assert item.credential.metadata == _PASSWORD_METADATA
+async def test_skyvern_credential_vault_update_preserves_omitted_password(tmp_path, monkeypatch) -> None:
+ monkeypatch.setattr(settings, "LOCAL_CREDENTIAL_VAULT_PATH", str(tmp_path))
+ monkeypatch.setattr(settings, "LOCAL_CREDENTIAL_VAULT_KEY", None)
+ monkeypatch.setattr(app.DATABASE, "credentials", _FakeCredentialRepository())
+
+ service = SkyvernCredentialVaultService()
+ credential = await service.create_credential(
+ "org_test", _password_request(password="old-password", metadata=_PASSWORD_METADATA)
+ )
+
+ updated = await service.update_credential(credential, _password_request(name="Login Renamed", password=_UNSET))
+
+ item = await service.get_credential_item(updated)
+ assert item.credential.password == "old-password"
+ assert item.credential.metadata == _PASSWORD_METADATA
+
+
+async def test_skyvern_credential_vault_update_blanks_explicitly_empty_password(tmp_path, monkeypatch) -> None:
+ monkeypatch.setattr(settings, "LOCAL_CREDENTIAL_VAULT_PATH", str(tmp_path))
+ monkeypatch.setattr(settings, "LOCAL_CREDENTIAL_VAULT_KEY", None)
+ monkeypatch.setattr(app.DATABASE, "credentials", _FakeCredentialRepository())
+
+ service = SkyvernCredentialVaultService()
+ credential = await service.create_credential("org_test", _password_request(password="old-password"))
+
+ updated = await service.update_credential(credential, _password_request(password=""))
+
+ item = await service.get_credential_item(updated)
+ assert item.credential.password == ""
+
+
+async def test_skyvern_credential_vault_update_rejects_non_password_vault_item(tmp_path, monkeypatch) -> None:
+ """A row/vault type disagreement must fail the update, not blank the stored secret.
+
+ The relaxed schema defaults `password` to "", so an omitted password on a credential whose
+ vault item is not password-shaped would otherwise overwrite the real secret with "".
+ """
+ monkeypatch.setattr(settings, "LOCAL_CREDENTIAL_VAULT_PATH", str(tmp_path))
+ monkeypatch.setattr(settings, "LOCAL_CREDENTIAL_VAULT_KEY", None)
+ monkeypatch.setattr(app.DATABASE, "credentials", _FakeCredentialRepository())
+
+ service = SkyvernCredentialVaultService()
+ credential = await service.create_credential("org_test", _password_request(password="old-password"))
+
+ card = CreditCardCredential(
+ card_number="4242424242424242",
+ card_cvv="123",
+ card_exp_month="12",
+ card_exp_year="2030",
+ card_brand="visa",
+ card_holder_name="Test Person",
+ )
+ monkeypatch.setattr(
+ service,
+ "get_credential_item",
+ AsyncMock(
+ return_value=CredentialItem(
+ item_id="i",
+ name="Login",
+ credential_type=CredentialType.CREDIT_CARD,
+ credential=card,
+ )
+ ),
+ )
+
+ with pytest.raises(CredentialVaultShapeMismatchError):
+ await service.update_credential(credential, _password_request(name="Renamed", password=_UNSET))
+
+
+async def test_skyvern_credential_vault_create_stores_omitted_password_as_empty(tmp_path, monkeypatch) -> None:
+ monkeypatch.setattr(settings, "LOCAL_CREDENTIAL_VAULT_PATH", str(tmp_path))
+ monkeypatch.setattr(settings, "LOCAL_CREDENTIAL_VAULT_KEY", None)
+ monkeypatch.setattr(app.DATABASE, "credentials", _FakeCredentialRepository())
+
+ service = SkyvernCredentialVaultService()
+ credential = await service.create_credential("org_test", _password_request(password=_UNSET))
+
+ item = await service.get_credential_item(credential)
+ assert item.credential.password == ""
+ assert item.credential.username == "[email protected]"
+
+
@pytest.mark.asyncio
async def test_skyvern_credential_vault_cleans_item_when_create_db_fails(tmp_path, monkeypatch) -> None:
monkeypatch.setattr(settings, "LOCAL_CREDENTIAL_VAULT_PATH", str(tmp_path))
diff --git a/tests/unit/test_taskv3_loop.py b/tests/unit/test_taskv3_loop.py
index 5e2f70129..e4bf4fc1e 100644
--- a/tests/unit/test_taskv3_loop.py
+++ b/tests/unit/test_taskv3_loop.py
@@ -38,6 +38,7 @@ from skyvern.forge.taskv3.loop import (
ToolHandler,
ToolResult,
ToolSpec,
+ _canonical_perception_content,
_PerceptionLedger,
make_finish_tool,
run_agent_tool_loop,
@@ -1714,7 +1715,7 @@ async def test_stall_nudge_is_delivered_once_per_streak_not_once_per_turn() -> N
nudges = [
message
for message in outcome.messages
- if message.get("role") == "user" and "byte-identical output" in str(message.get("content"))
+ if message.get("role") == "user" and "identical output" in str(message.get("content"))
]
assert len(nudges) == 1
@@ -1723,7 +1724,7 @@ def _stall_warnings(outcome: LoopOutcome) -> list[dict[str, Any]]:
return [
message
for message in outcome.messages
- if message.get("role") == "user" and "byte-identical output" in str(message.get("content"))
+ if message.get("role") == "user" and "identical output" in str(message.get("content"))
]
@@ -3323,3 +3324,101 @@ async def test_shadow_and_suppressed_lines_carry_the_hash_fields() -> None:
)
shadow = [e for e in logs if e["event"] == PERCEPTION_STALL_SHADOW_EVENT][0]
assert len(shadow["snapshot_digest"]) == 16 and len(shadow["action_key_hash"]) == 16
+
+
+def _replaced_node_observe(counter: int) -> str:
+ # A node-replacing framework loses data-tv3 with each rebuilt node, so observe re-mints values
+ # from the monotonic counter; every semantic byte below is frozen across calls.
+ return (
+ "url=https://site.test/form title='Form' (2 interactive elements)\n"
+ f"[[data-tv3=\"t{counter}\"]] input/text 'First name'\n"
+ f"[[data-tv3=\"t{counter + 1}-1\"]] button 'Continue' *required"
+ )
+
+
+async def test_marker_churn_on_a_frozen_page_still_trips_the_stall_guard_through_observe() -> None:
+ # SKY-14658 Direction B mode 2: the re-minted marker values are the only bytes that change, so
+ # byte-identity on the raw payload can never form a streak — the digest must be computed on
+ # marker-canonicalized content for the guard to do its primary job on a re-rendering page.
+ contents = [_replaced_node_observe(5 * i) for i in range(20)]
+ script = [[("observe", {})] for _ in range(20)]
+ script.append([("finish", {"status": "completed", "reason": "done"})])
+ tools = [_perception_tool("observe", contents), make_finish_tool()]
+ outcome, _ = await _run(script, tools, max_turns=200, max_tool_calls=500)
+ assert outcome.status == "terminated"
+ assert outcome.reason.startswith(PERCEPTION_STALL_REASON_PREFIX)
+
+
+async def test_marker_churn_on_a_frozen_page_still_trips_the_stall_guard_through_get_html() -> None:
+ contents = [
+ f'<form><input data-tv3="t{7 * i}" name="q"><button data-tv3="t{7 * i + 3}-2">Go</button></form>'
+ for i in range(20)
+ ]
+ script = [[("get_html", {})] for _ in range(20)]
+ script.append([("finish", {"status": "completed", "reason": "done"})])
+ tools = [_perception_tool("get_html", contents), make_finish_tool()]
+ outcome, _ = await _run(script, tools, max_turns=200, max_tool_calls=500)
+ assert outcome.status == "terminated"
+ assert outcome.reason.startswith(PERCEPTION_STALL_REASON_PREFIX)
+
+
+async def test_semantic_change_under_marker_churn_still_reads_as_progress() -> None:
+ # The canonicalization may only merge snapshots whose every semantic byte matches: when the
+ # page genuinely changes call over call (and markers churn too), the streak must keep resetting.
+ contents = [_replaced_node_observe(5 * i).replace("'Form'", f"'Form step {i}'") for i in range(20)]
+ script = [[("observe", {})] for _ in range(20)]
+ script.append([("finish", {"status": "completed", "reason": "done"})])
+ tools = [_perception_tool("observe", contents), make_finish_tool()]
+ outcome, _ = await _run(script, tools, max_turns=200, max_tool_calls=500)
+ assert outcome.status == "completed"
+ assert not outcome.reason.startswith(PERCEPTION_STALL_REASON_PREFIX)
+
+
+def test_canonicalization_normalizes_only_engine_minted_marker_values() -> None:
+ # Minted values (t<counter>, optionally -<n> disambiguated) are identity handles, not page
+ # semantics: both shapes normalize, in observe rendering and raw HTML alike.
+ assert _canonical_perception_content('[[data-tv3="t12"]] input') == _canonical_perception_content(
+ '[[data-tv3="t9004"]] input'
+ )
+ assert _canonical_perception_content('<a data-tv3="t3-1">x</a>') == _canonical_perception_content(
+ '<a data-tv3="t77">x</a>'
+ )
+ # A page-authored data-tv3 value is page content like any other attribute — left alone.
+ assert _canonical_perception_content('<a data-tv3="decoy">x</a>') != _canonical_perception_content(
+ '<a data-tv3="other">x</a>'
+ )
+ # The positional menu markers are stable on a frozen page and stay significant.
+ assert _canonical_perception_content('[[data-tv3-menu="2"]] row') != _canonical_perception_content(
+ '[[data-tv3-menu="3"]] row'
+ )
+
+
+async def test_a_marker_cut_open_by_the_get_html_truncation_does_not_leak_churn() -> None:
+ # get_html truncates at a fixed byte budget BEFORE the loop hashes, so a marker straddling the
+ # cut has no closing quote and its churning digits were the one leak canonicalization missed.
+ frozen_prefix = "<form>" + "<input name=q>" * 10 + '<button data-tv3="t'
+ contents = [f"{frozen_prefix}{100 + i}…[truncated at 20000 chars]" for i in range(20)]
+ script = [[("get_html", {})] for _ in range(20)]
+ script.append([("finish", {"status": "completed", "reason": "done"})])
+ tools = [_perception_tool("get_html", contents), make_finish_tool()]
+ outcome, _ = await _run(script, tools, max_turns=200, max_tool_calls=500)
+ assert outcome.status == "terminated"
+ assert outcome.reason.startswith(PERCEPTION_STALL_REASON_PREFIX)
+
+
+def test_canonicalization_covers_a_marker_fragment_left_open_at_the_tail() -> None:
+ # The cut can land anywhere in the value — after the digits, mid-digits, or before them.
+ assert _canonical_perception_content(
+ '<a data-tv3="t12…[truncated at 20000 chars]'
+ ) == _canonical_perception_content('<a data-tv3="t907-3…[truncated at 20000 chars]')
+ assert _canonical_perception_content('x data-tv3="t') == _canonical_perception_content('x data-tv3="t44-')
+ # A closed marker earlier in the content does not shield the open tail fragment, and a closed
+ # tail marker is not double-rewritten.
+ assert _canonical_perception_content('<a data-tv3="t1">y</a><b data-tv3="t2') == _canonical_perception_content(
+ '<a data-tv3="t9">y</a><b data-tv3="t8'
+ )
+ assert _canonical_perception_content('tail closed data-tv3="t5"') == 'tail closed data-tv3="*"'