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:
@@ -153,6 +153,39 @@ public sealed class StreamAnalyzerTests
|
||||
Assert.Empty(analyzer.GetResult().Blocks);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Extracts_Terminal_Reason_And_Errors_For_Max_Turns()
|
||||
{
|
||||
var analyzer = new StreamAnalyzer();
|
||||
analyzer.ProcessLine("""{"type":"result","subtype":"error_max_turns","terminal_reason":"max_turns","errors":["Reached maximum number of turns (30)"],"session_id":"s1"}""");
|
||||
var result = analyzer.GetResult();
|
||||
Assert.Equal("max_turns", result.TerminalReason);
|
||||
Assert.Equal("error_max_turns", result.ResultSubtype);
|
||||
Assert.Single(result.Errors);
|
||||
Assert.Equal("Reached maximum number of turns (30)", result.Errors[0]);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Extracts_Terminal_Reason_And_Result_Text_For_Api_Error()
|
||||
{
|
||||
var analyzer = new StreamAnalyzer();
|
||||
analyzer.ProcessLine("""{"type":"result","terminal_reason":"api_error","result":"You've hit your session limit – resets 1pm (Europe/Berlin)","session_id":"s1"}""");
|
||||
var result = analyzer.GetResult();
|
||||
Assert.Equal("api_error", result.TerminalReason);
|
||||
Assert.Contains("session limit", result.ResultMarkdown);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void No_Terminal_Reason_Fields_Means_Null_And_Empty()
|
||||
{
|
||||
var analyzer = new StreamAnalyzer();
|
||||
analyzer.ProcessLine("""{"type":"result","result":"done","session_id":"s1"}""");
|
||||
var result = analyzer.GetResult();
|
||||
Assert.Null(result.TerminalReason);
|
||||
Assert.Null(result.ResultSubtype);
|
||||
Assert.Empty(result.Errors);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Duplicate_Marker_In_Assistant_And_Result_Is_Collected_Once()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user