Skip to content

Graceful Degradation with Feature Flags and Capacity Shedding#137

Merged
JamesEjembi merged 3 commits into
VeriNode-Labs:mainfrom
Husten150:feat/graceful-degradation-ff-capacity-shedding
Jul 22, 2026
Merged

Graceful Degradation with Feature Flags and Capacity Shedding#137
JamesEjembi merged 3 commits into
VeriNode-Labs:mainfrom
Husten150:feat/graceful-degradation-ff-capacity-shedding

Conversation

@Husten150

@Husten150 Husten150 commented Jul 20, 2026

Copy link
Copy Markdown
Contributor

Summary

Implements system-wide graceful degradation with feature flags and capacity shedding as described in issue #107.

Changes

Feature Flag System (src/lib/feature-flags.ts, src/components/FeatureFlagProvider.tsx)

  • Defines all feature flags as a typed union (staking, governance, quadratic-voting, collateral, analytics, notification, explorer)
  • URL parameter overrides: ?feature_staking=false
  • localStorage persistence for dev toggling
  • React context provider with useFeatureFlag() and useFeatureFlags() hooks
  • Priority-based fallback: computeFeatureFlags() merges defaults, code overrides, localStorage, and URL params

Capacity Shedding (src/lib/capacity-shedding.ts, src/components/CapacitySheddingProvider.tsx)

  • Monitors response time, queue size, error rate, and memory usage against configurable thresholds
  • Three capacity levels: healthy -> degraded -> critical
  • Priority-based shedding: critical features always available, low-priority shed first
  • Periodic metrics collection with auto-adjusting capacity state
  • subscribeToLevelChanges() for external monitoring integration

Graceful Degradation (src/components/DegradableFeature.tsx)

  • Wraps any feature with automatic fallback UI when disabled or shed
  • Shows "currently unavailable" message with feature name when degraded
  • Customizable fallback via fallback prop

UI Indicators (src/components/CapacityIndicator.tsx)

  • Shows banner when system is degraded or critical
  • Color-coded: green (healthy, hidden), yellow (degraded), red (critical, animated)
  • Expandable details explaining current system state

Client Broadcast Recovery Queue

  • src/hooks/useTxRetryQueue.ts: Persistent retry queue with LRU eviction, duplicate detection, exponential backoff
  • src/components/RetryWatcher.tsx: Background worker that retries pending transactions with polling
  • src/components/PendingTransactionsBanner.tsx: UI banner showing pending count with expandable details
  • src/components/Toast.tsx: Toast notification system for user feedback

Staking Integration

  • src/hooks/useSorobanStaking.ts: Staking hook with retry queue integration and refresh recovery
  • src/lib/stellar/rpcClient.ts: RPC client with proper PENDING/ERROR status handling
  • src/lib/sessionStore.ts: SessionStorage wrapper for persistent queue state

Tests

  • tests/graceful-degradation.spec.ts: Playwright tests for feature flags and capacity shedding
  • tests/retry-queue.spec.ts: Playwright tests for retry queue and duplicate detection

Bug Fixes

  • Stale closure in FeatureFlagProvider: Fixed onPopState callback to use useRef instead of capturing stale overrides from closure
  • updateEntry with null txHash: Fixed recoverFromRefresh to properly update entries with null txHash
  • sendTransaction always returning confirmed: Fixed rpcClient to check actual RPC response status
  • Missing pending status handling: Added pending status handling in RetryWatcher and useSorobanStaking

Closes #107

Husten150 and others added 3 commits July 20, 2026 17:14
…shedding

- Add FeatureFlagProvider with URL param and localStorage overrides
- Add capacity-shedding module with configurable thresholds and priority levels
- Add CapacityIndicator banner for degraded/critical state visibility
- Add DegradableFeature wrapper for graceful component fallback
- Add CapacitySheddingProvider for periodic health monitoring
- Update layout with new providers and capacity indicator
- Wrap staking page with DegradableFeature for feature flag control
- Add comprehensive Playwright tests for all degradation scenarios

Closes VeriNode-Labs#107
…ing system

- Fix stale closure in FeatureFlagProvider onPopState callback (useRef)
- Fix updateEntry not finding entries with null txHash in recoverFromRefresh
- Fix rpcClient sendTransaction always returning 'confirmed' regardless of actual RPC status
- Add handling for 'pending' status in RetryWatcher and useSorobanStaking
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Graceful Degradation with Feature Flags and Capacity Shedding

2 participants