What it is
Every MokoGIT instance registers a set of Actions maintenance crons at startup through a single entry point, initActionsTasks(). These are the background sweepers that keep continuous integration from wedging. A long-running CI platform accumulates three kinds of stuck work: a task whose runner crashed and will never report back (a zombie), a task that keeps checking in but never finishes (an endless run), and jobs or runs that were never picked up or never advanced (abandoned work). Each has its own reaper, with its own timeout and schedule, so the right remedy is applied to the right failure mode.
The two headline janitors are stop_zombie_tasks and stop_endless_tasks. They sit alongside the stock start_schedule_tasks and cleanup_actions crons that any Gitea-derived forge ships, plus MokoGIT additions such as cancel_abandoned_jobs, cancel_abandoned_runs, heal_wedged_runners, detect_dispatch_stall, detect_missing_release_runs, and purge_held_runs.
Why and when it matters
A CI task holds a dispatch slot for the duration of its run. If the runner executing that task dies - the host is rebooted, the container is killed, the network drops - the task row stays in a running state forever because nothing is left to report its completion. That dead task continues to count against capacity, and on a strict-FIFO dispatcher it can starve every build queued behind it. The same is true of a task that genuinely never terminates: a shell loop with no timeout, a hung network call, a process waiting on input that will never come.
Without a janitor, an operator has to notice the wedge, find the stuck task, and cancel it by hand. The janitor crons do this automatically and continuously, so a single dead runner does not quietly drain CI throughput across the whole instance.
How it works
The crons are registered in services/cron/tasks_actions.go. The whole suite is gated on Actions being enabled; if Actions is off, none of them register. Each one is a thin wrapper that calls into the Actions service layer on a schedule.
stop_zombie_tasks
Schedule: every 5 minutes, and it also runs at startup. It finds every task still marked running whose last update is older than the zombie timeout (ZOMBIE_TASK_TIMEOUT, default 10 minutes). The key signal is staleness: a healthy running task heartbeats as it streams logs and status, so a running task that has not been touched in ten minutes is almost certainly orphaned by a dead runner. Each matching task is stopped with a failure status, its logs are transferred to storage, and its parent job is re-notified so commit statuses and downstream jobs update correctly.
stop_endless_tasks
Schedule: every 30 minutes, also at startup. This targets the opposite pathology: a task that is still checking in (so it is not a zombie) but has been started longer ago than the endless timeout (ENDLESS_TASK_TIMEOUT, default 3 hours). Here the signal is total elapsed time since start, not staleness. A build that has genuinely been executing for three hours is treated as runaway and stopped with a failure status the same way a zombie is.
Both reapers share one internal routine. For each task it finds, inside a transaction it marks the task failed, loads the parent job, transfers the task log to object storage, and flags the log as stored. After the sweep it fires the workflow-and-run status-update notifiers and re-evaluates any jobs that are now ready to proceed. Because the work is done per task and skips on any individual error, one problematic task cannot block the rest of the sweep.
The rest of the suite
- cancel_abandoned_jobs (every 6 hours, at startup) - cancels jobs stuck in
waitingorblockedthat no runner picked up before the abandoned-job timeout (default 24 hours). Dedup-held runs are excluded so deliberately parked duplicates are left alone. - cancel_abandoned_runs (every 24 hours, at startup) - reaps whole runs wedged in
waiting/blockedthat the job-level reaper cannot clear, because they have no cancellable job rows. The canonical case is a dispatch against a now-missing workflow or branch that never parsed into jobs, or a run whose jobs all went terminal but whose aggregate status never advanced. A run with any still-running job is skipped, and dedup-held runs are excluded. - heal_wedged_runners (every 2 minutes) - frees dispatch slots held by tasks whose runner has gone offline, keyed on runner liveness rather than a timeout, and re-nudges a stalled queue.
- detect_dispatch_stall (every 5 minutes) - alerts when a job waits past the grace window while an online, idle, label-capable runner for its repo exists (head-of-line starvation). Detect-and-alert only; it does not cancel.
- detect_missing_release_runs (every 15 minutes) - alerts on a production commit that produced no workflow run at all - an interrupted push whose release never cut. It can optionally re-fire the release workflow to self-heal, but that auto-dispatch is off by default.
- purge_held_runs (every hour) - cancels dedup-held duplicate runs once their hold time-to-live has expired. Held runs with no TTL are never auto-purged.
- start_schedule_tasks (every minute) and cleanup_actions (nightly) - the stock schedule launcher and artifact/log cleanup.
Note the deliberate division of labor: stop_zombie_tasks keys on staleness, stop_endless_tasks on total runtime, heal_wedged_runners on runner liveness, and the cancel_abandoned_* pair on queue age. They overlap only by design, so a stuck item is caught by whichever detector matches its failure mode first.
Step by step: tuning and running
Adjust the timeouts (app.ini)
The thresholds live in the [actions] section of your MokoGIT configuration. The defaults are sensible for most instances; raise them if you legitimately run very long builds, or lower them to reclaim slots faster.
[actions]
ZOMBIE_TASK_TIMEOUT = 10m
ENDLESS_TASK_TIMEOUT = 3h
ABANDONED_JOB_TIMEOUT = 24h
ABANDONED_RUN_TIMEOUT = 24h
After editing, restart MokoGIT so the new durations are loaded.
Run a janitor on demand (admin UI)
- Sign in as a site administrator.
- Go to Site Administration, then Monitoring, then Cron Tasks.
- Find the task you want (for example
stop_zombie_tasksorstop_endless_tasks). - Click its Run action to trigger it immediately rather than waiting for the next scheduled cycle.
Run a janitor on demand (API)
Each cron can be listed and triggered through the admin cron API:
# List all cron tasks and their schedules
curl -H "Authorization: token YOUR_ADMIN_TOKEN" \
https://git.mokoenterprises.us/api/v1/admin/cron
# Trigger the zombie-task reaper now
curl -X POST -H "Authorization: token YOUR_ADMIN_TOKEN" \
https://git.mokoenterprises.us/api/v1/admin/cron/stop_zombie_tasks
Caveats
- These crons only register when Actions is enabled on the instance. On a forge with CI turned off, none of them run.
stop_zombie_tasksandstop_endless_tasksstop a stuck task with a failure status - the run is marked failed, not merely cancelled. This is intentional so the result is visibly red rather than silently vanishing, but it means a wrongly-tuned (too-short) timeout can fail a slow-but-healthy build. Tune the thresholds to your real workloads.- The zombie reaper keys on last update time, so a build that genuinely streams no output for longer than the timeout can be misread as dead. If you have a legitimately quiet long step, raise
ZOMBIE_TASK_TIMEOUTor ensure the step produces periodic output. - The
cancel_abandoned_*crons andpurge_held_runsdeliberately exclude dedup-held runs so they never cancel a duplicate that was parked on purpose. detect_dispatch_stallanddetect_missing_release_runsare detectors, not reapers - they raise an alert (see the ntfy per-event alerting article) and, except for the opt-in release auto-dispatch, take no corrective action themselves.
Get help
Open a support ticket or call (931) 820-0265.