mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-11-24 14:20:12 +01:00
Fence idle receipts across worker lifecycle changes
Invalidate scans when a worker changes state and discard old local holds before a new controller attempt, even without an intervening normal call. Recheck live worker identity and status after the parallel drain. Verified 44 focused SDK, process-boundary and persisted-work tests, including repeated idle ownership without an explicit worker release. Co-Authored-By: Paperclip <noreply@paperclip.ing>
This commit is contained in:
1 parent
70ef58a726
commit
7ad01714d2
2 files changed
+11
-1
No files matched your search
@@ -33,6 +33,11 @@ describe("plugin manager idle receipts", () => {
|
||||
expect(await handle.prepareIdleSleep!({ ...lease, ownerId: "stale" })).toBe("unknown");
|
||||
stopTaskDrain(); handle.releaseIdleSleep!();
|
||||
expect(await handle.call("health", {})).toMatchObject({ status: "ok" });
|
||||
expect(await handle.prepareIdleSleep!(hold())).toBe("none");
|
||||
stopTaskDrain();
|
||||
// No intervening request or explicit worker release: the next controller
|
||||
// attempt must discard the worker manager's previous ownership record.
|
||||
expect(await handle.prepareIdleSleep!(hold())).toBe("none");
|
||||
} finally { stopTaskDrain(); await handle.stop(); }
|
||||
});
|
||||
|
||||
|
||||
@@ -1049,6 +1049,8 @@ export function createPluginWorkerHandle(
|
||||
// -----------------------------------------------------------------------
|
||||
|
||||
function setStatus(newStatus: WorkerStatus): void {
|
||||
const done = beginIdleTrackedWork();
|
||||
done();
|
||||
const prev = status;
|
||||
if (prev === newStatus) return;
|
||||
status = newStatus;
|
||||
@@ -3455,6 +3457,9 @@ export function createPluginWorkerHandle(
|
||||
const drain = readTaskDrain(new Date());
|
||||
if (drain?.ownerId !== hold.ownerId || drain.expiresAt?.getTime() !== hold.expiresAt ||
|
||||
hold.expiresAt <= Date.now()) return "unknown";
|
||||
// Clear a previous hold even when this idle worker received no ordinary
|
||||
// call between two controller attempts.
|
||||
idleSleepHeld();
|
||||
if (status !== "running" || totalCrashes > 0) return "unknown";
|
||||
if (!supportedMethods.includes("prepareIdleSleep")) return "present";
|
||||
if (unsettledCalls.size || activeHostHandlers || loginPtyRoutesByHostRouteId.size ||
|
||||
@@ -3722,7 +3727,7 @@ export function createPluginWorkerManager(
|
||||
const snapshot = [...workers.entries()];
|
||||
const results = await Promise.all(snapshot.map(async ([, worker]) =>
|
||||
worker.prepareIdleSleep ? worker.prepareIdleSleep(hold) : "unknown"));
|
||||
if (startupLocks.size || snapshot.length !== workers.size || snapshot.some(([id, worker]) => workers.get(id) !== worker)) {
|
||||
if (startupLocks.size || snapshot.length !== workers.size || snapshot.some(([id, worker]) => workers.get(id) !== worker || worker.status !== "running")) {
|
||||
return { backgroundWork: "unknown", pluginIds: [] };
|
||||
}
|
||||
const backgroundWork = results.includes("present") ? "present" : results.includes("unknown") ? "unknown" : "none";
|
||||
|
||||
Reference in new issue
Block a user