Skip to content

fix(mining): gate /contacts person INSERT realtime by active mining - #2884

Merged
malek10xdev merged 1 commit into
mainfrom
feat/contacts-realtime-insert-gating
Sep 11, 2026
Merged

fix(mining): gate /contacts person INSERT realtime by active mining#2884
malek10xdev merged 1 commit into
mainfrom
feat/contacts-realtime-insert-gating

Conversation

@malek10xdev

Copy link
Copy Markdown
Collaborator

Summary

Split from #2881 (now closed): the frontend half, extracted so it can land independently of the refine-persons SQL changes in #2883.

The contacts page subscribed to all persons changes (event: '*'), so background/passive mining streamed every new person INSERT into the client — flooding /contacts mid-session and starving other realtime channels on the tenant (credits-profile, etc.), surfacing as MessagePerSecondRateLimitReached.

Key changes

  • buildPersonChangeFilters() in contacts-realtime.ts: the channel listens UPDATE + DELETE always, and INSERT only while a foreground mining is active.
  • The contacts store builds the channel via createContactsRealtimeChannel() and rebuilds it when activeMiningTask flips — the postgres_changes filter set is fixed at subscribe time, so rebuilding is the only way to toggle the INSERT listener server-side (new contacts mined in the background appear on reload/page entry).
  • handlePersonRealtimeEvent() / syncRealtimeInsertListener() in the store; the non-gating behavior (reconcile path, UPDATE/DELETE) is unchanged.
  • Unit tests for buildPersonChangeFilters (INSERT excluded when idle, included while mining).

Notes

Testing

  • Frontend: npm run test -- --run src/tests/unit/contacts-realtime.test.ts — 17/17 green; prettier + eslint clean (0 errors).
  • Manual: with a passive-mining cycle running in the background, /contacts no longer receives INSERT events mid-session; UPDATE/DELETE reconcile stays live.

Resolves #2867.

The contacts channel subscribed to all person changes, so background/passive
mining flooded the client and the realtime tenant (dropping profile/credits
events). The postgres_changes filter set is fixed at subscribe time, so:

- add buildPersonChangeFilters(): UPDATE+DELETE always, INSERT only while a
  foreground mining is active;
- rebuild the channel when activeMiningTask flips so the server-side filter
  stops delivering INSERTs outside foreground mining (keep-last; new contacts
  appear on reload/page entry).
@malek10xdev
malek10xdev merged commit 1601831 into main Sep 11, 2026
14 checks passed
@malek10xdev
malek10xdev deleted the feat/contacts-realtime-insert-gating branch September 11, 2026 18:39
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.

leadminer — fix release-blocking bugs & minor issues

1 participant