tribunal-kit 4.2.0 → 4.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.agent/ARCHITECTURE.md +21 -14
- package/.agent/agents/swarm-worker-contracts.md +5 -5
- package/.agent/agents/ui-ux-auditor.md +292 -0
- package/.agent/rules/GEMINI.md +8 -8
- package/.agent/scripts/__pycache__/_colors.cpython-311.pyc +0 -0
- package/.agent/scripts/__pycache__/_utils.cpython-311.pyc +0 -0
- package/.agent/scripts/__pycache__/case_law_manager.cpython-311.pyc +0 -0
- package/.agent/scripts/_colors.js +18 -0
- package/.agent/scripts/_utils.js +42 -0
- package/.agent/scripts/auto_preview.js +197 -0
- package/.agent/scripts/bundle_analyzer.js +290 -0
- package/.agent/scripts/case_law_manager.js +684 -0
- package/.agent/scripts/checklist.js +266 -0
- package/.agent/scripts/colors.js +17 -0
- package/.agent/scripts/compress_skills.js +141 -0
- package/.agent/scripts/consolidate_skills.js +149 -0
- package/.agent/scripts/context_broker.js +609 -0
- package/.agent/scripts/deep_compress.js +150 -0
- package/.agent/scripts/dependency_analyzer.js +272 -0
- package/.agent/scripts/graph_builder.js +199 -0
- package/.agent/scripts/graph_zoom.js +154 -0
- package/.agent/scripts/inner_loop_validator.js +465 -0
- package/.agent/scripts/lint_runner.js +187 -0
- package/.agent/scripts/minify_context.js +100 -0
- package/.agent/scripts/patch_skills_meta.js +156 -0
- package/.agent/scripts/patch_skills_output.js +244 -0
- package/.agent/scripts/schema_validator.js +297 -0
- package/.agent/scripts/security_scan.js +303 -0
- package/.agent/scripts/session_manager.js +276 -0
- package/.agent/scripts/skill_evolution.js +644 -0
- package/.agent/scripts/skill_integrator.js +313 -0
- package/.agent/scripts/strengthen_skills.js +193 -0
- package/.agent/scripts/strip_tribunal.js +47 -0
- package/.agent/scripts/swarm_dispatcher.js +360 -0
- package/.agent/scripts/test_runner.js +193 -0
- package/.agent/scripts/utils.js +32 -0
- package/.agent/scripts/verify_all.js +256 -0
- package/.agent/skills/agent-organizer/SKILL.md +12 -4
- package/.agent/skills/agentic-patterns/SKILL.md +12 -4
- package/.agent/skills/ai-prompt-injection-defense/SKILL.md +12 -4
- package/.agent/skills/api-patterns/SKILL.md +209 -201
- package/.agent/skills/api-security-auditor/SKILL.md +12 -4
- package/.agent/skills/app-builder/SKILL.md +12 -4
- package/.agent/skills/app-builder/templates/SKILL.md +76 -68
- package/.agent/skills/app-builder/templates/astro-static/TEMPLATE.md +1 -1
- package/.agent/skills/app-builder/templates/chrome-extension/TEMPLATE.md +1 -1
- package/.agent/skills/app-builder/templates/cli-tool/TEMPLATE.md +1 -1
- package/.agent/skills/app-builder/templates/electron-desktop/TEMPLATE.md +1 -1
- package/.agent/skills/app-builder/templates/express-api/TEMPLATE.md +1 -1
- package/.agent/skills/app-builder/templates/flutter-app/TEMPLATE.md +1 -1
- package/.agent/skills/app-builder/templates/monorepo-turborepo/TEMPLATE.md +1 -1
- package/.agent/skills/app-builder/templates/nextjs-fullstack/TEMPLATE.md +1 -1
- package/.agent/skills/app-builder/templates/nextjs-saas/TEMPLATE.md +1 -1
- package/.agent/skills/app-builder/templates/nextjs-static/TEMPLATE.md +1 -1
- package/.agent/skills/app-builder/templates/nuxt-app/TEMPLATE.md +1 -1
- package/.agent/skills/app-builder/templates/python-fastapi/TEMPLATE.md +1 -1
- package/.agent/skills/app-builder/templates/react-native-app/TEMPLATE.md +1 -1
- package/.agent/skills/appflow-wireframe/SKILL.md +12 -4
- package/.agent/skills/architecture/SKILL.md +12 -4
- package/.agent/skills/authentication-best-practices/SKILL.md +12 -4
- package/.agent/skills/bash-linux/SKILL.md +12 -4
- package/.agent/skills/behavioral-modes/SKILL.md +12 -4
- package/.agent/skills/brainstorming/SKILL.md +12 -4
- package/.agent/skills/building-native-ui/SKILL.md +12 -4
- package/.agent/skills/clean-code/SKILL.md +12 -4
- package/.agent/skills/code-review-checklist/SKILL.md +12 -4
- package/.agent/skills/config-validator/SKILL.md +12 -4
- package/.agent/skills/csharp-developer/SKILL.md +12 -4
- package/.agent/skills/data-validation-schemas/SKILL.md +290 -282
- package/.agent/skills/database-design/SKILL.md +202 -194
- package/.agent/skills/deployment-procedures/SKILL.md +12 -4
- package/.agent/skills/devops-engineer/SKILL.md +12 -4
- package/.agent/skills/devops-incident-responder/SKILL.md +12 -4
- package/.agent/skills/doc.md +1 -1
- package/.agent/skills/documentation-templates/SKILL.md +12 -4
- package/.agent/skills/edge-computing/SKILL.md +12 -4
- package/.agent/skills/error-resilience/SKILL.md +390 -382
- package/.agent/skills/extract-design-system/SKILL.md +12 -4
- package/.agent/skills/framer-motion-expert/SKILL.md +206 -199
- package/.agent/skills/frontend-design/SKILL.md +163 -155
- package/.agent/skills/game-design-expert/SKILL.md +12 -4
- package/.agent/skills/game-engineering-expert/SKILL.md +12 -4
- package/.agent/skills/geo-fundamentals/SKILL.md +12 -4
- package/.agent/skills/github-operations/SKILL.md +12 -4
- package/.agent/skills/gsap-core/SKILL.md +54 -48
- package/.agent/skills/gsap-frameworks/SKILL.md +54 -48
- package/.agent/skills/gsap-performance/SKILL.md +54 -48
- package/.agent/skills/gsap-plugins/SKILL.md +54 -48
- package/.agent/skills/gsap-react/SKILL.md +54 -48
- package/.agent/skills/gsap-scrolltrigger/SKILL.md +54 -48
- package/.agent/skills/gsap-timeline/SKILL.md +54 -48
- package/.agent/skills/gsap-utils/SKILL.md +54 -48
- package/.agent/skills/i18n-localization/SKILL.md +12 -4
- package/.agent/skills/intelligent-routing/SKILL.md +41 -33
- package/.agent/skills/knowledge-graph/SKILL.md +36 -0
- package/.agent/skills/lint-and-validate/SKILL.md +12 -4
- package/.agent/skills/llm-engineering/SKILL.md +12 -4
- package/.agent/skills/local-first/SKILL.md +12 -4
- package/.agent/skills/mcp-builder/SKILL.md +12 -4
- package/.agent/skills/mobile-design/SKILL.md +225 -217
- package/.agent/skills/monorepo-management/SKILL.md +296 -288
- package/.agent/skills/motion-engineering/SKILL.md +195 -187
- package/.agent/skills/nextjs-react-expert/SKILL.md +196 -188
- package/.agent/skills/nodejs-best-practices/SKILL.md +12 -4
- package/.agent/skills/observability/SKILL.md +12 -4
- package/.agent/skills/parallel-agents/SKILL.md +12 -4
- package/.agent/skills/performance-profiling/SKILL.md +12 -4
- package/.agent/skills/plan-writing/SKILL.md +12 -4
- package/.agent/skills/platform-engineer/SKILL.md +12 -4
- package/.agent/skills/playwright-best-practices/SKILL.md +12 -4
- package/.agent/skills/powershell-windows/SKILL.md +12 -4
- package/.agent/skills/project-idioms/SKILL.md +12 -4
- package/.agent/skills/python-patterns/SKILL.md +12 -4
- package/.agent/skills/python-pro/SKILL.md +285 -277
- package/.agent/skills/react-specialist/SKILL.md +239 -231
- package/.agent/skills/readme-builder/SKILL.md +12 -4
- package/.agent/skills/realtime-patterns/SKILL.md +12 -4
- package/.agent/skills/red-team-tactics/SKILL.md +12 -4
- package/.agent/skills/rust-pro/SKILL.md +12 -4
- package/.agent/skills/seo-fundamentals/SKILL.md +12 -4
- package/.agent/skills/server-management/SKILL.md +12 -4
- package/.agent/skills/shadcn-ui-expert/SKILL.md +12 -4
- package/.agent/skills/skill-creator/SKILL.md +12 -4
- package/.agent/skills/sql-pro/SKILL.md +12 -4
- package/.agent/skills/supabase-postgres-best-practices/SKILL.md +12 -4
- package/.agent/skills/swiftui-expert/SKILL.md +12 -4
- package/.agent/skills/systematic-debugging/SKILL.md +12 -4
- package/.agent/skills/tailwind-patterns/SKILL.md +12 -4
- package/.agent/skills/tdd-workflow/SKILL.md +12 -4
- package/.agent/skills/test-result-analyzer/SKILL.md +12 -4
- package/.agent/skills/testing-patterns/SKILL.md +12 -4
- package/.agent/skills/trend-researcher/SKILL.md +12 -4
- package/.agent/skills/typescript-advanced/SKILL.md +297 -289
- package/.agent/skills/ui-ux-pro-max/SKILL.md +12 -4
- package/.agent/skills/ui-ux-researcher/SKILL.md +12 -4
- package/.agent/skills/vue-expert/SKILL.md +237 -229
- package/.agent/skills/vulnerability-scanner/SKILL.md +12 -4
- package/.agent/skills/web-accessibility-auditor/SKILL.md +12 -4
- package/.agent/skills/web-design-guidelines/SKILL.md +12 -4
- package/.agent/skills/webapp-testing/SKILL.md +12 -4
- package/.agent/skills/whimsy-injector/SKILL.md +12 -4
- package/.agent/skills/workflow-optimizer/SKILL.md +12 -4
- package/.agent/workflows/audit.md +6 -6
- package/.agent/workflows/deploy.md +1 -1
- package/.agent/workflows/generate.md +23 -6
- package/.agent/workflows/session.md +5 -5
- package/.agent/workflows/swarm.md +2 -2
- package/README.md +242 -186
- package/bin/tribunal-kit.js +297 -57
- package/package.json +81 -77
- package/scripts/changelog.js +167 -0
- package/scripts/sync-version.js +81 -0
- package/scripts/validate-payload.js +73 -0
- package/.agent/scripts/__pycache__/auto_preview.cpython-311.pyc +0 -0
- package/.agent/scripts/__pycache__/bundle_analyzer.cpython-311.pyc +0 -0
- package/.agent/scripts/__pycache__/checklist.cpython-311.pyc +0 -0
- package/.agent/scripts/__pycache__/dependency_analyzer.cpython-311.pyc +0 -0
- package/.agent/scripts/__pycache__/security_scan.cpython-311.pyc +0 -0
- package/.agent/scripts/__pycache__/session_manager.cpython-311.pyc +0 -0
- package/.agent/scripts/__pycache__/skill_integrator.cpython-311.pyc +0 -0
- package/.agent/scripts/__pycache__/swarm_dispatcher.cpython-311.pyc +0 -0
- package/.agent/scripts/__pycache__/test_runner.cpython-311.pyc +0 -0
- package/.agent/scripts/__pycache__/verify_all.cpython-311.pyc +0 -0
- package/.agent/scripts/auto_preview.py +0 -180
- package/.agent/scripts/bundle_analyzer.py +0 -259
- package/.agent/scripts/case_law_manager.py +0 -755
- package/.agent/scripts/checklist.py +0 -209
- package/.agent/scripts/compress_skills.py +0 -167
- package/.agent/scripts/consolidate_skills.py +0 -173
- package/.agent/scripts/deep_compress.py +0 -202
- package/.agent/scripts/dependency_analyzer.py +0 -247
- package/.agent/scripts/lint_runner.py +0 -188
- package/.agent/scripts/minify_context.py +0 -80
- package/.agent/scripts/patch_skills_meta.py +0 -177
- package/.agent/scripts/patch_skills_output.py +0 -285
- package/.agent/scripts/schema_validator.py +0 -279
- package/.agent/scripts/security_scan.py +0 -224
- package/.agent/scripts/session_manager.py +0 -261
- package/.agent/scripts/skill_evolution.py +0 -563
- package/.agent/scripts/skill_integrator.py +0 -234
- package/.agent/scripts/strengthen_skills.py +0 -220
- package/.agent/scripts/strip_tribunal.py +0 -41
- package/.agent/scripts/swarm_dispatcher.py +0 -350
- package/.agent/scripts/test_runner.py +0 -192
- package/.agent/scripts/test_swarm_dispatcher.py +0 -163
- package/.agent/scripts/verify_all.py +0 -195
|
@@ -1,386 +1,386 @@
|
|
|
1
|
-
---
|
|
2
|
-
name: error-resilience
|
|
3
|
-
description: Error resilience and fault tolerance mastery. Retry strategies (exponential backoff with jitter), circuit breakers, bulkheads, graceful degradation, React error boundaries, dead letter queues, timeout patterns, fallback chains, and idempotent error recovery. Use when building fault-tolerant systems, handling flaky external services, or preventing cascading failures.
|
|
4
|
-
allowed-tools: Read, Write, Edit, Glob, Grep
|
|
5
|
-
version: 1.0.0
|
|
6
|
-
last-updated: 2026-04-17
|
|
7
|
-
applies-to-model: gemini-2.5-pro, claude-3-7-sonnet
|
|
8
|
-
---
|
|
9
|
-
|
|
10
|
-
## Hallucination Traps (Read First)
|
|
11
|
-
- ❌ Retrying non-idempotent operations (POST payments) without idempotency keys -> ✅ Always require idempotency keys for non-safe HTTP methods before retrying
|
|
12
|
-
- ❌ Using fixed delay retries instead of exponential backoff -> ✅ Exponential backoff with jitter prevents thundering herd
|
|
13
|
-
- ❌ Catching all errors and swallowing them -> ✅ Only catch recoverable (operational) errors; let programmer errors crash
|
|
14
|
-
|
|
15
|
-
---
|
|
16
|
-
|
|
17
|
-
# Error Resilience — Fault-Tolerant Systems
|
|
18
|
-
|
|
19
|
-
---
|
|
20
|
-
|
|
21
|
-
## Error Classification (Always Do This First)
|
|
22
|
-
|
|
23
|
-
```typescript
|
|
24
|
-
// ✅ CRITICAL: Classify errors before handling them
|
|
25
|
-
// Operational errors = expected failures you CAN recover from
|
|
26
|
-
// Programmer errors = bugs you CANNOT recover from
|
|
27
|
-
|
|
28
|
-
class OperationalError extends Error {
|
|
29
|
-
constructor(message: string, public readonly isRetryable: boolean = false) {
|
|
30
|
-
super(message);
|
|
31
|
-
this.name = "OperationalError";
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
// ❌ BAD: Treating all errors the same
|
|
36
|
-
catch (e) { console.log(e); }
|
|
37
|
-
|
|
38
|
-
// ✅ GOOD: Classifying and routing
|
|
39
|
-
catch (error) {
|
|
40
|
-
if (error instanceof OperationalError && error.isRetryable) {
|
|
41
|
-
return retry(operation);
|
|
42
|
-
}
|
|
43
|
-
if (error instanceof OperationalError) {
|
|
44
|
-
return fallback(error);
|
|
45
|
-
}
|
|
46
|
-
// Programmer error — crash fast, fix the bug
|
|
47
|
-
throw error;
|
|
48
|
-
}
|
|
49
|
-
```
|
|
50
|
-
|
|
51
|
-
```
|
|
52
|
-
┌─────────────────────────────────────────────────────────────┐
|
|
53
|
-
│ Operational (recoverable) │
|
|
54
|
-
├─────────────────────────────────────────────────────────────┤
|
|
55
|
-
│ Network timeout → Retry with backoff │
|
|
56
|
-
│ Rate limited (429) → Retry after Retry-After header │
|
|
57
|
-
│ Service unavailable (503) → Circuit breaker + fallback │
|
|
58
|
-
│ Database connection lost → Reconnect with pool │
|
|
59
|
-
│ Input validation failed → Return 400 to client │
|
|
60
|
-
│ File not found → Return 404 or create default │
|
|
61
|
-
├─────────────────────────────────────────────────────────────┤
|
|
62
|
-
│ Programmer (crash immediately) │
|
|
63
|
-
├─────────────────────────────────────────────────────────────┤
|
|
64
|
-
│ TypeError / ReferenceError → Bug — fix the code │
|
|
65
|
-
│ Assertion failure → Invariant violated — fix logic │
|
|
66
|
-
│ Undefined is not a function → Missing import or typo │
|
|
67
|
-
│ Stack overflow → Infinite recursion — fix logic │
|
|
68
|
-
└─────────────────────────────────────────────────────────────┘
|
|
69
|
-
```
|
|
70
|
-
|
|
71
|
-
---
|
|
72
|
-
|
|
73
|
-
## Retry with Exponential Backoff + Jitter
|
|
74
|
-
|
|
75
|
-
```typescript
|
|
76
|
-
interface RetryOptions {
|
|
77
|
-
maxRetries: number;
|
|
78
|
-
baseDelayMs: number;
|
|
79
|
-
maxDelayMs: number;
|
|
80
|
-
retryableErrors?: (error: unknown) => boolean;
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
const DEFAULT_RETRY: RetryOptions = {
|
|
84
|
-
maxRetries: 3,
|
|
85
|
-
baseDelayMs: 500,
|
|
86
|
-
maxDelayMs: 15_000,
|
|
87
|
-
retryableErrors: (err) =>
|
|
88
|
-
err instanceof Error && (
|
|
89
|
-
err.message.includes("ECONNRESET") ||
|
|
90
|
-
err.message.includes("ETIMEDOUT") ||
|
|
91
|
-
err.message.includes("503") ||
|
|
92
|
-
err.message.includes("429")
|
|
93
|
-
),
|
|
94
|
-
};
|
|
95
|
-
|
|
96
|
-
async function withRetry<T>(
|
|
97
|
-
fn: () => Promise<T>,
|
|
98
|
-
options: Partial<RetryOptions> = {},
|
|
99
|
-
): Promise<T> {
|
|
100
|
-
const opts = { ...DEFAULT_RETRY, ...options };
|
|
101
|
-
|
|
102
|
-
for (let attempt = 0; attempt <= opts.maxRetries; attempt++) {
|
|
103
|
-
try {
|
|
104
|
-
return await fn();
|
|
105
|
-
} catch (error) {
|
|
106
|
-
const isLast = attempt === opts.maxRetries;
|
|
107
|
-
const isRetryable = opts.retryableErrors?.(error) ?? true;
|
|
108
|
-
|
|
109
|
-
if (isLast || !isRetryable) throw error;
|
|
110
|
-
|
|
111
|
-
// Exponential backoff with full jitter
|
|
112
|
-
const exponential = opts.baseDelayMs * 2 ** attempt;
|
|
113
|
-
const capped = Math.min(exponential, opts.maxDelayMs);
|
|
114
|
-
const jitter = Math.random() * capped;
|
|
115
|
-
|
|
116
|
-
console.warn(
|
|
117
|
-
`[RETRY] Attempt ${attempt + 1}/${opts.maxRetries} failed. ` +
|
|
118
|
-
`Retrying in ${Math.round(jitter)}ms...`
|
|
119
|
-
);
|
|
120
|
-
|
|
121
|
-
await sleep(jitter);
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
throw new Error("Unreachable");
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
function sleep(ms: number): Promise<void> {
|
|
128
|
-
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
// ❌ NEVER retry non-idempotent operations without idempotency keys
|
|
132
|
-
// ❌ withRetry(() => createPayment(order)); // could charge twice!
|
|
133
|
-
// ✅ withRetry(() => createPayment(order, { idempotencyKey: order.id }));
|
|
134
|
-
```
|
|
135
|
-
|
|
136
|
-
---
|
|
137
|
-
|
|
138
|
-
## Circuit Breaker
|
|
139
|
-
|
|
140
|
-
```typescript
|
|
141
|
-
enum CircuitState {
|
|
142
|
-
CLOSED = "CLOSED", // Normal — requests pass through
|
|
143
|
-
OPEN = "OPEN", // Tripped — requests fail immediately
|
|
144
|
-
HALF_OPEN = "HALF_OPEN", // Testing — one request allowed
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
class CircuitBreaker {
|
|
148
|
-
private state = CircuitState.CLOSED;
|
|
149
|
-
private failureCount = 0;
|
|
150
|
-
private lastFailureTime = 0;
|
|
151
|
-
private successCount = 0;
|
|
152
|
-
|
|
153
|
-
constructor(
|
|
154
|
-
private readonly threshold: number = 5,
|
|
155
|
-
private readonly resetTimeoutMs: number = 30_000,
|
|
156
|
-
private readonly halfOpenMax: number = 3,
|
|
157
|
-
) {}
|
|
158
|
-
|
|
159
|
-
async execute<T>(fn: () => Promise<T>, fallback?: () => T): Promise<T> {
|
|
160
|
-
if (this.state === CircuitState.OPEN) {
|
|
161
|
-
if (Date.now() - this.lastFailureTime > this.resetTimeoutMs) {
|
|
162
|
-
this.state = CircuitState.HALF_OPEN;
|
|
163
|
-
this.successCount = 0;
|
|
164
|
-
} else {
|
|
165
|
-
if (fallback) return fallback();
|
|
166
|
-
throw new Error(`Circuit OPEN — service unavailable`);
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
try {
|
|
171
|
-
const result = await fn();
|
|
172
|
-
this.onSuccess();
|
|
173
|
-
return result;
|
|
174
|
-
} catch (error) {
|
|
175
|
-
this.onFailure();
|
|
176
|
-
if (fallback) return fallback();
|
|
177
|
-
throw error;
|
|
178
|
-
}
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
private onSuccess(): void {
|
|
182
|
-
if (this.state === CircuitState.HALF_OPEN) {
|
|
183
|
-
this.successCount++;
|
|
184
|
-
if (this.successCount >= this.halfOpenMax) {
|
|
185
|
-
this.state = CircuitState.CLOSED; // Recovery confirmed
|
|
186
|
-
this.failureCount = 0;
|
|
187
|
-
}
|
|
188
|
-
} else {
|
|
189
|
-
this.failureCount = 0;
|
|
190
|
-
}
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
private onFailure(): void {
|
|
194
|
-
this.failureCount++;
|
|
195
|
-
this.lastFailureTime = Date.now();
|
|
196
|
-
if (this.failureCount >= this.threshold) {
|
|
197
|
-
this.state = CircuitState.OPEN;
|
|
198
|
-
}
|
|
199
|
-
}
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
// Usage
|
|
203
|
-
const paymentCircuit = new CircuitBreaker(5, 30_000);
|
|
204
|
-
|
|
205
|
-
const result = await paymentCircuit.execute(
|
|
206
|
-
() => paymentGateway.charge(amount),
|
|
207
|
-
() => ({ status: "deferred", message: "Payment queued for retry" }),
|
|
208
|
-
);
|
|
209
|
-
```
|
|
210
|
-
|
|
211
|
-
---
|
|
212
|
-
|
|
213
|
-
## React Error Boundaries
|
|
214
|
-
|
|
215
|
-
```tsx
|
|
216
|
-
// ✅ Error boundary with recovery
|
|
217
|
-
import { Component, type ReactNode } from "react";
|
|
218
|
-
|
|
219
|
-
interface Props {
|
|
220
|
-
children: ReactNode;
|
|
221
|
-
fallback?: ReactNode;
|
|
222
|
-
onError?: (error: Error, errorInfo: React.ErrorInfo) => void;
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
interface State {
|
|
226
|
-
hasError: boolean;
|
|
227
|
-
error: Error | null;
|
|
228
|
-
}
|
|
229
|
-
|
|
230
|
-
class ErrorBoundary extends Component<Props, State> {
|
|
231
|
-
state: State = { hasError: false, error: null };
|
|
232
|
-
|
|
233
|
-
static getDerivedStateFromError(error: Error): State {
|
|
234
|
-
return { hasError: true, error };
|
|
235
|
-
}
|
|
236
|
-
|
|
237
|
-
componentDidCatch(error: Error, errorInfo: React.ErrorInfo) {
|
|
238
|
-
this.props.onError?.(error, errorInfo);
|
|
239
|
-
// Send to error tracking (Sentry, etc.)
|
|
240
|
-
}
|
|
241
|
-
|
|
242
|
-
render() {
|
|
243
|
-
if (this.state.hasError) {
|
|
244
|
-
return this.props.fallback ?? (
|
|
245
|
-
<div role="alert">
|
|
246
|
-
<h2>Something went wrong</h2>
|
|
247
|
-
<button onClick={() => this.setState({ hasError: false, error: null })}>
|
|
248
|
-
Try Again
|
|
249
|
-
</button>
|
|
250
|
-
</div>
|
|
251
|
-
);
|
|
252
|
-
}
|
|
253
|
-
return this.props.children;
|
|
254
|
-
}
|
|
255
|
-
}
|
|
256
|
-
|
|
257
|
-
// ❌ TRAP: Error boundaries do NOT catch:
|
|
258
|
-
// - Event handlers (use try/catch inside handlers)
|
|
259
|
-
// - Async code (use Promise.catch or error state)
|
|
260
|
-
// - Server-side rendering errors
|
|
261
|
-
// - Errors in the error boundary itself
|
|
262
|
-
```
|
|
263
|
-
|
|
264
|
-
---
|
|
265
|
-
|
|
266
|
-
## Timeout Patterns
|
|
267
|
-
|
|
268
|
-
```typescript
|
|
269
|
-
// ✅ AbortController-based timeout (modern, cancellable)
|
|
270
|
-
async function withTimeout<T>(
|
|
271
|
-
fn: (signal: AbortSignal) => Promise<T>,
|
|
272
|
-
timeoutMs: number,
|
|
273
|
-
): Promise<T> {
|
|
274
|
-
const controller = new AbortController();
|
|
275
|
-
const timer = setTimeout(() => controller.abort(), timeoutMs);
|
|
276
|
-
|
|
277
|
-
try {
|
|
278
|
-
return await fn(controller.signal);
|
|
279
|
-
} catch (error) {
|
|
280
|
-
if (controller.signal.aborted) {
|
|
281
|
-
throw new OperationalError(`Operation timed out after ${timeoutMs}ms`, true);
|
|
282
|
-
}
|
|
283
|
-
throw error;
|
|
284
|
-
} finally {
|
|
285
|
-
clearTimeout(timer);
|
|
286
|
-
}
|
|
287
|
-
}
|
|
288
|
-
|
|
289
|
-
// Usage
|
|
290
|
-
const data = await withTimeout(
|
|
291
|
-
(signal) => fetch("https://api.example.com/data", { signal }),
|
|
292
|
-
5000,
|
|
293
|
-
);
|
|
294
|
-
```
|
|
295
|
-
|
|
296
|
-
---
|
|
297
|
-
|
|
298
|
-
## Graceful Degradation (Fallback Chains)
|
|
299
|
-
|
|
300
|
-
```typescript
|
|
301
|
-
// ✅ Layered fallback: primary → cache → stale → default
|
|
302
|
-
async function getUserProfile(userId: string): Promise<UserProfile> {
|
|
303
|
-
// Layer 1: Primary source
|
|
304
|
-
try {
|
|
305
|
-
return await api.getUser(userId);
|
|
306
|
-
} catch { /* fall through */ }
|
|
307
|
-
|
|
308
|
-
// Layer 2: Cache
|
|
309
|
-
try {
|
|
310
|
-
const cached = await cache.get(`user:${userId}`);
|
|
311
|
-
if (cached) return { ...cached, _stale: true };
|
|
312
|
-
} catch { /* fall through */ }
|
|
313
|
-
|
|
314
|
-
// Layer 3: Default
|
|
315
|
-
return {
|
|
316
|
-
id: userId,
|
|
317
|
-
name: "Unknown User",
|
|
318
|
-
avatar: "/default-avatar.png",
|
|
319
|
-
_stale: true,
|
|
320
|
-
_default: true,
|
|
321
|
-
};
|
|
322
|
-
}
|
|
323
|
-
|
|
324
|
-
// ❌ BAD: Crash the whole page because one API is down
|
|
325
|
-
// ✅ GOOD: Show stale/partial data with a warning banner
|
|
326
|
-
```
|
|
327
|
-
|
|
328
|
-
---
|
|
329
|
-
|
|
330
|
-
## Dead Letter Queue Pattern
|
|
331
|
-
|
|
332
|
-
```typescript
|
|
333
|
-
// When a message/job fails after all retries, don't lose it
|
|
334
|
-
interface DeadLetter<T> {
|
|
335
|
-
payload: T;
|
|
336
|
-
error: string;
|
|
337
|
-
failedAt: string;
|
|
338
|
-
attempts: number;
|
|
339
|
-
originalQueue: string;
|
|
340
|
-
}
|
|
341
|
-
|
|
342
|
-
async function processWithDLQ<T>(
|
|
343
|
-
payload: T,
|
|
344
|
-
processor: (item: T) => Promise<void>,
|
|
345
|
-
dlqStore: { push: (item: DeadLetter<T>) => Promise<void> },
|
|
346
|
-
): Promise<void> {
|
|
347
|
-
try {
|
|
348
|
-
await withRetry(() => processor(payload), { maxRetries: 3 });
|
|
349
|
-
} catch (error) {
|
|
350
|
-
// Exhausted retries — park in dead letter queue
|
|
351
|
-
await dlqStore.push({
|
|
352
|
-
payload,
|
|
353
|
-
error: error instanceof Error ? error.message : String(error),
|
|
354
|
-
failedAt: new Date().toISOString(),
|
|
355
|
-
attempts: 4,
|
|
356
|
-
originalQueue: "main",
|
|
357
|
-
});
|
|
358
|
-
// Don't throw — the message is preserved for manual review
|
|
359
|
-
}
|
|
360
|
-
}
|
|
361
|
-
```
|
|
362
|
-
|
|
363
|
-
---
|
|
364
|
-
|
|
365
|
-
## Anti-Patterns (Never Do These)
|
|
366
|
-
|
|
367
|
-
```
|
|
368
|
-
❌ Swallowing errors silently: catch (e) { /* empty */ }
|
|
369
|
-
❌ Retrying infinitely without a max — causes resource exhaustion
|
|
370
|
-
❌ Retrying POST/DELETE without idempotency keys
|
|
371
|
-
❌ Using fixed-delay retries — causes thundering herd
|
|
372
|
-
❌ Catching Error base class when you mean a specific subclass
|
|
373
|
-
❌ Logging error.message but not error.stack
|
|
374
|
-
❌ Returning null to indicate failure (use Result type or throw)
|
|
375
|
-
❌ Wrapping synchronous code in try/catch when it can't fail
|
|
376
|
-
```
|
|
377
|
-
|
|
378
|
-
---
|
|
1
|
+
---
|
|
2
|
+
name: error-resilience
|
|
3
|
+
description: Error resilience and fault tolerance mastery. Retry strategies (exponential backoff with jitter), circuit breakers, bulkheads, graceful degradation, React error boundaries, dead letter queues, timeout patterns, fallback chains, and idempotent error recovery. Use when building fault-tolerant systems, handling flaky external services, or preventing cascading failures.
|
|
4
|
+
allowed-tools: Read, Write, Edit, Glob, Grep
|
|
5
|
+
version: 1.0.0
|
|
6
|
+
last-updated: 2026-04-17
|
|
7
|
+
applies-to-model: gemini-2.5-pro, claude-3-7-sonnet
|
|
8
|
+
---
|
|
9
|
+
|
|
10
|
+
## Hallucination Traps (Read First)
|
|
11
|
+
- ❌ Retrying non-idempotent operations (POST payments) without idempotency keys -> ✅ Always require idempotency keys for non-safe HTTP methods before retrying
|
|
12
|
+
- ❌ Using fixed delay retries instead of exponential backoff -> ✅ Exponential backoff with jitter prevents thundering herd
|
|
13
|
+
- ❌ Catching all errors and swallowing them -> ✅ Only catch recoverable (operational) errors; let programmer errors crash
|
|
14
|
+
|
|
15
|
+
---
|
|
16
|
+
|
|
17
|
+
# Error Resilience — Fault-Tolerant Systems
|
|
18
|
+
|
|
19
|
+
---
|
|
20
|
+
|
|
21
|
+
## Error Classification (Always Do This First)
|
|
22
|
+
|
|
23
|
+
```typescript
|
|
24
|
+
// ✅ CRITICAL: Classify errors before handling them
|
|
25
|
+
// Operational errors = expected failures you CAN recover from
|
|
26
|
+
// Programmer errors = bugs you CANNOT recover from
|
|
27
|
+
|
|
28
|
+
class OperationalError extends Error {
|
|
29
|
+
constructor(message: string, public readonly isRetryable: boolean = false) {
|
|
30
|
+
super(message);
|
|
31
|
+
this.name = "OperationalError";
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
// ❌ BAD: Treating all errors the same
|
|
36
|
+
catch (e) { console.log(e); }
|
|
37
|
+
|
|
38
|
+
// ✅ GOOD: Classifying and routing
|
|
39
|
+
catch (error) {
|
|
40
|
+
if (error instanceof OperationalError && error.isRetryable) {
|
|
41
|
+
return retry(operation);
|
|
42
|
+
}
|
|
43
|
+
if (error instanceof OperationalError) {
|
|
44
|
+
return fallback(error);
|
|
45
|
+
}
|
|
46
|
+
// Programmer error — crash fast, fix the bug
|
|
47
|
+
throw error;
|
|
48
|
+
}
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
```
|
|
52
|
+
┌─────────────────────────────────────────────────────────────┐
|
|
53
|
+
│ Operational (recoverable) │
|
|
54
|
+
├─────────────────────────────────────────────────────────────┤
|
|
55
|
+
│ Network timeout → Retry with backoff │
|
|
56
|
+
│ Rate limited (429) → Retry after Retry-After header │
|
|
57
|
+
│ Service unavailable (503) → Circuit breaker + fallback │
|
|
58
|
+
│ Database connection lost → Reconnect with pool │
|
|
59
|
+
│ Input validation failed → Return 400 to client │
|
|
60
|
+
│ File not found → Return 404 or create default │
|
|
61
|
+
├─────────────────────────────────────────────────────────────┤
|
|
62
|
+
│ Programmer (crash immediately) │
|
|
63
|
+
├─────────────────────────────────────────────────────────────┤
|
|
64
|
+
│ TypeError / ReferenceError → Bug — fix the code │
|
|
65
|
+
│ Assertion failure → Invariant violated — fix logic │
|
|
66
|
+
│ Undefined is not a function → Missing import or typo │
|
|
67
|
+
│ Stack overflow → Infinite recursion — fix logic │
|
|
68
|
+
└─────────────────────────────────────────────────────────────┘
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
---
|
|
72
|
+
|
|
73
|
+
## Retry with Exponential Backoff + Jitter
|
|
74
|
+
|
|
75
|
+
```typescript
|
|
76
|
+
interface RetryOptions {
|
|
77
|
+
maxRetries: number;
|
|
78
|
+
baseDelayMs: number;
|
|
79
|
+
maxDelayMs: number;
|
|
80
|
+
retryableErrors?: (error: unknown) => boolean;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
const DEFAULT_RETRY: RetryOptions = {
|
|
84
|
+
maxRetries: 3,
|
|
85
|
+
baseDelayMs: 500,
|
|
86
|
+
maxDelayMs: 15_000,
|
|
87
|
+
retryableErrors: (err) =>
|
|
88
|
+
err instanceof Error && (
|
|
89
|
+
err.message.includes("ECONNRESET") ||
|
|
90
|
+
err.message.includes("ETIMEDOUT") ||
|
|
91
|
+
err.message.includes("503") ||
|
|
92
|
+
err.message.includes("429")
|
|
93
|
+
),
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
async function withRetry<T>(
|
|
97
|
+
fn: () => Promise<T>,
|
|
98
|
+
options: Partial<RetryOptions> = {},
|
|
99
|
+
): Promise<T> {
|
|
100
|
+
const opts = { ...DEFAULT_RETRY, ...options };
|
|
379
101
|
|
|
102
|
+
for (let attempt = 0; attempt <= opts.maxRetries; attempt++) {
|
|
103
|
+
try {
|
|
104
|
+
return await fn();
|
|
105
|
+
} catch (error) {
|
|
106
|
+
const isLast = attempt === opts.maxRetries;
|
|
107
|
+
const isRetryable = opts.retryableErrors?.(error) ?? true;
|
|
108
|
+
|
|
109
|
+
if (isLast || !isRetryable) throw error;
|
|
110
|
+
|
|
111
|
+
// Exponential backoff with full jitter
|
|
112
|
+
const exponential = opts.baseDelayMs * 2 ** attempt;
|
|
113
|
+
const capped = Math.min(exponential, opts.maxDelayMs);
|
|
114
|
+
const jitter = Math.random() * capped;
|
|
115
|
+
|
|
116
|
+
console.warn(
|
|
117
|
+
`[RETRY] Attempt ${attempt + 1}/${opts.maxRetries} failed. ` +
|
|
118
|
+
`Retrying in ${Math.round(jitter)}ms...`
|
|
119
|
+
);
|
|
120
|
+
|
|
121
|
+
await sleep(jitter);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
throw new Error("Unreachable");
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
function sleep(ms: number): Promise<void> {
|
|
128
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
// ❌ NEVER retry non-idempotent operations without idempotency keys
|
|
132
|
+
// ❌ withRetry(() => createPayment(order)); // could charge twice!
|
|
133
|
+
// ✅ withRetry(() => createPayment(order, { idempotencyKey: order.id }));
|
|
134
|
+
```
|
|
380
135
|
|
|
381
136
|
---
|
|
382
137
|
|
|
383
|
-
##
|
|
138
|
+
## Circuit Breaker
|
|
139
|
+
|
|
140
|
+
```typescript
|
|
141
|
+
enum CircuitState {
|
|
142
|
+
CLOSED = "CLOSED", // Normal — requests pass through
|
|
143
|
+
OPEN = "OPEN", // Tripped — requests fail immediately
|
|
144
|
+
HALF_OPEN = "HALF_OPEN", // Testing — one request allowed
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
class CircuitBreaker {
|
|
148
|
+
private state = CircuitState.CLOSED;
|
|
149
|
+
private failureCount = 0;
|
|
150
|
+
private lastFailureTime = 0;
|
|
151
|
+
private successCount = 0;
|
|
152
|
+
|
|
153
|
+
constructor(
|
|
154
|
+
private readonly threshold: number = 5,
|
|
155
|
+
private readonly resetTimeoutMs: number = 30_000,
|
|
156
|
+
private readonly halfOpenMax: number = 3,
|
|
157
|
+
) {}
|
|
158
|
+
|
|
159
|
+
async execute<T>(fn: () => Promise<T>, fallback?: () => T): Promise<T> {
|
|
160
|
+
if (this.state === CircuitState.OPEN) {
|
|
161
|
+
if (Date.now() - this.lastFailureTime > this.resetTimeoutMs) {
|
|
162
|
+
this.state = CircuitState.HALF_OPEN;
|
|
163
|
+
this.successCount = 0;
|
|
164
|
+
} else {
|
|
165
|
+
if (fallback) return fallback();
|
|
166
|
+
throw new Error(`Circuit OPEN — service unavailable`);
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
try {
|
|
171
|
+
const result = await fn();
|
|
172
|
+
this.onSuccess();
|
|
173
|
+
return result;
|
|
174
|
+
} catch (error) {
|
|
175
|
+
this.onFailure();
|
|
176
|
+
if (fallback) return fallback();
|
|
177
|
+
throw error;
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
private onSuccess(): void {
|
|
182
|
+
if (this.state === CircuitState.HALF_OPEN) {
|
|
183
|
+
this.successCount++;
|
|
184
|
+
if (this.successCount >= this.halfOpenMax) {
|
|
185
|
+
this.state = CircuitState.CLOSED; // Recovery confirmed
|
|
186
|
+
this.failureCount = 0;
|
|
187
|
+
}
|
|
188
|
+
} else {
|
|
189
|
+
this.failureCount = 0;
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
private onFailure(): void {
|
|
194
|
+
this.failureCount++;
|
|
195
|
+
this.lastFailureTime = Date.now();
|
|
196
|
+
if (this.failureCount >= this.threshold) {
|
|
197
|
+
this.state = CircuitState.OPEN;
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
// Usage
|
|
203
|
+
const paymentCircuit = new CircuitBreaker(5, 30_000);
|
|
204
|
+
|
|
205
|
+
const result = await paymentCircuit.execute(
|
|
206
|
+
() => paymentGateway.charge(amount),
|
|
207
|
+
() => ({ status: "deferred", message: "Payment queued for retry" }),
|
|
208
|
+
);
|
|
209
|
+
```
|
|
210
|
+
|
|
211
|
+
---
|
|
212
|
+
|
|
213
|
+
## React Error Boundaries
|
|
214
|
+
|
|
215
|
+
```tsx
|
|
216
|
+
// ✅ Error boundary with recovery
|
|
217
|
+
import { Component, type ReactNode } from "react";
|
|
218
|
+
|
|
219
|
+
interface Props {
|
|
220
|
+
children: ReactNode;
|
|
221
|
+
fallback?: ReactNode;
|
|
222
|
+
onError?: (error: Error, errorInfo: React.ErrorInfo) => void;
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
interface State {
|
|
226
|
+
hasError: boolean;
|
|
227
|
+
error: Error | null;
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
class ErrorBoundary extends Component<Props, State> {
|
|
231
|
+
state: State = { hasError: false, error: null };
|
|
232
|
+
|
|
233
|
+
static getDerivedStateFromError(error: Error): State {
|
|
234
|
+
return { hasError: true, error };
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
componentDidCatch(error: Error, errorInfo: React.ErrorInfo) {
|
|
238
|
+
this.props.onError?.(error, errorInfo);
|
|
239
|
+
// Send to error tracking (Sentry, etc.)
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
render() {
|
|
243
|
+
if (this.state.hasError) {
|
|
244
|
+
return this.props.fallback ?? (
|
|
245
|
+
<div role="alert">
|
|
246
|
+
<h2>Something went wrong</h2>
|
|
247
|
+
<button onClick={() => this.setState({ hasError: false, error: null })}>
|
|
248
|
+
Try Again
|
|
249
|
+
</button>
|
|
250
|
+
</div>
|
|
251
|
+
);
|
|
252
|
+
}
|
|
253
|
+
return this.props.children;
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
// ❌ TRAP: Error boundaries do NOT catch:
|
|
258
|
+
// - Event handlers (use try/catch inside handlers)
|
|
259
|
+
// - Async code (use Promise.catch or error state)
|
|
260
|
+
// - Server-side rendering errors
|
|
261
|
+
// - Errors in the error boundary itself
|
|
262
|
+
```
|
|
263
|
+
|
|
264
|
+
---
|
|
265
|
+
|
|
266
|
+
## Timeout Patterns
|
|
267
|
+
|
|
268
|
+
```typescript
|
|
269
|
+
// ✅ AbortController-based timeout (modern, cancellable)
|
|
270
|
+
async function withTimeout<T>(
|
|
271
|
+
fn: (signal: AbortSignal) => Promise<T>,
|
|
272
|
+
timeoutMs: number,
|
|
273
|
+
): Promise<T> {
|
|
274
|
+
const controller = new AbortController();
|
|
275
|
+
const timer = setTimeout(() => controller.abort(), timeoutMs);
|
|
276
|
+
|
|
277
|
+
try {
|
|
278
|
+
return await fn(controller.signal);
|
|
279
|
+
} catch (error) {
|
|
280
|
+
if (controller.signal.aborted) {
|
|
281
|
+
throw new OperationalError(`Operation timed out after ${timeoutMs}ms`, true);
|
|
282
|
+
}
|
|
283
|
+
throw error;
|
|
284
|
+
} finally {
|
|
285
|
+
clearTimeout(timer);
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
// Usage
|
|
290
|
+
const data = await withTimeout(
|
|
291
|
+
(signal) => fetch("https://api.example.com/data", { signal }),
|
|
292
|
+
5000,
|
|
293
|
+
);
|
|
294
|
+
```
|
|
295
|
+
|
|
296
|
+
---
|
|
297
|
+
|
|
298
|
+
## Graceful Degradation (Fallback Chains)
|
|
299
|
+
|
|
300
|
+
```typescript
|
|
301
|
+
// ✅ Layered fallback: primary → cache → stale → default
|
|
302
|
+
async function getUserProfile(userId: string): Promise<UserProfile> {
|
|
303
|
+
// Layer 1: Primary source
|
|
304
|
+
try {
|
|
305
|
+
return await api.getUser(userId);
|
|
306
|
+
} catch { /* fall through */ }
|
|
307
|
+
|
|
308
|
+
// Layer 2: Cache
|
|
309
|
+
try {
|
|
310
|
+
const cached = await cache.get(`user:${userId}`);
|
|
311
|
+
if (cached) return { ...cached, _stale: true };
|
|
312
|
+
} catch { /* fall through */ }
|
|
313
|
+
|
|
314
|
+
// Layer 3: Default
|
|
315
|
+
return {
|
|
316
|
+
id: userId,
|
|
317
|
+
name: "Unknown User",
|
|
318
|
+
avatar: "/default-avatar.png",
|
|
319
|
+
_stale: true,
|
|
320
|
+
_default: true,
|
|
321
|
+
};
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
// ❌ BAD: Crash the whole page because one API is down
|
|
325
|
+
// ✅ GOOD: Show stale/partial data with a warning banner
|
|
326
|
+
```
|
|
327
|
+
|
|
328
|
+
---
|
|
329
|
+
|
|
330
|
+
## Dead Letter Queue Pattern
|
|
331
|
+
|
|
332
|
+
```typescript
|
|
333
|
+
// When a message/job fails after all retries, don't lose it
|
|
334
|
+
interface DeadLetter<T> {
|
|
335
|
+
payload: T;
|
|
336
|
+
error: string;
|
|
337
|
+
failedAt: string;
|
|
338
|
+
attempts: number;
|
|
339
|
+
originalQueue: string;
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
async function processWithDLQ<T>(
|
|
343
|
+
payload: T,
|
|
344
|
+
processor: (item: T) => Promise<void>,
|
|
345
|
+
dlqStore: { push: (item: DeadLetter<T>) => Promise<void> },
|
|
346
|
+
): Promise<void> {
|
|
347
|
+
try {
|
|
348
|
+
await withRetry(() => processor(payload), { maxRetries: 3 });
|
|
349
|
+
} catch (error) {
|
|
350
|
+
// Exhausted retries — park in dead letter queue
|
|
351
|
+
await dlqStore.push({
|
|
352
|
+
payload,
|
|
353
|
+
error: error instanceof Error ? error.message : String(error),
|
|
354
|
+
failedAt: new Date().toISOString(),
|
|
355
|
+
attempts: 4,
|
|
356
|
+
originalQueue: "main",
|
|
357
|
+
});
|
|
358
|
+
// Don't throw — the message is preserved for manual review
|
|
359
|
+
}
|
|
360
|
+
}
|
|
361
|
+
```
|
|
362
|
+
|
|
363
|
+
---
|
|
364
|
+
|
|
365
|
+
## Anti-Patterns (Never Do These)
|
|
366
|
+
|
|
367
|
+
```
|
|
368
|
+
❌ Swallowing errors silently: catch (e) { /* empty */ }
|
|
369
|
+
❌ Retrying infinitely without a max — causes resource exhaustion
|
|
370
|
+
❌ Retrying POST/DELETE without idempotency keys
|
|
371
|
+
❌ Using fixed-delay retries — causes thundering herd
|
|
372
|
+
❌ Catching Error base class when you mean a specific subclass
|
|
373
|
+
❌ Logging error.message but not error.stack
|
|
374
|
+
❌ Returning null to indicate failure (use Result type or throw)
|
|
375
|
+
❌ Wrapping synchronous code in try/catch when it can't fail
|
|
376
|
+
```
|
|
377
|
+
|
|
378
|
+
---
|
|
379
|
+
|
|
380
|
+
|
|
381
|
+
---
|
|
382
|
+
|
|
383
|
+
|
|
384
384
|
|
|
385
385
|
AI coding assistants often fall into specific bad habits when dealing with this domain. These are strictly forbidden:
|
|
386
386
|
|
|
@@ -392,7 +392,7 @@ AI coding assistants often fall into specific bad habits when dealing with this
|
|
|
392
392
|
|
|
393
393
|
---
|
|
394
394
|
|
|
395
|
-
|
|
395
|
+
|
|
396
396
|
|
|
397
397
|
**Slash command: `/review` or `/tribunal-full`**
|
|
398
398
|
**Active reviewers: `logic-reviewer` · `security-auditor`**
|
|
@@ -403,7 +403,7 @@ AI coding assistants often fall into specific bad habits when dealing with this
|
|
|
403
403
|
2. **Silent Degradation:** Catching and suppressing errors without logging or handling.
|
|
404
404
|
3. **Context Amnesia:** Forgetting the user's constraints and offering generic advice instead of tailored solutions.
|
|
405
405
|
|
|
406
|
-
|
|
406
|
+
|
|
407
407
|
|
|
408
408
|
Review these questions before confirming output:
|
|
409
409
|
```
|
|
@@ -417,4 +417,12 @@ Review these questions before confirming output:
|
|
|
417
417
|
|
|
418
418
|
**CRITICAL:** You must follow a strict "evidence-based closeout" state machine.
|
|
419
419
|
- ❌ **Forbidden:** Declaring a task complete because the output "looks correct."
|
|
420
|
-
- ✅ **Required:** You are explicitly forbidden from finalizing any task without providing **concrete evidence** (terminal output, passing tests, compile success, or equivalent proof) that your output works as intended.
|
|
420
|
+
- ✅ **Required:** You are explicitly forbidden from finalizing any task without providing **concrete evidence** (terminal output, passing tests, compile success, or equivalent proof) that your output works as intended.
|
|
421
|
+
|
|
422
|
+
|
|
423
|
+
## Pre-Flight Checklist
|
|
424
|
+
- [ ] Have I reviewed the user's specific constraints and requests?
|
|
425
|
+
- [ ] Have I checked the environment for relevant existing implementations?
|
|
426
|
+
|
|
427
|
+
## VBC Protocol (Verification-Before-Completion)
|
|
428
|
+
You MUST verify existing code signatures and variables before attempting to modify or call them. No hallucination is permitted.
|