Skip to content

Fixed expired complimentary members not triggering webhooks#28444

Open
9larsons wants to merge 1 commit into
mainfrom
codex/model-event-bridge-worker-jobs
Open

Fixed expired complimentary members not triggering webhooks#28444
9larsons wants to merge 1 commit into
mainfrom
codex/model-event-bridge-worker-jobs

Conversation

@9larsons

@9larsons 9larsons commented Jun 9, 2026

Copy link
Copy Markdown
Contributor

Summary

  • add a narrow worker-to-host model event bridge for allowlisted lifecycle events
  • route model-event worker messages through the bridge without dispatching them as raw domain events
  • emit member.edited model-event messages from clean-expired-comped after direct DB cleanup
  • cover bridge handling, worker message payloads, and webhook member payload serialization

Test notes

  • pnpm --dir ghost/core test:single test/unit/server/services/jobs/job-service.test.js
  • pnpm --dir ghost/core test:single test/unit/server/services/jobs/worker-model-event-bridge.test.js
  • pnpm --dir ghost/core test:single test/unit/server/services/members/clean-expired-comped.test.js
  • pnpm --dir ghost/core test:single test/unit/server/services/webhooks/serialize.test.js
  • pnpm --dir ghost/core exec eslint core/server/services/jobs/job-service.js core/server/services/jobs/worker-model-event-bridge.js core/server/services/members/jobs/clean-expired-comped.js test/unit/server/services/jobs/job-service.test.js test/unit/server/services/jobs/worker-model-event-bridge.test.js test/unit/server/services/members/clean-expired-comped.test.js test/unit/server/services/webhooks/serialize.test.js

no ref

Direct DB updates in worker jobs bypass model lifecycle events, so expiring a comped member updated access without emitting member.edited.

This keeps workers model-free and adds a narrow worker-to-host bridge instead of initializing Ghost models inside the worker runtime.
@coderabbitai

coderabbitai Bot commented Jun 9, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Walkthrough

This PR introduces a worker-to-model-event bridge system for translating job worker messages into application domain events. A new WorkerModelEventBridge module validates model-event type messages, reconstructs model state by fetching the target instance and normalizing date fields, and emits corresponding application events with internal context. JobService is wired to detect and route model-event messages to the bridge. The clean-expired-comped job is updated to emit a model-event message per affected member when transitioning status to free, capturing consistent timestamps. Comprehensive unit tests cover bridge validation/emission paths, error handling, job service routing, job behavior, and downstream webhook serialization of reconstructed model state.

Possibly related PRs

  • TryGhost/Ghost#28399: Modifies the same clean-expired-comped.js job around updating member updated_at during comped member expiration.
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and specifically describes the main fix: enabling webhooks to fire when expired complimentary members are processed.
Description check ✅ Passed The description provides a clear, well-structured summary of the changes including the new bridge, message routing, event emissions, and test coverage related to the webhook fix.
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.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ 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 codex/model-event-bridge-worker-jobs

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 and usage tips.

@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 `@ghost/core/core/server/services/jobs/worker-model-event-bridge.js`:
- Around line 62-64: The current validation uses a truthy guard so
message.options === null slips through and later causes an internal handler
error when accessing options.context; update the validation around
message.options (using the existing isObject helper) to explicitly reject
non-objects and null (e.g., change the check to ensure isObject(message.options)
is true or explicitly test message.options == null) so that the function returns
'Invalid options' for null/invalid payloads before reaching the code that reads
options.context.
🪄 Autofix (Beta)

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: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 4c4e7238-1b92-4037-a86f-8ce1d2c41871

📥 Commits

Reviewing files that changed from the base of the PR and between 381a648 and b047424.

📒 Files selected for processing (7)
  • ghost/core/core/server/services/jobs/job-service.js
  • ghost/core/core/server/services/jobs/worker-model-event-bridge.js
  • ghost/core/core/server/services/members/jobs/clean-expired-comped.js
  • ghost/core/test/unit/server/services/jobs/job-service.test.js
  • ghost/core/test/unit/server/services/jobs/worker-model-event-bridge.test.js
  • ghost/core/test/unit/server/services/members/clean-expired-comped.test.js
  • ghost/core/test/unit/server/services/webhooks/serialize.test.js

Comment on lines +62 to +64
if (message.options && !isObject(message.options)) {
return 'Invalid options';
}

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.

⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Reject options: null during validation to avoid false handler-error reporting

Line 62 uses a truthy guard, so options: null bypasses validation and later throws at Line 103 when reading options.context, which gets reported as an internal handler error instead of an invalid payload.

Proposed fix
-        if (message.options && !isObject(message.options)) {
+        if (message.options !== undefined && !isObject(message.options)) {
             return 'Invalid options';
         }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if (message.options && !isObject(message.options)) {
return 'Invalid options';
}
if (message.options !== undefined && !isObject(message.options)) {
return 'Invalid options';
}
🤖 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 `@ghost/core/core/server/services/jobs/worker-model-event-bridge.js` around
lines 62 - 64, The current validation uses a truthy guard so message.options ===
null slips through and later causes an internal handler error when accessing
options.context; update the validation around message.options (using the
existing isObject helper) to explicitly reject non-objects and null (e.g.,
change the check to ensure isObject(message.options) is true or explicitly test
message.options == null) so that the function returns 'Invalid options' for
null/invalid payloads before reaching the code that reads options.context.

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