mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-12-06 07:38:47 +01:00
Signal only expiry when an open decision is created
Co-Authored-By: Paperclip <noreply@paperclip.ing>
This commit is contained in:
1 parent
f7c61e9912
commit
aa03d2c4c2
5 files changed
+57
-6
No files matched your search
@@ -1,7 +1,7 @@
|
||||
import { randomUUID } from "node:crypto";
|
||||
import { eq, sql } from "drizzle-orm";
|
||||
import { afterAll, afterEach, beforeAll, beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import { activityLog, agents, companies, createDb, decisionBundles, decisionEffectExecutions, decisions,
|
||||
import { activityLog, agents, companies, createDb, subscribeDatabaseWork, decisionBundles, decisionEffectExecutions, decisions,
|
||||
decisionTargetIssues, heartbeatRuns, issues } from "@paperclipai/db";
|
||||
import { getEmbeddedPostgresTestSupport, startEmbeddedPostgresTestDatabase } from "./helpers/embedded-postgres.js";
|
||||
import { resolveExternalTestDatabaseUrl } from "./helpers/external-test-database.js";
|
||||
@@ -10,6 +10,7 @@ import { registerDecisionExpiryWork } from "../services/decision-expiry-work.js"
|
||||
import { registerDecisionContinuationWork } from "../services/decision-continuation-work.js";
|
||||
import { createDeliveryWorkCoordinator } from "../services/delivery-work-coordinator.js";
|
||||
import { idleWorkSnapshot } from "../services/task-admission.js";
|
||||
import { DELIVERY_QUEUES } from "../services/delivery-work-notifications.js";
|
||||
|
||||
const externalUrl = resolveExternalTestDatabaseUrl("PAPERCLIP_DECISION_EXPIRY_TEST_DATABASE_URL");
|
||||
const support = externalUrl ? { supported: true } : await getEmbeddedPostgresTestSupport();
|
||||
@@ -96,6 +97,28 @@ const support = externalUrl ? { supported: true } : await getEmbeddedPostgresTes
|
||||
expect(await db.select().from(activityLog).where(eq(activityLog.action, "decision.expired"))).toHaveLength(1);
|
||||
});
|
||||
|
||||
it.each(["single", "bundle"] as const)("arms expiry without waking continuation recovery for %s creation", async mode => {
|
||||
await start(); await quiet();
|
||||
const events: string[] = [];
|
||||
const unsubscribe = subscribeDatabaseWork(db, DELIVERY_QUEUES.decisionContinuation, event => { events.push(event); });
|
||||
try {
|
||||
const deadline = new Date(Date.now() + 120_000);
|
||||
const row = mode === "single" ? await create(deadline) : (await service().createBundle({
|
||||
companyId, actor: actor(), agentId, runId, title: "Bundle", summary: "Summary", decisions: [input(deadline)],
|
||||
})).decisions[0];
|
||||
expect(events).toEqual([]);
|
||||
await vi.waitFor(async () => {
|
||||
await vi.advanceTimersByTimeAsync(1);
|
||||
expect(coordinator!.nextWakeAt()).toBe(deadline.getTime());
|
||||
});
|
||||
expect(wake).not.toHaveBeenCalled();
|
||||
await service().cancel(row.id, { actorType: "agent", actorId: agentId });
|
||||
await quiet();
|
||||
expect(events).toEqual(["intent", "settled"]);
|
||||
expect(wake).toHaveBeenCalledTimes(1);
|
||||
} finally { unsubscribe(); }
|
||||
});
|
||||
|
||||
it("honors the configured expiry batch size", async () => {
|
||||
vi.stubEnv("PAPERCLIP_DECISIONS_SWEEP_BATCH_SIZE", "2");
|
||||
const seed = await create(); await db.delete(decisions).where(eq(decisions.id, seed.id));
|
||||
|
||||
@@ -1,6 +1,10 @@
|
||||
import type { Db } from "@paperclipai/db";
|
||||
import { DELIVERY_QUEUES, notifyDeliveryWork } from "./delivery-work-notifications.js";
|
||||
|
||||
export function notifyDecisionCreated(transaction: object) {
|
||||
return notifyDeliveryWork(transaction, DELIVERY_QUEUES.decisionExpiry);
|
||||
}
|
||||
|
||||
export async function notifyDecisionChange(transaction: object) {
|
||||
await notifyDeliveryWork(transaction, DELIVERY_QUEUES.decisionContinuation);
|
||||
await notifyDeliveryWork(transaction, DELIVERY_QUEUES.decisionExpiry);
|
||||
|
||||
@@ -16,7 +16,7 @@ import { decisionRetentionService, hashAttentionArchiveManifest } from "./decisi
|
||||
|
||||
import { decisionContinuationService, type DecisionContinuationWake } from "./decision-continuations.js";
|
||||
import { decisionExpiryService } from "./decision-expiry.js";
|
||||
import { notifyDecisionChange, writeDecisionChange } from "./decision-work-notifications.js";
|
||||
import { notifyDecisionCreated, writeDecisionChange } from "./decision-work-notifications.js";
|
||||
|
||||
type Snapshot = { status: string; assigneeAgentId: string | null; assigneeUserId: string | null; updatedAt: string;
|
||||
descendantCount?: number; descendantIds?: string[]; childCount?: number; attentionArchive?: unknown };
|
||||
@@ -235,7 +235,7 @@ export function decisionService(db: Db, options: DecisionServiceOptions) {
|
||||
...(input.additionalTargetSnapshots ?? {}),
|
||||
};
|
||||
const id = randomUUID();
|
||||
await notifyDecisionChange(dbOrTx);
|
||||
await notifyDecisionCreated(dbOrTx);
|
||||
const [created] = await dbOrTx.insert(decisions).values({ id, companyId: input.companyId, bundleId: input.bundleId ?? null,
|
||||
originAgentId: input.agentId, originIssueId: provenance.issueId, originRunId: input.runId, ruleKey: input.ruleKey ?? null,
|
||||
title: input.title, body: input.body, options: input.options, inputs: input.inputs ?? null, expiresAt,
|
||||
|
||||
Reference in new issue
Block a user