Skip to content

feat(api): add scheduled cleanup task for specific workflow logs#31843

Merged
hjlarry merged 18 commits intolanggenius:mainfrom
razerzhang:feature/specific-workflow-log-cleanup
Feb 11, 2026
Merged

feat(api): add scheduled cleanup task for specific workflow logs#31843
hjlarry merged 18 commits intolanggenius:mainfrom
razerzhang:feature/specific-workflow-log-cleanup

Conversation

@razerzhang
Copy link
Contributor

@razerzhang razerzhang commented Feb 2, 2026

Add a new Celery task to clean up workflow run logs for specific workflows with an independent retention policy. This allows setting different retention periods for high-volume workflows without affecting others.

Configuration:

  • SPECIFIC_WORKFLOW_LOG_CLEANUP_ENABLED: enable/disable the task
  • SPECIFIC_WORKFLOW_IDS: comma-separated workflow IDs to clean
  • SPECIFIC_WORKFLOW_LOG_RETENTION_DAYS: retention period (default: 7 days)

The task runs daily at 3:00 AM and cascades deletion to all related records.

close #31883

Summary

Screenshots

Before After
... ...

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 added a test for each change that was introduced, and I tried as much as possible to make a single atomic change.
  • I've updated the documentation accordingly.
  • I ran make lint and make type-check (backend) and cd web && npx lint-staged (frontend) to appease the lint gods

Add a new Celery task to clean up workflow run logs for specific workflows
with an independent retention policy. This allows setting different retention
periods for high-volume workflows without affecting others.

Configuration:
- SPECIFIC_WORKFLOW_LOG_CLEANUP_ENABLED: enable/disable the task
- SPECIFIC_WORKFLOW_IDS: comma-separated workflow IDs to clean
- SPECIFIC_WORKFLOW_LOG_RETENTION_DAYS: retention period (default: 7 days)

The task runs daily at 3:00 AM and cascades deletion to all related records.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@dosubot dosubot bot added the size:L This PR changes 100-499 lines, ignoring generated files. label Feb 2, 2026
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @razerzhang, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request introduces a significant enhancement to workflow log management by implementing a dedicated, scheduled cleanup task for specific workflows. This allows for more granular control over log retention, enabling different policies for high-volume workflows without affecting the general log retention settings. The change improves system maintainability and resource utilization by providing targeted log cleanup capabilities.

Highlights

  • New Configuration for Specific Workflow Log Cleanup: Introduced SpecificWorkflowLogConfig to manage cleanup settings for designated workflows, including enablement, specific workflow IDs, and retention days.
  • Scheduled Celery Task: A new Celery task, clean_specific_workflow_logs, has been added and scheduled to run daily at 3:00 AM, specifically targeting logs of configured workflows.
  • Granular Log Retention: This feature allows administrators to define independent log retention policies for high-volume workflows, preventing them from impacting the retention of other workflow logs.
  • Cascading Deletion with Retry Mechanism: The cleanup task ensures comprehensive deletion by cascading to all related records (messages, conversations, etc.) and incorporates a retry mechanism for robust batch processing.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@dosubot dosubot bot added the 🌊 feat:workflow Workflow related stuff. label Feb 2, 2026
Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a new scheduled task to clean up workflow run logs for specific workflows, allowing for more granular retention policies. The changes, including new configuration options and the Celery task implementation, are well-structured and follow good practices like batch processing and retry mechanisms.

My primary feedback concerns code duplication. The new cleanup logic in clean_specific_workflow_logs.py is nearly identical to existing cleanup tasks. I've provided a comment with a suggestion to refactor this duplicated code into a shared utility to enhance long-term maintainability.

@crazywoola
Copy link
Member

Please link an issue in the description.

Copy link
Member

@crazywoola crazywoola left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These variables should be add to env fires as well.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds a scheduled Celery task to clean up workflow run logs for specific workflows with an independent retention policy, enabling different retention periods for high-volume workflows.

Changes:

  • New scheduled task clean_specific_workflow_logs that runs daily at 3:00 AM
  • Configuration options for enabling the task, specifying workflow IDs, and setting retention days
  • Cascading deletion of all related records (messages, conversations, workflow logs, etc.)

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.

File Description
api/schedule/clean_specific_workflow_logs.py Implements the cleanup task with batch processing, retry logic, and cascading deletion of related records
api/extensions/ext_celery.py Registers the new cleanup task in the Celery beat schedule at 3:00 AM
api/configs/feature/init.py Adds configuration class for the specific workflow log cleanup feature

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

razerzhang and others added 3 commits February 3, 2026 15:30
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Add the new environment variables for specific workflow log cleanup
to both api/.env.example and docker/.env.example files.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@razerzhang razerzhang requested a review from laipz8200 as a code owner February 3, 2026 12:43
@hj24 hj24 requested a review from hjlarry February 4, 2026 08:16
razerzhang and others added 2 commits February 6, 2026 00:17
…low log cleanup

Replace direct WorkflowRun model queries with repository layer methods
(count_expired_runs_by_workflow_ids, get_expired_run_ids_by_workflow_ids)
and change Celery task queue from "dataset" to "retention".

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Copy link
Contributor Author

@razerzhang razerzhang left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1

@razerzhang razerzhang requested a review from hj24 February 5, 2026 16:23
@hjlarry
Copy link
Contributor

hjlarry commented Feb 6, 2026

/gemini review

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request enhances the workflow log cleanup task by adding an optional filter to target specific workflow IDs. The implementation refactors the existing cleanup logic to use repository patterns for data access and deletion.

However, there are a few points to consider:

  • The pull request description seems to be out of sync with the implementation. It mentions a 'new Celery task' and an 'independent retention policy' with a new configuration variable, but the code modifies an existing task and reuses the global retention policy. It would be beneficial to update the description to match the actual changes.
  • There's a potential risk in the current implementation where an empty WORKFLOW_LOG_CLEANUP_SPECIFIC_WORKFLOW_IDS value will cause the task to clean up logs for all workflows. This could be surprising and lead to unintended data loss. I've added a comment with more details.
  • I've also suggested a minor refactoring to improve the readability of the batch deletion logic.

Overall, the changes are a good step towards more granular control over log cleanup. Addressing the points above will improve the safety and maintainability of the feature.

@dosubot dosubot bot added the lgtm This PR has been approved by a maintainer label Feb 6, 2026
Copy link
Contributor

@hj24 hj24 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@hjlarry hjlarry merged commit 32350f7 into langgenius:main Feb 11, 2026
13 checks passed
fatelei pushed a commit to fatelei/dify that referenced this pull request Feb 12, 2026
…ggenius#31843)

Co-authored-by: 章润喆 <zhangrunzhe@zhangrunzhedeMacBook-Air.local>
Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: hjlarry <hjlarry@163.com>
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
Co-authored-by: hj24 <mambahj24@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

🌊 feat:workflow Workflow related stuff. lgtm This PR has been approved by a maintainer size:L This PR changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Refactor/Chore] Clean up the specific workflow logs

4 participants