From ad307423744483386b8aa680d49656d71f7f7791 Mon Sep 17 00:00:00 2001 From: Accusys Date: Sun, 4 Oct 2026 15:55:04 +0800 Subject: [PATCH] fix: integrate phase_completed into status logic (A-9) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Issue: phase_completed was calculated but never used File: src/api/files.rs:1982 Root cause: - phase_completed = (phase == "COMPLETED") - But new_status only checked all_consistent and any_json_exists - This caused inconsistency between DB phase and reported status Solution: - Add phase_completed as highest priority condition - If phase is COMPLETED and any_json_exists → status = completed - This ensures DB phase is respected when available Logic: 1. phase_completed + any_json_exists → completed (trust DB) 2. all_consistent + any_json_exists → completed (all JSONs ready) 3. any_json_exists → scanning (in progress) 4. no JSONs → registered (not started) Benefits: - Fixes G-1 gate condition - Resolves potential inconsistency between phase and status - Matches original design intent Verification: cargo check --lib passes References: - A-9 in Momentry_Release_Requirements_20261004.md v1.1 - G-1 in M5Max128_Portability_Install_Test_20261004.md --- src/api/files.rs | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/api/files.rs b/src/api/files.rs index 9aac40e4..b2f59491 100644 --- a/src/api/files.rs +++ b/src/api/files.rs @@ -1982,13 +1982,18 @@ async fn sync_file_status( let phase_completed = phase == "COMPLETED"; // 狀態判斷 - let new_status = if all_consistent && any_json_exists { + // Priority: phase completed > all_consistent > any_json_exists + let new_status = if phase_completed && any_json_exists { + // Phase marked completed in DB → trust it + "completed" + } else if all_consistent && any_json_exists { + // All processor JSONs consistent → completed "completed" } else if any_json_exists { - // 部分 JSON 存在或不一致 → 入庫中 + // Some JSONs exist but incomplete or inconsistent → scanning "scanning" } else { - // 無 JSON → 未開始 + // No JSONs → not started "registered" };