Skip to content

fix(auto-upload): stop the charging loop and endless conflict retries - #18160

Open
paroj wants to merge 3 commits into
nextcloud:masterfrom
paroj:fix/auto-upload-battery-loop
Open

paroj wants to merge 3 commits into
nextcloud:masterfrom
paroj:fix/auto-upload-battery-loop

Conversation

@paroj

@paroj paroj commented Nov 27, 2026

Copy link
Copy Markdown

Changes

Fixes the background-work part of #18148; independent of #18156.

  • Charging gate matches WorkManager — the worker used BatteryStatus.isCharging (EXTRA_STATUS) while the constraint uses BatteryManager.isCharging(). In the "plugged in but not charging" state (Protect battery at 80 %) they disagree, and the two reschedule each other ~60k times a night. Restores the check removed in 007de71 (fix(auto-upload): stop worker restart loop at battery charge limit #18049).
  • Only observe uploaded media collections — MediaStore.Files also fires for downloads and documents and started the whole pipeline; keep images and videos.
  • Non-retryable failures are terminal — a conflicted file was re-queued on every scan; a result that cannot succeed by retrying now leaves it handled.

Testing: the three affected test classes and spotlessKotlinCheck pass; detekt/spotbugs add no findings.

🏁 Checklist

  • ⛑️ Tests (unit and/or integration) are included or not needed
  • 🔙 Backport requests are created or not needed: /backport to stable-xx.x
  • 📅 Milestone is set
  • 🌸 PR title is meaningful (if it should be in the changelog: is it meaningful to users?)

🤖 AI (if applicable)

  • The content of this PR was partly or fully generated using AI (N/A)

The guard inside the worker and WorkManager's charging constraint read
different signals. In the "plugged in but not charging" state WorkManager
reports the constraint as unmet while the battery still reports
BATTERY_STATUS_CHARGING, so the guard did not fire: JobScheduler started
the work, WorkManager stopped it again and rescheduled, and both kept
doing that thousands of times per night.

Ask BatteryManager.isCharging(), the value WorkManager's
BatteryChargingTracker evaluates, so the worker and the constraint agree.

Assisted-by: OpenCode:DeepSeek V4.1 Flash
Signed-off-by: Pavel Rojtberg <rojtberg@gmail.com>
The external files collection changes on downloads, documents and other
files that auto upload never reads. Watching it made unrelated file
changes start the whole auto-upload pipeline. Observe the image and video
collections only.

Assisted-by: OpenCode:DeepSeek V4.1 Flash
Signed-off-by: Pavel Rojtberg <rojtberg@gmail.com>
Auto upload marks a conflicted file as handled, but the next scan saw a
failed upload row, deleted it and queued the file again. With the
ASK_USER collision policy nothing resolved the conflict, so the same
files were uploaded again on every scan.

Keep the file handled when the last result cannot succeed by retrying.
Resolving the conflict in the upload list still starts a new upload
through FileUploadWorker.

Assisted-by: OpenCode:DeepSeek V4.1 Flash
Signed-off-by: Pavel Rojtberg <rojtberg@gmail.com>

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant