Skip to content

Commit b40d7f7

Browse files
committed
fix(agents): fallback after replay-safe silent errors
1 parent f14674f commit b40d7f7

7 files changed

Lines changed: 258 additions & 133 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ Docs: https://docs.openclaw.ai
5858

5959
### Fixes
6060

61+
- **Model fallback for unclassified silent provider errors:** after bounded same-model retries, route replay-safe invisible assistant failures to the next configured model without cooling down auth profiles, so transient credential-file races no longer end as silent failures. Fixes #112226. Thanks @wenrizc.
6162
- **Microsoft Teams message-tool replies:** keep automatic live previews from duplicating a message already delivered to the current Teams conversation, while preserving distinct follow-up text and cross-conversation sends. Fixes #116397. (#116398) Thanks @a-tokyo.
6263
- **Buzz plugin packaging:** keep the live QA runner on the shipped QA runner SDK surface and remove the obsolete package shrinkwrap so standalone npm and ClawHub package builds use current host exports and dependency resolutions. Thanks @shakkernerd.
6364
- **Control UI sharing connection isolation:** discard stale visibility and membership mutation results after switching gateways or accounts so previous-connection refreshes and errors cannot update the replacement connection. Fixes #116800. Thanks @shakkernerd.

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

Lines changed: 0 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -34,53 +34,6 @@ describe("Claude CLI logged-out failures", () => {
3434
});
3535
});
3636

37-
describe("credentials file ENOENT failures", () => {
38-
it("classifies missing credentials files as auth failures", () => {
39-
expect(
40-
classifyFailoverReason(
41-
"ENOENT: no such file or directory, open '/home/operator/.config/openclaw/.credentials.json'",
42-
),
43-
).toBe("auth");
44-
});
45-
46-
it("classifies missing hidden token files as auth failures", () => {
47-
expect(
48-
classifyFailoverReason(
49-
"ENOENT: no such file or directory, open '/home/operator/.config/openclaw/.tokens.json'",
50-
),
51-
).toBe("auth");
52-
});
53-
54-
it("leaves unrelated missing local files unclassified", () => {
55-
expect(
56-
classifyFailoverReason(
57-
"ENOENT: no such file or directory, open '/home/operator/project/data.json'",
58-
),
59-
).toBeNull();
60-
});
61-
62-
it("does not classify unrelated open paths from wrapper credential text", () => {
63-
expect(
64-
classifyFailoverReason(
65-
"Credentials refresh failed: ENOENT: no such file or directory, open '/home/operator/project/data.json'",
66-
),
67-
).toBeNull();
68-
});
69-
70-
it("does not classify same-name non-credential workspace files", () => {
71-
expect(
72-
classifyFailoverReason(
73-
"ENOENT: no such file or directory, open '/home/operator/workspace/tokens.json'",
74-
),
75-
).toBeNull();
76-
expect(
77-
classifyFailoverReason(
78-
"ENOENT: no such file or directory, open '/home/operator/workspace/credentials/cache.json'",
79-
),
80-
).toBeNull();
81-
});
82-
});
83-
8437
describe("formatAssistantErrorText streaming JSON parse classification", () => {
8538
beforeEach(() => {
8639
toolPolicyAuditInfo.mockClear();

‎src/agents/embedded-agent-helpers/failover-matches.ts‎

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,6 @@ const COMMON_AUTH_ERROR_PATTERNS = [
4949
/\bfailed to (?:extract|parse|validate|decode)\b.*\btoken\b/,
5050
] as const satisfies readonly ErrorPattern[];
5151

52-
const ENOENT_OPEN_PATH_RE = /\benoent\b[\s\S]*?\bopen\s+(['"])([^'"]+)\1/i;
53-
const CREDENTIALS_FILE_BASENAME_RE = /^\.(?:credentials?|tokens?)(?:\.json)?$/i;
54-
5552
const CJK_AUTH_ERROR_PATTERNS = [
5653
"无权访问",
5754
"认证失败",
@@ -359,22 +356,13 @@ export function isAuthPermanentErrorMessage(raw: string): boolean {
359356
return matchesErrorPatternGroups(raw, [HIGH_CONFIDENCE_AUTH_PERMANENT_PATTERNS]);
360357
}
361358

362-
function isCredentialsFileEnoentErrorMessage(raw: string): boolean {
363-
const openedPath = raw.match(ENOENT_OPEN_PATH_RE)?.[2];
364-
const openedBasename = openedPath?.split(/[\\/]/).at(-1) ?? "";
365-
return CREDENTIALS_FILE_BASENAME_RE.test(openedBasename);
366-
}
367-
368359
export function isAuthErrorMessage(raw: string): boolean {
369-
return (
370-
isCredentialsFileEnoentErrorMessage(raw) ||
371-
matchesErrorPatternGroups(raw, [
372-
AMBIGUOUS_AUTH_ERROR_PATTERNS,
373-
COMMON_AUTH_ERROR_PATTERNS,
374-
ZAI_AUTH_ERROR_PATTERNS,
375-
CJK_AUTH_ERROR_PATTERNS,
376-
])
377-
);
360+
return matchesErrorPatternGroups(raw, [
361+
AMBIGUOUS_AUTH_ERROR_PATTERNS,
362+
COMMON_AUTH_ERROR_PATTERNS,
363+
ZAI_AUTH_ERROR_PATTERNS,
364+
CJK_AUTH_ERROR_PATTERNS,
365+
]);
378366
}
379367

380368
export function isOverloadedErrorMessage(raw: string): boolean {

‎src/agents/embedded-agent-runner/run/assistant-failure.ts‎

Lines changed: 33 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ export async function handleEmbeddedAssistantFailure(input: {
148148
assistantFailoverReason === "unclassified" ||
149149
assistantFailoverReason === "unknown" ||
150150
assistantFailoverReason === "server_error";
151-
if (
151+
const replaySafeSilentErrorFailure =
152152
!authFailure &&
153153
!rateLimitFailure &&
154154
!billingFailure &&
@@ -160,9 +160,8 @@ export async function handleEmbeddedAssistantFailure(input: {
160160
shouldRetrySilentErrorAssistantTurn({
161161
attempt: input.attempt,
162162
assistant: input.attemptAssistant,
163-
}) &&
164-
input.emptyErrorRetries < MAX_EMPTY_ERROR_RETRIES
165-
) {
163+
});
164+
if (replaySafeSilentErrorFailure && input.emptyErrorRetries < MAX_EMPTY_ERROR_RETRIES) {
166165
const emptyErrorRetries = input.emptyErrorRetries + 1;
167166
log.warn(
168167
`[empty-error-retry] stopReason=error non-visible-output; resubmitting ` +
@@ -179,12 +178,24 @@ export async function handleEmbeddedAssistantFailure(input: {
179178
});
180179
}
181180

181+
// The bounded same-model retry already proved this attempt had no visible output
182+
// or replay-unsafe effects. Once those retries are exhausted, skip profile
183+
// rotation and let the configured model fallback recover the invisible failure.
184+
const exhaustedUnclassifiedSilentError =
185+
input.fallbackConfigured &&
186+
assistantFailoverReason === null &&
187+
replaySafeSilentErrorFailure &&
188+
input.emptyErrorRetries >= MAX_EMPTY_ERROR_RETRIES;
189+
const effectiveFailoverReason = exhaustedUnclassifiedSilentError
190+
? ("unknown" as const)
191+
: assistantFailoverReason;
192+
182193
const failedProfileId = input.authProfileId;
183194
const logFailoverDecision = createFailoverDecisionLogger({
184195
stage: "assistant",
185196
runId: input.runParams.runId,
186197
rawError: input.attemptAssistant?.errorMessage?.trim(),
187-
failoverReason: assistantFailoverReason,
198+
failoverReason: effectiveFailoverReason,
188199
profileFailureReason: assistantProfileFailureReason,
189200
provider: input.activeErrorContext.provider,
190201
model: input.activeErrorContext.model,
@@ -229,17 +240,19 @@ export async function handleEmbeddedAssistantFailure(input: {
229240
);
230241
}
231242

232-
const initialDecision = resolveRunFailoverDecision({
233-
stage: "assistant",
234-
allowFormatRetry: cloudCodeAssistFormatError,
235-
terminal: input.attempt.terminal,
236-
signalOwnedInterruption,
237-
fallbackConfigured: input.fallbackConfigured,
238-
failoverFailure,
239-
failoverReason: assistantFailoverReason,
240-
harnessOwnsTransport: input.pluginHarnessOwnsTransport,
241-
profileRotated: false,
242-
});
243+
const initialDecision = exhaustedUnclassifiedSilentError
244+
? ({ action: "fallback_model", reason: "unknown" } as const)
245+
: resolveRunFailoverDecision({
246+
stage: "assistant",
247+
allowFormatRetry: cloudCodeAssistFormatError,
248+
terminal: input.attempt.terminal,
249+
signalOwnedInterruption,
250+
fallbackConfigured: input.fallbackConfigured,
251+
failoverFailure,
252+
failoverReason: assistantFailoverReason,
253+
harnessOwnsTransport: input.pluginHarnessOwnsTransport,
254+
profileRotated: false,
255+
});
243256
const outcome = await handleAssistantFailover({
244257
initialDecision,
245258
terminal: input.attempt.terminal,
@@ -288,14 +301,14 @@ export async function handleEmbeddedAssistantFailure(input: {
288301
const retryTraceResult =
289302
outcome.retryKind === "same_model_rate_limit"
290303
? "same_model_rate_limit"
291-
: outcome.retryKind === "same_model_idle_timeout" || assistantFailoverReason === "timeout"
304+
: outcome.retryKind === "same_model_idle_timeout" || effectiveFailoverReason === "timeout"
292305
? "timeout"
293306
: "rotate_profile";
294307
input.traceAttempts.push({
295308
provider: input.activeErrorContext.provider,
296309
model: input.activeErrorContext.model,
297310
result: retryTraceResult,
298-
...(assistantFailoverReason ? { reason: assistantFailoverReason } : {}),
311+
...(effectiveFailoverReason ? { reason: effectiveFailoverReason } : {}),
299312
stage: "assistant",
300313
});
301314
return buildOutcome(input, {
@@ -316,12 +329,12 @@ export async function handleEmbeddedAssistantFailure(input: {
316329
provider: input.activeErrorContext.provider,
317330
model: input.activeErrorContext.model,
318331
result:
319-
assistantFailoverReason === "timeout"
332+
effectiveFailoverReason === "timeout"
320333
? "timeout"
321334
: initialDecision.action === "fallback_model"
322335
? "fallback_model"
323336
: "error",
324-
...(assistantFailoverReason ? { reason: assistantFailoverReason } : {}),
337+
...(effectiveFailoverReason ? { reason: effectiveFailoverReason } : {}),
325338
stage: "assistant",
326339
...(typeof outcome.error.status === "number" ? { status: outcome.error.status } : {}),
327340
});

‎src/agents/embedded-agent-runner/run/failover-policy.test.ts‎

Lines changed: 0 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
// profile rotation, fallback model escalation, and user-visible errors.
33
import { describe, expect, it } from "vitest";
44
import { classifyAssistantFailoverReason } from "../../embedded-agent-helpers.js";
5-
import { makeAssistantMessageFixture } from "../../test-helpers/assistant-message-fixtures.js";
65
import { mergeRetryFailoverReason, resolveRunFailoverDecision } from "./failover-policy.js";
76

87
describe("resolveRunFailoverDecision", () => {
@@ -269,50 +268,6 @@ describe("resolveRunFailoverDecision", () => {
269268
});
270269
});
271270

272-
it("falls back for missing credentials files after assistant rotation is exhausted", () => {
273-
const assistantError = makeAssistantMessageFixture({
274-
errorMessage:
275-
"ENOENT: no such file or directory, open '/home/operator/.config/openclaw/.credentials.json'",
276-
});
277-
const failoverReason = classifyAssistantFailoverReason(assistantError);
278-
279-
expect(failoverReason).toBe("auth");
280-
expect(
281-
resolveRunFailoverDecision({
282-
stage: "assistant",
283-
terminal: { kind: "ok" },
284-
fallbackConfigured: true,
285-
failoverFailure: failoverReason !== null,
286-
failoverReason,
287-
profileRotated: true,
288-
}),
289-
).toEqual({
290-
action: "fallback_model",
291-
reason: "auth",
292-
});
293-
});
294-
295-
it("does not fall back for unrelated unclassified missing files", () => {
296-
const assistantError = makeAssistantMessageFixture({
297-
errorMessage: "ENOENT: no such file or directory, open '/home/operator/project/data.json'",
298-
});
299-
const failoverReason = classifyAssistantFailoverReason(assistantError);
300-
301-
expect(failoverReason).toBeNull();
302-
expect(
303-
resolveRunFailoverDecision({
304-
stage: "assistant",
305-
terminal: { kind: "ok" },
306-
fallbackConfigured: true,
307-
failoverFailure: failoverReason !== null,
308-
failoverReason,
309-
profileRotated: true,
310-
}),
311-
).toEqual({
312-
action: "continue_normal",
313-
});
314-
});
315-
316271
it("sends assistant TLS certificate failures directly to model fallback", () => {
317272
expect(
318273
resolveRunFailoverDecision({

0 commit comments

Comments
 (0)