mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-11-24 14:20:12 +01:00
Resume plugin crash recovery after idle holds
Keep a crashed worker's retry scheduled while an idle hold is active. Accepted startup work remains tracked instead of failing permanently. A recovered worker still cannot prove lost completion receipts. Verified all three real-process idle tests, including crash recovery through a hold and service restoration after release. Co-Authored-By: Paperclip <noreply@paperclip.ing>
This commit is contained in:
1 parent
7ad01714d2
commit
6a770ce096
3 files changed
+26
-3
No files matched your search
@@ -14,6 +14,7 @@ void Promise.all([
|
||||
return { status: "ok" };
|
||||
},
|
||||
async onEnvironmentProbe(params) {
|
||||
if (params.config.crash) process.exit(1);
|
||||
await new Promise((resolve) => setTimeout(resolve, params.config.delayMs));
|
||||
return { ok: true, summary: "fixture complete" };
|
||||
},
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { fileURLToPath } from "node:url";
|
||||
import { createRequire } from "node:module";
|
||||
import { setTimeout as delay } from "node:timers/promises";
|
||||
import { afterEach, describe, expect, it } from "vitest";
|
||||
import { createPluginWorkerHandle } from "../services/plugin-worker-manager.js";
|
||||
import { startTaskDrain, stopTaskDrain } from "../services/task-admission.js";
|
||||
@@ -53,4 +54,20 @@ describe("plugin manager idle receipts", () => {
|
||||
await expect.poll(() => handle.prepareIdleSleep!(lease)).toBe("none");
|
||||
} finally { stopTaskDrain(); await handle.stop(); }
|
||||
});
|
||||
|
||||
it("resumes crash recovery after an idle hold without discarding the restart", async () => {
|
||||
const handle = worker();
|
||||
await handle.start();
|
||||
handle.on("crash", () => { hold(); });
|
||||
try {
|
||||
await expect(handle.call("environmentProbe", { driverKey: "fixture", companyId: "fixture", environmentId: "fixture", config: { crash: true } })).rejects.toThrow();
|
||||
await delay(1_600);
|
||||
expect(handle.status).toBe("backoff");
|
||||
expect(handle.diagnostics().nextRestartAt).not.toBeNull();
|
||||
stopTaskDrain();
|
||||
await expect.poll(() => handle.status, { timeout: 5_000 }).toBe("running");
|
||||
// Recovery restores service, but lost completion receipts remain unsafe.
|
||||
expect(await handle.prepareIdleSleep!(hold())).toBe("unknown");
|
||||
} finally { stopTaskDrain(); await handle.stop(); }
|
||||
});
|
||||
});
|
||||
@@ -1049,10 +1049,10 @@ export function createPluginWorkerHandle(
|
||||
// -----------------------------------------------------------------------
|
||||
|
||||
function setStatus(newStatus: WorkerStatus): void {
|
||||
const done = beginIdleTrackedWork();
|
||||
done();
|
||||
const prev = status;
|
||||
if (prev === newStatus) return;
|
||||
const done = beginIdleTrackedWork();
|
||||
done();
|
||||
status = newStatus;
|
||||
log.debug({ from: prev, to: newStatus }, "worker status change");
|
||||
emitter.emit("status", { pluginId, status: newStatus, previousStatus: prev });
|
||||
@@ -3121,6 +3121,12 @@ export function createPluginWorkerHandle(
|
||||
backoffTimer = setTimeout(async () => {
|
||||
backoffTimer = null;
|
||||
nextRestartAt = null;
|
||||
// A temporary idle hold must not consume the crash-recovery attempt.
|
||||
// Keep the bounded backoff until admission reopens.
|
||||
if (readTaskDrain(new Date())?.ownerId) {
|
||||
scheduleRestart();
|
||||
return;
|
||||
}
|
||||
try {
|
||||
await startInternal();
|
||||
} catch (err) {
|
||||
@@ -3145,7 +3151,6 @@ export function createPluginWorkerHandle(
|
||||
// -----------------------------------------------------------------------
|
||||
|
||||
async function startInternal(): Promise<void> {
|
||||
if (readTaskDrain(new Date())?.ownerId) throw new Error("Plugin start is held for idle sleep");
|
||||
if (status === "running" || status === "starting") {
|
||||
throw new Error(`Worker for plugin "${pluginId}" is already ${status}`);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user