From c4d9011bdb8bc5ba4adfcd477048c93b1fb228b9 Mon Sep 17 00:00:00 2001 From: hanez Date: Sun, 19 Jul 2026 23:01:55 +0200 Subject: [PATCH] Show full AI error output instead of generic error message When an AI query fails (opencode exits non-zero), the bot previously sent a generic 'AI query failed (opencode exited with error)' message to IRC, discarding all useful output. Users had no way to diagnose why the query failed. Changes: - Redirect opencode's stderr into the capture pipe instead of /dev/null, so error messages that go to stderr are no longer lost. - On non-zero exit, include the actual captured output in the error message sent to IRC: 'AI error (exit N): ' (truncated to 4000 chars). If no output was captured, show 'AI error (exit N, no output)' instead. - Applied strip_formatting() to the error output before sending so ANSI codes and markdown don't leak into IRC. - Bumped VERSION to 0.34.3. --- CHANGELOG.md | 6 ++++++ zynk.c | 13 +++++++++---- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c860393..11ff400 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +2026.07.19 – Show full AI error output on failure. + +- AI error messages now include the actual opencode output instead of a generic "(opencode exited with error)" message. +- Captured stderr from opencode (previously sent to /dev/null) so error details are no longer lost. +- Version bumped to 0.34.3. + 2026.07.19 – Collapsed double spaces in `!forecast` and `!stock` responses - Collapsed double spaces in `!forecast` and `!stock` responses (e.g., when weather condition is empty). diff --git a/zynk.c b/zynk.c index 9fb0144..6e712fb 100644 --- a/zynk.c +++ b/zynk.c @@ -29,7 +29,7 @@ int asprintf(char **, const char *, ...); /* ---- constants ---- */ -#define VERSION "0.34.2" +#define VERSION "0.34.3" #define DEFAULT_SERVER "irc.libera.chat" #define OPENCODE_BIN "/usr/bin/opencode" #define CLR_RESET "\033[0m" @@ -1621,9 +1621,8 @@ static void ai_child_task(Session *s, long long id, const char *agent) { if (cmd_pid == 0) { close(ai_pipe[0]); dup2(ai_pipe[1], STDOUT_FILENO); + dup2(ai_pipe[1], STDERR_FILENO); close(ai_pipe[1]); - int dn = open("/dev/null", O_WRONLY); - if (dn >= 0) { dup2(dn, STDERR_FILENO); close(dn); } if (agent) execl(g_opencode_bin, "opencode", "run", "--dangerously-skip-permissions", "--agent", agent, combined, (char *)NULL); else @@ -1649,7 +1648,13 @@ static void ai_child_task(Session *s, long long id, const char *agent) { out[olen] = 0; int rc = WIFEXITED(status) ? WEXITSTATUS(status) : -1; if (rc != 0) { - ai_set_answer(id, "AI query failed (opencode exited with error)"); + char errmsg[4200]; + strip_formatting(out); + if (olen > 0) + snprintf(errmsg, sizeof errmsg, "AI error (exit %d): %.4000s", rc, out); + else + snprintf(errmsg, sizeof errmsg, "AI error (exit %d, no output)", rc); + ai_set_answer(id, errmsg); } else if (olen == 0) { ai_set_answer(id, "AI returned an empty response"); } else {