Skip to content

Automate browser based workflows with AI

Treat an Accept 422 as proof the Copilot proposal was not saved (#9006)

Aaron Perez5d657e14fff1
diff --git a/skyvern-frontend/src/routes/workflows/copilot/WorkflowCopilotChat.reviewGate.test.tsx b/skyvern-frontend/src/routes/workflows/copilot/WorkflowCopilotChat.reviewGate.test.tsx
index 4d110e9d4..3011673c3 100644
--- a/skyvern-frontend/src/routes/workflows/copilot/WorkflowCopilotChat.reviewGate.test.tsx
+++ b/skyvern-frontend/src/routes/workflows/copilot/WorkflowCopilotChat.reviewGate.test.tsx
@@ -638,6 +638,11 @@ async function acceptRefusedWith(status: number) {
});
}
+// The save path's own wording for a proposal whose block graph it refuses.
+const INVALID_GRAPH_DETAIL =
+ "Circular reference detected: some blocks form a loop through their next_block_label" +
+ " references, causing an infinite cycle.";
+
const proposedWorkflowPayload = (
overrides: Record<string, unknown> = {},
): Record<string, unknown> => ({
@@ -2772,7 +2777,7 @@ describe("WorkflowCopilotChat — g2 review gate", () => {
const owner = createYamlCommitOwner("wpid_1");
registerEditorOwner(owner);
if (mode === "HTTP rejection")
- cancelPost.mockRejectedValueOnce({ response: { status: 422 } });
+ cancelPost.mockRejectedValueOnce({ response: { status: 500 } });
vi.useFakeTimers();
await act(async () =>
fireEvent.click(screen.getByRole("button", { name: "Accept" })),
@@ -3330,7 +3335,7 @@ describe("WorkflowCopilotChat — g2 review gate", () => {
historyResponse.data.workflow_copilot_chat_id = null;
} else if (mode === "failed-server") {
historyResponse.data.proposed_workflow = proposedWorkflowPayload();
- cancelPost.mockRejectedValueOnce({ response: { status: 422 } });
+ cancelPost.mockRejectedValueOnce({ response: { status: 500 } });
} else {
cancelPost.mockResolvedValueOnce({
data: proposedWorkflowPayload({
@@ -4514,7 +4519,7 @@ describe("WorkflowCopilotChat — g2 review gate", () => {
if (mode !== "terminal") {
if (mode === "fallback") {
historyResponse.data.proposed_workflow = appliedWorkflow;
- cancelPost.mockRejectedValueOnce({ response: { status: 422 } });
+ cancelPost.mockRejectedValueOnce({ response: { status: 500 } });
} else cancelPost.mockResolvedValueOnce({ data: appliedWorkflow });
await act(async () =>
fireEvent.click(screen.getByRole("button", { name: "Accept" })),
@@ -7682,9 +7687,33 @@ describe("WorkflowCopilotChat — g2 review gate", () => {
expect(screen.getByRole("button", { name: "Accept" })).toBeTruthy();
});
- it.each([false, true])(
- "settles a surviving proposal from a newer canonical version only with no-write proof: %s",
- async (wroteNothing) => {
+ it.each([
+ {
+ refusal: "unproven",
+ error: new Error("Network Error"),
+ wroteNothing: false,
+ },
+ {
+ refusal: "409",
+ error: { response: { status: 409 } },
+ wroteNothing: true,
+ },
+ {
+ // SKY-18820: the save path refusing the proposal's own definition. While 422 was not
+ // no-write proof this entered the recovery poll instead, and the proposal the route
+ // restores on the way out keeps that poll running, so Send and Save never came back.
+ refusal: "422 invalid definition",
+ error: {
+ response: {
+ status: 422,
+ data: { detail: INVALID_GRAPH_DETAIL },
+ },
+ },
+ wroteNothing: true,
+ },
+ ])(
+ "settles a surviving proposal from a newer canonical version only with no-write proof: $refusal",
+ async ({ error: refusalError, wroteNothing }) => {
const onWorkflowUpdate = vi.fn();
useWorkflowHasChangesStore.setState({
getSaveData: () =>
@@ -7712,11 +7741,7 @@ describe("WorkflowCopilotChat — g2 review gate", () => {
path === "/workflows/wpid_1" ? { data: created } : historyResponse,
),
);
- cancelPost.mockRejectedValueOnce(
- wroteNothing
- ? { response: { status: 409 } }
- : new Error("Network Error"),
- );
+ cancelPost.mockRejectedValueOnce(refusalError);
await act(async () => {
fireEvent.click(screen.getByRole("button", { name: "Accept" }));
@@ -7743,6 +7768,18 @@ describe("WorkflowCopilotChat — g2 review gate", () => {
useWorkflowYamlEditorStore.getState().copilotAcceptance !== null,
).toBe(!wroteNothing);
if (wroteNothing) expect(screen.getByText("Not saved")).toBeTruthy();
+ // A refusal that names the problem has to reach the user: the toast is the only place the
+ // save path's verdict is shown, and it is what tells them what to change.
+ const detail = (
+ refusalError as { response?: { data?: { detail?: string } } }
+ ).response?.data?.detail;
+ if (detail)
+ expect(toast).toHaveBeenCalledWith(
+ expect.objectContaining({
+ title: "Accept failed",
+ description: detail,
+ }),
+ );
},
);
@@ -13214,7 +13251,7 @@ describe("WorkflowCopilotChat — g2 review gate", () => {
const owner = createYamlCommitOwner("wpid_1");
registerEditorOwner(owner);
if (mode === "HTTP rejection")
- cancelPost.mockRejectedValueOnce({ response: { status: 422 } });
+ cancelPost.mockRejectedValueOnce({ response: { status: 500 } });
vi.useFakeTimers();
await act(async () =>
fireEvent.click(screen.getByRole("button", { name: "Accept" })),
diff --git a/skyvern-frontend/src/routes/workflows/copilot/acceptFence.ts b/skyvern-frontend/src/routes/workflows/copilot/acceptFence.ts
index ce13bb168..ec6a2c710 100644
--- a/skyvern-frontend/src/routes/workflows/copilot/acceptFence.ts
+++ b/skyvern-frontend/src/routes/workflows/copilot/acceptFence.ts
@@ -19,12 +19,15 @@ export type AcceptAttempt = {
wroteNothing: boolean;
};
-// The only two statuses the apply route's refusal ladder raises, and it raises both before it
-// creates the version, so either proves no write. Nothing wider qualifies: a transport failure
-// carries no status at all, its 404 says the chat id did not resolve so a later read of that same
-// id proves nothing, and a gateway or auth 4xx never reached the ladder.
+// The statuses that prove the apply route wrote nothing. 400 and 409 are its own refusal ladder,
+// raised before it creates the version. 422 is the save path refusing the proposal's definition -
+// an invalid block graph, duplicate labels, reserved parameter keys - and those validators run
+// inside the version write transaction, ahead of the definition write, so the version row they
+// raise over rolls back with them. Nothing wider qualifies: a transport failure carries no status
+// at all, its 404 says the chat id did not resolve so a later read of that same id proves nothing,
+// and a gateway or auth 4xx never reached the route.
export const applyWroteNothing = (status: number | undefined): boolean =>
- status === 400 || status === 409;
+ status === 400 || status === 409 || status === 422;
export const proposalTokenOf = (
metadata: CopilotProposalMetadata | null,
@@ -246,5 +249,10 @@ export function definitiveAcceptRejection(error: unknown): string | null {
].includes(detail)
)
return detail;
+ // The save path refusing the proposal's definition. Its messages name the problem and say how to
+ // fix it ("Circular reference detected: ...", "Duplicate block label detected: ..."), and the set
+ // is open, so the status carries the proof and the message is passed through as written. FastAPI's
+ // own request-validation 422 sends a list, which the string check above already drops.
+ if (response?.status === 422) return detail;
return null;
}