Bugfix - Timer events not working#80
Merged
auslin-aot merged 2 commits intoMay 21, 2026
Merged
Conversation
PR Agent ReviewBlocking issues
Non-blocking suggestions
Recommended tests
Generated by model |
auslin-aot
reviewed
May 18, 2026
Collaborator
auslin-aot
left a comment
There was a problem hiding this comment.
While testing the Two Step Leave Approval sample template, I assigned a single user as the owner of the HR lane. This causes an error when the user in the Manager lane takes action.
Throws below error on
Whether this issue was introduced as part of this PR? It may have arisen after implementing the Swimlane Assignment Using Groups instead of Realm Roles PR.
Collaborator
Author
auslin-aot
approved these changes
May 21, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



JIRA Ticket
https://aottech.atlassian.net/browse/M8F-279
Description
This PR hardens M8Flow Celery execution for tenant-aware background tasks and restores timer progression compatibility with the current SpiffWorkflow runtime.
What changed
1. Rebrand Celery task names to M8Flow-owned task IDs
M8Flow now exposes process-instance Celery tasks under M8Flow-owned names instead of upstream
spiffworkflow_backend.*names:M8FLOW_CELERY_TASK_PROCESS_INSTANCE_RUNM8FLOW_CELERY_TASK_EVENT_NOTIFIERThis keeps task names and Flower UI branding aligned with M8Flow without modifying upstream SpiffWorkflow code.
2. Move tenant-context ownership into the M8Flow wrapper tasks
The M8Flow wrapper tasks now set and clear tenant context around the upstream raw task execution.
This was necessary because once the worker is dispatching the new M8Flow task names, those tasks are no longer just upstream Celery tasks. They are M8Flow wrappers, so tenant lifecycle must be owned at that wrapper boundary.
The wrapper task flow now:
process_instance_id.run()implementation3. Keep worker signal hooks as compatibility/fallback logic
set_tenant_context_for_task()andclear_tenant_context_for_task()incelery_worker.pywere updated to skip the two M8Flow wrapper task names.This prevents double tenant setup/cleanup for:
M8FLOW_CELERY_TASK_PROCESS_INSTANCE_RUNM8FLOW_CELERY_TASK_EVENT_NOTIFIERThe worker hooks still remain in place for:
4. Harden Celery worker database/session handling
Celery worker runtime handling was tightened to reduce session/connection leakage across prefork worker processes.
This includes:
process_instance_idusing a direct engine query instead of the shared scoped ORM session5. Restore timer wake-up behavior for current SpiffWorkflow runtime
A compatibility patch was added for timer catch events because the installed SpiffWorkflow version no longer refreshes waiting timer tasks in the way
spiffworkflow-backendexpects.The patch restores the expected behavior by revisiting waiting timer-catching tasks and forcing their state update, which allows due timers to advance the process instance correctly.
Why this was needed
These changes address two related problems:
Tenant-aware Celery execution was no longer safe once M8Flow introduced wrapper task names.
Without changing the worker hooks, tenant context could be applied twice or session state could leak across Celery tasks.
Timer-based process models could remain stuck even after Celery executed, because the current SpiffWorkflow runtime no longer refreshes waiting timer events the way upstream backend code expects.
Behavior after this PR
Files changed
m8flow-backend/src/m8flow_backend/background_processing/__init__.pym8flow-backend/src/m8flow_backend/background_processing/celery_worker.pym8flow-backend/src/m8flow_backend/background_processing/celery_tasks/process_instance_task.pym8flow-backend/src/m8flow_backend/services/celery_worker_runtime.pym8flow-backend/src/m8flow_backend/services/spiff_timer_refresh_patch.pym8flow-backend/src/m8flow_backend/startup/patch_registry.pyType
Changes
Testing
Validated with unit coverage around:
Also verified against the Docker containers by rebuilding/restarting the backend and Celery worker and running a fresh timer-based process instance to confirm the timer advanced to the expected ready/user-input state.
Related Issues
Closes #