diff --git a/src/agents/pi-embedded-runner/run.ts b/src/agents/pi-embedded-runner/run.ts index cf57890acd2..0c350d72b16 100644 --- a/src/agents/pi-embedded-runner/run.ts +++ b/src/agents/pi-embedded-runner/run.ts @@ -109,8 +109,10 @@ const ANTHROPIC_MAGIC_STRING_REPLACEMENT = "ANTHROPIC MAGIC STRING TRIGGER REFUS // Detect model safety-filter rejections (stop_reason: sensitive). // This is NOT a timeout — it is a content policy block that requires a user-facing message. +// Matches both bare text ("stop_reason: sensitive") and JSON-stringified variants +// ('"stop_reason":"sensitive"') since describeUnknownError uses JSON.stringify. const SENSITIVE_STOP_REASON_RE = - /\bunhandled\s+stop[_ ]reason:\s*sensitive\b|\bstop[_ ]reason:\s*sensitive\b|\breason:\s*sensitive\b/i; + /\bunhandled\s+stop[_ ]reason:\s*"?sensitive"?\b|\bstop[_ ]reason"?:\s*"?sensitive"?\b|\breason"?:\s*"?sensitive"?\b/i; function scrubAnthropicRefusalMagic(prompt: string): string { if (!prompt.includes(ANTHROPIC_MAGIC_STRING_TRIGGER_REFUSAL)) {