Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 27 additions & 13 deletions src/orchestrator/checkpoint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,15 +84,29 @@ export class CheckpointManager {

checkpoint.updatedAt = new Date().toISOString()

try {
writeFileSync(tempPath, JSON.stringify(checkpoint, null, 2))
renameSync(tempPath, path)
} catch (e) {
let lastError: any

// Windows often locks files briefly (EPERM/EBUSY), so we retry a few times
for (let attempt = 0; attempt < 5; attempt++) {
try {
unlinkSync(tempPath)
} catch {}
throw e
writeFileSync(tempPath, JSON.stringify(checkpoint, null, 2))
renameSync(tempPath, path)
return // Success
} catch (e: any) {
lastError = e
if (e.code !== "EPERM" && e.code !== "EBUSY") {
break // Don't retry other errors
}
// Wait with exponential backoff: 50, 100, 200, 400, 800ms
await new Promise((resolve) => setTimeout(resolve, 50 * Math.pow(2, attempt)))
}
}

// If we get here, all retries failed or it was a non-retriable error
try {
unlinkSync(tempPath)
} catch { }
throw lastError
}

async flush(runId?: string): Promise<void> {
Expand Down Expand Up @@ -270,12 +284,12 @@ export class CheckpointManager {
evaluated: questions.filter((q) => q.phases.evaluate.status === "completed").length,
...(episodesTotal > 0
? {
indexingEpisodes: {
total: episodesTotal,
completed: episodesCompleted,
failed: episodesFailed,
},
}
indexingEpisodes: {
total: episodesTotal,
completed: episodesCompleted,
failed: episodesFailed,
},
}
: {}),
}
}
Expand Down