Skip to content

Shared task board where people and AI coding agents work as teammates. Source-available, self-hostable.

Go

MUL-7164 fix(tasks): classify concurrent request rejections (#8200)

mrlonely9d3613653e31
diff --git a/server/internal/service/task_complete_race_test.go b/server/internal/service/task_complete_race_test.go
index 66e4e9e905..8f7ed42c21 100644
--- a/server/internal/service/task_complete_race_test.go
+++ b/server/internal/service/task_complete_race_test.go
@@ -257,6 +257,9 @@ func TestTaskFailureClassifiers(t *testing.T) {
// Transient mid-stream provider disconnect (MUL-4910): retryable, and
// resume-safe so the retry continues the truncated conversation.
{reason: "agent_error.provider_network", wantType: "agent_error", wantResumeOK: true, wantRetry: true},
+ // Capacity/rate-limit failures keep their existing user-retry posture.
+ // Correcting a misleading auth label must not enable an automatic resend.
+ {reason: "agent_error.provider_capacity_or_rate_limit", wantType: "agent_error", wantResumeOK: true, wantRetry: false},
{reason: "runtime_recovery", wantType: "runtime", wantResumeOK: true, wantRetry: true},
{reason: "iteration_limit", wantType: "agent_output", wantResumeOK: false, wantRetry: false},
{reason: "api_invalid_request", wantType: "agent_error", wantResumeOK: false, wantRetry: false},
diff --git a/server/pkg/taskfailure/classify.go b/server/pkg/taskfailure/classify.go
index adaee013d9..f8d8b1badc 100644
--- a/server/pkg/taskfailure/classify.go
+++ b/server/pkg/taskfailure/classify.go
@@ -35,6 +35,14 @@ var (
httpCapacityCodeRe = regexp.MustCompile(`(^|[^0-9])(429|529)([^0-9]|$)`)
)
+// concurrentRequestLimitWitness is emitted by Anthropic-compatible providers
+// that use HTTP 403 for a transient concurrency rejection. Claude Code may
+// prefix it with an authentication or access-token failure, but credentials
+// remain valid and a later request can succeed. Match the semantic witness
+// before both token-window and generic auth rules so the persisted reason and
+// member-facing recovery guidance describe the actual failure.
+const concurrentRequestLimitWitness = "concurrent request limit"
+
// Classify maps a free-form error string from the agent runtime / CLI
// to one of the 14 agent_error.* sub-reasons. Always returns a valid
// Reason; falls back to ReasonAgentUnknown when no rule matches and for
@@ -71,6 +79,12 @@ func Classify(rawError string) Reason {
lower := strings.ToLower(trimmed)
switch {
+ // A concurrent-request rejection can contain both "access token" and HTTP
+ // 403. Its specific semantic witness must beat the broader context and auth
+ // rules below; this classification does not itself make the reason retryable.
+ case strings.Contains(lower, concurrentRequestLimitWitness):
+ return ReasonAgentProviderCapacityOrRateLimit
+
// 1. Context / token window overflow. Checked early so "token
// limit" doesn't get swallowed by the broader "limit" / "quota"
// rule below.
@@ -453,6 +467,17 @@ var legacyOpencodeStreamEndedReasons = map[string]bool{
"agent_error": true,
}
+// legacyConcurrentRequestLimitReasons are the stale buckets emitted by daemons
+// whose classifiers let a generic token/context or HTTP 403 rule win over this
+// more specific wire shape. The raw witness keeps the upgrade narrow; unrelated
+// context overflows and authentication failures retain their original reason.
+var legacyConcurrentRequestLimitReasons = map[string]bool{
+ string(ReasonAgentContextOverflow): true,
+ string(ReasonAgentProviderAuthOrAccess): true,
+ string(ReasonAgentUnknown): true,
+ "agent_error": true,
+}
+
// NormalizeDaemonReason upgrades a failure_reason reported by an older daemon
// onto the taxonomy this server understands, using the raw error text as the
// witness. It returns the reason unchanged when nothing applies.
@@ -469,6 +494,10 @@ var legacyOpencodeStreamEndedReasons = map[string]bool{
// can be deleted once no daemon old enough to produce its wire shape is still
// reporting.
func NormalizeDaemonReason(reason, rawError string) Reason {
+ if legacyConcurrentRequestLimitReasons[reason] &&
+ strings.Contains(strings.ToLower(rawError), concurrentRequestLimitWitness) {
+ return ReasonAgentProviderCapacityOrRateLimit
+ }
if legacySkillBundleReasons[reason] &&
strings.HasPrefix(strings.TrimSpace(rawError), legacySkillBundlePrefix) {
return ReasonSkillBundleUnavailable
diff --git a/server/pkg/taskfailure/classify_test.go b/server/pkg/taskfailure/classify_test.go
index 18a2c36c11..32d900df62 100644
--- a/server/pkg/taskfailure/classify_test.go
+++ b/server/pkg/taskfailure/classify_test.go
@@ -222,6 +222,12 @@ func TestClassifyOrderingPriorities(t *testing.T) {
// auth rejection.
{"missing api key beats 401", "missing api_key for openai (401 returned downstream)", ReasonAgentMissingConfig},
+ // Some Anthropic-compatible providers return 403 for a transient
+ // concurrency rejection. The semantic witness must beat generic auth and
+ // token/context matching even when the CLI prefixes both misleadingly.
+ {"403 concurrent request limit beats auth", "Failed to authenticate. API Error: 403 You've reached your concurrent request limit. Please wait for your ongoing requests to finish and try again.", ReasonAgentProviderCapacityOrRateLimit},
+ {"access token concurrent request limit beats context", "Failed to refresh access token. API Error: 403 You've reached your concurrent request limit.", ReasonAgentProviderCapacityOrRateLimit},
+
// Both "429" and "rate limit" present — should still land in
// the capacity bucket, not the quota bucket.
{"429 rate limit", "API Error: 429 rate limit reached", ReasonAgentProviderCapacityOrRateLimit},
@@ -241,6 +247,30 @@ func TestClassifyOrderingPriorities(t *testing.T) {
}
}
+func TestNormalizeDaemonReasonUpgradesConcurrentRequestLimit(t *testing.T) {
+ t.Parallel()
+
+ const raw = "Failed to refresh access token. API Error: 403 You've reached your concurrent request limit."
+
+ for _, reason := range []string{
+ string(ReasonAgentContextOverflow),
+ string(ReasonAgentProviderAuthOrAccess),
+ string(ReasonAgentUnknown),
+ "agent_error",
+ } {
+ if got := NormalizeDaemonReason(reason, raw); got != ReasonAgentProviderCapacityOrRateLimit {
+ t.Errorf("NormalizeDaemonReason(%q, concurrent request rejection) = %q, want %q", reason, got, ReasonAgentProviderCapacityOrRateLimit)
+ }
+ }
+
+ if got := NormalizeDaemonReason(string(ReasonAgentProviderAuthOrAccess), "API Error: 403 Forbidden"); got != ReasonAgentProviderAuthOrAccess {
+ t.Errorf("plain 403 auth rejection changed to %q", got)
+ }
+ if got := NormalizeDaemonReason(string(ReasonAgentContextOverflow), "you exceeded the token limit"); got != ReasonAgentContextOverflow {
+ t.Errorf("ordinary token overflow changed to %q", got)
+ }
+}
+
// TestClassify5xxRegex pins the boundary behavior of the 5xx HTTP
// status detector. The SQL classifier uses an anchored regex
// `(^|[^0-9])5[0-9][0-9]([^0-9]|$)`; this Go classifier mirrors it via