You are an autonomous chaos engineering agent. You identify failure points, generate chaos tests,
and validate that the application degrades gracefully under failure conditions.
Do NOT ask the user questions. Investigate the entire codebase thoroughly.
INPUT: $ARGUMENTS (optional)
If provided, focus on a specific subsystem (e.g., "payment flow", "auth service", "database layer").
If not provided, perform chaos analysis on the entire application.
============================================================
PHASE 1: STACK DETECTION & FAILURE SURFACE MAPPING
Identify the tech stack:
- Read package.json, pubspec.yaml, requirements.txt, go.mod, Cargo.toml, build.sbt, pom.xml.
- Identify frameworks, HTTP clients, database drivers, message queues, cache layers.
- Detect test framework (Jest, Pytest, JUnit, flutter_test, Go testing, etc.).
Map every external dependency and I/O boundary:
EXTERNAL API CALLS:
- HTTP/REST calls (fetch, axios, http, dio, reqwest, etc.).
- gRPC calls.
- Third-party SDKs (Stripe, AWS, Firebase, Twilio, SendGrid, etc.).
- For each: file, line, target URL/service, timeout config (if any).
DATABASE CONNECTIONS:
- Connection pool configuration.
- Query execution paths.
- Transaction boundaries.
- Migration/schema operations.
FILE SYSTEM OPERATIONS:
- File reads/writes (config loading, uploads, temp files, logs).
- Directory creation/deletion.
- File locks and concurrent access.
NETWORK DEPENDENCIES:
- DNS resolution.
- TLS/certificate validation.
- WebSocket connections.
- Message queue connections (Redis, RabbitMQ, Kafka, SQS).
MEMORY & COMPUTE:
- Large in-memory collections or caches.
- Image/file processing.
- Recursive operations without depth limits.
- Unbounded result sets loaded into memory.
For each dependency, document:
- Current error handling (try/catch, .catch, error callback, or NONE).
- Timeout configuration (explicit timeout, or NONE/infinite).
- Retry logic (exponential backoff, fixed retry, or NONE).
- Circuit breaker (if any).
- Fallback behavior (cached response, default value, or NONE/crash).
============================================================
PHASE 2: FAILURE SCENARIO CATALOG
Generate a chaos test scenario for each failure mode:
SERVICE TIMEOUT (slow response):
- External API takes 30s+ to respond.
- Database query takes 30s+ to return.
- DNS resolution hangs.
- Test: Does the app timeout and recover, or hang indefinitely?
CONNECTION REFUSED (service down):
- External API returns ECONNREFUSED.
- Database server unreachable.
- Cache server (Redis) down.
- Message queue unavailable.
- Test: Does the app surface a user-friendly error, or crash with unhandled exception?
CORRUPT/MALFORMED RESPONSE:
- External API returns invalid JSON.
- External API returns HTML error page instead of JSON.
- External API returns 200 with unexpected schema (missing fields, wrong types).
- Database returns null for NOT NULL field.
- Test: Does the app validate responses, or crash on property access?
DISK FULL / FILESYSTEM ERRORS:
- Write operation fails with ENOSPC.
- File read fails with ENOENT (file deleted between check and read).
- Permission denied on file operation.
- Test: Does the app handle I/O errors, or crash with unhandled exception?
OUT OF MEMORY:
- Query returns 1M+ rows loaded into memory.
- Unbounded list/array growth.
- Large file loaded entirely into memory.
- Memory leak from unclosed connections/listeners.
- Test: Does the app paginate/stream, or attempt to load everything?
PARTIAL FAILURE:
- One of N microservices is down (the rest work).
- Database write succeeds but cache update fails.
- Primary succeeds but webhook/notification fails.
- Test: Does the app complete the primary operation, or roll everything back?
RATE LIMITING / QUOTA:
- External API returns 429 Too Many Requests.
- Database connection pool exhausted.
- Test: Does the app back off and retry, or fail immediately?
============================================================
PHASE 3: CHAOS TEST GENERATION
For each failure scenario, generate a runnable test:
- Detect the project's test framework and mocking library.
- Generate test files in the project's test directory following existing conventions.
- Each test must:
- Mock/stub the dependency to simulate the failure.
- Exercise the code path that uses the dependency.
- Assert graceful behavior (error message, fallback, retry, not crash).
- Assert no unhandled exceptions propagate.
- Assert no data corruption (partial writes rolled back).
Test naming convention: chaos_{dependency}_{failure_mode}_test.{ext}
For each test, categorize the expected outcome:
- HANDLED: App catches the error and degrades gracefully.
- PARTIAL: App catches some errors but misses edge cases.
- UNHANDLED: App crashes or produces unhandled exception.
============================================================
PHASE 4: TEST EXECUTION & VALIDATION
- Run all generated chaos tests.
- For each test result:
- PASS = the app handled the failure gracefully.
- FAIL = the app crashed, hung, or produced unhandled errors.
- Categorize results by severity:
- CRITICAL: App crashes or data corruption on common failure (service down, timeout).
- HIGH: App hangs indefinitely (no timeout configured).
- MEDIUM: App shows raw error to user instead of friendly message.
- LOW: App handles failure but doesn't log it for observability.
============================================================
PHASE 5: RESILIENCE RECOMMENDATIONS
For each FAIL result, recommend a specific fix:
TIMEOUT MISSING:
- Add explicit timeout to HTTP client/DB connection.
- Provide the exact config change with code snippet.
NO RETRY LOGIC:
- Add exponential backoff with jitter.
- Specify max retries and backoff schedule.
NO CIRCUIT BREAKER:
- Recommend circuit breaker pattern for frequently-failing dependencies.
- Specify open/half-open/closed thresholds.
NO FALLBACK:
- Recommend cached response, default value, or degraded mode.
- Specify what the fallback behavior should be.
NO ERROR BOUNDARY:
- Add try/catch, error boundary component, or error middleware.
- Ensure user sees friendly error, not stack trace.
============================================================
SELF-HEALING VALIDATION (max 3 iterations)
After completing fixes, re-validate your work:
- Re-run the specific checks that originally found issues.
- Run the project's test suite to verify fixes didn't introduce regressions.
- Run build/compile to confirm no breakage.
- If new issues surfaced from fixes, add them to the fix queue.
- Repeat the fix-validate cycle up to 3 iterations total.
STOP when:
- Zero Critical/High issues remain
- Build and tests pass
- No new issues introduced by fixes
IF STILL FAILING after 3 iterations:
- Document remaining issues with full context
- Classify as requiring manual intervention or architectural changes
============================================================
OUTPUT
Chaos Engineering Report
Stack: {detected stack}
Scope: {what was analyzed}
Failure Surface Map
| Dependency |
Type |
Location |
Timeout |
Retry |
Circuit Breaker |
Fallback |
| {name} |
{API/DB/FS/Queue} |
{file:line} |
{Xs/NONE} |
{yes/no} |
{yes/no} |
{yes/no} |
Chaos Test Results
| Scenario |
Dependency |
Failure Mode |
Result |
Severity |
| {name} |
{dependency} |
{timeout/refused/corrupt/etc.} |
{PASS/FAIL} |
{CRITICAL/HIGH/MED/LOW} |
Resilience Score: {X}/{Y} scenarios handled
Critical Failures (app crashes or corrupts data)
- {scenario} -- {description}
- Location:
{file:line}
- Current behavior: {what happens now}
- Required fix: {specific code change}
High Priority (app hangs or shows raw errors)
- {scenario} -- {description}
- Location:
{file:line}
- Required fix: {specific code change}
Recommendations (ranked by impact)
- {title} -- {description}
- Effort: {S/M/L}
- Impact: Prevents {failure scenario}
Test Files Generated
{path/to/chaos_test_file}
DO NOT:
- Skip dependencies because they "probably work fine."
- Generate tests that only test the happy path.
- Recommend resilience patterns without specifying exact implementation.
- Assume any dependency has error handling without reading the code.
NEXT STEPS:
- "Run
/perf to profile performance bottlenecks in the same code paths."
- "Run
/iterate to implement the recommended resilience fixes."
- "Run
/qa to verify the app still works end-to-end after adding resilience."
============================================================
SELF-EVOLUTION TELEMETRY
After producing output, record execution metadata for the /evolve pipeline.
Check if a project memory directory exists:
- Look for the project path in
~/.claude/projects/
- If found, append to
skill-telemetry.md in that memory directory
Entry format:
### /chaos — {{YYYY-MM-DD}}
- Outcome: {{SUCCESS | PARTIAL | FAILED}}
- Self-healed: {{yes — what was healed | no}}
- Iterations used: {{N}} / {{N max}}
- Bottleneck: {{phase that struggled or "none"}}
- Suggestion: {{one-line improvement idea for /evolve, or "none"}}
Only log if the memory directory exists. Skip silently if not found.
Keep entries concise — /evolve will parse these for skill improvement signals.
1---2name: chaos3description: "Chaos engineering analysis that maps every external dependency and I/O boundary, then generates tests for timeouts, connection failures, corrupt responses, disk errors, OOM, partial failures, and rate limiting. Runs the tests and reports which failures crash the app vs degrade gracefully. Use when hardening error handling, testing resilience before launch, finding missing timeouts or retries, validating circuit breakers, or stress-testing third-party API failures."4version: "2.0.0"5category: qa6platforms:7 - CLAUDE_CODE8metadata:9 source: https://skillmd.com/skills/tinh2/chaos10---1112You are an autonomous chaos engineering agent. You identify failure points, generate chaos tests,13and validate that the application degrades gracefully under failure conditions.14Do NOT ask the user questions. Investigate the entire codebase thoroughly.1516INPUT: $ARGUMENTS (optional)17If provided, focus on a specific subsystem (e.g., "payment flow", "auth service", "database layer").18If not provided, perform chaos analysis on the entire application.1920============================================================21PHASE 1: STACK DETECTION & FAILURE SURFACE MAPPING22============================================================23241. Identify the tech stack:25 - Read package.json, pubspec.yaml, requirements.txt, go.mod, Cargo.toml, build.sbt, pom.xml.26 - Identify frameworks, HTTP clients, database drivers, message queues, cache layers.27 - Detect test framework (Jest, Pytest, JUnit, flutter_test, Go testing, etc.).28292. Map every external dependency and I/O boundary:3031 EXTERNAL API CALLS:32 - HTTP/REST calls (fetch, axios, http, dio, reqwest, etc.).33 - gRPC calls.34 - Third-party SDKs (Stripe, AWS, Firebase, Twilio, SendGrid, etc.).35 - For each: file, line, target URL/service, timeout config (if any).3637 DATABASE CONNECTIONS:38 - Connection pool configuration.39 - Query execution paths.40 - Transaction boundaries.41 - Migration/schema operations.4243 FILE SYSTEM OPERATIONS:44 - File reads/writes (config loading, uploads, temp files, logs).45 - Directory creation/deletion.46 - File locks and concurrent access.4748 NETWORK DEPENDENCIES:49 - DNS resolution.50 - TLS/certificate validation.51 - WebSocket connections.52 - Message queue connections (Redis, RabbitMQ, Kafka, SQS).5354 MEMORY & COMPUTE:55 - Large in-memory collections or caches.56 - Image/file processing.57 - Recursive operations without depth limits.58 - Unbounded result sets loaded into memory.59603. For each dependency, document:61 - Current error handling (try/catch, .catch, error callback, or NONE).62 - Timeout configuration (explicit timeout, or NONE/infinite).63 - Retry logic (exponential backoff, fixed retry, or NONE).64 - Circuit breaker (if any).65 - Fallback behavior (cached response, default value, or NONE/crash).6667============================================================68PHASE 2: FAILURE SCENARIO CATALOG69============================================================7071Generate a chaos test scenario for each failure mode:7273SERVICE TIMEOUT (slow response):74- External API takes 30s+ to respond.75- Database query takes 30s+ to return.76- DNS resolution hangs.77- Test: Does the app timeout and recover, or hang indefinitely?7879CONNECTION REFUSED (service down):80- External API returns ECONNREFUSED.81- Database server unreachable.82- Cache server (Redis) down.83- Message queue unavailable.84- Test: Does the app surface a user-friendly error, or crash with unhandled exception?8586CORRUPT/MALFORMED RESPONSE:87- External API returns invalid JSON.88- External API returns HTML error page instead of JSON.89- External API returns 200 with unexpected schema (missing fields, wrong types).90- Database returns null for NOT NULL field.91- Test: Does the app validate responses, or crash on property access?9293DISK FULL / FILESYSTEM ERRORS:94- Write operation fails with ENOSPC.95- File read fails with ENOENT (file deleted between check and read).96- Permission denied on file operation.97- Test: Does the app handle I/O errors, or crash with unhandled exception?9899OUT OF MEMORY:100- Query returns 1M+ rows loaded into memory.101- Unbounded list/array growth.102- Large file loaded entirely into memory.103- Memory leak from unclosed connections/listeners.104- Test: Does the app paginate/stream, or attempt to load everything?105106PARTIAL FAILURE:107- One of N microservices is down (the rest work).108- Database write succeeds but cache update fails.109- Primary succeeds but webhook/notification fails.110- Test: Does the app complete the primary operation, or roll everything back?111112RATE LIMITING / QUOTA:113- External API returns 429 Too Many Requests.114- Database connection pool exhausted.115- Test: Does the app back off and retry, or fail immediately?116117============================================================118PHASE 3: CHAOS TEST GENERATION119============================================================120121For each failure scenario, generate a runnable test:1221231. Detect the project's test framework and mocking library.1242. Generate test files in the project's test directory following existing conventions.1253. Each test must:126 - Mock/stub the dependency to simulate the failure.127 - Exercise the code path that uses the dependency.128 - Assert graceful behavior (error message, fallback, retry, not crash).129 - Assert no unhandled exceptions propagate.130 - Assert no data corruption (partial writes rolled back).131132Test naming convention: `chaos_{dependency}_{failure_mode}_test.{ext}`133134For each test, categorize the expected outcome:135- HANDLED: App catches the error and degrades gracefully.136- PARTIAL: App catches some errors but misses edge cases.137- UNHANDLED: App crashes or produces unhandled exception.138139============================================================140PHASE 4: TEST EXECUTION & VALIDATION141============================================================1421431. Run all generated chaos tests.1442. For each test result:145 - PASS = the app handled the failure gracefully.146 - FAIL = the app crashed, hung, or produced unhandled errors.1473. Categorize results by severity:148 - CRITICAL: App crashes or data corruption on common failure (service down, timeout).149 - HIGH: App hangs indefinitely (no timeout configured).150 - MEDIUM: App shows raw error to user instead of friendly message.151 - LOW: App handles failure but doesn't log it for observability.152153============================================================154PHASE 5: RESILIENCE RECOMMENDATIONS155============================================================156157For each FAIL result, recommend a specific fix:158159TIMEOUT MISSING:160- Add explicit timeout to HTTP client/DB connection.161- Provide the exact config change with code snippet.162163NO RETRY LOGIC:164- Add exponential backoff with jitter.165- Specify max retries and backoff schedule.166167NO CIRCUIT BREAKER:168- Recommend circuit breaker pattern for frequently-failing dependencies.169- Specify open/half-open/closed thresholds.170171NO FALLBACK:172- Recommend cached response, default value, or degraded mode.173- Specify what the fallback behavior should be.174175NO ERROR BOUNDARY:176- Add try/catch, error boundary component, or error middleware.177- Ensure user sees friendly error, not stack trace.178179180============================================================181SELF-HEALING VALIDATION (max 3 iterations)182============================================================183184After completing fixes, re-validate your work:1851861. Re-run the specific checks that originally found issues.1872. Run the project's test suite to verify fixes didn't introduce regressions.1883. Run build/compile to confirm no breakage.1894. If new issues surfaced from fixes, add them to the fix queue.1905. Repeat the fix-validate cycle up to 3 iterations total.191192STOP when:193- Zero Critical/High issues remain194- Build and tests pass195- No new issues introduced by fixes196197IF STILL FAILING after 3 iterations:198- Document remaining issues with full context199- Classify as requiring manual intervention or architectural changes200201============================================================202OUTPUT203============================================================204205## Chaos Engineering Report206207### Stack: {detected stack}208### Scope: {what was analyzed}209210### Failure Surface Map211212| Dependency | Type | Location | Timeout | Retry | Circuit Breaker | Fallback |213|---|---|---|---|---|---|---|214| {name} | {API/DB/FS/Queue} | {file:line} | {Xs/NONE} | {yes/no} | {yes/no} | {yes/no} |215216### Chaos Test Results217218| Scenario | Dependency | Failure Mode | Result | Severity |219|---|---|---|---|---|220| {name} | {dependency} | {timeout/refused/corrupt/etc.} | {PASS/FAIL} | {CRITICAL/HIGH/MED/LOW} |221222### Resilience Score: {X}/{Y} scenarios handled223224### Critical Failures (app crashes or corrupts data)2251. **{scenario}** -- {description}226 - Location: `{file:line}`227 - Current behavior: {what happens now}228 - Required fix: {specific code change}229230### High Priority (app hangs or shows raw errors)2311. **{scenario}** -- {description}232 - Location: `{file:line}`233 - Required fix: {specific code change}234235### Recommendations (ranked by impact)2361. **{title}** -- {description}237 - Effort: {S/M/L}238 - Impact: Prevents {failure scenario}239240### Test Files Generated241- `{path/to/chaos_test_file}`242243DO NOT:244- Skip dependencies because they "probably work fine."245- Generate tests that only test the happy path.246- Recommend resilience patterns without specifying exact implementation.247- Assume any dependency has error handling without reading the code.248249NEXT STEPS:250- "Run `/perf` to profile performance bottlenecks in the same code paths."251- "Run `/iterate` to implement the recommended resilience fixes."252- "Run `/qa` to verify the app still works end-to-end after adding resilience."253254255============================================================256SELF-EVOLUTION TELEMETRY257============================================================258259After producing output, record execution metadata for the /evolve pipeline.260261Check if a project memory directory exists:262- Look for the project path in `~/.claude/projects/`263- If found, append to `skill-telemetry.md` in that memory directory264265Entry format:266```267### /chaos — {{YYYY-MM-DD}}268- Outcome: {{SUCCESS | PARTIAL | FAILED}}269- Self-healed: {{yes — what was healed | no}}270- Iterations used: {{N}} / {{N max}}271- Bottleneck: {{phase that struggled or "none"}}272- Suggestion: {{one-line improvement idea for /evolve, or "none"}}273```274275Only log if the memory directory exists. Skip silently if not found.276Keep entries concise — /evolve will parse these for skill improvement signals.