Skip to content

Commit 813e5f2

Browse files
committed
fix(agents): scope 1305 diagnostic to z.ai provider without changing failover
- REMOVE classifyFailoverReason hook from z.ai plugin — overriding to "overloaded" changes cooldown from model-scoped (rate_limit) to profile-wide, which is incorrect for this fix - ADD optional provider param to formatRateLimitOrOverloadedErrorCopy - PASS provider from errors.ts:1542 (primary API error path) via opts?.provider - SCOPE ZAI_CODE_1305_RE check to z.ai provider when context is available; fall back to unfiltered check when provider is unknown (backward compat for call sites without provider context) - Keep code 1305 classified as rate_limit by generic classifier (model-scoped cooldown preserved) Addresses ClawSweeper review: scope copy without changing failover.
1 parent dbc1d3a commit 813e5f2

3 files changed

Lines changed: 10 additions & 14 deletions

File tree

‎extensions/zai/index.ts‎

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -345,17 +345,6 @@ export default definePluginEntry({
345345
id: PROVIDER_ID,
346346
name: "Z.AI Provider",
347347
description: "Bundled Z.AI provider plugin",
348-
classifyFailoverReason: ({ errorMessage, code }) => {
349-
// z.ai code 1305 can indicate overload, rate-limit, or possible
350-
// content-based rejection from the Coding Plan endpoint.
351-
// Explicitly classify as "overloaded" before the generic classifier
352-
// runs, so the ZAI_CODE_1305_RE check in formatRateLimitOrOverloadedErrorCopy
353-
// can surface a more specific diagnostic for this known payload.
354-
if (code === "1305" || /"code"\s*:\s*"?"?1305"?\b/.test(errorMessage)) {
355-
return "overloaded";
356-
}
357-
return undefined;
358-
},
359348
register(api) {
360349
api.registerProvider({
361350
id: PROVIDER_ID,

‎src/agents/embedded-agent-helpers/errors.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1539,7 +1539,7 @@ export function formatAssistantErrorText(
15391539
return formatBillingErrorMessage(opts?.provider, opts?.model ?? msg.model, opts?.authMode);
15401540
}
15411541

1542-
const transientCopy = formatRateLimitOrOverloadedErrorCopy(raw);
1542+
const transientCopy = formatRateLimitOrOverloadedErrorCopy(raw, opts?.provider);
15431543
if (transientCopy) {
15441544
return transientCopy;
15451545
}

‎src/agents/embedded-agent-helpers/sanitize-user-facing-text.ts‎

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,10 @@ function extractProviderRateLimitMessage(raw: string): string | undefined {
136136
return `⚠️ ${trimmed}`;
137137
}
138138

139-
export function formatRateLimitOrOverloadedErrorCopy(raw: string): string | undefined {
139+
export function formatRateLimitOrOverloadedErrorCopy(
140+
raw: string,
141+
provider?: string,
142+
): string | undefined {
140143
if (MODEL_CAPACITY_ERROR_RE.test(raw)) {
141144
return MODEL_CAPACITY_ERROR_USER_MESSAGE;
142145
}
@@ -149,7 +152,11 @@ export function formatRateLimitOrOverloadedErrorCopy(raw: string): string | unde
149152
}
150153
// Z.ai code 1305 surfaces as "overloaded" but can be a content-based rejection or overload
151154
// when the system prompt contains the OpenClaw signature line (#103529).
152-
if (ZAI_CODE_1305_RE.test(raw)) {
155+
// Only surface the z.ai 1305 diagnostic when the provider is known to be
156+
// z.ai (or unknown — the classifyFailoverReason hook is NOT used for this
157+
// PR, so code 1305 remains classified as rate_limit for model-scoped
158+
// cooldown). Call sites that track provider identity should pass it in.
159+
if (ZAI_CODE_1305_RE.test(raw) && (!provider || provider === "zai")) {
153160
return "⚠️ Provider returned code 1305. This can be a transient overload or a provider-side content restriction — try again later or with a different model.";
154161
}
155162
// Retry classification still owns 429 backoff; user copy can preserve the provider's

0 commit comments

Comments
 (0)