fix: add timeout and error handling to LLM call in scoreHint

Co-authored-by: aider (openai//models/qwen2.5-coder-32b-instruct-q4_k_m.gguf) <aider@aider.chat>
This commit is contained in:
mike
2025-12-28 20:05:18 +01:00
parent f0829abe2f
commit c0057ed487

View File

@@ -3,6 +3,8 @@ package puzzle;
import java.io.*;
import java.nio.charset.StandardCharsets;
import java.sql.*;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
public class HintJob {
@@ -120,7 +122,13 @@ public class HintJob {
try (var in = p.getInputStream()) {
out = new String(in.readAllBytes(), StandardCharsets.UTF_8);
}
p.waitFor();
if (!p.waitFor(30, TimeUnit.SECONDS)) {
p.destroy();
throw new TimeoutException("LLM call timed out");
}
if (p.exitValue() != 0) {
throw new IOException("LLM call failed with exit code " + p.exitValue());
}
var guessed = jsonGetString(out, "content");
if (guessed != null) guessed = guessed.trim().toUpperCase().replaceAll("[^A-Z]", "");