mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-08 22:58:26 +00:00
fix(agents): reduce billing false positives on long text (#25680)
Land PR #25680 from @lairtonlelis. Retain explicit status/code/http 402 detection for oversized structured payloads. Co-authored-by: Ailton <lairton@telnyx.com>
This commit is contained in:
@@ -69,6 +69,40 @@ describe("isBillingErrorMessage", () => {
|
||||
expect(isBillingErrorMessage(sample)).toBe(false);
|
||||
}
|
||||
});
|
||||
it("does not false-positive on long assistant responses mentioning billing keywords", () => {
|
||||
// Simulate a multi-paragraph assistant response that mentions billing terms
|
||||
const longResponse =
|
||||
"Sure! Here's how to set up billing for your SaaS application.\n\n" +
|
||||
"## Payment Integration\n\n" +
|
||||
"First, you'll need to configure your payment gateway. Most providers offer " +
|
||||
"a dashboard where you can manage credits, view invoices, and upgrade your plan. " +
|
||||
"The billing page typically shows your current balance and payment history.\n\n" +
|
||||
"## Managing Credits\n\n" +
|
||||
"Users can purchase credits through the billing portal. When their credit balance " +
|
||||
"runs low, send them a notification to upgrade their plan or add more credits. " +
|
||||
"You should also handle insufficient balance cases gracefully.\n\n" +
|
||||
"## Subscription Plans\n\n" +
|
||||
"Offer multiple plan tiers with different features. Allow users to upgrade or " +
|
||||
"downgrade their plan at any time. Make sure the billing cycle is clear.\n\n" +
|
||||
"Let me know if you need more details on any of these topics!";
|
||||
expect(longResponse.length).toBeGreaterThan(512);
|
||||
expect(isBillingErrorMessage(longResponse)).toBe(false);
|
||||
});
|
||||
it("still matches explicit 402 markers in long payloads", () => {
|
||||
const longStructuredError =
|
||||
'{"error":{"code":402,"message":"payment required","details":"' + "x".repeat(700) + '"}}';
|
||||
expect(longStructuredError.length).toBeGreaterThan(512);
|
||||
expect(isBillingErrorMessage(longStructuredError)).toBe(true);
|
||||
});
|
||||
it("does not match long numeric text that is not a billing error", () => {
|
||||
const longNonError =
|
||||
"Quarterly report summary: subsystem A returned 402 records after retry. " +
|
||||
"This is an analytics count, not an HTTP/API billing failure. " +
|
||||
"Notes: " +
|
||||
"x".repeat(700);
|
||||
expect(longNonError.length).toBeGreaterThan(512);
|
||||
expect(isBillingErrorMessage(longNonError)).toBe(false);
|
||||
});
|
||||
it("still matches real HTTP 402 billing errors", () => {
|
||||
const realErrors = [
|
||||
"HTTP 402 Payment Required",
|
||||
|
||||
Reference in New Issue
Block a user