| 314 | } |
| 315 | |
| 316 | func ExecuteAutoCompactWithRetry(ctx context.Context, messages []map[string]any, systemPrompt string, llmClientFunc LLMClientFunc) (string, error) { |
| 317 | currentMessages := deepcopy.Copy(messages).([]map[string]any) |
| 318 | for attempt := 0; attempt <= MaxPtlRetries; attempt++ { |
| 319 | summary, err := llmClientFunc(ctx, currentMessages, systemPrompt) |
| 320 | if err == nil { |
| 321 | return summary, nil |
| 322 | } |
| 323 | if !isPtlError(err) { |
| 324 | return "", err |
| 325 | } |
| 326 | if attempt >= MaxPtlRetries { |
| 327 | slog.Warn(fmt.Sprintf("PTL retry exhausted (%d attempts), giving up.", attempt+1)) |
| 328 | return "", errors.New("PTL retry exhausted") |
| 329 | } |
| 330 | slog.Warn(fmt.Sprintf("PTL error on auto compact attempt %d/%d: %s", attempt+1, MaxPtlRetries+1, err.Error())) |
| 331 | currentMessages = TruncateHeadForPtlRetry(ctx, currentMessages) |
| 332 | } |
| 333 | return "", errors.New("unreachable") |
| 334 | } |
| 335 | |
| 336 | func RunPostCompactCleanUp(ctx context.Context, state any, recentReadFiles []map[string]string) { |
| 337 | if recentReadFiles == nil { |