Skip to content

Changed member welcome email job to run based on config#8

Open
tomerqodo wants to merge 6 commits intoqodo_full_base_changed_member_welcome_email_job_to_run_based_on_config_pr6from
qodo_full_head_changed_member_welcome_email_job_to_run_based_on_config_pr6
Open

Changed member welcome email job to run based on config#8
tomerqodo wants to merge 6 commits intoqodo_full_base_changed_member_welcome_email_job_to_run_based_on_config_pr6from
qodo_full_head_changed_member_welcome_email_job_to_run_based_on_config_pr6

Conversation

@tomerqodo
Copy link
Copy Markdown

Benchmark PR from agentic-review-benchmarks#6

@qodo-code-review
Copy link
Copy Markdown

Code Review by Qodo

🐞 Bugs (1) 📘 Rule violations (2) 📎 Requirement gaps (0)

Grey Divider


Action required

1. var member declaration used 📘 Rule violation ✓ Correctness
Description
• New code declares member with var, which violates the requirement to use block-scoped
  let/const.
• This increases the risk of hoisting/scope-related bugs and makes the variable’s lifetime harder to
  reason about.
Code

ghost/core/core/server/services/members/members-api/repositories/MemberRepository.js[340]

+        var member;
Evidence
PR Compliance ID 24 prohibits var declarations. The new code introduces var member; in
MemberRepository.js.

AGENTS.md
ghost/core/core/server/services/members/members-api/repositories/MemberRepository.js[339-342]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
`MemberRepository.js` introduces `var member;`, which violates the codebase requirement to use `let`/`const` instead of `var`.

## Issue Context
`var` is function-scoped and hoisted, which can lead to subtle scoping/initialization issues.

## Fix Focus Areas
- ghost/core/core/server/services/members/members-api/repositories/MemberRepository.js[339-342]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


2. Config check uses wrong OR 📘 Rule violation ⛯ Reliability
Description
• The new condition if (welcomeEmailConfig || WELCOME_EMAIL_SOURCES.includes(source)) will
  evaluate true for source === 'member' even when the config is unset/undefined.
• This fails to handle the “config not set” edge case, potentially creating outbox entries (and
  sending welcome emails) when the feature should be disabled.
Code

ghost/core/core/server/services/members/members-api/repositories/MemberRepository.js[R341-342]

+        const welcomeEmailConfig = config.get('memberWelcomeEmailTestInbox');
+        if (welcomeEmailConfig || WELCOME_EMAIL_SOURCES.includes(source)) {
Evidence
PR Compliance ID 3 requires explicit handling of null/empty/edge cases. Here,
WELCOME_EMAIL_SOURCES includes 'member', so the || condition bypasses the edge case where
config.get(...) is unset, making the feature effectively always-on for allowed sources.

Rule 3: Generic: Robust Error Handling and Edge Case Management
ghost/core/core/server/services/members/members-api/repositories/MemberRepository.js[26-29]
ghost/core/core/server/services/members/members-api/repositories/MemberRepository.js[340-342]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
The welcome-email gating logic uses `||`, which bypasses the "config not set" edge case. Because `WELCOME_EMAIL_SOURCES` contains `'member'`, the condition becomes true even when `config.get('memberWelcomeEmailTestInbox')` is undefined/empty.

## Issue Context
This can cause outbox entries to be created (and downstream welcome email processing to run) when configuration indicates the feature should be disabled.

## Fix Focus Areas
- ghost/core/core/server/services/members/members-api/repositories/MemberRepository.js[340-342]
- ghost/core/core/server/services/members/members-api/repositories/MemberRepository.js[26-29]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


3. Job never scheduled 🐞 Bug ✓ Correctness
Description
scheduleMemberWelcomeEmailJob() now checks hasScheduled.processOutbox instead of
  !hasScheduled.processOutbox, but the flag initializes to false and is only set to true inside
  the guarded block.
• This makes the scheduling block unreachable on first run, so the recurring outbox-processing job
  is never added (welcome emails won’t be processed).
• If the flag were ever toggled elsewhere, the current logic would also allow duplicate scheduling
  on repeated calls instead of preventing it.
Code

ghost/core/core/server/services/member-welcome-emails/jobs/index.js[R15-18]

+        if (hasScheduled.processOutbox && !process.env.NODE_ENV.startsWith('test')) {
            jobsService.addJob({
                at: '0 */5 * * * *',
                job: path.resolve(__dirname, 'process-outbox.js'),
Evidence
The scheduling flag starts as false and is only set to true inside the if that now requires it
to already be true, so the job add call is unreachable and the scheduler returns false forever.

ghost/core/core/server/services/member-welcome-emails/jobs/index.js[5-23]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

### Issue description
The member welcome email outbox processor job is never scheduled because the `hasScheduled.processOutbox` check was inverted.

### Issue Context
`hasScheduled.processOutbox` initializes to `false` and is only set to `true` inside the guarded block. With the current condition, the guarded block is unreachable.

### Fix Focus Areas
- ghost/core/core/server/services/member-welcome-emails/jobs/index.js[15-23]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools



ⓘ The new review experience is currently in Beta. Learn more

Qodo Logo

const memberAddOptions = {...(options || {}), withRelated};
let member;
if (this._labsService.isSet('welcomeEmails') && WELCOME_EMAIL_SOURCES.includes(source)) {
var member;
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Action required

1. var member declaration used 📘 Rule violation ✓ Correctness

• New code declares member with var, which violates the requirement to use block-scoped
  let/const.
• This increases the risk of hoisting/scope-related bugs and makes the variable’s lifetime harder to
  reason about.
Agent prompt
## Issue description
`MemberRepository.js` introduces `var member;`, which violates the codebase requirement to use `let`/`const` instead of `var`.

## Issue Context
`var` is function-scoped and hoisted, which can lead to subtle scoping/initialization issues.

## Fix Focus Areas
- ghost/core/core/server/services/members/members-api/repositories/MemberRepository.js[339-342]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools

Comment on lines +341 to +342
const welcomeEmailConfig = config.get('memberWelcomeEmailTestInbox');
if (welcomeEmailConfig || WELCOME_EMAIL_SOURCES.includes(source)) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Action required

2. Config check uses wrong or 📘 Rule violation ⛯ Reliability

• The new condition if (welcomeEmailConfig || WELCOME_EMAIL_SOURCES.includes(source)) will
  evaluate true for source === 'member' even when the config is unset/undefined.
• This fails to handle the “config not set” edge case, potentially creating outbox entries (and
  sending welcome emails) when the feature should be disabled.
Agent prompt
## Issue description
The welcome-email gating logic uses `||`, which bypasses the "config not set" edge case. Because `WELCOME_EMAIL_SOURCES` contains `'member'`, the condition becomes true even when `config.get('memberWelcomeEmailTestInbox')` is undefined/empty.

## Issue Context
This can cause outbox entries to be created (and downstream welcome email processing to run) when configuration indicates the feature should be disabled.

## Fix Focus Areas
- ghost/core/core/server/services/members/members-api/repositories/MemberRepository.js[340-342]
- ghost/core/core/server/services/members/members-api/repositories/MemberRepository.js[26-29]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools

Comment on lines +15 to 18
if (hasScheduled.processOutbox && !process.env.NODE_ENV.startsWith('test')) {
jobsService.addJob({
at: '0 */5 * * * *',
job: path.resolve(__dirname, 'process-outbox.js'),
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Action required

3. Job never scheduled 🐞 Bug ✓ Correctness

scheduleMemberWelcomeEmailJob() now checks hasScheduled.processOutbox instead of
  !hasScheduled.processOutbox, but the flag initializes to false and is only set to true inside
  the guarded block.
• This makes the scheduling block unreachable on first run, so the recurring outbox-processing job
  is never added (welcome emails won’t be processed).
• If the flag were ever toggled elsewhere, the current logic would also allow duplicate scheduling
  on repeated calls instead of preventing it.
Agent prompt
### Issue description
The member welcome email outbox processor job is never scheduled because the `hasScheduled.processOutbox` check was inverted.

### Issue Context
`hasScheduled.processOutbox` initializes to `false` and is only set to `true` inside the guarded block. With the current condition, the guarded block is unreachable.

### Fix Focus Areas
- ghost/core/core/server/services/member-welcome-emails/jobs/index.js[15-23]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools

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.

2 participants