Signal only expiry when an open decision is created

Co-Authored-By: Paperclip <noreply@paperclip.ing>
This commit is contained in:
DottaandPaperclip committed 2026-10-27 17:57:36 -05:00
1 parent f7c61e9912
commit aa03d2c4c2
5 files changed
+57 -6

No files matched your search

+21 -2
View File
@@ -7,8 +7,9 @@ recovery, and retention remain separate duties.
## Producers and transaction ownership
Creation and bundle creation notify before the decision insert in their existing
transaction. Existing decision updates share `notifyDecisionChange`, which now
Creation and bundle creation call `notifyDecisionCreated` before the decision
insert in their existing transaction. It signals expiry only: an open row cannot
owe continuation delivery yet. Existing decision updates share `notifyDecisionChange`, which now
signals expiry as well as continuation delivery. Cancellation, dismissal, and
execution claims therefore remove obsolete expiry deadlines. All production
inserts and updates are in the decision owner; acknowledgement only changes
@@ -156,3 +157,21 @@ scoped-deadline cases and server types/build pass with the rebuilt Runner vendor
The previous full 130-case selection remains evidence at its stated revision.
No migration SQL changed, and five generated snapshots remain. Fresh head CI
and reviews are required after this parent integration.
## Creation notification review repair
Single and bundle creation previously notified continuation recovery even though
the inserted decision was open. Two real producer regressions failed before
repair because continuation received intent and settlement. Creation now uses the
existing central notification file's expiry-only `notifyDecisionCreated` helper.
Update and terminal transitions keep `notifyDecisionChange`, including the normal
continuation signal. No optional flags, per-route bookkeeping or new table is
needed. Both regressions verify the exact future expiry, no early wake, and a
subsequent cancellation that still signals and delivers continuation normally.
All 117 current expiry/decision/startup/deadline cases pass, including 20 expiry
cases. Server types/build pass. The preceding f7 candidate's identical-tree
merge proof remains history; this subsequent creation-signal repair changes
runtime behavior and has its own acceptance above. Fresh current-head CI and
both reviews are required.
@@ -16,7 +16,7 @@ Do not mark an item done from a timer removal or a green check alone.
| 02 | Remaining chat maintenance | Provider runtime discovery; voice reconciliation; milestones; wake notices; interaction continuations; terminal confirmations; GitHub recovery; Teams maintenance, separately by owner | Pending |
| 03 | Run and task recovery | Orphan runs and active leases; shutdown workspace settlement; scheduled retries; queued runs; stranded assignments; resolved dependencies; task watchdogs; silent-run monitoring; stale locks | Pending |
| 04 | Decision retention and notifications | Retention deadlines and notification delivery are separate reasons | Retention pending; archive delivery [#17475](https://github.com/paperclipai/paperclip/pull/17475) merged after exact-head 5/5 reviews and passing current CI |
| 05 | Decision expiry and interrupted effects | Expiry, effect recovery, continuation recovery | Continuations [#17478](https://github.com/paperclipai/paperclip/pull/17478), expiry [#17479](https://github.com/paperclipai/paperclip/pull/17479), and effects [#17482](https://github.com/paperclipai/paperclip/pull/17482) await fresh current-head gates; target invalidation review repair remains in progress |
| 05 | Decision expiry and interrupted effects | Expiry, effect recovery, continuation recovery | Continuations [#17478](https://github.com/paperclipai/paperclip/pull/17478) merged; expiry [#17479](https://github.com/paperclipai/paperclip/pull/17479), effects [#17482](https://github.com/paperclipai/paperclip/pull/17482), and targets [#17486](https://github.com/paperclipai/paperclip/pull/17486) await current-head review/CI gates |
| 06 | Tool connection health | Configuration/use activation and defined proactive health deadlines | Pending |
| 07 | Secret proposals, tool reviews, gateway tokens | Separate expiry/scrub/recovery owners | Slices 02–07 merged: [secret proposals](https://github.com/paperclipai/paperclip/pull/17446), [credentials](https://github.com/paperclipai/paperclip/pull/17450), [review expiry](https://github.com/paperclipai/paperclip/pull/17453), [approved recovery](https://github.com/paperclipai/paperclip/pull/17454), [interrupted claims](https://github.com/paperclipai/paperclip/pull/17458), [projection](https://github.com/paperclipai/paperclip/pull/17468) |
@@ -522,3 +522,8 @@ deadline cases, server types/build and migration replay. The parent continuation
coalescing and deterministic cross-pool contention regression remain intact.
The archive parent now targets master after projection #17468 merged. Fresh
current-head reviews and CI remain required in dependency order.
Slice 10 creation signal follow-up: single and bundle creation now notify expiry
only through the central owner. Terminal updates still signal continuation. Both
real regressions failed before repair; all 117 current expiry/decision/startup/
deadline cases, server types and build pass. Fresh CI/reviews remain required.
@@ -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);
+2 -2
View File
@@ -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,