Merge 927331297ca88f940cd5b89c98ad4ad48049477d into 8a05c05596ca9ba0735dafd8e359885de4c2c969
This commit is contained in:
commit
2a88b9f629
@ -108,6 +108,13 @@ const OVERLOAD_FAILOVER_BACKOFF_POLICY: BackoffPolicy = {
|
||||
const ANTHROPIC_MAGIC_STRING_TRIGGER_REFUSAL = "ANTHROPIC_MAGIC_STRING_TRIGGER_REFUSAL";
|
||||
const ANTHROPIC_MAGIC_STRING_REPLACEMENT = "ANTHROPIC MAGIC STRING TRIGGER REFUSAL (redacted)";
|
||||
|
||||
// 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;
|
||||
|
||||
function scrubAnthropicRefusalMagic(prompt: string): string {
|
||||
if (!prompt.includes(ANTHROPIC_MAGIC_STRING_TRIGGER_REFUSAL)) {
|
||||
return prompt;
|
||||
@ -1328,6 +1335,33 @@ export async function runEmbeddedPiAgent(
|
||||
authRetryPending = true;
|
||||
continue;
|
||||
}
|
||||
// Handle sensitive stop_reason (content safety filter) with a user-friendly message
|
||||
if (SENSITIVE_STOP_REASON_RE.test(errorText)) {
|
||||
return {
|
||||
payloads: [
|
||||
{
|
||||
text:
|
||||
"I can't respond to that - the content was flagged by the model's safety filter. " +
|
||||
"Please rephrase or try a different topic.",
|
||||
isError: true,
|
||||
},
|
||||
],
|
||||
meta: {
|
||||
durationMs: Date.now() - started,
|
||||
agentMeta: buildErrorAgentMeta({
|
||||
sessionId: sessionIdUsed,
|
||||
provider,
|
||||
model: model.id,
|
||||
usageAccumulator,
|
||||
lastRunPromptUsage,
|
||||
lastAssistant,
|
||||
lastTurnTotal,
|
||||
}),
|
||||
systemPromptReport: attempt.systemPromptReport,
|
||||
error: { kind: "sensitive", message: errorText },
|
||||
},
|
||||
};
|
||||
}
|
||||
// Handle role ordering errors with a user-friendly message
|
||||
if (/incorrect role information|roles must alternate/i.test(errorText)) {
|
||||
return {
|
||||
|
||||
@ -41,7 +41,8 @@ export type EmbeddedPiRunMeta = {
|
||||
| "compaction_failure"
|
||||
| "role_ordering"
|
||||
| "image_size"
|
||||
| "retry_limit";
|
||||
| "retry_limit"
|
||||
| "sensitive";
|
||||
message: string;
|
||||
};
|
||||
/** Stop reason for the agent run (e.g., "completed", "tool_calls"). */
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user