Add change-detection and trigger registry - #8
Conversation
- Add ChangeDetectionJob and TriggerState model with migration - Introduce TriggerCollection and stable trigger `unique_key` values - Add ChangeDetecting concern for detector triggers and scheduler support - Have RecurringTasksConfig schedule ChangeDetectionJob for detectors - Make RunWorkflowJob accept `trigger_key` and payload; pass payload to workflow - Add tests and fake trigger; update schema, docs, HTTP client, and add pg gem
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 46d1d430a9
ℹ️ 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".
There was a problem hiding this comment.
Pull request overview
This PR adds a change-detection pipeline for workflows by introducing change-detecting triggers, persistent per-trigger state, and a registry keyed by stable unique_key values so schedulers/jobs can reliably resolve triggers and pass runtime payloads into workflow execution.
Changes:
- Added
ChangeDetectionJob+TriggerStatemodel/migration to persist detector state and enqueue runs only on detected changes. - Introduced
TriggerCollectionand per-triggerunique_keyfor trigger de-duplication and lookup, updating scheduling to key tasks byworkflow_key + trigger_key. - Updated
RunWorkflowJob/execution context to accepttrigger_keyand a runtime payload, and added supporting tests + a fake change-detecting trigger.
Reviewed changes
Copilot reviewed 20 out of 21 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
test/support/fake_change_detecting_trigger.rb |
Adds a test-only change-detecting trigger with stable identity-based unique_key. |
test/lib/r3x/workflow_test.rb |
Extends trigger validation tests and adds coverage for duplicate trigger keys and key stability. |
test/lib/r3x/workflow_context_test.rb |
Adds coverage for exposing runtime payload via trigger execution. |
test/lib/r3x/recurring_tasks_config_test.rb |
Updates recurring-task expectations for trigger-keyed tasks and adds change-detection scheduling coverage. |
test/jobs/r3x/run_workflow_job_test.rb |
Updates RunWorkflowJob tests for trigger_key lookup and payload pass-through. |
test/jobs/r3x/change_detection_job_test.rb |
Adds end-to-end tests for change detection, state persistence, enqueueing, and error recording. |
lib/r3x/workflow.rb |
Replaces array trigger storage with TriggerCollection and adds triggers_by_key. |
lib/r3x/triggers/concerns/change_detecting.rb |
Adds ChangeDetecting concern contract (change_detecting?, detect_changes). |
lib/r3x/triggers/base.rb |
Adds default change_detecting?/cron_schedulable? and a hashed unique_key. |
lib/r3x/trigger_execution.rb |
Adds payload to runtime trigger execution object. |
lib/r3x/trigger_collection.rb |
New collection enforcing unique trigger keys and providing lookup by key. |
lib/r3x/recurring_tasks_config.rb |
Generates Solid Queue recurring tasks keyed by workflow_key:trigger_key, scheduling detection job for detectors. |
db/schema.rb |
Adds trigger_states table schema. |
db/migrate/20260318100000_create_trigger_states.rb |
Migration creating trigger_states with indexes. |
app/models/r3x/trigger_state.rb |
Adds model validations and helpers to record checks/errors. |
app/lib/r3x/client/http.rb |
Changes get return value and adds post. |
app/jobs/r3x/run_workflow_job.rb |
Switches to trigger lookup by trigger_key and passes runtime payload into context. |
app/jobs/r3x/change_detection_job.rb |
New job to evaluate detector triggers, update TriggerState, and enqueue workflow runs on changes. |
Gemfile / Gemfile.lock |
Adds pg and bumps loofah. |
AGENTS.md |
Updates codebase map and control-flow formatting; documents change-detection components. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
- Remove fetch_body, discord_output, and http_client methods. - Change made in `lib/r3x/workflow_context.rb`. - Reduce hidden dependencies and side effects in the context. - Encourage injection of HTTP clients/outputs for testability.
- Make trigger state update and job enqueue atomic in ChangeDetectionJob - Add argument normalization to RunWorkflowJob and ChangeDetectionJob - Add test that simulates enqueue failure and preserves trigger state - Adjust test payload expectation to use symbolized keys - Update AGENTS.md to document Solid Queue transactional behavior
* Add change-detection and trigger registry - Add ChangeDetectionJob and TriggerState model with migration - Introduce TriggerCollection and stable trigger `unique_key` values - Add ChangeDetecting concern for detector triggers and scheduler support - Have RecurringTasksConfig schedule ChangeDetectionJob for detectors - Make RunWorkflowJob accept `trigger_key` and payload; pass payload to workflow - Add tests and fake trigger; update schema, docs, HTTP client, and add pg gem * Update app/models/r3x/trigger_state.rb Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Remove HTTP/Discord helpers from WorkflowContext - Remove fetch_body, discord_output, and http_client methods. - Change made in `lib/r3x/workflow_context.rb`. - Reduce hidden dependencies and side effects in the context. - Encourage injection of HTTP clients/outputs for testability. * Make enqueueing atomic for change detection - Make trigger state update and job enqueue atomic in ChangeDetectionJob - Add argument normalization to RunWorkflowJob and ChangeDetectionJob - Add test that simulates enqueue failure and preserves trigger state - Adjust test payload expectation to use symbolized keys - Update AGENTS.md to document Solid Queue transactional behavior --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
* Add change-detection and trigger registry - Add ChangeDetectionJob and TriggerState model with migration - Introduce TriggerCollection and stable trigger `unique_key` values - Add ChangeDetecting concern for detector triggers and scheduler support - Have RecurringTasksConfig schedule ChangeDetectionJob for detectors - Make RunWorkflowJob accept `trigger_key` and payload; pass payload to workflow - Add tests and fake trigger; update schema, docs, HTTP client, and add pg gem * Update app/models/r3x/trigger_state.rb * Remove HTTP/Discord helpers from WorkflowContext - Remove fetch_body, discord_output, and http_client methods. - Change made in `lib/r3x/workflow_context.rb`. - Reduce hidden dependencies and side effects in the context. - Encourage injection of HTTP clients/outputs for testability. * Make enqueueing atomic for change detection - Make trigger state update and job enqueue atomic in ChangeDetectionJob - Add argument normalization to RunWorkflowJob and ChangeDetectionJob - Add test that simulates enqueue failure and preserves trigger state - Adjust test payload expectation to use symbolized keys - Update AGENTS.md to document Solid Queue transactional behavior --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
unique_keyvaluestrigger_keyand payload; pass payload to workflow