fix: treat Claude safeguards refusals as failures, reset the session

Claude Code returns "API Error: <model>'s safeguards flagged this message"
as a success-typed result. EJClaw delivered it as the owner's answer,
handed it to reviewer/arbiter, resumed the refused session (refused again)
and carried the banner forward into the next task.

Now it is a `safety-refusal` trigger: the raw banner is suppressed, the
Claude session is cleared, the paired task closes as
`claude_safety_refusal`, the room gets a short Korean notice, and refusal
banners are never carried forward. Global memory gains a rule not to read
thinking blocks from session transcripts (the reasoning_extraction trigger
of the 2026-10-12 incident).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Codex
2026-10-12 13:17:22 +09:00
parent e22feb0215
commit f579b4f406
11 changed files with 240 additions and 13 deletions

View File

@@ -7,6 +7,7 @@ import {
isClaudeAuthError,
isClaudeAuthExpiredMessage,
isClaudeOrgAccessDeniedMessage,
isClaudeSafetyRefusalMessage,
isClaudeUsageExhaustedMessage,
type AgentTriggerReason,
} from './agent-error-detection.js';
@@ -68,8 +69,9 @@ export function evaluateStreamedOutput(
if (
primaryAgent === 'claude' &&
output.status === 'success' &&
!state.sawOutput &&
typeof outputText === 'string'
typeof outputText === 'string' &&
// A safeguards refusal is never a real answer, even after earlier output.
(!state.sawOutput || isClaudeSafetyRefusalMessage(outputText))
) {
const triggerReason = classifyClaudeSuccessTrigger(outputText);
if (triggerReason) {
@@ -208,6 +210,7 @@ function suppressRetryableSessionFailure(
function classifyClaudeSuccessTrigger(
outputText: string,
): AgentTriggerReason | undefined {
if (isClaudeSafetyRefusalMessage(outputText)) return 'safety-refusal';
if (isClaudeUsageExhaustedMessage(outputText)) return 'usage-exhausted';
const authClassification = classifyClaudeAuthError(outputText);