Fix tasks history retention: UI filter + DB cleanup (tasks_history_delay) #5001
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.
Context
TeamPass has two distinct data sets related to the Task Manager:
teampass_background_tasks_logs, controlled bytasks_log_retention_delay(days).teampass_background_tasksandteampass_background_subtasks, controlled bytasks_history_delay(stored in seconds, displayed as days in the UI).The UI parameter “Tasks history retention (in days)” was not consistently applied: some records were displayed far beyond the configured retention and database cleanup was incomplete. Additionally, failed tasks were being removed by a separate cleanup path using a fixed ~15-day rolling cutoff, which caused the oldest “Done” entries to disappear minute-by-minute.
Root cause
tasks_history_delay.scripts/background_tasks___handler.phpremovedstatus='failed'tasks using a rolling cutoff based on an internal/fallback value (~15 days) instead oftasks_history_delay.Changes
tasks_history_delay(seconds) to match the configured retention window.finished_at != "") unchanged in my local setup to minimize risk. It may be more robust to usefinished_at > 0given the schema stores timestamps as strings, but I’m leaving this decision to maintainers.tasks_history_delay: delete old finished tasks frombackground_tasksand related rows inbackground_subtasks.tasks_history_delayis unexpectedly stored in days, auto-convert to seconds.status='failed'cleanup withtasks_history_delay(instead of the hardcoded/fallback ~15 days), so failed tasks are retained consistently with the Task Manager history setting.finished_at > 0when removing old failed tasks.How it was validated
tasks_history_delayand confirmed the “Done” tab immediately reflects the configured retention window.tasks_history_delay(e.g. ~60 days).Notes / considerations