# Kuan Yin — Incident Response

> Technical doc 32.16.1.15. Surfaces in `@kuanyin/dharma-analytics`
> (`safety-protocols.ts`, `crisis-intervention.ts`) and
> `@kuanyin/community-harmony` (`raid-defense.ts`, `post-incident-healing.ts`).

Incidents fall into three families: **safety crises** (a person at risk),
**coordinated attacks** (raids/brigading), and **system incidents** (outages,
SLA breaches). The first two are unique to Kuan Yin and take priority.

## Safety crises (P1)

1. **Detect** — `crisis-intervention.ts` scores crisis state beyond keywords
   (plan + means weighted, protective factors lower it) and recognises indirect
   ideation.
2. **Escalate** — `escalateCrisis({ type, hasImmediateRisk })` routes to
   `crisis_team` / `human_moderator`; `requiresHumanNow` forces immediate human
   contact for life-safety types.
3. **Resource** — deliver region-aware helpline resources
   (`getSelfHarmResources`, 50-country registry) and victim support
   (`getVictimSupportResources`).
4. **Consent-gated contact** — `emergencyContactProtocol` notifies a contact
   only with consent (imminent risk overrides); `lawEnforcementLiaison` engages
   with a high bar and evidence hashing.
5. **Comply** — `mandatoryReport` handles Tarasoff/CPS/CSAM→NCMEC obligations.
6. **Follow up** — acuity-scaled check-ins and continuity-of-care documentation.

## Coordinated attacks (P1/P2)

1. **Detect** — `raid-defense.ts`: `detectTrafficSpike`,
   `detectNewAccountFlood`, `detectCoordinatedMessaging`,
   `detectCrossPlatformCoordination`, `analyzeTimingPatterns`,
   `identifySourceCommunity`.
2. **Defend** — `activateDefenseMode`, `throttleNewUsers`, `restrictPosting`,
   `enableTrustedOnlyMode`.
3. **Document** — `documentRaid` captures evidence for platform reporting.
4. **Heal** — `post-incident-healing.ts`: community check-in, affected-user
   outreach, healing circles, trust rebuilding, recovery tracking.

## System incidents

Follow standard SRE practice — but Kuan Yin's degradation must **fail safe**:
under load, `degradationPlan` sheds deep analysis and non-critical traffic while
**preserving** the protection hot path. An outage must never silently disable
shields; if protection cannot run, default to the most protective posture and
queue content for human review rather than letting it through.

## Emergency shutdown

`triggerEmergencyShutdown({ scope, reason, at })` (scope: `feature` /
`community` / `platform`) is the kill switch; `getShutdownState` and
`liftEmergencyShutdown` manage the lifecycle. Use the narrowest scope that
contains the incident.

## Post-incident

Reconstruct the timeline with event replay (`05-event-system.md`) and
`reconstructForensicTimeline`; write a blameless retro; feed lessons into policy
(`post-incident-healing` policy-improvement) and the model evaluation suite as
new edge cases.
