fix: avoid duplicate webhooks during concurrent automod events - #46
Conversation
Share in-flight channel webhook lookup and creation within a Worker instance, clearing failures for subsequent retries. Keep unrelated channels independent and retain the existing successful cache TTL.
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
|
Codex review: needs real behavior proof before merge. Reviewed September 15, 2026, 11:48 PM ET / September 16, 2026, 03:48 UTC. ClawSweeper reviewWhat this changesShare pending channel webhook lookups and creation across concurrent automod events, with retry cleanup, regression tests, and documentation. Merge readiness⛔ Blocked before merge - 2 items remain The fix remains necessary on current main and has no identified blocking code defect. Real transport behavior proof is still required before merge. Priority: P2 Review scores
Verification
How this fits togetherHermit handles Discord automoderation events in a Cloudflare Worker. Its webhook helper finds or creates a channel webhook, which the event handler uses to repost moderated content. flowchart TD
A[Automod events] --> B[Channel webhook helper]
B --> C{Cached or pending?}
C -->|Yes| D[Reuse webhook or await lookup]
C -->|No| E[Discord lookup or creation]
E --> F[Cache success and clear pending]
D --> G[Repost moderated content]
F --> G
Before merge
Agent review detailsSecurityNone. Review metrics
Technical reviewBest possible solution: Keep deduplication at the existing channel cache boundary, preserving retry behavior and the documented Worker-instance scope. Do we have a high-confidence way to reproduce the issue? Yes, source establishes the race: simultaneous empty-cache callers can each finish an empty lookup and create a webhook before any result is cached. This review did not execute that path. Is this the best way to solve the issue? Yes, sharing the pending operation in the existing helper is a narrow solution that preserves successful caching and retries without adding configuration or distributed coordination. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 8c7c5e1931b0. LabelsLabel changes:
Label justifications:
EvidenceWhat I checked:
Likely related people:
Rank-up movesOptional improvements that raise the rating; they are not merge blockers.
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
|
What Problem This Solves
Fixes concurrent automod events creating duplicate webhooks when a channel's cache is empty.
User Impact
Events handled by the same Worker instance share one channel lookup and creation attempt. This avoids wasting Discord webhook slots during a burst. Failures remain retryable, and independent channels proceed independently. Separate Worker instances still have separate caches.
Why This Change Was Made
The cache previously became visible only after network requests completed, allowing every concurrent caller to start creation. Tracking the pending operation at the cache boundary closes that gap, while clearing it in
finallypreserves retries.Evidence
A synthetic 20-call reproduction against the production helper issued 20 list calls and 20 create calls before the fix; afterward it issues one of each and returns the same webhook to every caller. Five of six regression tests failed before the fix; all six now pass, including lookup/create/missing-token failures, retry, existing webhook reuse, and channel independence. No live Discord webhook was created.
Independent P0–P2 review is scoped-clean. Worker and forwarder frozen installs/typechecks, the Worker dry-run build, and all 356 tests in the combined tree passed. GitHub CI validates the exact PR head before merge.