Skip to content

fix(event_type_filter): wrap operations in SQLite transaction for iso… - #316

Merged
godamongstmen897 merged 3 commits into
Goldii-locks:mainfrom
benedictworks-home:fix/188-event-type-filter-transaction-isolation
Aug 30, 2026
Merged

fix(event_type_filter): wrap operations in SQLite transaction for iso…#316
godamongstmen897 merged 3 commits into
Goldii-locks:mainfrom
benedictworks-home:fix/188-event-type-filter-transaction-isolation

Conversation

@benedictworks-home

Copy link
Copy Markdown
Contributor

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

  1. db.ts — Cleanup & deduplication
    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.
  2. dispatcher.ts — Use correct APIs + event type filtering
    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

…lation

Ensures event_type_filter DB writes commit atomically and roll back
fully on failure, protecting data consistency under load.

Fixes Goldii-locks#188
@drips-wave

drips-wave Bot commented Aug 26, 2026

Copy link
Copy Markdown

@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! 🚀

Learn more about application limits

@godamongstmen897
godamongstmen897 merged commit 20fcd2e into Goldii-locks:main Aug 30, 2026
1 check failed
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.

Implement database transaction isolation in event_type_filter

2 participants