Skip to content

Add snapshot compaction to utils/history.ts BoundedHistory to bound retained memory #85

Description

@Jagadeeshftw

📌 Description

BoundedHistory<T> in src/utils/history.ts caps entry count (e.g. last 50/200 reads per the README's metrics and audit sections), but each retained entry can itself grow (e.g. a settlement snapshot referencing a large route array). Long-running processes under heavy GET /api/v1/metrics traffic could retain more memory than the count cap implies.

🧩 Requirements and context

  • Add an optional per-entry size estimate/compaction step so BoundedHistory can also cap total retained payload size, not just count.
  • Keep the existing count-based API (push, iteration) backward compatible for current callers (routes/metrics.ts, middleware/auditLog.ts).
  • Document the memory-bounding guarantee in a code comment on the class.

🛠️ Suggested execution

  • Extend BoundedHistory in src/utils/history.ts with an optional size-aware eviction path.
  • Add tests in src/utils/history.test.ts for size-based eviction alongside the existing count-based tests.
  • Confirm routes/metrics.ts and middleware/auditLog.ts callers are unaffected if they don't opt in.

✅ Acceptance criteria

  • BoundedHistory can be configured with a size bound in addition to a count bound.
  • Existing count-only callers are unaffected.
  • Tests cover both eviction modes.

🔒 Security notes

Reduces memory-exhaustion risk from sustained traffic producing large retained snapshots.

📋 Guidelines

  • Minimum 95% test coverage
  • Clear documentation
  • Timeframe: 96 hours

Metadata

Metadata

Assignees

Labels

GrantFox OSSGrantFox open-source programMaybe RewardedGrantFox: potentially rewarded contributionOfficial Campaign | FWC26GrantFox official campaign issuebackendBackend service workperformancePerformance / caching

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions