diff --git a/apps/sim/lib/guardrails/mask-client.ts b/apps/sim/lib/guardrails/mask-client.ts index a2c2acb03a3..e5543996186 100644 --- a/apps/sim/lib/guardrails/mask-client.ts +++ b/apps/sim/lib/guardrails/mask-client.ts @@ -26,15 +26,17 @@ const logger = createLogger('PiiMaskClient') const CHUNK_CONCURRENCY = env.PII_MASK_CHUNK_CONCURRENCY ?? 64 /** - * Attempts per chunk for transient failures (network errors, 408/429/5xx), the - * standard retry budget of the AWS and model-provider SDKs. A large payload fans - * out into many chunk requests, so one blip (a dropped connection, a Presidio - * worker restart) must not fail the whole redaction, but every retry re-runs the - * chunk's full NER pass: a chunk that timed out or failed on its own input fails - * the same way again, so more attempts only multiply the work and delay the - * fail-safe. With the default jittered backoff this covers about 1.5s of failures; - * a longer outage falls to the caller's fail-safe. Deterministic failures (4xx, - * shape mismatches) throw immediately. + * Attempts per chunk for transient failures (network errors, timeouts, and the + * statuses in {@link RETRYABLE_STATUSES}), the 3-attempt default of the AWS SDK + * standard retry mode and the OpenAI and Anthropic SDKs. A large payload fans out into many chunk requests, so one blip (a + * dropped connection, a Presidio worker restart, a request queued behind a busy + * fleet) must not fail the whole redaction. The budget stays small because every + * retry re-runs the chunk's full NER pass, so a chunk that fails on its own input (a + * 500 from a recognizer) only repeats that work before reaching the fail-safe. + * Without a `Retry-After`, the jittered backoff spans about 1.5s; an outage + * (502/503/504) that outlasts it falls to the caller's fail-safe, which with + * {@link MaskPIIBatchOptions.failedChunkPlaceholder} also scrubs chunks not yet sent. + * Any other status and shape mismatches throw immediately. */ const MAX_CHUNK_ATTEMPTS = 3