Skip to content

fix(taskprocessing): delete AI tasks of deleted users and register their cleanup jobs - #67075

Open
julien-nc wants to merge 2 commits into
masterfrom
fix/setup-task-cleanup-background-jobs
Open

julien-nc wants to merge 2 commits into
masterfrom
fix/setup-task-cleanup-background-jobs

Conversation

@julien-nc

@julien-nc julien-nc commented Nov 27, 2026 •

Copy link
Copy Markdown
Member

Summary

Deleting a Nextcloud account left its task processing, text processing and text to image tasks and their generated files in place. The tasks are bound to the user id alone, so a new account created later with the same user id inherited the previous holder's tasks: their prompts and results were readable, and their output files could be downloaded.

A UserDeletedEvent listener now deletes a user's rows from all three task tables together with the files they generated in appdata. Each cleanup step catches its own errors so a failure never blocks the account deletion.

While investigating this, Setup::installBackgroundJobs() turned out to only register the text processing cleanup job. Fresh installations therefore never ran the task processing and text to image cleanups; both jobs are now registered as well, matching what the repair step does on upgraded instances.

Testing

A new regression test covers finished, exempt and still scheduled tasks of a deleted user, their output files, and the legacy text processing and text to image rows, and asserts that another user's tasks survive. The task processing test suite passes (65 tests, 341 assertions) and the setup tests pass (19 tests), both tested on sqlite locally.

Assisted by OpenCode:glm-5.3-flash

Checklist

AI (if applicable)

  • The content of this PR was partly or fully generated using AI

Setup::installBackgroundJobs() only registered the TextProcessing
RemoveOldTasks job, so a fresh installation ran the task processing
and text2image cleanups never, while the AddRemoveOldTasksBackgroundJob
repair step registers all three. Register the TaskProcessing and
TextToImage jobs as well so old tasks and their output files are
cleaned up on every installation, not only on upgraded ones.

Assisted-by: OpenCode:glm-5.3-flash
Signed-off-by: Julien Veyssier <julien-nc@posteo.net>
Deleting a Nextcloud account left its task processing, text processing
and text to image tasks and their generated files in place. The tasks
are bound to the user id alone, so a new account created later with the
same user id inherited the previous holder's tasks: their prompts and
results were readable, and their output files could be downloaded.

Add a UserDeletedEvent listener that deletes a user's rows from all
three task tables together with the files they generated in appdata,
without blocking the account deletion on failure.

Assisted-by: OpenCode:glm-5.3-flash
Signed-off-by: Julien Veyssier <julien-nc@posteo.net>
@julien-nc julien-nc added this to the Nextcloud 36 milestone Nov 27, 2026
@julien-nc
julien-nc requested a review from a team as a code owner November 27, 2026 11:48
@julien-nc julien-nc added the bug label Nov 27, 2026
@julien-nc
julien-nc removed the request for review from a team November 27, 2026 11:48
@julien-nc julien-nc added the 3. to review Waiting for reviews label Nov 27, 2026
@julien-nc

Copy link
Copy Markdown
Member Author

/backport to stable35

@julien-nc

Copy link
Copy Markdown
Member Author

/backport to stable34

@julien-nc

Copy link
Copy Markdown
Member Author

/backport to stable33

@marcelklehr

Copy link
Copy Markdown
Member

Do we also delete tasks by users that were deleted before these changes are released, or do we rely on the OldTaskRemovalJobs only?

@julien-nc

Copy link
Copy Markdown
Member Author

@marcelklehr We rely on the old jobs.

So rows with allow_cleanup = 0 are never removed by the aging job, so the leftovers of such tasks and their output files can persist indefinitely, even after this change.

We could fix that with repair step that delete the rows linked to a non-existing user.

Wdyt?

@marcelklehr

Copy link
Copy Markdown
Member

We could fix that with repair step that delete the rows linked to a non-existing user.

If the goal is to have no entries in the tasks table that belong to non-existent users, let's go with the repair step :)

This branch has not been deployed

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants