mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-24 15:34:28 +00:00
fix(agents): prevent false billing error replacing valid response text (#40616)
Merged via squash.
Prepared head SHA: 05179362b4
Co-authored-by: ingyukoh <6015960+ingyukoh@users.noreply.github.com>
Co-authored-by: altaywtf <9790196+altaywtf@users.noreply.github.com>
Reviewed-by: @altaywtf
This commit is contained in:
@@ -166,9 +166,9 @@ export function extractAssistantText(message: unknown): string | undefined {
|
||||
normalizeText: (text) => text.trim(),
|
||||
}) ?? "";
|
||||
const stopReason = (message as { stopReason?: unknown }).stopReason;
|
||||
const errorMessage = (message as { errorMessage?: unknown }).errorMessage;
|
||||
const errorContext =
|
||||
stopReason === "error" || (typeof errorMessage === "string" && Boolean(errorMessage.trim()));
|
||||
// Gate on stopReason only — a non-error response with a stale/background errorMessage
|
||||
// should not have its content rewritten with error templates (#13935).
|
||||
const errorContext = stopReason === "error";
|
||||
|
||||
return joined ? sanitizeUserFacingText(joined, { errorContext }) : undefined;
|
||||
}
|
||||
|
||||
@@ -199,6 +199,16 @@ describe("extractAssistantText", () => {
|
||||
"Firebase downgraded us to the free Spark plan. Check whether billing should be re-enabled.",
|
||||
);
|
||||
});
|
||||
|
||||
it("preserves successful turns with stale background errorMessage", () => {
|
||||
const message = {
|
||||
role: "assistant",
|
||||
stopReason: "end_turn",
|
||||
errorMessage: "insufficient credits for embedding model",
|
||||
content: [{ type: "text", text: "Handle payment required errors in your API." }],
|
||||
};
|
||||
expect(extractAssistantText(message)).toBe("Handle payment required errors in your API.");
|
||||
});
|
||||
});
|
||||
|
||||
describe("resolveAnnounceTarget", () => {
|
||||
|
||||
Reference in New Issue
Block a user