mirror of
https://github.com/danny-avila/LibreChat.git
synced 2026-11-21 15:33:45 +00:00
✅ fix: Submit Tool Approvals When the Generation Epoch Is Unknown (#17928)
* 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
This commit is contained in:
parent
93f0563153
commit
cbc7d94f6b
4 changed files with 81 additions and 11 deletions
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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', () => {
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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<void>) | 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<string, unknown>;
|
||||
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();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue