mirror of
https://github.com/openclaw/openclaw.git
synced 2026-06-07 22:09:57 +00:00
fix(agents): narrow billing error 402 regex to avoid false positives on issue IDs
The broad /\b402\b/ regex in ERROR_PATTERNS.billing matched any text containing '402' (e.g., 'CHE-402', '#402', 'Room 402'), causing sanitizeUserFacingText() to replace valid agent responses with a billing error message. Replace with a context-aware pattern that only matches HTTP 402 error contexts (e.g., 'status: 402', 'HTTP 402', 'error code 402'). Fixes #13822
This commit is contained in:
@@ -27,4 +27,29 @@ describe("isBillingErrorMessage", () => {
|
||||
expect(isBillingErrorMessage("invalid api key")).toBe(false);
|
||||
expect(isBillingErrorMessage("context length exceeded")).toBe(false);
|
||||
});
|
||||
it("does not false-positive on issue IDs or text containing 402", () => {
|
||||
const falsePositives = [
|
||||
"Fixed issue CHE-402 in the latest release",
|
||||
"See ticket #402 for details",
|
||||
"ISSUE-402 has been resolved",
|
||||
"Room 402 is available",
|
||||
"Error code 403 was returned, not 402-related",
|
||||
"The building at 402 Main Street",
|
||||
];
|
||||
for (const sample of falsePositives) {
|
||||
expect(isBillingErrorMessage(sample)).toBe(false);
|
||||
}
|
||||
});
|
||||
it("still matches real HTTP 402 billing errors", () => {
|
||||
const realErrors = [
|
||||
"HTTP 402 Payment Required",
|
||||
"status: 402",
|
||||
"error code 402",
|
||||
"http 402",
|
||||
"status=402 payment required",
|
||||
];
|
||||
for (const sample of realErrors) {
|
||||
expect(isBillingErrorMessage(sample)).toBe(true);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
@@ -535,7 +535,7 @@ const ERROR_PATTERNS = {
|
||||
overloaded: [/overloaded_error|"type"\s*:\s*"overloaded_error"/i, "overloaded"],
|
||||
timeout: ["timeout", "timed out", "deadline exceeded", "context deadline exceeded"],
|
||||
billing: [
|
||||
/\b402\b/,
|
||||
/(?:status|code|http|error)\s*[:=]?\s*402\b|^\s*402\s+payment/i,
|
||||
"payment required",
|
||||
"insufficient credits",
|
||||
"credit balance",
|
||||
|
||||
Reference in New Issue
Block a user