From 4fea80126df0c268f8b6b8d8ae27a45738e7e02e Mon Sep 17 00:00:00 2001 From: MoerAI Date: Tue, 17 Mar 2026 20:02:46 +0900 Subject: [PATCH] fix: match stop_reason (underscore) variant in sensitive detection regex The regex only matched 'stop reason' (space) but some error text uses the canonical key form 'stop_reason' (underscore). Use [_ ] character class to match both. --- src/agents/pi-embedded-runner/run.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/agents/pi-embedded-runner/run.ts b/src/agents/pi-embedded-runner/run.ts index 2d18955d184..71d7ae34ad5 100644 --- a/src/agents/pi-embedded-runner/run.ts +++ b/src/agents/pi-embedded-runner/run.ts @@ -109,7 +109,7 @@ 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. 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)) {