Skip to content

[Feat] [Automations] Event-Driven Trigger Type with document.entered_folder#1449

Merged
MODSetter merged 23 commits into
MODSetter:devfrom
CREDO23:feature-automations-v2
May 30, 2026
Merged

[Feat] [Automations] Event-Driven Trigger Type with document.entered_folder#1449
MODSetter merged 23 commits into
MODSetter:devfrom
CREDO23:feature-automations-v2

Conversation

@CREDO23
Copy link
Copy Markdown
Contributor

@CREDO23 CREDO23 commented May 29, 2026

Summary

  • Adds a generic in-process EventBus (app/event_bus/) with a typed EventCatalog — decoupled from Celery (SRP)
  • Introduces document.entered_folder as the first built-in event type, published via SQLAlchemy after_commit hooks (ORM-level CDC, no external daemon)
  • Adds the event trigger type for automations, mirroring the schedule trigger pattern (source → selector → inputs → dispatch)
  • Fixes bulk_move_documents to use ORM objects so session hooks fire correctly on bulk moves
  • Fixes frontend Zod schema to accept event trigger type
  • Fixes JSON editor to coerce numeric strings back to numbers (filter value type safety)

Test plan

  • Move a document into a watched folder and confirm the automation fires
  • Confirm no automation fires when moving to an unwatched folder
  • Run unit tests: uv run pytest tests/unit/

High-level PR Summary

This PR introduces an event-driven automation trigger system centered around the document.entered_folder event. It adds a new in-process EventBus with a typed EventCatalog that decouples domain events from Celery, publishes document.entered_folder events via SQLAlchemy after_commit hooks when documents move into folders, and implements a new event trigger type for automations that matches events using a JSON filter grammar. The PR also refactors the existing automation dispatch logic to use a unified launch_run entry point, fixes bulk_move_documents to fire ORM session hooks properly, and updates the frontend to accept the event trigger type while fixing numeric type coercion in the JSON editor.

⏱️ Estimated Review Time: 30-90 minutes

💡 Review Order Suggestion
Order File Path
1 .gitignore
2 surfsense_backend/alembic/versions/147_add_event_to_automation_trigger_type.py
3 surfsense_backend/app/event_bus/event.py
4 surfsense_backend/app/event_bus/catalog.py
5 surfsense_backend/app/event_bus/bus.py
6 surfsense_backend/app/event_bus/__init__.py
7 surfsense_backend/app/event_bus/events/__init__.py
8 surfsense_backend/app/event_bus/events/document_entered_folder.py
9 surfsense_backend/app/session_events.py
10 surfsense_backend/app/automations/persistence/enums/trigger_type.py
11 surfsense_backend/app/automations/triggers/builtin/event/params.py
12 surfsense_backend/app/automations/triggers/builtin/event/filter.py
13 surfsense_backend/app/automations/triggers/builtin/event/match.py
14 surfsense_backend/app/automations/triggers/builtin/event/inputs.py
15 surfsense_backend/app/automations/triggers/builtin/event/definition.py
16 surfsense_backend/app/automations/triggers/builtin/event/source.py
17 surfsense_backend/app/automations/triggers/builtin/event/selector.py
18 surfsense_backend/app/automations/triggers/builtin/event/__init__.py
19 surfsense_backend/app/automations/triggers/__init__.py
20 surfsense_backend/app/automations/triggers/builtin/__init__.py
21 surfsense_backend/app/automations/dispatch/resolve.py
22 surfsense_backend/app/automations/dispatch/inputs.py
23 surfsense_backend/app/automations/dispatch/launch.py
24 surfsense_backend/app/automations/dispatch/__init__.py
25 surfsense_backend/app/automations/triggers/builtin/schedule/inputs.py
26 surfsense_backend/app/automations/triggers/builtin/schedule/source.py
27 surfsense_backend/app/automations/triggers/builtin/schedule/selector.py
28 surfsense_backend/app/automations/triggers/builtin/schedule/__init__.py
29 surfsense_backend/app/automations/actions/builtin/__init__.py
30 surfsense_backend/app/automations/actions/__init__.py
31 surfsense_backend/app/routes/folders_routes.py
32 surfsense_backend/app/app.py
33 surfsense_backend/app/celery_app.py
34 surfsense_backend/app/automations/services/automation.py
35 surfsense_backend/app/automations/services/trigger.py
36 surfsense_web/contracts/types/automation.types.ts
37 surfsense_web/components/json-view.tsx
38 surfsense_backend/tests/unit/event_bus/conftest.py
39 surfsense_backend/tests/unit/event_bus/test_event.py
40 surfsense_backend/tests/unit/event_bus/test_catalog.py
41 surfsense_backend/tests/unit/event_bus/test_bus.py
42 surfsense_backend/tests/unit/event_bus/test_document_entered_folder.py
43 surfsense_backend/tests/unit/event_bus/test_entered_folder_predicate.py
44 surfsense_backend/tests/unit/automations/triggers/builtin/event/test_params.py
45 surfsense_backend/tests/unit/automations/triggers/builtin/event/test_filter.py
46 surfsense_backend/tests/unit/automations/triggers/builtin/event/test_match.py
47 surfsense_backend/tests/unit/automations/triggers/builtin/event/test_inputs.py
48 surfsense_backend/tests/unit/automations/triggers/builtin/event/test_definition.py
49 surfsense_backend/tests/unit/automations/dispatch/test_inputs.py
50 surfsense_backend/tests/unit/automations/test_persistence_enums.py

Need help? Join our Discord

CREDO23 added 23 commits May 29, 2026 15:26
A standalone, domain-agnostic pub/sub seam: an EventBus that owns its
subscriber registry and streams Event values from producers to listeners
in process. Boundary-crossing (Celery/DB/workers) is left to subscribers,
keeping the bus single-responsibility. Includes the immutable Event value
object and full unit coverage.
@vercel
Copy link
Copy Markdown

vercel Bot commented May 29, 2026

@CREDO23 is attempting to deploy a commit to the Rohan Verma's projects Team on Vercel.

A member of the Team first needs to authorize it.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 29, 2026

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 6797a930-d0cc-4eae-81de-e9cce13c4ebe

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

@MODSetter MODSetter merged commit 7972901 into MODSetter:dev May 30, 2026
3 of 12 checks passed
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