fix(event_type_filter): wrap operations in SQLite transaction for iso… - #316
Merged
godamongstmen897 merged 3 commits intoAug 30, 2026
Conversation
…lation Ensures event_type_filter DB writes commit atomically and roll back fully on failure, protecting data consistency under load. Fixes Goldii-locks#188
|
@benedictworks-home Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
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 — Issue #188: Database Transaction Isolation in event_type_filter
Investigation Findings
The codebase had two competing webhook subscription systems with severe conflicts:
Active/correct path — addSubscription / removeSubscription in db.ts with per-contract subscriptions + event type filtering (contract_id, webhook_url, event_types columns). These already had db.transaction() wrappers (correct).
Legacy/broken path — addWebhookSubscription / removeWebhookSubscription / getWebhookSubscriptions in the same file using a non-existent url column schema. These had no transactions and would crash at runtime with SQLITE_ERROR: no such column: url.
Duplicate artifacts:
Two conflicting WebhookSubscription interfaces (different fields)
Two conflicting CREATE TABLE webhook_subscriptions (the second silently no-oped due to IF NOT EXISTS)
dispatcher.ts called the broken old functions
Changes Made
Removed duplicate WebhookSubscription interface (old one at ~lines 534-538 with url). The remaining interface at ~lines 751-757 correctly matches the table schema: { id, contract_id, webhook_url, event_types, created_at }.
Removed duplicate CREATE TABLE in runMigrations() bootstrap. The second DDL (wrong schema with only url column) was dead code that confused anyone reading the migration. Kept the correct DDL with contract_id, webhook_url, event_types columns and UNIQUE(contract_id, webhook_url).
Removed broken legacy functions addWebhookSubscription, removeWebhookSubscription, getWebhookSubscriptions. These queried non-existent columns, had no transactions, and were only called by unused code in dispatcher.ts.
Replaced import: Now uses getSubscriptionsForContract(payload.contractId) instead of the removed getWebhookSubscriptions().
Added event type filter subscriptionsMatchEventType() (same logic as in webhook-delivery.ts), so milestone dispatch respects each subscription's event_types filter (wildcard "*" or explicit list like ["funded", "approved"]).
Added status→event reverse mapping: Dispatcher receives newStatus string ("delivered", "approved", "disputed", "resolved"), maps it back to the raw event_type so the filter can be applied correctly.
Uses correct field: Delivers to subscription.webhook_url instead of the old non-existent subscription.url.
Verification Results
Check Result
tsc --noEmit (TypeScript) ✅ Clean — 0 errors
npm test -- --testPathPatterns="event_type_filter" ✅ 16/16 passed
npm test -- --testPathPatterns="webhooks" ✅ 17/17 passed
Full test suite npm test ✅ 771/771 passed (48 suites)
Ensures event_type_filter DB writes commit atomically and roll back fully on failure, protecting data consistency under load.
Fixes #188