feat(forwarder): make checkpoint recovery idempotent

Preserve interrupted provider output, keep checkpoint projections deterministic, and enforce proto snapshot synchronization.
This commit is contained in:
leokun
2026-08-06 21:08:43 +08:00
parent 0d1cedda5b
commit 2e265d415e
13 changed files with 6059 additions and 3618 deletions
+12
View File
@@ -690,9 +690,21 @@ func appendEntriesInPlace(conversation *ConversationFile, entries []HistoryEntry
}
now := time.Now().UTC()
assigned := make([]HistoryEntry, 0, len(entries))
existingIdempotencyKeys := make(map[string]struct{})
for _, existing := range conversation.Entries {
if key := strings.TrimSpace(existing.IdempotencyKey); key != "" {
existingIdempotencyKeys[key] = struct{}{}
}
}
maxTurnSeq := conversation.NextTurnSeq - 1
for _, entry := range entries {
next := entry
if key := strings.TrimSpace(next.IdempotencyKey); key != "" {
if _, exists := existingIdempotencyKeys[key]; exists {
continue
}
existingIdempotencyKeys[key] = struct{}{}
}
if next.CreatedAt.IsZero() {
next.CreatedAt = now
}