--- title: Sync Status Completed Logic Fix version: 1.0 date: 2026-07-28 author: Core Team status: draft --- # Sync Status "Completed" Logic Fix ## Problem The `sync_file_status` endpoint (`POST /api/v1/file/:file_uuid/sync-status`) incorrectly returns `"completed"` status when some processor JSON files are missing. ### Root Cause In `src/api/files.rs:1673-1753`, the `all_consistent` flag is only updated when `json_exists = true`: ```rust if json_exists { any_json_exists = true; // ... check consistency, set consistent ... if !consistent { all_consistent = false; // Only executed when JSON exists! } } // When json_exists = false: consistent = false, but all_consistent stays true ``` This means if `asr.json` doesn't exist: - `consistent = false` (initialized at line 1676) - But the `if !consistent` block is never reached - `all_consistent` remains `true` - Status becomes `"completed"` instead of `"scanning"` ## Design ### Processor JSON Files (7 required) | Processor | Filename | Special Cases | |-----------|----------|---------------| | ASR | `{uuid}.asr.json` | `"status": "no_audio_track"` or `"silent_audio"` | | ASRX | `{uuid}.asrx.json` | `"status": "no_audio_track"` | | OCR | `{uuid}.ocr.json` | Always exists if processor ran | | Pose | `{uuid}.pose.json` | Always exists if processor ran | | CUT | `{uuid}.cut.json` | Always exists if processor ran | | Face | `{uuid}.face.json` | `"status": "no_faces"` | | Face Cluster | `{uuid}.face_cluster.json` | `"status": "no_faces"` or `"no_embeddings"` | **Key principle**: ALL processors produce their JSON files, even for special cases. The JSON file exists but may contain empty arrays or special status fields. ### Status Determination Logic | Condition | Status | |-----------|--------| | All 7 JSONs exist AND all consistent AND has TKG edges | `agent_ready` | | All 7 JSONs exist AND all consistent AND no TKG edges | `completed` | | Any JSON exists (but not all, or not consistent) | `scanning` | | No JSON exists | `registered` | ### Fix Move the `all_consistent` update outside the `json_exists` block: ```rust for (name, filename) in &processors { let path = ...; let json_exists = path.exists(); let mut consistent = false; if json_exists { any_json_exists = true; // ... check consistency, set consistent ... } // MOVED HERE: JSON not existing = not consistent if !consistent { all_consistent = false; } processor_status.insert(...); } ``` ## Impact - **API**: No change to response format - **Behavior**: Files missing any JSON will show `"scanning"` instead of `"completed"` - **Backward compat**: No breaking changes ## Testing 1. File with all 7 JSONs → `completed` or `agent_ready` 2. File with 6 JSONs (1 missing) → `scanning` 3. File with no JSONs → `registered` 4. Special case (no audio, no faces) → all JSONs exist with special status → `completed`