Skip to content

refactor(api): inject trigger workflow dispatch and execution logging - #45195

Open
hjlarry wants to merge 1 commit into
hjlarry/trigger-renewal-scanfrom
hjlarry/trigger-workflow-dispatch
Open

hjlarry wants to merge 1 commit into
hjlarry/trigger-renewal-scanfrom
hjlarry/trigger-workflow-dispatch

Conversation

@hjlarry

@hjlarry hjlarry commented Oct 31, 2026

Copy link
Copy Markdown
Contributor

Summary

Part of #39993. Stacked on #45190; merge that PR first.

Move trigger workflow dispatch and execution logging behind injected services, repositories, and gateways. Webhook, plugin-event, and scheduled callers share the dispatch service; plugin-event orchestration moves out of the Celery task.

Workflow queries return detached snapshots with tenant, app, and workflow ownership checks. Producer log writes use short transactions that finish before billing and broker calls, and invocation-failure records are persisted atomically. Existing queue selection, task payloads, quota reservations, and per-event error isolation are preserved.

Replace mock-heavy dispatch tests with real SQLite, local Billing HTTP, and in-memory Celery coverage. The existing gap between successful broker publication and recording the task ID remains; this change does not introduce an outbox. Broader webhook, schedule, debug, and execution lifecycle changes remain in subsequent layers.

Screenshots

Checklist

  • This change requires a documentation update, included: Dify Document
  • I understand that this PR may be closed in case there was no previous discussion or issues. (This doesn't apply to typos!)
  • I've verified the change and added or updated tests where meaningful regression risk justifies coverage.
  • I've updated the documentation accordingly.
  • I ran make lint && make type-check (backend) and vp staged (frontend) to appease the lint gods

@hjlarry
hjlarry added this pull request to stack #44506 October 31, 2026 08:20
@github-actions github-actions Bot added the size:XXL This PR changes 1000+ lines, ignoring generated files. label Oct 31, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Pyrefly Type Coverage

Metric Base PR Delta
Type coverage 76.93% 76.97% +0.03%
Strict coverage 76.62% 76.65% +0.03%
Typed symbols 66,331 66,385 +54
Untyped symbols 19,970 19,950 -20
Modules 3906 3909 +3

@github-actions

Copy link
Copy Markdown
Contributor

Pyrefly Diff

base → PR
--- /tmp/pyrefly_base.txt	2026-10-31 08:21:47.310481718 +0000
+++ /tmp/pyrefly_pr.txt	2026-10-31 08:21:38.514409382 +0000
@@ -745,7 +745,7 @@
 ERROR Argument `Literal['normal']` is not assignable to parameter `status` with type `SQLCoreOperations[TenantStatus] | TenantStatus` in function `models.account.Tenant.__init__` [bad-argument-type]
   --> tests/test_containers_integration_tests/services/test_webhook_service_relationships.py:68:72
 ERROR Class `WebhookServiceRelationshipFactory` has no class attribute `_read_cache` [missing-attribute]
-   --> tests/test_containers_integration_tests/services/test_webhook_service_relationships.py:546:26
+   --> tests/test_containers_integration_tests/services/test_webhook_service_relationships.py:548:26
 ERROR Object of class `NoneType` has no attribute `id` [missing-attribute]
    --> tests/test_containers_integration_tests/services/test_workflow_app_service.py:125:38
 ERROR Object of class `NoneType` has no attribute `status` [missing-attribute]
@@ -1202,10 +1202,12 @@
    --> tests/test_containers_integration_tests/test_workflow_pause_integration.py:929:27
 ERROR Argument `Literal['owner']` is not assignable to parameter `role` with type `SQLCoreOperations[TenantAccountRole] | TenantAccountRole` in function `models.account.TenantAccountJoin.__init__` [bad-argument-type]
   --> tests/test_containers_integration_tests/trigger/conftest.py:37:79
+ERROR Argument `str | None` is not assignable to parameter `workflow_id` with type `SQLCoreOperations[str] | str` in function `models.trigger.WorkflowTriggerLog.__init__` [bad-argument-type]
+   --> tests/test_containers_integration_tests/trigger/test_trigger_e2e.py:207:25
 ERROR Argument `dict[str, str | dict[str, str | dict[str, str]]]` is not assignable to parameter `node_config` with type `NodeConfigDict` in function `core.trigger.debug.event_selectors.TriggerDebugEventPoller.__init__` [bad-argument-type]
-   --> tests/test_containers_integration_tests/trigger/test_trigger_e2e.py:306:21
+   --> tests/test_containers_integration_tests/trigger/test_trigger_e2e.py:310:21
 ERROR Argument `dict[str, Any]` is not assignable to parameter `node_config` with type `NodeConfigDict` in function `services.trigger.schedule_service.ScheduleService.to_schedule_config` [bad-argument-type]
-   --> tests/test_containers_integration_tests/trigger/test_trigger_e2e.py:604:49
+   --> tests/test_containers_integration_tests/trigger/test_trigger_e2e.py:611:49
 ERROR Argument `list[FromClause]` is not assignable to parameter `tables` with type `Sequence[Table] | None` in function `sqlalchemy.sql.schema.MetaData.create_all` [bad-argument-type]
    --> tests/unit_tests/commands/test_archive_workflow_runs.py:181:16
 ERROR Expected a callable, got `None` [not-callable]
@@ -1605,7 +1607,7 @@
 ERROR Object of class `FromClause` has no attribute `drop` [missing-attribute]
   --> tests/unit_tests/controllers/trigger/test_trigger.py:46:5
 ERROR `_RequestStub` is not assignable to attribute `request` with type `Request` [bad-assignment]
-  --> tests/unit_tests/controllers/trigger/test_webhook.py:41:22
+  --> tests/unit_tests/controllers/trigger/test_webhook.py:47:22
 ERROR Object of class `Exception` has no attribute `data` [missing-attribute]
    --> tests/unit_tests/controllers/web/test_app.py:250:16
 ERROR Object of class `ModuleType` has no attribute `web_ns` [missing-attribute]
@@ -4908,8 +4910,6 @@
    --> tests/unit_tests/services/test_app_service.py:355:17
 ERROR Argument `Literal['advanced-chat', 'agent', 'agent-chat', 'channel', 'chat', 'completion', 'rag-pipeline', 'workflow']` is not assignable to parameter `mode` with type `Literal['advanced-chat', 'agent', 'agent-chat', 'chat', 'completion', 'workflow']` in function `services.entities.app_entities.CreateAppParams.__init__` [bad-argument-type]
    --> tests/unit_tests/services/test_app_service.py:356:65
-ERROR `in` is not supported between `Literal['Quota limit reached']` and `None` [not-iterable]
-   --> tests/unit_tests/services/test_async_workflow_service.py:344:16
 ERROR Argument `BillingInfo` is not assignable to parameter `result` with type `dict[Unknown, Unknown]` in function `TestBillingServiceSubscriptionInfoDataType._assert_billing_info_types` [bad-argument-type]
     --> tests/unit_tests/services/test_billing_service.py:1853:41
 ERROR Argument `BillingInfo` is not assignable to parameter `result` with type `dict[Unknown, Unknown]` in function `TestBillingServiceSubscriptionInfoDataType._assert_billing_info_types` [bad-argument-type]
@@ -5063,33 +5063,33 @@
 ERROR Argument `list[File]` is not assignable to parameter `value` with type `list[object]` in function `services.variable_truncator.VariableTruncator._truncate_array` [bad-argument-type]
    --> tests/unit_tests/services/test_variable_truncator.py:751:44
 ERROR Argument `dict[str, dict[Unknown, Unknown]]` is not assignable to parameter `node_config` with type `NodeConfigDict` in function `services.trigger.webhook_service.WebhookService.generate_webhook_response` [bad-argument-type]
-   --> tests/unit_tests/services/test_webhook_service.py:516:79
+   --> tests/unit_tests/services/test_webhook_service.py:493:79
 ERROR Argument `dict[str, dict[str, int | str]]` is not assignable to parameter `node_config` with type `NodeConfigDict` in function `services.trigger.webhook_service.WebhookService.generate_webhook_response` [bad-argument-type]
-   --> tests/unit_tests/services/test_webhook_service.py:526:79
+   --> tests/unit_tests/services/test_webhook_service.py:503:79
 ERROR Argument `dict[str, dict[str, int | str]]` is not assignable to parameter `node_config` with type `NodeConfigDict` in function `services.trigger.webhook_service.WebhookService.generate_webhook_response` [bad-argument-type]
-   --> tests/unit_tests/services/test_webhook_service.py:536:79
+   --> tests/unit_tests/services/test_webhook_service.py:513:79
 ERROR Argument `dict[str, dict[str, int | str]]` is not assignable to parameter `node_config` with type `NodeConfigDict` in function `services.trigger.webhook_service.WebhookService.generate_webhook_response` [bad-argument-type]
-   --> tests/unit_tests/services/test_webhook_service.py:545:79
+   --> tests/unit_tests/services/test_webhook_service.py:522:79
 ERROR Argument `dict[str, dict[str, int | str]]` is not assignable to parameter `node_config` with type `NodeConfigDict` in function `services.trigger.webhook_service.WebhookService.generate_webhook_response` [bad-argument-type]
-   --> tests/unit_tests/services/test_webhook_service.py:554:79
+   --> tests/unit_tests/services/test_webhook_service.py:531:79
 ERROR Argument `dict[str, dict[str, int | str]]` is not assignable to parameter `node_config` with type `NodeConfigDict` in function `services.trigger.webhook_service.WebhookService.generate_webhook_response` [bad-argument-type]
-   --> tests/unit_tests/services/test_webhook_service.py:564:79
+   --> tests/unit_tests/services/test_webhook_service.py:541:79
 ERROR Argument `dict[str, dict[str, list[dict[str, bool | str]] | str]]` is not assignable to parameter `node_config` with type `NodeConfigDict` in function `services.trigger.webhook_service.WebhookService.extract_and_validate_webhook_data` [bad-argument-type]
-   --> tests/unit_tests/services/test_webhook_service.py:806:88
+   --> tests/unit_tests/services/test_webhook_service.py:783:88
 ERROR Argument `dict[str, dict[str, str]]` is not assignable to parameter `node_config` with type `NodeConfigDict` in function `services.trigger.webhook_service.WebhookService.extract_and_validate_webhook_data` [bad-argument-type]
-   --> tests/unit_tests/services/test_webhook_service.py:833:83
+   --> tests/unit_tests/services/test_webhook_service.py:810:83
 ERROR Argument `dict[str, dict[str, str]]` is not assignable to parameter `node_config` with type `NodeConfigDict` in function `services.trigger.webhook_service.WebhookService.extract_and_validate_webhook_data` [bad-argument-type]
-   --> tests/unit_tests/services/test_webhook_service.py:853:83
+   --> tests/unit_tests/services/test_webhook_service.py:830:83
 ERROR Argument `dict[str, dict[str, list[dict[str, bool | str]] | str]]` is not assignable to parameter `node_config` with type `NodeConfigDict` in function `services.trigger.webhook_service.WebhookService.extract_and_validate_webhook_data` [bad-argument-type]
-   --> tests/unit_tests/services/test_webhook_service.py:871:86
+   --> tests/unit_tests/services/test_webhook_service.py:848:86
 ERROR Argument `dict[str, dict[str, list[dict[str, bool | str]] | str]]` is not assignable to parameter `node_config` with type `NodeConfigDict` in function `services.trigger.webhook_service.WebhookService.extract_and_validate_webhook_data` [bad-argument-type]
-   --> tests/unit_tests/services/test_webhook_service.py:890:91
+   --> tests/unit_tests/services/test_webhook_service.py:867:91
 ERROR Argument `dict[str, dict[str, list[dict[str, bool | str]] | str]]` is not assignable to parameter `node_config` with type `NodeConfigDict` in function `services.trigger.webhook_service.WebhookService.extract_and_validate_webhook_data` [bad-argument-type]
-   --> tests/unit_tests/services/test_webhook_service.py:912:86
+   --> tests/unit_tests/services/test_webhook_service.py:889:86
 ERROR Argument `dict[str, dict[str, list[dict[str, bool | str]] | str]]` is not assignable to parameter `node_config` with type `NodeConfigDict` in function `services.trigger.webhook_service.WebhookService.extract_and_validate_webhook_data` [bad-argument-type]
-   --> tests/unit_tests/services/test_webhook_service.py:931:86
+   --> tests/unit_tests/services/test_webhook_service.py:908:86
 ERROR Argument `dict[str, dict[str, list[dict[str, bool | str]] | str]]` is not assignable to parameter `node_config` with type `NodeConfigDict` in function `services.trigger.webhook_service.WebhookService.extract_and_validate_webhook_data` [bad-argument-type]
-   --> tests/unit_tests/services/test_webhook_service.py:949:91
+   --> tests/unit_tests/services/test_webhook_service.py:926:91
 ERROR Argument `dict[str, str | dict[str, str]]` is not assignable to parameter `webhook_data` with type `RawWebhookDataDict` in function `services.trigger.webhook_service.WebhookService._validate_http_metadata` [bad-argument-type]
    --> tests/unit_tests/services/test_webhook_service_additional.py:249:57
 ERROR Argument `dict[str, dict[str, int] | dict[str, str]]` is not assignable to parameter `webhook_data` with type `RawWebhookDataDict` in function `services.trigger.webhook_service.WebhookService.build_workflow_inputs` [bad-argument-type]

@codecov

codecov Bot commented Oct 31, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 67.40741% with 88 lines in your changes missing coverage. Please review.
✅ Project coverage is 80.32%. Comparing base (bf7fb91) to head (93391a4).

Files with missing lines Patch % Lines
api/services/trigger/workflow_dispatch_service.py 30.00% 77 Missing ⚠️
...pi/repositories/app_definition_query_repository.py 80.76% 5 Missing ⚠️
api/tasks/workflow_schedule_tasks.py 0.00% 3 Missing ⚠️
api/services/trigger/workflow_dispatch_gateway.py 81.81% 2 Missing ⚠️
api/tasks/trigger_processing_tasks.py 75.00% 1 Missing ⚠️

❌ Your project check has failed because the head coverage (80.32%) is below the adjusted base coverage (87.12%). You can increase the head coverage or adjust the Removed Code Behavior.

❗ There is a different number of reports uploaded between BASE (bf7fb91) and HEAD (93391a4). Click for more details.

HEAD has 1 upload less than BASE
Flag BASE (bf7fb91) HEAD (93391a4)
api 3 2
Additional details and impacted files
@@                       Coverage Diff                        @@
##           hjlarry/trigger-renewal-scan   #45195      +/-   ##
================================================================
- Coverage                         88.12%   80.32%   -7.80%     
================================================================
  Files                              5587     5532      -55     
  Lines                            334262   323122   -11140     
  Branches                          66811    66169     -642     
================================================================
- Hits                             294555   259561   -34994     
- Misses                            34486    59141   +24655     
+ Partials                           5221     4420     -801     
Flag Coverage Δ
api 73.99% <67.40%> (-13.66%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:XXL This PR changes 1000+ lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant