Repeating tasks disappear from the task manager once a run finishes
❌ This issue is not open for contribution. Visit Contributing guidelines to learn about the contributing process and how to find suitable issues.
Overview
- Repeating tasks disappear from the task manager the instant a run ends, so a manual KDP sync never shows a "Finished" panel.
- Record each run's outcome on the job row and keep the task listed, reading as completed and scheduled again.
- Applies to every repeating job, so a scheduled sync that fails and retries becomes visible too.
Complexity: Medium Target branch: develop
Context
Originally reported by @pcenov in https://github.com/learningequality/kolibri/issues/15052#issuecomment-5090270523: syncing to KDP completes correctly, but the task is removed from the task manager the moment it finishes, so the 'Finished' task is never displayed. Syncing to a peer device still shows it.
https://github.com/user-attachments/assets/df01c599-bd7e-48ee-a6f2-5ebd4bdaf8ba
Three things compose to produce this:
enqueue_automatic_kdp_syncgives every KDP-registered facility a daily recurring sync withrepeat=None(kolibri/core/auth/tasks.py:369).- #15052 gave the manual KDP sync the same deterministic
job_id, so "Sync" now runs on that recurring row instead of a fresh one-off. - A finished recurring job is re-scheduled immediately:
reschedule_finished_job_if_needed→schedule()setsstate=QUEUEDwith a futurescheduled_time(kolibri/core/tasks/storage.py:639,:979). The row never sits inCOMPLETED, and the task manager hidesrepeat === nullrows unless they areRUNNING(facilityTasksQueue.js:16, deliberate since a7bf6db03006942af423b177ab5b2978593fa14b).
Peer syncs behave identically once a schedule to that peer exists — the reported peer device had none, which is why it still showed 'Finished'.
The same cause produces two unreported effects:
- A scheduled sync that fails re-schedules onto
retry_interval(hourly for KDP), so a persistently failing automatic sync is invisible in the UI. progress,exception,tracebackandresultlive insaved_joband are cleared neither at reschedule nor at the start of the next run, so a run inherits the previous run's progress bar and exception.
The Change
A repeating task stays listed after each run, reading as completed and scheduled again:
Sync 'Facility name (a1b2)' — Kolibri Data Portal
Finished 2 minutes ago · next sync in 24 hours
1.2 MB sent • 340 kB received
A failed run reads Failed 5 minutes ago · retrying in 1 hour. This survives a page reload — no client-held state. A schedule that has never run stays out of the task manager; it belongs on Manage sync schedule.
Storage
Jobgainslast_finished_state(char 20, nullable) andlast_finished_time(datetime, nullable), with a migration inkolibri/core/tasks/migrations/.reschedule_finished_job_if_neededwrites the finishing state and the current time to those columns in the same transaction as the reschedule, covering all three exits: recurrence, failure retry, and a task-requestedretry_indelay.mark_job_as_runningclearsprogress,total_progress,exception,tracebackandresultso a new run does not inherit the last one's.- Those fields are not cleared at reschedule time: the queued row still describes the run that just finished.
extra_metadatais untouched:sync_state,bytes_sentandbytes_receivedare what the panel renders for the finished run.restart_jobclears and re-enqueues a fresh row, so it drops the snapshot.
API
TasksViewSet._job_to_responsegainslast_finished_statusandlast_finished_datetime, mirroring the existingstate → statusandscheduled_time → scheduled_datetimenaming.clearablestays state-derived, so a re-scheduled recurring row is not clearable.- "Clear completed" therefore cannot delete a schedule.
Frontend
facilityTasksQueue.isActiveTaskshows arepeat === nullrow when it isRUNNINGor has alast_finished_datetime.facilityTasksQueue.facilityIsSyncingderives "is syncing" from!task.clearableover the active list.- With recurring rows always present, that pins every registered facility to a permanent "Syncing" spinner.
- Re-base it on
status === RUNNING. syncFacilityTaskDisplayInfodrives the status line and byte counts offlast_finished_status/last_finished_datetimefor a non-running row.- It adds the next-run clause from
scheduled_datetime. - Its
isRunningmust requirestatus === RUNNING. isRunningcurrently infers fromextra_metadata.sync_state, which is stale (COMPLETED) on a re-queued row.FacilitiesTasksPage.vue:19testsfacilityTasks.length === 0for its empty state.- A device whose only task is a hidden schedule therefore renders neither tasks nor the "no tasks" message.
- Test
activeFacilityTasksthere instead. index.vue'sisRepeatingTaskCompletedinfers completion from aRUNNING → QUEUEDtransition.- Use a change in
last_finished_datetimeinstead. - Manage sync schedule gains a last-run column from the same fields.
- New translator strings are needed for the relative finished/failed status and the next-run clause.
FacilityNameAndSyncStatuscarries an unusednextSyncstring — reuse or delete it.
How to Get There
- Register a facility to the Data Portal (Device > Facilities > Register facility). This is what creates the daily recurring KDP sync.
- Press Sync on that facility, choose Kolibri Data Portal, and watch Device > Facilities > Task manager as the sync finishes.
- For the peer equivalent, first create a sync schedule to a peer device via Manage sync schedule, then use Sync.
- For the failure path, make KDP unreachable (offline device) so the scheduled sync fails and re-schedules onto its hourly retry.
Out of Scope
- The deterministic-id dedup from #15052 stays. A manual sync landing on the existing schedule is the intended behaviour.
- Facility-level
last_successful_sync/last_failed_sync(morango transfer-session subqueries inkolibri/core/auth/viewsets/facility.py) remain the facility list's source; they are per-facility, not per-schedule. - No UI for repeating tasks outside the facility queue (vacuum, soud). They gain the data; nothing renders it yet.
Acceptance Criteria
- [ ] After a manual KDP sync completes, the task stays in Device > Facilities > Task manager showing the finished status, a relative finish time, the bytes sent and received, and the next sync time.
- [ ] The entry is still present with the same information after a page reload.
- [ ] The entry offers neither Clear nor Retry, and "Clear completed" neither removes it nor deletes the schedule.
- [ ] A facility row shows "Syncing" only while a sync for it is actually running.
- [ ] A scheduled sync that fails shows the failed status and the time of its next retry.
- [ ] A second run of a repeating task starts with no progress or exception carried over from the previous run.
- [ ] A peer device with a sync schedule behaves as above; a peer without one still shows a one-off finished entry that is clearable.
- [ ] A schedule that has never run does not appear in the task manager.
- [ ] The task manager shows its "no tasks" message when a never-run schedule is the only task.
Testing
kolibri/core/tasks/test/test_job_storage.py:- snapshot written on recurrence, on failure retry and on
retry_in - no snapshot when a finished job is not re-scheduled
- per-run fields cleared at
mark_job_as_running clear(force=False)leaves a re-scheduled recurring row in place
- snapshot written on recurrence, on failure retry and on
kolibri/core/tasks/test/test_api.py:- both new keys present in the response
clearablefalse for a re-scheduled recurring row
packages/kolibri-common/utils/__tests__/syncTaskUtils.spec.js: display info for a re-scheduled recurring row — finished, failed, and with a stalesync_state.- Jest coverage of the
isActiveTaskandfacilityIsSyncingfilters.
AI usage
I used Claude Code to trace the regression through the task storage and facility task UI, and to draft this issue. I confirmed each code reference and the root-cause chain myself, and decided the field-level design and scope.
Plan: A repeating task (KDP/peer sync schedule) stays in the task manager after each run, reading as finished-and-scheduled-again, instead of vanishing the instant the run ends.
- [x] Storage records the run that just ended
- [x] A new run starts clean
- [x] The tasks API exposes the snapshot
- [x] Shared display logic reads the last run
- [x] Device > Facilities keeps the row and drops the permanent spinner
- [x] Facility > Data page stops spinning forever
- [x] Manage sync schedule shows the last run
Implemented in #15093.
@rtibblesbot's comments are generated by an LLM, and should be evaluated accordingly
How was this generated?
- Implemented code following the pre-approved plan using test-driven development (red-green-refactor)
- Ran the project's full test suite and linter before committing
- For UI changes: captured live screenshots to verify rendering
- For backend changes: verified with example API/CLI output
Acceptance criteria — all verified. Walked end to end on two live Kolibri servers: device A (:8451) owning "QA Facility", device B (:8452) having imported it, with a real peer sync schedule between them.
No Data Portal account is reachable from this environment, and registering one in dev would push real data to the live portal — so the KDP-worded criteria were exercised against an equivalent peer schedule. That is the same code path: both syncdataportal and peerfacilitysync are repeating rows re-queued by reschedule_finished_job_if_needed, and the issue notes peer syncs behave identically once a schedule to that peer exists.
This account cannot edit issue bodies (UpdateIssue is not permitted for it), so the checklist below — verbatim from the issue — is the record of the ticks.
- [x] After a manual KDP sync completes, the task stays in Device > Facilities > Task manager showing the finished status, a relative finish time, the bytes sent and received, and the next sync time.
→
Finished 30 seconds ago · next sync in 1 hour/10 KB sent • 23 KB received - [x] The entry is still present with the same information after a page reload. → Unchanged; the snapshot is server-side, no client-held state.
- [x] The entry offers neither Clear nor Retry, and "Clear completed" neither removes it nor deletes the schedule.
→ No buttons rendered;
POST /api/tasks/tasks/clearall/returned 200 and left both row and schedule intact. - [x] A facility row shows "Syncing" only while a sync for it is actually running.
→ Sampled
QUEUED → RUNNING → QUEUED; the row reads "Syncing" only across theRUNNINGwindow. - [x] A scheduled sync that fails shows the failed status and the time of its next retry.
→
Failed 20 seconds ago · retrying in 5 minutes, counting down to the 5-minuteretry_interval. - [x] A second run of a repeating task starts with no progress or exception carried over from the previous run.
→ At the transition into
RUNNING:exception: null,percentage: 0; the panel reads "Waiting", not "Finished". - [x] A peer device with a sync schedule behaves as above; a peer without one still shows a one-off finished entry that is clearable.
→ Peer without a schedule produced a one-off
repeat: 0Finished entry with CLEAR. - [x] A schedule that has never run does not appear in the task manager. → Absent.
- [x] The task manager shows its "no tasks" message when a never-run schedule is the only task. → Shown.
Plan items, for completeness:
- [x] Storage records the run that just ended
- [x] A new run starts clean
- [x] The tasks API exposes the snapshot
- [x] Shared display logic reads the last run
- [x] Device > Facilities keeps the row and drops the permanent spinner
- [x] Facility > Data page stops spinning forever
- [x] Manage sync schedule shows the last run
| Finished, on the schedule | ![]() |
| Failed, retrying | ![]() |
| Never-run schedule only | ![]() |
| Peer without a schedule — clearable | ![]() |
| Manage sync schedule | ![]() |
| Row during a run | ![]() |
| Row after the run | ![]() |
No code changes came out of this pass; #15093 is unchanged.
@rtibblesbot's comments are generated by an LLM, and should be evaluated accordingly
The bot has been waiting for a response for 2 hour(s). It will resume automatically when someone replies.
The bot has been waiting for a response for 2 hour(s). It will resume automatically when someone replies.
The bot has been waiting for a response for 2 hour(s). It will resume automatically when someone replies.
The bot has been waiting for a response for 2 hour(s). It will resume automatically when someone replies.






