Skip to content

Enqueue inactivity notifications concurrently - #2661

Open
kaladivo wants to merge 1 commit into
mainfrom
fix/inactivity-enqueue-concurrency
Open

Enqueue inactivity notifications concurrently#2661
kaladivo wants to merge 1 commit into
mainfrom
fix/inactivity-enqueue-concurrency

Conversation

@kaladivo

@kaladivo kaladivo commented Aug 10, 2026

Copy link
Copy Markdown
Collaborator

The inactivity-notification enqueue loop in notifyUsersAboutInactivity ran Effect.all with the default sequential concurrency, so each MQ entry was enqueued one round-trip at a time. The first run after deploying the new inactivity cadence can select every long-inactive user at once, which would serialize thousands of enqueues for no reason.

Switch to Effect.allWith({concurrency: 'unbounded'}), matching the NewUserNotificationMqEntry enqueue loop earlier in the same file. Per-entry failures are already caught and logged individually, so concurrent execution doesn't change error behavior.

Summary by CodeRabbit

  • Improvements
    • Inactivity notifications are now processed concurrently, helping them be queued more quickly when many notifications need to be sent.
    • Existing individual notification error handling remains unchanged, so one failed notification does not prevent others from being processed.

@coderabbitai

coderabbitai Bot commented Aug 10, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

The inactivity notification flow now enqueues notifications with unbounded concurrency. Per-notification error handling remains unchanged.

Changes

Inactivity notifications

Layer / File(s) Summary
Update enqueue concurrency
apps/contact-service/src/services/UserNotificationService.ts
notifyUsersAboutInactivity now runs notification enqueue effects with unbounded concurrency.

Estimated code review effort: 1 (Trivial) | ~5 minutes

Possibly related PRs

  • vexl-it/vexl#2658: Introduces the inactivity-notification flow modified by this PR.
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change: concurrent enqueueing of inactivity notifications.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/inactivity-enqueue-concurrency

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

ESLint install failed. For unrecoverable errors, disable the tool in CodeRabbit configuration.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 9322337f3b

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

)
),
Effect.all,
Effect.allWith({concurrency: 'unbounded'}),

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Bound inactivity enqueue concurrency

When the first cadence run returns a large inactive-user backlog, this starts every queue.add operation simultaneously; createFindUsersToNotifyAboutInactivity has no pagination or limit, so the batch can span the entire eligible user population. That creates an equally large number of fibers, promises, and outstanding Redis commands, risking contact-service memory exhaustion or Redis overload. Because the users are marked as notified before this loop and per-entry enqueue failures are swallowed, overload can also suppress reminders until their next cadence step. Use a finite concurrency limit or process the query in bounded batches instead.

Useful? React with 👍 / 👎.

@greptile-apps

greptile-apps Bot commented Aug 10, 2026

Copy link
Copy Markdown

Greptile Summary

This PR parallelizes inactivity-notification MQ enqueues to reduce the duration of large scheduled runs.

  • Replaces the sequential Effect collector with unbounded concurrency.
  • Preserves the existing per-entry enqueue error handling and tracing.

Confidence Score: 4/5

The PR appears safe to merge, although the enqueue loop should use a finite concurrency limit to avoid unlimited process and Redis-command pressure during unusually large runs.

The change retains functional enqueue behavior and per-entry error isolation, but starts every operation in the unpaginated batch simultaneously rather than preserving bounded backpressure.

Files Needing Attention: apps/contact-service/src/services/UserNotificationService.ts

Important Files Changed

Filename Overview
apps/contact-service/src/services/UserNotificationService.ts Parallelizes the inactivity enqueue batch, but uses an unlimited concurrency setting despite the batch itself having no fixed bound.

Reviews (1): Last reviewed commit: "Enqueue inactivity notifications concurr..." | Re-trigger Greptile

)
),
Effect.all,
Effect.allWith({concurrency: 'unbounded'}),

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Unbounded inactivity enqueue batch

If a daily run selects a large number of inactive users, unbounded concurrency allocates every payload encoding, promise, closure, and pending Redis command at once, creating avoidable memory and event-loop pressure; use a finite concurrency limit to retain parallelism with backpressure.

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@apps/contact-service/src/services/UserNotificationService.ts`:
- Line 426: Limit the enqueue work in notifyUsersAboutInactivity by replacing
the unbounded Effect.allWith concurrency with a bounded concurrency or batching
strategy before enqueueUserNotification calls. Preserve the existing per-user
notification behavior while preventing Queue.add from overwhelming client,
Redis, or BullMQ resources.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: e75c5ef9-68cd-4df3-bcf9-51f5acb5f080

📥 Commits

Reviewing files that changed from the base of the PR and between 8e9bd7a and 9322337.

📒 Files selected for processing (1)
  • apps/contact-service/src/services/UserNotificationService.ts

)
),
Effect.all,
Effect.allWith({concurrency: 'unbounded'}),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🩺 Stability & Availability | 🟠 Major | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/usr/bin/env bash
set -euo pipefail

rg -n -C 8 \
  '\bEnqueueUserNotification\b|\benqueueUserNotification\s*=' \
  apps/contact-service packages/server-utils

rg -n -C 8 \
  'notifyUsersAboutInactivity|scheduledTaskWorkers|Schedule|repeat|cron|interval|Semaphore|Queue|rate.?limit' \
  apps/contact-service packages/server-utils

rg -n -C 8 \
  'findUsersToNotifyAboutInactivity|LIMIT|batch|chunk|concurrency' \
  apps/contact-service packages/server-utils

Repository: vexl-it/vexl

Length of output: 50369


🏁 Script executed:

#!/usr/bin/env bash
set -euo pipefail

# Inspect the exact producer implementation and scheduled task around the warning.
sed -n '1,150p' packages/server-utils/src/mqService.ts
printf '\n--- schedule task around inactivity worker ---\n'
rg -n -C 12 'notifyUsersAboutInactivity|schedule.*Inactivity|inactivity|intervalMs|cronPattern|limit' apps/contact-service/packages/contact-service apps/contact-service/src packages/server-utils/src || true
printf '\n--- UserNotificationService relevant lines ---\n'
sed -n '340,440p' apps/contact-service/src/services/UserNotificationService.ts
sed -n '1,130p' apps/contact-service/src/scheduledTaskWorkers.ts

Repository: vexl-it/vexl

Length of output: 50369


🏁 Script executed:

#!/usr/bin/env bash
set -euo pipefail

printf '%s\n' '--- packages/server-utils/src/mqService.ts ---'
sed -n '1,140p' packages/server-utils/src/mqService.ts

printf '%s\n' '--- apps/contact-service/src/scheduledTaskWorkers.ts ---'
sed -n '1,160p' apps/contact-service/src/scheduledTaskWorkers.ts

printf '%s\n' '--- UserNotificationService enqueue lines ---'
sed -n '350,435p' apps/contact-service/src/services/UserNotificationService.ts

printf '%s\n' '--- focused config/search for inactivity concurrency/interval ---'
rg -n -i -C 6 'inactivity|notifyUsersAboutInactivity|intervalMs|cronPattern|concurrency|maxJobRuntime|stallCheck|connection|Queue|latency' apps/contact-service src packages/server-utils/src --glob '!**/node_modules/**' --glob '!**/*.test.ts' --glob '!**/dist/**' | sed -n '1,220p'

Repository: vexl-it/vexl

Length of output: 29042


Limit inactivity notification enqueues before adding jobs.

notifyUsersAboutInactivity scans all due inactive users and uses Effect.allWith({concurrency: 'unbounded'}) to enqueue one BullMQ job per user. enqueueUserNotification creates jobs directly via Queue.add without concurrency or rate-limiting protection, so a large backlog can saturate client/Redis/MQ resources while previously recorded sends are already marked. Use a bounded concurrency limit or bounded queue for these enqueues, or batch them before enqueueing.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@apps/contact-service/src/services/UserNotificationService.ts` at line 426,
Limit the enqueue work in notifyUsersAboutInactivity by replacing the unbounded
Effect.allWith concurrency with a bounded concurrency or batching strategy
before enqueueUserNotification calls. Preserve the existing per-user
notification behavior while preventing Queue.add from overwhelming client,
Redis, or BullMQ resources.

Source: MCP tools

@github-actions

Copy link
Copy Markdown

📱 Preview on the staging app

Open Vexl (stage) → Account → Scan QR code and scan this:

PR preview QR code

Preview link: stagingapp.vexl.it://link/?type=load-pr-preview&channel=pr-2661&version=1.44.2

Channel pr-2661
Commit 9322337
Runtime 877ab8d4b6cd1b3aa836dbda494b4c893150919e, b5c07c542487bc7e92539b0b09860763590fefd5
Dashboard update group

The preview only loads into staging builds with a matching runtime — if this PR changes native code, ship a new staging build first. To go back to the staging channel: debug screen → "Clear PR preview".

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