Skip to content

fix: violations and AI referrals are neither sent twice nor lost during an outage - #106

Merged
cport1 merged 1 commit into
mainfrom
fix/violation-and-referral-delivery
Oct 2, 2026
Merged

cport1 merged 1 commit into
mainfrom
fix/violation-and-referral-delivery

Conversation

@cport1

@cport1 cport1 commented Oct 2, 2026

Copy link
Copy Markdown
Contributor

For WebDecoy/app#1245, item 7.

  • Violations sent twice: every request that records a violation drains the spool at shutdown, and the cron drains too. Two drains at once read the same oldest rows and sent them twice.
    • Drains now take an atomic add_option() lock. A lock older than 60s, left by a request that died, is taken over.
  • Violations lost in an outage: each refused send spent an attempt, so two refused drains discarded the spool.
    • A refusal (no answer, 429, 5xx) now keeps the rows and their attempts and starts the shared 60s pause.
    • Only a rejected batch (other 4xx) spends attempts.
  • AI referrals lost on 429: the batch was deleted.
    • It's now kept and resent under the same id, which ingest deduplicates, and flushing waits out the pause.

Tests: php tests/run.php gives 196 passed (7 new, in ViolationDrainTest.php).

  • Mutation-checked: removing the lock, the refusal handling, or the referral 429 handling each fails a test.
  • The test add_option stub now fails on an existing option, as WordPress does. The existing suite still passes.

…ng an outage

- Violation drains take an add_option() lock. Every request that recorded
  a violation drains at shutdown and the cron drains too; two at once read
  the same oldest rows and sent them twice. A lock older than 60s is taken
  over.
- A refusal (no answer, 429, 5xx) keeps the batch and its attempts and
  starts the shared 60s pause; only a rejected batch spends attempts.
  Before, two refused drains discarded the spool.
- AI referrals: a 429 keeps the batch for resend under its id (ingest
  deduplicates it) instead of deleting it, and flushing waits out the pause.
- The test add_option stub now fails on an existing option, as WordPress
  does.
@cport1
cport1 merged commit 073b0ba into main Oct 2, 2026
4 checks passed
@cport1
cport1 deleted the fix/violation-and-referral-delivery branch October 2, 2026 22:05
@cport1 cport1 mentioned this pull request Oct 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant