feat: record task attempt chains

This commit is contained in:
2026-05-11 22:39:45 +08:00
parent 4c2de4b4c9
commit 0049b246c1
9 changed files with 492 additions and 9 deletions
@@ -722,6 +722,31 @@ WHERE reference_type = 'gateway_task'
if failoverTask.Task.Status != "succeeded" {
t.Fatalf("failover task should succeed through second client: %+v", failoverTask.Task)
}
var failoverDetail struct {
Attempts []struct {
AttemptNo int `json:"attemptNo"`
PlatformName string `json:"platformName"`
Status string `json:"status"`
Retryable bool `json:"retryable"`
ErrorCode string `json:"errorCode"`
ErrorMessage string `json:"errorMessage"`
ResponseMS int64 `json:"responseDurationMs"`
} `json:"attempts"`
Metrics map[string]any `json:"metrics"`
}
doJSON(t, server.URL, http.MethodGet, "/api/v1/tasks/"+failoverTask.Task.ID, apiKeyResponse.Secret, nil, http.StatusOK, &failoverDetail)
if len(failoverDetail.Attempts) != 2 {
t.Fatalf("failover task history should include two attempts, got %+v", failoverDetail.Attempts)
}
if failoverDetail.Attempts[0].PlatformName != "OpenAI Retryable Failure" || failoverDetail.Attempts[0].Status != "failed" || !failoverDetail.Attempts[0].Retryable || failoverDetail.Attempts[0].ErrorCode == "" {
t.Fatalf("first failover attempt should preserve failed platform and reason: %+v", failoverDetail.Attempts[0])
}
if failoverDetail.Attempts[1].PlatformName != "OpenAI Retry Success" || failoverDetail.Attempts[1].Status != "succeeded" || failoverDetail.Attempts[1].ResponseMS <= 0 {
t.Fatalf("second failover attempt should preserve successful platform: %+v", failoverDetail.Attempts[1])
}
if summary, ok := failoverDetail.Metrics["attempts"].([]any); !ok || len(summary) != 2 {
t.Fatalf("task metrics should keep attempt-chain summary, got %+v", failoverDetail.Metrics)
}
var degradePolicySet struct {
ID string `json:"id"`