| 1 | package cli |
| 2 | |
| 3 | import ( |
| 4 | "context" |
| 5 | "errors" |
| 6 | |
| 7 | "reasonix/internal/agent" |
| 8 | "reasonix/internal/event" |
| 9 | ) |
| 10 | |
| 11 | type runCompletion struct { |
| 12 | outcome string |
| 13 | subtype string |
| 14 | // class is the benchmark-facing failure taxonomy. It names which guard or |
| 15 | // transport ended the run and never affects the exit code or wire outcome. |
| 16 | class string |
| 17 | isError bool |
| 18 | exitCode int |
| 19 | } |
| 20 | |
| 21 | func classifyRunCompletion(err error) runCompletion { |
| 22 | if err == nil { |
| 23 | return runCompletion{subtype: "success", class: "success"} |
| 24 | } |
| 25 | var pauseErr *agent.RecoveryPauseError |
| 26 | if errors.As(err, &pauseErr) { |
| 27 | return runCompletion{ |
| 28 | outcome: event.TurnOutcomeRecoveryPaused, |
| 29 | subtype: event.TurnOutcomeRecoveryPaused, |
| 30 | class: event.TurnOutcomeRecoveryPaused, |
| 31 | exitCode: 0, |
| 32 | } |
| 33 | } |
| 34 | return runCompletion{ |
| 35 | subtype: "error_during_execution", |
| 36 | class: runFailureClass(err), |
| 37 | isError: true, |
| 38 | exitCode: 1, |
| 39 | } |
| 40 | } |
| 41 | |
| 42 | func runFailureClass(err error) string { |
| 43 | if class := agent.PauseClass(err); class != "" { |
| 44 | return class |
| 45 | } |
| 46 | switch { |
| 47 | case errors.Is(err, context.DeadlineExceeded): |
| 48 | return "timeout" |
| 49 | case errors.Is(err, context.Canceled): |
| 50 | return "cancelled" |
| 51 | } |
| 52 | return "error_during_execution" |
| 53 | } |
| 54 |