AgentSkillsCN

resilience-audit

验证离线功能与状态恢复,以践行优雅降级的承诺。

SKILL.md
--- frontmatter
name: resilience-audit
description: Offline functionality and state recovery verification for graceful degradation commitment.
compatibility: Service Worker support, IndexedDB
metadata:
  invocation: both
  inputs: |
    - scope: string (optional, all|offline|recovery|sync, default: all)
    - simulate: boolean (optional, simulate network conditions, default: false)
  outputs: |
    - report: string (markdown resilience analysis)
    - gaps: array (resilience gaps identified)

Resilience Audit

Verify graceful degradation and state recovery capabilities.

Purpose

Ensure the application handles adverse conditions gracefully:

  • Network outages
  • Server errors
  • Browser crashes
  • Slow connections
  • Interrupted operations

Checks Performed

1. Offline Capability

CheckLevelDescription
Core readEssentialView existing data offline
Core writeEnhancedQueue changes for sync
Full offlineCompleteWork entirely offline

2. State Recovery

CheckExpectation
Page refreshState preserved
Browser crashDraft recovery
Tab close/reopenSession restore
Multi-tab syncConsistent state

3. Network Resilience

ConditionExpected Behavior
Slow 3GUsable with feedback
OfflineClear indication + queuing
Flaky connectionRetry with backoff
Server 500Graceful error + retry option

4. Data Sync

CheckExpectation
Conflict resolutionDefined strategy
Sync statusVisible to user
Offline queuePersisted
Retry logicExponential backoff

Usage

bash
# Full resilience audit
./scripts/resilience-audit.sh

# Offline focus
./scripts/resilience-audit.sh --scope offline

# With network simulation
./scripts/resilience-audit.sh --simulate

Output Format

markdown
## Resilience Audit Report

**Date:** 2025-01-20

### Offline Capability

| Feature | Offline Status | Notes |
|---------|----------------|-------|
| View cards | ✅ Works | Cached in IndexedDB |
| Create card | ⚠️ Partial | Queued but no feedback |
| Search | ❌ Fails | Requires server |
| Settings | ✅ Works | Local storage |

### State Recovery

| Scenario | Status | Notes |
|----------|--------|-------|
| Page refresh | ✅ | URL state preserved |
| Form in progress | ⚠️ | Lost on refresh |
| Crash recovery | ❌ | No draft persistence |
| Tab sync | ✅ | Real-time sync works |

### Network Resilience

| Condition | Tested | Result |
|-----------|--------|--------|
| Offline indicator | ✅ | Shows banner |
| Retry button | ⚠️ | Only on some errors |
| Request timeout | ✅ | 30s with feedback |
| Exponential backoff | ❌ | Fixed 5s retry |

### Data Sync

| Check | Status |
|-------|--------|
| Sync queue visible | ❌ No UI |
| Conflict resolution | ✅ Last-write-wins |
| Offline queue persisted | ✅ IndexedDB |
| Sync on reconnect | ✅ Automatic |

### Recommendations

1. **HIGH**: Add draft persistence for forms
2. **HIGH**: Implement exponential backoff for retries
3. **MEDIUM**: Show pending sync count to users
4. **MEDIUM**: Add offline-capable search with local index
5. **LOW**: Add conflict resolution UI for complex cases

Resilience Patterns

Offline-First Architecture

code
┌─────────────────────────────────────────┐
│              Application                │
├─────────────────────────────────────────┤
│  ┌─────────┐  ┌─────────┐  ┌─────────┐ │
│  │ UI Layer│──│ Service │──│  Sync   │ │
│  │         │  │ Worker  │  │ Manager │ │
│  └─────────┘  └─────────┘  └─────────┘ │
│       │            │            │       │
│  ┌─────────────────────────────────────┐│
│  │           IndexedDB                 ││
│  │     (Source of Truth)               ││
│  └─────────────────────────────────────┘│
└─────────────────────────────────────────┘
                    │
              [Network]
                    │
              ┌─────────┐
              │ Server  │
              └─────────┘

State Recovery Strategy

Data TypeStorageRecovery
User sessionlocalStorageAuto-restore
Form draftsIndexedDBPrompt to restore
Pending syncsIndexedDBAuto-retry
UI stateURL paramsBookmark-safe

Retry Strategy

javascript
// Exponential backoff with jitter
const retryDelays = [1000, 2000, 4000, 8000, 16000];
const jitter = Math.random() * 1000;
const delay = retryDelays[attempt] + jitter;

Prerequisites

  • Service Worker support
  • IndexedDB for offline storage
  • Network Information API (optional)

See Also