Skip to content

Added background cleaning - #2633

Open
jessevz wants to merge 2 commits into
masterfrom
2510-enhancement-move-cleaning-stuff-to-background
Open

jessevz wants to merge 2 commits into
masterfrom
2510-enhancement-move-cleaning-stuff-to-background

Conversation

@jessevz

@jessevz jessevz commented Nov 16, 2026

Copy link
Copy Markdown
Contributor

Added background cleaning for:

  • agent statistics
  • zap queue
  • stale tus file uploads
  • expired refresh tokens

@jessevz
jessevz requested a balanced review from Copilot November 16, 2026 17:58
@jessevz jessevz linked an issue Nov 16, 2026 that may be closed by this pull request

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

The new migration generates config ID 80, which already exists, causing a duplicate-key failure that blocks fresh PostgreSQL setup before the server starts.

1 open issue
What changed in this PR

Moves server housekeeping out of agent progress requests and into scheduled background jobs, using the existing job runner.

Changes:

  • Adds configurable periodic scheduling and cleanup for agent statistics, zap entries, stale uploads, expired refresh tokens, and old job history.
  • Corrects upload-expiration cleanup and reports deletion counts and per-step failures.
  • Adds database migrations and tests for scheduling, cleanup, and interval validation.
File Description
src/​migrations/​postgres/​20261112120000_cleaning-interval-config.sql Adds the PostgreSQL cleaning interval setting.
src/​migrations/​mysql/​20261112120000_cleaning-interval-config.sql Adds the MySQL cleaning interval setting.
src/​inc/​utils/​RefreshTokenUtils.php Returns the number of expired tokens deleted.
src/​inc/​utils/​Lock.php Defines a periodic-scheduler lock.
src/​inc/​utils/​ConfigUtils.php Requires a positive cleaning interval.
src/​inc/​Util.php Removes inline scheduling, returns cleanup counts, and corrects upload expiry handling.
src/​inc/​templating/​Statement.php Removes the obsolete cleaning constant registration.
src/​inc/​jobs/​PeriodicJobScheduler.php Schedules due jobs using persisted timestamps and unfinished-job checks.
src/​inc/​jobs/​PeriodicBackgroundJobHandler.php Defines the periodic job interface.
src/​inc/​jobs/​handlers/​CleaningJob.php Runs housekeeping steps and prunes old job history.
src/​inc/​jobs/​BackgroundJobRegistry.php Registers cleaning and discovers periodic handlers.
src/​inc/​defines/​DConfig.php Defines and describes the cleaning interval setting.
src/​inc/​defines/​DCleaning.php Removes the obsolete cleanup timestamp constant.
src/​inc/​defines/​DBackgroundJobType.php Adds the cleaning job type.
src/​inc/​cron.php Schedules periodic jobs before draining the queue.
src/​inc/​apiv2/​helper/​ImportFileHelperAPI.php Deletes only the expired upload addressed by the request.
src/​inc/​agentapi/​model/​SendProgressAction.php Stops running cleanup during progress reports.
ci/​phpunit/​inc/​jobs/​PeriodicJobSchedulerTest.php Tests scheduling cadence and duplicate prevention.
ci/​phpunit/​inc/​jobs/​CleaningJobTest.php Tests cleanup behavior and result reporting.
ci/​apiv2/​test_config.py Tests rejection of a zero cleaning interval.
ci/​apiv2/​test_backgroundjob.py Tests cron-driven cleaning and interval enforcement.

Review effort: Balanced

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 Approval recommended

No active review issues were identified for the move of server housekeeping into periodic background jobs.

No open issues 🎉

1 resolved since last review

Review effort: Balanced

@jessevz
jessevz requested a review from s3inlc November 17, 2026 08:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[ENHANCEMENT]: Move cleaning stuff to background

2 participants