mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-12-06 07:38:47 +01:00
Preserve failed retry notices over restored-input wake repair
Normal merge keeps the complete tested slice and adopts the parent transaction notification for restored ordinary input. Focused combined-producer verification follows. Co-Authored-By: Paperclip <noreply@paperclip.ing>
This commit is contained in:
commit
1caa4c1901
3 files changed
+100
No files matched your search
@@ -8,6 +8,7 @@ import { cloudActorHeaderSourceFromHeaders, resolveCloudTenantActor } from "../m
|
||||
import { cloudTenantPrimaryCompanyId } from "../services/cloud-instance.js";
|
||||
import { accessService } from "../services/access.js";
|
||||
import { signalDatabaseWork, subscribeDatabaseWork } from "@paperclipai/db";
|
||||
import { claimTaskRetryInput, releaseUnadmittedTaskRetryInput } from "../services/chat-channels/task-retry-input.js";
|
||||
import { restoreNativeChatReviewPresentationInTransaction } from "../services/native-runtime/native-chat-review-presentation.js";
|
||||
import { notifyChatEndpointConfiguration, notifyChatCompanyConfiguration } from "../services/chat-channels/configuration-work-notifications.js";
|
||||
import { deleteCompany } from "../services/company-deletion.js";
|
||||
@@ -74382,6 +74383,63 @@ describeEmbeddedPostgres("chat channel control-plane integration", () => {
|
||||
}
|
||||
});
|
||||
|
||||
it("reactivates restored ordinary input after an earlier Retry notice wake is consumed", async () => {
|
||||
const context = await deferredChatQueueFixture();
|
||||
const retryId = randomUUID(), intentId = randomUUID();
|
||||
const scope = { companyId: context.fixture.companyId, issueId: context.conversation.issueId };
|
||||
const errors: unknown[] = [], events: string[] = [];
|
||||
const coordinator = createDeliveryWorkCoordinator({ owner: db, canRun: () => true,
|
||||
canReconcile: () => true, onError: error => errors.push(error) });
|
||||
let unsubscribe = () => {};
|
||||
try {
|
||||
const [receipt] = await readAgentWakeupRequestsById(context.action.id);
|
||||
await db.insert(chatActions).values({ ...context.action, id: retryId,
|
||||
kind: "failed_run_retry", status: "failed", providerActionId: `task-retry-restore:${retryId}`,
|
||||
payload: { issueId: scope.issueId, taskRetryIntentId: intentId },
|
||||
});
|
||||
await db.insert(agentWakeupRequests).values({ ...receipt, id: retryId, status: "failed",
|
||||
idempotencyKey: `task-retry-restore:${retryId}`,
|
||||
});
|
||||
await db.transaction(tx => claimTaskRetryInput(tx, { companyId: scope.companyId,
|
||||
retryActionId: retryId, sourceActionIds: [context.action.id] }));
|
||||
expect((await readAgentWakeupRequestsById(context.action.id))[0]).toMatchObject({
|
||||
status: "coalesced", runId: null, payload: { coalescedIntoWakeupRequestId: retryId },
|
||||
});
|
||||
vi.useFakeTimers({ toFake: ["Date", "setTimeout", "clearTimeout"], shouldAdvanceTime: true });
|
||||
const settle = async () => vi.waitFor(async () => {
|
||||
await vi.advanceTimersByTimeAsync(1000);
|
||||
expect(idleWorkSnapshot().active).toBe(0); expect(coordinator.nextWakeAt()).toBeNull();
|
||||
}, { timeout: 10_000 });
|
||||
await chatInboundWakeNoticeWork(context.service).register(coordinator, () => true).ready;
|
||||
await db.transaction(tx => signalDatabaseWork(tx, DELIVERY_QUEUES.chatInboundWakeNotices, JSON.stringify(scope)));
|
||||
await settle();
|
||||
expect(await readChatPublicationsByEndpointId(context.endpoint.id)).toEqual([]);
|
||||
const select = vi.spyOn(db, "select"), transaction = vi.spyOn(db, "transaction");
|
||||
try {
|
||||
await vi.advanceTimersByTimeAsync(120_000);
|
||||
expect(select).not.toHaveBeenCalled(); expect(transaction).not.toHaveBeenCalled();
|
||||
} finally { select.mockRestore(); transaction.mockRestore(); }
|
||||
unsubscribe = subscribeDatabaseWork(db, DELIVERY_QUEUES.chatInboundWakeNotices, (event, scopes) => {
|
||||
if ([...scopes ?? []].some(value => value !== "*" && JSON.parse(value).companyId === scope.companyId)) events.push(event);
|
||||
});
|
||||
await releaseUnadmittedTaskRetryInput(db, { companyId: scope.companyId, retryActionId: retryId });
|
||||
expect((await readAgentWakeupRequestsById(context.action.id))[0]).toMatchObject({ status: "deferred_issue_execution", runId: null });
|
||||
expect(events).toContain("intent"); expect(events).toContain("settled");
|
||||
await vi.waitFor(async () => {
|
||||
await vi.advanceTimersByTimeAsync(1000);
|
||||
expect(await readChatPublicationsByEndpointId(context.endpoint.id)).toEqual([expect.objectContaining({
|
||||
commentId: context.action.payload.commentId, payload: { text: "Your follow-up is queued.", progressState: "queued" },
|
||||
})]);
|
||||
expect(coordinator.nextWakeAt()).toBeNull(); expect(idleWorkSnapshot().active).toBe(0);
|
||||
}, { timeout: 10_000 });
|
||||
expect(errors).toEqual([]);
|
||||
} finally {
|
||||
unsubscribe(); await coordinator.stop(); vi.useRealTimers(); await context.service.shutdown();
|
||||
await db.delete(chatActions).where(eq(chatActions.id, retryId));
|
||||
await db.delete(agentWakeupRequests).where(eq(agentWakeupRequests.id, retryId));
|
||||
}
|
||||
});
|
||||
|
||||
it("isolates pre-run FIFO reconciliation scopes and exhausts published history", async () => {
|
||||
const first = await deferredChatQueueFixture();
|
||||
const second = await deferredChatQueueFixture();
|
||||
|
||||
@@ -2,6 +2,7 @@ import { z } from "zod";
|
||||
import { and, asc, eq, gt, inArray, isNull, or, sql } from "drizzle-orm";
|
||||
import { agentWakeupRequests, chatActions, chatConversations, chatEndpoints, heartbeatRuns, issues, type Db } from "@paperclipai/db";
|
||||
import type { DbOrTransaction } from "./runtime-types.js";
|
||||
import { notifyChatInboundWakeNotices } from "../chat-inbound-wake-notice-notifications.js";
|
||||
|
||||
export const taskRetryInputSchema = z.object({
|
||||
// This is a server-selected snapshot of the durable queue, not client input.
|
||||
@@ -89,6 +90,7 @@ export async function releaseUnadmittedTaskRetryInput(db: Db, input: { companyId
|
||||
eq(agentWakeupRequests.companyId, input.companyId), eq(agentWakeupRequests.id, input.retryActionId),
|
||||
)).for("update");
|
||||
if (receipt?.runId) return;
|
||||
await notifyChatInboundWakeNotices(tx, { companyId: input.companyId, issueId: issue.id });
|
||||
await tx.update(agentWakeupRequests).set({ status: "deferred_issue_execution", finishedAt: null,
|
||||
payload: sql`${agentWakeupRequests.payload} - 'coalescedIntoWakeupRequestId'`, updatedAt: new Date(),
|
||||
}).where(and(eq(agentWakeupRequests.companyId, input.companyId), eq(agentWakeupRequests.status, "coalesced"),
|
||||
|
||||
Reference in new issue
Block a user