audit-g3: lifecycle batch — recovery sweeps, retention, timeouts #51
Reference in New Issue
Block a user
Delete Branch "dev"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Summary
Group 3 of the 2026-06-02 multi-system drift audit. Plugs the FC long-running-entity discipline gaps the audit flagged: every entity that can get stuck now has recovery + retention + timeout, and the long-runners no longer collide with the FC-3i
recover_stalled_task_runs5-min default.Recovery sweeps (every 5 min, beat schedule)
recover_stalled_backup_runs— flipsBackupRunstuck inrunning/restoringpast 7h (covers the 6.5h images-backup hard limit) toerror.prune_backupsdocstring corrected — the FC-3i TaskRun sweep never touched BackupRun rows; the dashboard was showing phantom in-flight backups.recover_stalled_library_audit_runs— flipsLibraryAuditRunstuck past 135 min (10-min buffer abovescan_library_for_rule's 2h5m hard limit) toerror. Previously a SIGKILL'd row blocked all future audits until manual DB surgery.recover_stalled_import_batches— finalizesImportBatchrows stuck running >2h whose child tasks are all terminal (orphan case where the orchestrator crashed before the closing UPDATE). Uses the same EXISTS predicate/api/system/statsalready had.Retention (daily, beat schedule)
prune_library_audit_runs— 30-day window. Audit rows carrymatched_idsJSONB blobs that can hold tens of thousands of ids.prune_import_batches— 30-day window. Cascades toImportTaskvia the model relationship.Time limits on five long-runners
Every one of these previously had no
time_limitand collided with the recover-stalled-task-runs 5-min default — they could be markederrormid-flight:scan_directory: soft 60m / hard 70mverify_integrity: 60m / 70mbackfill_phash: 30m / 35mapply_allowlist_tags: 30m / 35mrecompute_centroids: 30m / 35mQUEUE_STUCK_THRESHOLD_MINUTESnow coversmaintenance(75) andscan(75) — above the longest task on each — with per-task overrides for the outliers (backup_images_task: 420,restore_images_task: 420,scan_library_for_rule: 130).Smaller fixes
start_audit_runis now age-aware: arunningrow older than the audit hard limit no longer blocks a new run (the sweep will catch it within 5 min). Previously a SIGKILL'd row blocked forever./api/import/statusnow uses the same EXISTS predicate/api/system/statsdoes. The UI banner no longer says "Scanning…" indefinitely while the stats card says idle.DownloadEvent.started_atresets onpending→runningso a freshly-promoted event from a busy queue isn't measured against its original enqueue time. Was racingrecover_stalled_download_eventson heavy-queue days.Test Plan
BackupRunrow flips toerrorinstead of stayingrunningforeverImportBatch, then kill the orchestrator after all child tasks complete — wait 5 min, confirm the batch finalizes tocompleteand the UI banner clearsverify_integrityon a large library — confirm it runs to completion without being markederrorby the 5-min sweepLibraryAuditRun/ImportBatchrows are prunedAudit reference
Closes Group 3 of plan task
Scribe #551. Group 4 (status-enum miss batch: download_service handling offailed/refreshed, FE handlers fordeferred, VALIDATION_FAILED backfill auto-complete, archive dispatch artist/source threading, celery_signals queue mapping) next.🤖 Generated with Claude Code