Commit Graph
1 Commits
Author SHA1 Message Date
Test 9ed6c2638d feat(T2.7): implement workflow history pruning
- Add internal/history package for pruning workflow history
- Implement HistoryPruner with configurable pruning policies
- Automatic pruning on size/age/count thresholds
- Archive old entries to disk for compliance
- Memory-efficient history management
- Continue-as-new compatible design
- 17 history tests, all passing

Features:
- AddEntry() for adding task history
- Automatic pruning by:
  - Maximum history size (default 100MB)
  - Maximum entry age (default 24 hours)
  - Maximum entry count (default 1000)
- Manual Prune() trigger
- GetEntries() with filters (status, time range, recent)
- UpdateEntry() for status changes
- Archive old entries to configurable directory
- Clear() to reset history

Pruning Strategy:
- Entries sorted by end time (oldest first)
- Remove entries exceeding any threshold
- Archive to disk for historical analysis
- Keep recent entries for debugging
- 90% threshold triggers auto-pruning

Memory Management:
- Constant memory growth even with 1000s of tasks
- Estimated size calculated per entry
- Size ratio tracked (current vs max)
- Memory info reporting

Statistics:
- Total size and entry count
- Average entry size
- Prune and archive counts
- Last prune timestamp
- Usage ratio (%)
- Memory growth rate

Archival:
- Optional archive directory
- Entries saved as JSON for analysis
- Timestamp included in filename
- Non-blocking archive operations

Test Coverage:
- 17 history tests (add, query, prune, archive)
- Constant memory growth verified (1000 tasks)
- Age-based pruning verified
- Archive directory creation tested
- Status filtering tested
- Recent entries retrieval tested
- Update operations tested
- Policy defaults verified

Verification:
- Memory stays within bounds ✓
- Old entries pruned correctly ✓
- Recent entries preserved ✓
- Archive functionality working ✓
- Concurrent safe (RWMutex) ✓

Next: T2.8 (Distributed lock optimization)
2026-08-23 17:24:46 -07:00