stemedb/applications/aphoria/dogfood/cachewrap/docs/sources/redis-spec.md
jml e758f2ebfb feat(aphoria): implement programmatic extractors for Option<T> semantics
Completes Task #3 of httpclient dogfooding with 100% detection rate (7/7 violations).

## New Extractors

- **OptionBoundsExtractor**: Detects Option<T> fields set to None (unbounded)
- **OptionValueExtractor**: Extracts values from Some(n) for threshold checks

Both extractors use context-aware pattern matching to understand Rust Option<T>
semantics, which declarative extractors cannot handle.

## Implementation

**Files Created**:
- applications/aphoria/src/extractors/option_bounds.rs (257 lines)
- applications/aphoria/src/extractors/option_value.rs (277 lines)
- applications/aphoria/docs/examples/extractors/programmatic-option-semantics.md

**Files Modified**:
- applications/aphoria/src/extractors/mod.rs - Added module declarations
- applications/aphoria/src/extractors/registry.rs - Registered extractors
- applications/aphoria/dogfood/httpclient/.aphoria/claims.toml - Added 4 claims
- applications/aphoria/dogfood/httpclient/TASK-1-SUMMARY.md - Task #3 completion

## Results

| Metric | Value |
|--------|-------|
| Detection Rate | 100% (7/7 violations) |
| Improvement | +29 percentage points (from 71%) |
| New Violations | 2 (max_redirects, max_retries unbounded) |
| Unit Tests | 13 (all passing) |

## Two-Claim Strategy

For each bounded Option<T> field:
1. **configured** claim - Detects None (unbounded)
2. **max_value** claim - Validates Some(n) threshold

Example:
- `max_redirects: None` → CONFLICT (not configured)
- `max_redirects: Some(20)` → CONFLICT (exceeds 10)
- `max_redirects: Some(5)` → PASS

## Enterprise Quality

✓ Proper error handling (no unwrap/expect)
✓ Comprehensive tests (6+7 unit tests)
✓ Full documentation with examples
✓ Reusable for 10+ similar patterns
✓ Screening patterns for performance

## Cachewrap Dogfood

Also includes complete cachewrap dogfood exercise:
- 10 claims for Redis cache wrapper
- Day 1-5 summaries
- Full retrospective and evaluation
- Declarative extractors for all patterns

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-02-11 06:43:10 +00:00

3.5 KiB

Redis Protocol Specification - Key Excerpts for Cache Client

Authority Tier: Tier 1 (Standards) Source: https://redis.io/docs/reference/protocol-spec/ + https://redis.io/commands/ Relevance: Defines canonical behavior for TTL, eviction, key formats, and command semantics


TTL and Expiration (SETEX, EXPIRE, EXPIREAT commands)

User fills in: Fetch Redis command documentation for SETEX, EXPIRE, EXPIREAT

Look for language like:

  • "SETEX key seconds value - Set key to hold string value with TTL of seconds"
  • "Keys are evicted when their TTL expires"
  • "If no expiration is set, keys persist indefinitely"

Key Claims:

  • cache/ttl :: required = true

    • Consequence: Missing TTL causes memory leak - cached values never expire, unbounded growth
  • cache/ttl :: minimum = 1

    • Consequence: TTL=0 means immediate expiration - cached value unusable
  • cache/expiration_strategy :: values = ["passive", "active"]

    • Consequence: Wrong strategy affects memory vs CPU tradeoff

Eviction Policies (MAXMEMORY-POLICY)

User fills in: Fetch Redis documentation for maxmemory-policy configuration

Look for:

  • LRU (Least Recently Used)
  • LFU (Least Frequently Used)
  • Random eviction
  • No eviction (return errors when memory full)

Key Claims:

  • cache/eviction_policy :: required = true

    • Consequence: No eviction policy means undefined behavior when cache full (errors or random eviction)
  • cache/eviction_policy :: recommended = "LRU"

    • Consequence: Wrong policy (e.g., random) degrades hit rates
  • cache/max_size :: required = true

    • Consequence: Unbounded cache size causes OOM under sustained load

Key Format and Validation

User fills in: Fetch Redis documentation on key restrictions

Look for:

  • Maximum key length (512 MB but practically much smaller)
  • Forbidden characters (control characters, null bytes)
  • Key naming best practices

Key Claims:

  • cache/key_validation :: required = true

    • Consequence: Unvalidated keys enable injection attacks (control characters, escape sequences)
  • cache/key_length :: maximum = 1024

    • Consequence: Excessively long keys waste memory and degrade performance

Connection Semantics

User fills in: Fetch Redis documentation on connection handling, pipelining, pooling

Look for:

  • Connection persistence recommendations
  • Pipelining for performance
  • Connection pool sizing

Key Claims:

  • cache/connection_pooling :: required = true

    • Consequence: No pooling means new connection per request - resource exhaustion
  • cache/connection_timeout :: minimum = 1

    • Consequence: timeout=0 causes indefinite blocking on connection failures

Extraction Guide

  1. Fetch documentation:

    # Navigate to Redis official docs
    open https://redis.io/docs/
    
  2. Search for key sections:

    • Commands: SETEX, EXPIRE, GET, SET
    • Configuration: maxmemory-policy, timeout
    • Best practices: Key design, connection management
  3. Extract MUST/SHOULD patterns:

    • Look for normative language (MUST, SHOULD, SHALL)
    • Document consequences from "Common Pitfalls" sections
    • Note performance implications
  4. Map to concept paths:

    • cache/ttl
    • cache/eviction_policy
    • cache/key_validation
    • cache/connection_pooling
  5. Add to claims with provenance:

    • Provenance: "Redis Protocol Specification v7.0 - SETEX command"
    • Link to specific command or config doc