From cbc7d94f6b37b4ef000df04a69ba6d79fe1aad08 Mon Sep 17 00:00:00 2001 From: Marco Beretta <81851188+berry-13@users.noreply.github.com> Date: Fri, 13 Nov 2026 00:46:39 +0100 Subject: [PATCH] =?UTF-8?q?=E2=9C=85=20fix:=20Submit=20Tool=20Approvals=20?= =?UTF-8?q?When=20the=20Generation=20Epoch=20Is=20Unknown=20(#17928)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix: Submit Tool Approvals Without a Known Generation Epoch The resume submit hook required the client-side generation epoch, so when it was unavailable Submit returned before calling the mutation and the approval card stayed pending with no error. The resume route validates generationCreatedAt only when present and fences on the authoritative job and actionId, so the epoch is now sent as an optional extra fence. * test: Cover Approval Submit When the Status Omits the Generation Epoch --- .../Chat/Messages/Content/ApprovalContext.tsx | 10 ++-- .../__tests__/ApprovalContext.test.tsx | 21 ++++++- client/src/data-provider/SSE/mutations.ts | 6 +- e2e/specs/mock/tool-approvals.spec.ts | 55 +++++++++++++++++++ 4 files changed, 81 insertions(+), 11 deletions(-) diff --git a/client/src/components/Chat/Messages/Content/ApprovalContext.tsx b/client/src/components/Chat/Messages/Content/ApprovalContext.tsx index 290b12f88c..1e06faeddc 100644 --- a/client/src/components/Chat/Messages/Content/ApprovalContext.tsx +++ b/client/src/components/Chat/Messages/Content/ApprovalContext.tsx @@ -468,16 +468,14 @@ export function useResumeSubmit() { const buildResumeFields = useCallback((): ResumeAgentFields | null => { const conversationId = conversation?.conversationId; - if ( - !conversationId || - conversationId === Constants.NEW_CONVO || - activeGenerationCreatedAt == null - ) { + if (!conversationId || conversationId === Constants.NEW_CONVO) { return null; } return { conversationId, - generationCreatedAt: activeGenerationCreatedAt, + /** Sent as a replacement fence when known. Without it the server still + * resolves the action against its own job and rejects a stale actionId. */ + ...(activeGenerationCreatedAt != null && { generationCreatedAt: activeGenerationCreatedAt }), endpoint: conversation?.endpoint, endpointType: conversation?.endpointType, agent_id: conversation?.agent_id, diff --git a/client/src/components/Chat/Messages/Content/__tests__/ApprovalContext.test.tsx b/client/src/components/Chat/Messages/Content/__tests__/ApprovalContext.test.tsx index 299a4b9025..3389b9d47d 100644 --- a/client/src/components/Chat/Messages/Content/__tests__/ApprovalContext.test.tsx +++ b/client/src/components/Chat/Messages/Content/__tests__/ApprovalContext.test.tsx @@ -459,7 +459,7 @@ describe('useResumeSubmit', () => { expect(result.current.isReady('action-1')).toBe(true); }); - test('keeps approval and ask-answer resume controls inert before the generation epoch exists', () => { + test('submits approval and ask-answer resumes without an epoch when none is known', () => { const { result } = renderHook( () => ({ approval: useApprovalContext(), @@ -474,12 +474,27 @@ describe('useResumeSubmit', () => { tool_call_id: 'call-1', decision: 'approve', }); + }); + act(() => { result.current.resume.submitToolApproval('action-1'); result.current.resume.submitAskAnswer('ask-1', 'answer'); }); - expect(mockApprovalMutate).not.toHaveBeenCalled(); - expect(mockAskMutate).not.toHaveBeenCalled(); + expect(mockApprovalMutate).toHaveBeenCalledTimes(1); + expect(mockApprovalMutate).toHaveBeenCalledWith( + expect.objectContaining({ + conversationId: 'conversation-1', + actionId: 'action-1', + decisions: [{ tool_call_id: 'call-1', decision: 'approve' }], + }), + expect.any(Object), + ); + expect(mockApprovalMutate.mock.calls[0][0]).not.toHaveProperty('generationCreatedAt'); + expect(mockAskMutate).toHaveBeenCalledTimes(1); + expect(mockAskMutate.mock.calls[0][0]).toEqual( + expect.objectContaining({ conversationId: 'conversation-1', actionId: 'ask-1' }), + ); + expect(mockAskMutate.mock.calls[0][0]).not.toHaveProperty('generationCreatedAt'); }); test('synchronously deduplicates ask answers and unlocks a retryable error', () => { diff --git a/client/src/data-provider/SSE/mutations.ts b/client/src/data-provider/SSE/mutations.ts index 07d519a725..ae574623dd 100644 --- a/client/src/data-provider/SSE/mutations.ts +++ b/client/src/data-provider/SSE/mutations.ts @@ -43,8 +43,10 @@ export function useAbortStreamMutation() { */ export interface ResumeAgentFields { conversationId: string; - /** Exact paused generation being resumed. */ - generationCreatedAt: number; + /** Exact paused generation being resumed. Optional: when the client has not + * observed the epoch, the server resolves against its authoritative job and + * still fences on `actionId`. */ + generationCreatedAt?: number; endpoint?: EModelEndpoint | string | null; endpointType?: EModelEndpoint | string | null; agent_id?: string | null; diff --git a/e2e/specs/mock/tool-approvals.spec.ts b/e2e/specs/mock/tool-approvals.spec.ts index 3a688b5467..4910b60e4e 100644 --- a/e2e/specs/mock/tool-approvals.spec.ts +++ b/e2e/specs/mock/tool-approvals.spec.ts @@ -463,6 +463,61 @@ test.describe('tool approvals', () => { } }); + test('submits a rehydrated approval when the status omits the generation epoch @scenario:approval-submit-without-epoch', async ({ + page, + }) => { + test.setTimeout(120000); + const label = uniqueLabel(); + const toolCallId = `call_e2e_approval_${label}`; + const originalValue = `original-${label}`; + const executedText = `E2E approval probe executed: ${originalValue}`; + let agentId: string | undefined; + let statusHandler: ((route: Route) => Promise) | undefined; + clearApprovalInvocations(originalValue); + + try { + agentId = await createAndSelectApprovalAgent(page); + await startApproval(page, label); + const conversationPath = new URL(page.url()).pathname; + + /** The status snapshot is where a reloaded page learns the generation epoch; + * without it the rehydrated card has no epoch to send. */ + let strippedEpochs = 0; + statusHandler = async (route) => { + const response = await route.fetch(); + const status = (await response.json()) as Record; + if (status.createdAt != null) { + strippedEpochs++; + } + delete status.createdAt; + await route.fulfill({ response, json: status }); + }; + await page.route('**/api/agents/chat/status/**', statusHandler); + + await page.reload({ waitUntil: 'domcontentloaded' }); + await expect.poll(() => new URL(page.url()).pathname).toBe(conversationPath); + await collapseComposerApproval(page); + const card = approvalCard(page, toolCallId); + await expect(card).toBeVisible({ timeout: 30000 }); + expect(strippedEpochs).toBeGreaterThan(0); + + await card.getByRole('button', { name: 'Approve' }).click(); + const { body } = await submitAndCapture(page, card.getByRole('button', { name: 'Submit' })); + expect(body.actionId).toBeTruthy(); + expect(body.conversationId).toBe(conversationPath.replace('/c/', '')); + expect(body).not.toHaveProperty('generationCreatedAt'); + await expectCompletedApprovalToolOutput(page, toolCallId, executedText); + await expectApprovalInvocationCount(originalValue, 1); + await expect(approvalCards(page)).toHaveCount(0); + } finally { + if (statusHandler) { + await page.unroute('**/api/agents/chat/status/**', statusHandler); + } + clearApprovalInvocations(originalValue); + await cleanupAgent(page, agentId); + } + }); + test('sends only one resume request for two synchronous submit clicks', async ({ page }) => { test.setTimeout(120000); const label = uniqueLabel();