fix(worker): surface the real reason a Claude run failed instead of a generic exit-code message

StreamAnalyzer now reads subtype/terminal_reason/errors from the CLI's result
event, and TaskRunner builds a specific ErrorMarkdown from them: max_turns names
the turn budget and points at set_task_config + requeue, api_error passes
through the provider's own message (which carries the reset time), and any
other terminal_reason is appended to the previous generic text instead of
staying invisible. Falls through to the old "exited with code N and no result"
text when there's no terminal_reason at all (a real crash).
This commit is contained in:
mika kuns
2026-08-05 15:55:09 +02:00
parent 83ea429b8a
commit 2ebdadff08
6 changed files with 298 additions and 1 deletions
+25
View File
@@ -352,6 +352,9 @@ public sealed class TaskRunner
},
ct);
if (!result.IsSuccess)
result = result with { ErrorMarkdown = BuildFailureMarkdown(result, config.MaxTurns) };
// Update the run record with results. Use CancellationToken.None:
// this is a terminal write that must always complete, even if the
// caller's token is already cancelled.
@@ -597,6 +600,28 @@ public sealed class TaskRunner
return string.Join("\n\n", trimmed);
}
public static string? BuildFailureMarkdown(RunResult result, int? configuredMaxTurns)
{
switch (result.TerminalReason)
{
case "max_turns":
var ofConfigured = configuredMaxTurns is int m ? $" von {m}" : "";
return $"Turn-Budget erschöpft ({result.TurnCount}{ofConfigured} Turns). "
+ "Erhöhe `maxTurns` am Task (`set_task_config`) und stelle den Task erneut in die Queue "
+ " der Worktree bleibt erhalten.";
case "api_error":
if (!string.IsNullOrWhiteSpace(result.ResultMarkdown)) return result.ResultMarkdown;
if (result.Errors.Count > 0) return string.Join(" ", result.Errors);
return result.ErrorMarkdown;
default:
return string.IsNullOrWhiteSpace(result.TerminalReason)
? result.ErrorMarkdown
: $"{result.ErrorMarkdown} (terminal_reason: {result.TerminalReason})";
}
}
public static string BuildRetryPrompt(string? capturedError)
{
var basePrompt = PromptFiles.ReadOrDefault(PromptKind.Retry);