📌 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
🔒 Security notes
Reduces memory-exhaustion risk from sustained traffic producing large retained snapshots.
📋 Guidelines
- Minimum 95% test coverage
- Clear documentation
- Timeframe: 96 hours
📌 Description
BoundedHistory<T>insrc/utils/history.tscaps 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 largeroutearray). Long-running processes under heavyGET /api/v1/metricstraffic could retain more memory than the count cap implies.🧩 Requirements and context
BoundedHistorycan also cap total retained payload size, not just count.push, iteration) backward compatible for current callers (routes/metrics.ts,middleware/auditLog.ts).🛠️ Suggested execution
BoundedHistoryinsrc/utils/history.tswith an optional size-aware eviction path.src/utils/history.test.tsfor size-based eviction alongside the existing count-based tests.routes/metrics.tsandmiddleware/auditLog.tscallers are unaffected if they don't opt in.✅ Acceptance criteria
BoundedHistorycan be configured with a size bound in addition to a count bound.🔒 Security notes
Reduces memory-exhaustion risk from sustained traffic producing large retained snapshots.
📋 Guidelines