Database governance built for humans and agents — controlling changes and access across every major database.
Go cicddata-governancedata-maskingdata-securitydatabase-accessdatabase-governancedevopsdevsecopsflywaygitopsliquibasemongodbmysqloraclepostgresqlschema-migrationssecuritysql-clientsqlservertidb
feat: improve page agent interrupted retry flow (#19693)
p0nyf9400e542eba
diff --git a/frontend/src/locales/en-US.json b/frontend/src/locales/en-US.jsonindex 94feae37c3..7d4be9ff30 100644--- a/frontend/src/locales/en-US.json+++ b/frontend/src/locales/en-US.json@@ -2971,6 +2971,8 @@"result": "Result:","stop": "Stop","interrupted": "Interrupted",+ "retry-last-turn": "Retry last turn",+ "interrupted-retry-hint": "Retry reruns the interrupted turn with the current page state.","new-thread": "New thread","reset-thread": "Reset thread","thread-select-label": "Thread",diff --git a/frontend/src/locales/es-ES.json b/frontend/src/locales/es-ES.jsonindex 480f2e7fd4..a552028640 100644--- a/frontend/src/locales/es-ES.json+++ b/frontend/src/locales/es-ES.json@@ -2480,6 +2480,8 @@"result": "Resultado:","stop": "Detener","interrupted": "Interrumpido",+ "retry-last-turn": "Reintentar el último turno",+ "interrupted-retry-hint": "Reintentar vuelve a ejecutar el turno interrumpido con el estado actual de la página.","new-thread": "Nuevo hilo","reset-thread": "Restablecer hilo","thread-select-label": "Hilo",diff --git a/frontend/src/locales/ja-JP.json b/frontend/src/locales/ja-JP.jsonindex 7c0ed1abe1..01f6a16195 100644--- a/frontend/src/locales/ja-JP.json+++ b/frontend/src/locales/ja-JP.json@@ -2480,6 +2480,8 @@"result": "結果:","stop": "停止","interrupted": "中断",+ "retry-last-turn": "直前のターンを再試行",+ "interrupted-retry-hint": "再試行すると、現在のページ状態で中断されたターンをやり直します。","new-thread": "新しいスレッド","reset-thread": "スレッドをリセット","thread-select-label": "スレッド",diff --git a/frontend/src/locales/vi-VN.json b/frontend/src/locales/vi-VN.jsonindex d81307d95f..6b269e7011 100644--- a/frontend/src/locales/vi-VN.json+++ b/frontend/src/locales/vi-VN.json@@ -2480,6 +2480,8 @@"result": "Kết quả:","stop": "Dừng","interrupted": "Bị gián đoạn",+ "retry-last-turn": "Thử lại lượt trước",+ "interrupted-retry-hint": "Thử lại sẽ chạy lại lượt bị gián đoạn với trạng thái trang hiện tại.","new-thread": "Luồng mới","reset-thread": "Đặt lại luồng","thread-select-label": "Luồng",diff --git a/frontend/src/locales/zh-CN.json b/frontend/src/locales/zh-CN.jsonindex 15da1bc3dd..630f5e9a0f 100644--- a/frontend/src/locales/zh-CN.json+++ b/frontend/src/locales/zh-CN.json@@ -2971,6 +2971,8 @@"result": "结果:","stop": "停止","interrupted": "已中断",+ "retry-last-turn": "重试上一轮",+ "interrupted-retry-hint": "重试会基于当前页面状态重新运行已中断的这一轮。","new-thread": "新线程","reset-thread": "重置线程","thread-select-label": "线程",diff --git a/frontend/src/plugins/agent/components/AgentInput.test.ts b/frontend/src/plugins/agent/components/AgentInput.test.tsindex 6782e41e3c..1733d4eb27 100644--- a/frontend/src/plugins/agent/components/AgentInput.test.ts+++ b/frontend/src/plugins/agent/components/AgentInput.test.ts@@ -43,6 +43,9 @@ vi.mock("vue-router", () => ({const getTextareaValue = (wrapper: ReturnType<typeof mount>) => {return (wrapper.find("textarea").element as HTMLTextAreaElement).value;};+const findButtonByText = (wrapper: ReturnType<typeof mount>, text: string) => {+ return wrapper.findAll("button").find((button) => button.text() === text);+};const flushPromises = async () => {await Promise.resolve();await Promise.resolve();@@ -61,8 +64,14 @@ const i18n = createI18n({locale: "en-US",messages: {"en-US": {+ common: {+ dismiss: "Dismiss",+ },agent: {interrupted: "Interrupted",+ "retry-last-turn": "Retry last turn",+ "interrupted-retry-hint":+ "Retry reruns the interrupted turn with the current page state.","input-placeholder": "Ask anything...",send: "Send",reply: "Reply",@@ -335,6 +344,194 @@ describe("AgentInput", () => {});});+ test("shows retry CTA and reruns interrupted turns from the last stable input", async () => {+ const store = useAgentStore();+ const threadId = store.currentThreadId!;++ store.updateThreadPage(threadId, {+ path: "/projects/original",+ title: "Original Page",+ });+ store.addMessage({+ threadId,+ role: "user",+ content: "inspect this page",+ metadata: {+ route: "/projects/original",+ },+ });+ store.addMessage({+ threadId,+ role: "assistant",+ content: "Partial answer",+ metadata: {+ route: "/projects/original",+ runId: "run-1",+ },+ });+ store.addMessage({+ threadId,+ role: "tool",+ toolCallId: "tool-1",+ content: JSON.stringify({ partial: true }),+ metadata: {+ route: "/projects/original",+ runId: "run-1",+ },+ });+ store.interruptRun(threadId);+ store.getThread(threadId)!.runId = "run-1";++ mockRoute.fullPath = "/projects/current";+ document.title = "Current Page";+ mockRunAgentLoop.mockResolvedValue({+ kind: "completed",+ text: "Done",+ success: true,+ explicit: true,+ });++ const wrapper = mount(AgentInput, {+ global: {+ plugins: [pinia, i18n],+ },+ });++ expect(wrapper.text()).toContain("Retry reruns the interrupted turn");+ await findButtonByText(wrapper, "Retry last turn")!.trigger("click");+ await flushPromises();++ expect(mockBuildSystemPrompt).toHaveBeenCalledWith({+ path: "/projects/current",+ title: "Current Page",+ });++ const [messages] = mockRunAgentLoop.mock.calls[0];+ expect(messages).toEqual(+ expect.arrayContaining([+ expect.objectContaining({ role: "system", content: "system-prompt" }),+ expect.objectContaining({+ role: "user",+ content: "inspect this page",+ }),+ ])+ );+ expect(messages).not.toEqual(+ expect.arrayContaining([+ expect.objectContaining({+ role: "assistant",+ content: "Partial answer",+ }),+ expect.objectContaining({+ role: "tool",+ toolCallId: "tool-1",+ }),+ ])+ );+ expect(+ store+ .getMessages(threadId)+ .some((message) => message.content === "Partial answer")+ ).toBe(false);+ expect(+ store+ .getMessages(threadId)+ .some((message) => message.toolCallId === "tool-1")+ ).toBe(false);+ expect(store.getThread(threadId)?.interrupted).toBe(false);+ expect(store.getThread(threadId)?.page).toEqual({+ path: "/projects/current",+ title: "Current Page",+ });+ });++ test("preserves the latest page snapshot when an interrupted run ends on a new page", async () => {+ const store = useAgentStore();+ const threadId = store.currentThreadId!;++ store.updateThreadPage(threadId, {+ path: "/projects/original",+ title: "Original Page",+ });++ mockRunAgentLoop.mockImplementation(async () => {+ mockRoute.fullPath = "/projects/navigated";+ document.title = "Navigated Page";+ return { kind: "aborted" };+ });++ const wrapper = mount(AgentInput, {+ global: {+ plugins: [pinia, i18n],+ },+ });++ await wrapper.find("textarea").setValue("inspect this page");+ await findButtonByText(wrapper, "Send")!.trigger("click");+ await flushPromises();++ expect(store.getThread(threadId)?.interrupted).toBe(true);+ expect(store.getThread(threadId)?.page).toEqual({+ path: "/projects/navigated",+ title: "Navigated Page",+ });+ });++ test("dismissing interrupted state removes partial run output", async () => {+ const store = useAgentStore();+ const threadId = store.currentThreadId!;++ store.addMessage({+ threadId,+ role: "user",+ content: "inspect this page",+ });+ store.addMessage({+ threadId,+ role: "assistant",+ content: "Partial answer",+ metadata: {+ runId: "run-1",+ },+ });+ store.addMessage({+ threadId,+ role: "tool",+ toolCallId: "tool-1",+ content: JSON.stringify({ partial: true }),+ metadata: {+ runId: "run-1",+ },+ });+ store.interruptRun(threadId);+ store.getThread(threadId)!.runId = "run-1";++ const wrapper = mount(AgentInput, {+ global: {+ plugins: [pinia, i18n],+ },+ });++ await findButtonByText(wrapper, "Dismiss")!.trigger("click");+ await flushPromises();++ expect(store.getThread(threadId)?.interrupted).toBe(false);+ expect(store.getThread(threadId)?.runId).toBeNull();+ expect(+ store.getMessages(threadId).map((message) => ({+ role: message.role,+ content: message.content,+ toolCallId: message.toolCallId,+ }))+ ).toEqual([+ {+ role: "user",+ content: "inspect this page",+ toolCallId: undefined,+ },+ ]);+ });+test("keeps the latest run cancellable when an earlier aborted run settles late", async () => {const store = useAgentStore();const threadId = store.currentThreadId!;@@ -376,13 +573,13 @@ describe("AgentInput", () => {});await wrapper.find("textarea").setValue("first request");- await wrapper.find("button").trigger("click");+ await findButtonByText(wrapper, "Send")!.trigger("click");await flushPromises();expect(store.abortController?.signal).toBe(firstSignal);expect(store.loading).toBe(true);- await wrapper.find("button").trigger("click");+ await findButtonByText(wrapper, "Stop")!.trigger("click");await flushPromises();expect(firstSignal?.aborted).toBe(true);@@ -390,7 +587,7 @@ describe("AgentInput", () => {expect(store.loading).toBe(false);await wrapper.find("textarea").setValue("second request");- await wrapper.find("button").trigger("click");+ await findButtonByText(wrapper, "Send")!.trigger("click");await flushPromises();expect(store.abortController?.signal).toBe(secondSignal);diff --git a/frontend/src/plugins/agent/components/AgentInput.vue b/frontend/src/plugins/agent/components/AgentInput.vueindex 4c9e0666b9..87ae491a55 100644--- a/frontend/src/plugins/agent/components/AgentInput.vue+++ b/frontend/src/plugins/agent/components/AgentInput.vue@@ -1,4 +1,5 @@<script setup lang="ts">+import { v4 as uuidv4 } from "uuid";import { computed, ref, watch } from "vue";import { useI18n } from "vue-i18n";import { useRoute, useRouter } from "vue-router";@@ -15,7 +16,9 @@ const agentStore = useAgentStore();const input = ref("");let currentRunToken = 0;+const currentThread = computed(() => agentStore.currentThread);const currentPendingAsk = computed(() => agentStore.currentPendingAsk);+const isInterrupted = computed(() => Boolean(currentThread.value?.interrupted));const chooseOptions = computed(() =>currentPendingAsk.value?.kind === "choose"? (currentPendingAsk.value.options ?? [])@@ -97,15 +100,7 @@ const handleOutcome = (agentStore.awaitUser(threadId, outcome.ask);return;case "aborted":- agentStore.addMessage({- threadId,- role: "assistant",- content: `_${t("agent.interrupted")}_`,- metadata: {- route: page.path,- },- });- agentStore.finishRun(threadId);+ agentStore.interruptRun(threadId, getCurrentPageSnapshot());return;case "error":agentStore.addMessage({@@ -127,7 +122,8 @@ const handleOutcome = (async function runThread(threadId: string,- page: { path: string; title: string }+ page: { path: string; title: string },+ runId: string) {const controller = new AbortController();const runToken = ++currentRunToken;@@ -158,6 +154,7 @@ async function runThread(toolCalls: message.toolCalls,metadata: {route: page.path,+ runId,},});},@@ -169,6 +166,7 @@ async function runThread(content: result,metadata: {route: page.path,+ runId,},});},@@ -182,6 +180,7 @@ async function runThread(content: text,metadata: {route: page.path,+ runId,},});},@@ -204,6 +203,29 @@ async function runThread(}}+async function startThreadRun(+ threadId: string,+ currentPage: { path: string; title: string },+ options: {+ preferCurrentPage?: boolean;+ } = {}+) {+ const threadPage = options.preferCurrentPage+ ? currentPage+ : resolveThreadPageSnapshot(threadId, currentPage);+ const runId = uuidv4();++ if (options.preferCurrentPage) {+ agentStore.updateThreadPage(threadId, threadPage);+ }++ agentStore.startRun(threadId, threadPage, {+ replacePage: options.preferCurrentPage,+ runId,+ });+ await runThread(threadId, threadPage, runId);+}+async function send() {if (agentStore.hasRunningThread) {return;@@ -212,7 +234,6 @@ async function send() {const currentPage = getCurrentPageSnapshot();const thread = agentStore.ensureCurrentThread(currentPage);const threadId = thread.id;- const threadPage = resolveThreadPageSnapshot(threadId, currentPage);agentStore.clearError(threadId);@@ -249,8 +270,7 @@ async function send() {} else {return;}- agentStore.startRun(threadId, threadPage);- await runThread(threadId, threadPage);+ await startThreadRun(threadId, currentPage);return;}@@ -268,8 +288,32 @@ async function send() {route: currentPage.path,},});- agentStore.startRun(threadId, threadPage);- await runThread(threadId, threadPage);+ await startThreadRun(threadId, currentPage);+}++async function retryLastTurn() {+ if (agentStore.hasRunningThread || !currentThread.value?.interrupted) {+ return;+ }++ const threadId = currentThread.value.id;+ const currentPage = getCurrentPageSnapshot();+ agentStore.removeMessagesByRunId(threadId, currentThread.value.runId);+ agentStore.clearError(threadId);+ await startThreadRun(threadId, currentPage, {+ preferCurrentPage: true,+ });+}++function dismissInterrupted() {+ if (!currentThread.value) {+ return;+ }+ agentStore.removeMessagesByRunId(+ currentThread.value.id,+ currentThread.value.runId+ );+ agentStore.clearError(currentThread.value.id);}async function submitConfirmation(confirmed: boolean) {@@ -285,7 +329,6 @@ async function submitConfirmation(confirmed: boolean) {const currentPage = getCurrentPageSnapshot();const thread = agentStore.ensureCurrentThread(currentPage);const threadId = thread.id;- const threadPage = resolveThreadPageSnapshot(threadId, currentPage);const answer = confirmed ? confirmLabel.value : cancelLabel.value;agentStore.clearError(threadId);@@ -300,8 +343,7 @@ async function submitConfirmation(confirmed: boolean) {route: currentPage.path,});- agentStore.startRun(threadId, threadPage);- await runThread(threadId, threadPage);+ await startThreadRun(threadId, currentPage);}async function submitChoice(option: AgentAskUserOption) {@@ -317,7 +359,6 @@ async function submitChoice(option: AgentAskUserOption) {const currentPage = getCurrentPageSnapshot();const thread = agentStore.ensureCurrentThread(currentPage);const threadId = thread.id;- const threadPage = resolveThreadPageSnapshot(threadId, currentPage);agentStore.clearError(threadId);agentStore.answerPendingAsk(@@ -331,8 +372,7 @@ async function submitChoice(option: AgentAskUserOption) {route: currentPage.path,});- agentStore.startRun(threadId, threadPage);- await runThread(threadId, threadPage);+ await startThreadRun(threadId, currentPage);}watch(@@ -374,6 +414,30 @@ watch(</div></div>+ <div+ v-if="isInterrupted"+ class="mb-3 rounded-md bg-red-50 px-3 py-2 text-xs text-red-700"+ >+ <div class="font-medium">{{ $t("agent.interrupted") }}</div>+ <div class="mt-1">{{ $t("agent.interrupted-retry-hint") }}</div>+ <div class="mt-2 flex flex-wrap gap-x-2 gap-y-2">+ <button+ class="rounded-md bg-red-500 px-3 py-2 text-sm text-white hover:bg-red-600 disabled:opacity-50"+ :disabled="agentStore.hasRunningThread"+ @click="retryLastTurn"+ >+ {{ $t("agent.retry-last-turn") }}+ </button>+ <button+ class="rounded-md border px-3 py-2 text-sm text-gray-700 hover:bg-gray-50 disabled:opacity-50"+ :disabled="agentStore.hasRunningThread"+ @click="dismissInterrupted"+ >+ {{ $t("common.dismiss") }}+ </button>+ </div>+ </div>+<div v-if="isAwaitingConfirm" class="flex flex-wrap gap-x-2 gap-y-2"><buttonclass="rounded-md bg-blue-500 px-3 py-2 text-sm text-white hover:bg-blue-600 disabled:opacity-50"diff --git a/frontend/src/plugins/agent/logic/agentLoop.ts b/frontend/src/plugins/agent/logic/agentLoop.tsindex 8966250926..53f72df407 100644--- a/frontend/src/plugins/agent/logic/agentLoop.ts+++ b/frontend/src/plugins/agent/logic/agentLoop.ts@@ -19,7 +19,7 @@ import type {ToolExecutor,} from "./types";-const MAX_ITERATIONS = 50;+const MAX_ITERATIONS = 1000;const MAX_RETRIES = 2;const RETRY_DELAY_MS = 1000;diff --git a/frontend/src/plugins/agent/logic/types.ts b/frontend/src/plugins/agent/logic/types.tsindex 4180dc0f1f..446af59d94 100644--- a/frontend/src/plugins/agent/logic/types.ts+++ b/frontend/src/plugins/agent/logic/types.ts@@ -49,6 +49,7 @@ export interface AgentThread {page?: AgentThreadSnapshot;lastError?: string | null;interrupted?: boolean;+ runId?: string | null;}export type AgentAskUserKind = "input" | "confirm" | "choose";diff --git a/frontend/src/plugins/agent/store/agent.test.ts b/frontend/src/plugins/agent/store/agent.test.tsindex 80800f9810..88cf610724 100644--- a/frontend/src/plugins/agent/store/agent.test.ts+++ b/frontend/src/plugins/agent/store/agent.test.ts@@ -89,6 +89,7 @@ describe("useAgentStore", () => {createdTs: 10,updatedTs: 20,status: "running",+ runId: "run-1",},],messagesByThreadId: {@@ -110,11 +111,33 @@ describe("useAgentStore", () => {const thread = store.currentThread;expect(thread).not.toBeNull();- expect(thread?.status).toBe("error");+ expect(thread?.status).toBe("idle");expect(thread?.interrupted).toBe(true);+ expect(thread?.runId).toBe("run-1");expect(store.loading).toBe(false);});+ test("clears interruption markers when a new run starts", () => {+ const store = createStore();+ const threadId = store.currentThreadId!;++ store.interruptRun(threadId);+ store.startRun(+ threadId,+ {+ path: "/projects/demo",+ title: "Demo",+ },+ {+ runId: "run-2",+ }+ );++ expect(store.getThread(threadId)?.status).toBe("running");+ expect(store.getThread(threadId)?.interrupted).toBe(false);+ expect(store.getThread(threadId)?.runId).toBe("run-2");+ });+test("persists the selected thread and resets thread messages in place", async () => {const store = createStore();const firstThreadId = store.currentThreadId!;diff --git a/frontend/src/plugins/agent/store/agent.ts b/frontend/src/plugins/agent/store/agent.tsindex 93fca4a7e7..b8eeaf73da 100644--- a/frontend/src/plugins/agent/store/agent.ts+++ b/frontend/src/plugins/agent/store/agent.ts@@ -48,6 +48,7 @@ const createThreadRecord = (options: CreateThreadOptions = {}): AgentThread => {page: options.page,lastError: null,interrupted: false,+ runId: null,};};@@ -189,6 +190,7 @@ const normalizeThread = (raw: unknown): AgentThread => {? null: null,interrupted: Boolean(thread.interrupted),+ runId: typeof thread.runId === "string" ? thread.runId : null,};};@@ -267,7 +269,7 @@ const normalizePersistedState = (raw: unknown): PersistedAgentState => {thread.updatedTs = Math.max(thread.updatedTs, lastMessage.createdTs);}if (thread.status === "running") {- thread.status = "error";+ thread.status = DEFAULT_THREAD_STATUS;thread.interrupted = true;thread.lastError = null;}@@ -472,6 +474,28 @@ export const useAgentStore = defineStore("agent", () => {return agentMessage;};+ const removeMessagesByRunId = (threadId: string, runId?: string | null) => {+ if (!runId) {+ return [];+ }+ const thread = getThread(threadId);+ if (!thread) {+ return [];+ }+ const existingMessages = getMessages(threadId);+ const removedMessages = existingMessages.filter(+ (message) => message.metadata?.runId === runId+ );+ if (removedMessages.length === 0) {+ return [];+ }+ messagesByThreadId.value[threadId] = existingMessages.filter(+ (message) => message.metadata?.runId !== runId+ );+ touchThread(threadId);+ return removedMessages;+ };+const appendToolCall = (threadId: string,messageId: string,@@ -525,6 +549,7 @@ export const useAgentStore = defineStore("agent", () => {thread.status = DEFAULT_THREAD_STATUS;thread.lastError = null;thread.interrupted = false;+ thread.runId = null;thread.updatedTs = Date.now();};@@ -542,25 +567,45 @@ export const useAgentStore = defineStore("agent", () => {}thread.lastError = null;thread.interrupted = false;+ thread.runId = null;if (thread.status === "error") {thread.status = DEFAULT_THREAD_STATUS;}touchThread(thread.id);};+ const interruptRun = (threadId: string, page?: AgentThreadSnapshot) => {+ setThreadStatus(threadId, DEFAULT_THREAD_STATUS, {+ interrupted: true,+ page,+ });+ };+const cancel = () => {abortController.value?.abort();abortController.value = null;if (runningThreadId.value) {- setThreadStatus(runningThreadId.value, DEFAULT_THREAD_STATUS);+ interruptRun(runningThreadId.value);}};- const startRun = (threadId: string, page?: AgentThreadSnapshot) => {+ const startRun = (+ threadId: string,+ page?: AgentThreadSnapshot,+ options: {+ replacePage?: boolean;+ runId?: string;+ } = {}+ ) => {const thread = getThread(threadId);+ const nextPage = options.replacePage ? page : (thread?.page ?? page);setThreadStatus(threadId, "running", {- page: thread?.page ?? page,+ page: nextPage,});+ const updatedThread = getThread(threadId);+ if (updatedThread) {+ updatedThread.runId = options.runId ?? updatedThread.runId ?? null;+ }};const finishRun = (@@ -574,6 +619,10 @@ export const useAgentStore = defineStore("agent", () => {lastError: options.lastError ?? null,interrupted: false,});+ const thread = getThread(threadId);+ if (thread) {+ thread.runId = null;+ }};const saveWindowState = () => {@@ -707,10 +756,12 @@ export const useAgentStore = defineStore("agent", () => {setThreadStatus,startRun,finishRun,+ interruptRun,awaitUser,answerPendingAsk,touchThread,addMessage,+ removeMessagesByRunId,appendToolCall,clearMessages,clearConversation,