📌 Description
dlqRepository.insert in src/db/repositories/dlqRepository.ts serializes the entry payload with JSON.stringify(entry.payload). If the payload contains circular references or BigInt/other non-serializable values, JSON.stringify throws an uncaught error that propagates out of the DLQ insert — exactly when the system is already in a failure path trying to record a dead letter.
💡 Why it matters: The DLQ is the last line of defense; an insert that throws on a weird payload means the failed delivery is lost rather than captured for later inspection.
🧩 Requirements and context
- Guard the serialization: catch
JSON.stringify failures (circular refs, BigInt) and fall back to a safe, lossy-but-recorded representation (e.g. a sanitized stringification noting the issue).
- Never let a serialization error prevent the DLQ row from being written.
- Record a metric/log when a payload required fallback serialization.
- Add unit tests with a circular-reference and a BigInt payload.
Non-functional requirements
- Must be secure, tested, and documented.
- Should be efficient and easy to review.
🛠️ Suggested execution
1. Fork the repo and create a branch
git checkout -b fix/dlq-insert-serialization-guard
2. Implement changes
- Write/modify the relevant source:
src/db/repositories/dlqRepository.ts
- Write comprehensive tests:
tests/dlq.test.ts
- Add documentation: inline TSDoc on fallback behavior
- Include TSDoc doc comments
- Validate security assumptions: fallback doesn't leak secrets
3. Test and commit
- Cover edge cases: circular ref payload, BigInt payload, normal payload
- Include test output and security notes in the PR description.
Example commit message
fix(dlq): guard JSON serialization in dlqRepository.insert
✅ Acceptance criteria
🔒 Security notes
Ensure the fallback representation does not inadvertently include sensitive fields.
📋 Guidelines
- Minimum 95% test coverage
- Clear documentation
- Timeframe: 96 hours
📌 Description
dlqRepository.insertinsrc/db/repositories/dlqRepository.tsserializes the entry payload withJSON.stringify(entry.payload). If the payload contains circular references or BigInt/other non-serializable values,JSON.stringifythrows an uncaught error that propagates out of the DLQ insert — exactly when the system is already in a failure path trying to record a dead letter.🧩 Requirements and context
JSON.stringifyfailures (circular refs, BigInt) and fall back to a safe, lossy-but-recorded representation (e.g. a sanitized stringification noting the issue).Non-functional requirements
🛠️ Suggested execution
1. Fork the repo and create a branch
2. Implement changes
src/db/repositories/dlqRepository.tstests/dlq.test.ts3. Test and commit
npm testExample commit message
✅ Acceptance criteria
🔒 Security notes
Ensure the fallback representation does not inadvertently include sensitive fields.
📋 Guidelines