From c0057ed48796e33d3be6e0ed686f811aabdcac19 Mon Sep 17 00:00:00 2001 From: mike Date: Sun, 28 Dec 2025 20:05:18 +0100 Subject: [PATCH] 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) --- src/puzzle/HintJob.java | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/puzzle/HintJob.java b/src/puzzle/HintJob.java index cbd6ddd..6e9931e 100644 --- a/src/puzzle/HintJob.java +++ b/src/puzzle/HintJob.java @@ -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]", "");