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:
ingyukoh
2026-03-12 04:00:11 +09:00
committed by GitHub
parent 78b9384aa7
commit 2a18cbb110
7 changed files with 54 additions and 14 deletions

View File

@@ -245,7 +245,9 @@ export function extractAssistantText(msg: AssistantMessage): string {
}) ?? "";
// Only apply keyword-based error rewrites when the assistant message is actually an error.
// Otherwise normal prose that *mentions* errors (e.g. "context overflow") can get clobbered.
const errorContext = msg.stopReason === "error" || Boolean(msg.errorMessage?.trim());
// Gate on stopReason only — a non-error response with an errorMessage set (e.g. from a
// background tool failure) should not have its content rewritten (#13935).
const errorContext = msg.stopReason === "error";
return sanitizeUserFacingText(extracted, { errorContext });
}