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]", "");