fix: harden restart recovery flow

This commit is contained in:
Eyejoker
2026-03-23 01:00:14 +09:00
parent a1324726b1
commit 28eb8c6cb1
6 changed files with 226 additions and 38 deletions

View File

@@ -30,6 +30,14 @@ export interface InferredRestartContext {
lines: string[];
}
export interface RestartRecoveryCandidate {
chatJid: string;
groupFolder: string;
status: RestartInterruptedGroup['status'];
pendingMessages: boolean;
pendingTasks: number;
}
const INFER_WINDOW_MS = 3 * 60 * 1000;
function getRestartContextPath(serviceId: string = SERVICE_ID): string {
@@ -229,6 +237,32 @@ export function buildRestartAnnouncement(context: RestartContext): string {
return lines.join('\n');
}
export function getInterruptedRecoveryCandidates(
context: RestartContext | null,
registeredGroups: Record<string, RegisteredGroup>,
): RestartRecoveryCandidate[] {
if (!context?.interruptedGroups?.length) return [];
const seen = new Set<string>();
const candidates: RestartRecoveryCandidate[] = [];
for (const interrupted of context.interruptedGroups) {
if (seen.has(interrupted.chatJid)) continue;
const group = registeredGroups[interrupted.chatJid];
if (!group) continue;
seen.add(interrupted.chatJid);
candidates.push({
chatJid: interrupted.chatJid,
groupFolder: group.folder,
status: interrupted.status,
pendingMessages: interrupted.pendingMessages,
pendingTasks: interrupted.pendingTasks,
});
}
return candidates;
}
export function inferRecentRestartContext(
registeredGroups: Record<string, RegisteredGroup>,
processStartedAtMs: number,