fix: hard-abort clears queues on /stop

This commit is contained in:
Peter Steinberger
2026-01-16 21:15:25 +00:00
parent d887027e95
commit 9072e35f08
10 changed files with 184 additions and 13 deletions

View File

@@ -0,0 +1,27 @@
import { resolveEmbeddedSessionLane } from "../../../agents/pi-embedded.js";
import { clearCommandLane } from "../../../process/command-queue.js";
import { clearFollowupQueue } from "./state.js";
export type ClearSessionQueueResult = {
followupCleared: number;
laneCleared: number;
keys: string[];
};
export function clearSessionQueues(keys: Array<string | undefined>): ClearSessionQueueResult {
const seen = new Set<string>();
let followupCleared = 0;
let laneCleared = 0;
const clearedKeys: string[] = [];
for (const key of keys) {
const cleaned = key?.trim();
if (!cleaned || seen.has(cleaned)) continue;
seen.add(cleaned);
clearedKeys.push(cleaned);
followupCleared += clearFollowupQueue(cleaned);
laneCleared += clearCommandLane(resolveEmbeddedSessionLane(cleaned));
}
return { followupCleared, laneCleared, keys: clearedKeys };
}

View File

@@ -55,3 +55,18 @@ export function getFollowupQueue(key: string, settings: QueueSettings): Followup
FOLLOWUP_QUEUES.set(key, created);
return created;
}
export function clearFollowupQueue(key: string): number {
const cleaned = key.trim();
if (!cleaned) return 0;
const queue = FOLLOWUP_QUEUES.get(cleaned);
if (!queue) return 0;
const cleared = queue.items.length + queue.droppedCount;
queue.items.length = 0;
queue.droppedCount = 0;
queue.summaryLines = [];
queue.lastRun = undefined;
queue.lastEnqueuedAt = 0;
FOLLOWUP_QUEUES.delete(cleaned);
return cleared;
}