fix(chatwoot-adapter): bound seen-marker growth with a 3-day TTL prune (#620)#32
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The Chatwoot adapter records one
ctx.storagemarker per relayed message, used to de-duplicate WhatsApp re-deliveries and to suppress the operator's own echoed sends. These markers were written once and never removed, so on a long-running instance the plugin's storage grew without bound, and the inbound-retry drain's periodic directory scan (storage.list, a fullreaddirSyncplus a per-file key decode) grew steadily more expensive as the marker count climbed.This change bounds the
seen:keyspace with a time-based retention window.Closes #620.
Changes
markSeennow stores{ t: <ms> }instead of a bare1;hasSeenis unchanged (it still checks presence only). This gives every marker an age.pruneSeen(now, ttl). A newMappingStoreprimitive that streams theseen:keys and deletes any older than the retention window. A pre-existing marker (stored as a bare1, with no timestamp) is adopted — re-stamped with the current time — rather than deleted, so the migration can never re-post a message as a duplicate; those adopted markers then age out one window later.SEEN_TTL_MSis 3 days and the prune cadence is hourly — hardcoded constants, matching the existing retry-timer tuning.Impact
minOpenWAVersionchange. Version 0.5.1 → 0.5.2 (patch).Testing
mapping-storeunit tests coverpruneSeen: TTL expiry, keeping recent markers, legacy-marker adoption (stamps rather than deletes), and touching onlyseen:-prefixed keys.tsc --noEmitclean, catalog in sync, andchatwoot-adapterpackages cleanly.