Kingrayhan/socket#103
Merged
kingRayhan merged 3 commits intomainfrom Apr 2, 2026
Merged
Conversation
- Added optional `id` field to the Reaction interface for better tracking. - Updated comment creation to generate a unique comment ID, improving notification consistency. - Introduced unique reaction IDs during reaction creation to enhance notification handling. - Refactored notification persistence to ensure reliable insertion and real-time publishing without duplicates.
- Changed `void publishMessage` to `await publishMessage` in comment actions to ensure proper asynchronous handling. - Updated the `publishMessage` function in pusher.server.ts to return a value, improving error handling and consistency in message publishing. - Adjusted notification function in inngest.ts to return the result of `publishMessage`, enhancing clarity in notification flow.
…ishing - Enhanced the `persistNotificationFn` to include error handling for both notification row insertion and message publishing. - Updated the insert and publish operations to return success status and messages, improving clarity and debugging capabilities.
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.
Problem
A single comment or reaction could produce many duplicate rows in
notifications(e.g. 10+). That showed up as a flood of identical notifications in the UI.Root cause
persist-notificationran as one Inngest handler with the DB insert and Pusher publish in the same execution. Inngest retries failed runs. If anything failed after a successful insert (timeout, transient error, downstream issue), the whole handler ran again and inserted again.inngest.sendhad no stable eventid, so duplicate or replayed events could not be deduplicated at the platform layer.What changed
1. Durable steps in
persistNotificationFn(src/lib/inngest.ts)step.run("insert-notification-row", …)— persists the notification row.step.run("publish-notification-realtime", …)— callspublishMessagefornotification.new.Completed steps are not re-executed on retry, so a retry after a partial failure does not insert duplicate notification rows.
Steps return small result objects (success / error info) for clearer runs in the Inngest UI.
2. Stable Inngest event IDs (
src/backend/services/comment.action.ts,reaction.actions.ts)id: notif:comment:{commentId}—commentIdis the same UUID used for the comment row (input.comment_id ?? random).id: notif:reaction:{reactionId}— explicitreactionIdgenerated before insert and stored on the new reaction row.Aligns each
app/notification.requestedsend with one logical notification and supports Inngest’s idempotent event processing when the sameidis seen again.3. Reaction row IDs (
src/backend/models/domain-models.ts,reaction.actions.ts)id?: stringonReactionso inserts can set a known UUID for correlation with the notification event id.4.
publishMessage(src/lib/pusher/pusher.server.ts)await pusherServer.trigger(…)inside try/catch so publishing is a real async operation; broker failures are logged and do not throw through callers that must stay best-effort.5. Comment mutations (
comment.action.ts)await publishMessage(…)for comment create/update/delete so the server action’s async boundary matches the Pusher call (consistent with the above).How to verify
persist-notificationrun: you should see two steps (insert, publish) and no duplicate inserts on retries.Files touched
src/lib/inngest.ts—step.runfor insert + publish; structured step results.src/backend/services/comment.action.ts— stable comment id,notif:comment:…event id,await publishMessage.src/backend/services/reaction.actions.ts— reaction UUID +notif:reaction:…event id.src/backend/models/domain-models.ts—Reaction.idoptional.src/lib/pusher/pusher.server.ts— await trigger, centralized error handling.