Commit Graph

451 Commits

Author SHA1 Message Date
Accusys d55d398832 fix: handle null status in face_traced.json for no-face videos
Issue: Files with face_traced.json status=null and total_faces=0 stuck in PROCESSING forever

Root cause:
- ingestion_complete checks trace_status == 'no_faces' to skip TKG
- But some old files have status=null instead of 'no_faces'
- TKG check fails because no nodes for no-face videos

Solution:
- Check both status='no_faces' AND total_faces=0
- Skip TKG check for no-face videos (total_faces=0)
- Also update face_cluster_done to handle total_faces=0

Impact:
- Fixes stuck files with null status in face_traced.json
- Consistent with scan.rs fix (commit 0d11c601)

Affected: M4ProMini file 18173b62d80bf829910348fa1a6ddcf5
2026-10-08 09:41:51 +08:00
Accusys 06a099e159 fix: 延長 VLM timeout 120s→300s(vlm_summary、agent analyze_frame、backfill_trace_vlm) 2026-10-08 09:30:48 +08:00
Accusys 2ec0bc6706 fix: use content instead of reasoning_content for VLM
- Gemma4 returns both content and reasoning_content
- reasoning_content is the thinking process, not the final answer
- content contains the actual scene description
- Changed priority: content first, reasoning_content as fallback

Fixes: Scene VLM generated 0 descriptions issue
Root cause: Using reasoning_content (thinking) instead of content (answer)
2026-10-08 01:13:42 +08:00
Accusys d5786608f0 fix: add 60s timeout to agent search
- Wrap run_tool_loop in tokio::time::timeout
- Return 408 Request Timeout with JSON error
- Prevent infinite loops from blocking server
- Log timeout events for monitoring

Fixes: search_agents timeout issue
2026-10-07 18:19:13 +08:00
Accusys 9596cec7ba fix: prevent empty body on search API errors
- Add ErrorResponse struct with success/error/results fields
- Replace StatusCode returns with Json<ErrorResponse>
- Ensure all error paths return proper JSON response
- Prevent frontend crash when embedding service fails

Fixes: M4 Visual Search fault (500 empty body)
Related: embeddinggemma_server.py MPS crash
2026-10-07 18:09:12 +08:00
Accusys cd00a7fec5 fix: worker finalize stuck processing files
- Improve face fast-path trigger: recognize has_faces with empty frames
- Add re-evaluation mechanism: check PROCESSING files every 10 mins
- Enhance ASRX silent fast-path: detect empty segments array
- Fix files stuck in PROCESSING status when all data is produced

Related: M4ProMini deep scan (114 files, 89 bad + 2 stuck)
Issue: ASRX & FACE_CLUSTER forever running/0, no completion trigger
2026-10-07 13:11:10 +08:00
Accusys ab54382834 fix: add validation functions for A-6
Added is_valid_file_uuid() and is_valid_chunk_id() in validator.rs

- is_valid_file_uuid: 32 chars, lowercase hex
- is_valid_chunk_id: [a-zA-Z0-9_-]+, max 128 chars
- Blocks path traversal sequences
2026-10-05 04:34:05 +08:00
Accusys 060edda3ae fix: A-6 security patch - path traversal prevention
**Security Issue**:
- chunk_thumbnail: file_uuid/chunk_id unvalidated → path traversal
- chunk_thumbnail: cache-hit missing JPEG validation → content-type confusion
- scene_thumbnail: file_uuid unvalidated → path traversal

**Fixes**:
1. Added is_valid_file_uuid() in validator.rs
   - 32 chars, lowercase hex only
   - Blocks any path containing / or ..

2. Added is_valid_chunk_id() in validator.rs
   - [a-zA-Z0-9_-]+, length <= 128
   - Matches all 5226 existing chunks (cut_, time_, pure digits)
   - Blocks traversal sequences

3. chunk_thumbnail (media_api.rs:1162):
   - Added validation before path construction
   - Added JPEG validation for cache-hit
   - Returns 404 for invalid input

4. scene_thumbnail (media_api.rs:965):
   - Added file_uuid validation
   - filename already validated (scene_<N>.jpg)

**Verification**:
- Defense in depth: character whitelist + canonicalize
- No regression: all existing chunk_id formats pass
- Mitigation: both handlers behind protected_routes (auth required)
2026-10-05 04:32:28 +08:00
Accusys e398595734 fix: revert file_uuid to simple format (32 chars)
**Problem**:
- Changed to hyphenated format (36 chars)
- videos.file_uuid is varchar(32)
- Caused regression: 'value too long for type'

**Fix**:
- Reverted to simple().to_string() (32 chars)
- Schema convention: ~10 tables use varchar(32)
- Hyphenated format is for command_id, not file_uuid

**Kept**:
- FFPROBE_PATH environment variable (verified working)

**Reference**: M4 analysis of schema constraints
2026-10-05 04:17:54 +08:00
Accusys 76c52f12fc fix: file_uuid format + ffprobe path
**Fixes**:
1. file_uuid: Use standard format with hyphens (consistent with other 11 places)
   - Changed from simple().to_string() to to_string()
   - Format: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx

2. ffprobe: Use FFPROBE_PATH environment variable
   - Fallback to 'ffprobe' in PATH
   - Follows project convention (DATABASE_URL, AUDIT_ENCRYPTION_KEY)
   - Solves non-interactive PATH issue

**Rationale**:
- Both are one-line changes
- Reduces packaging cycles (avoiding 4th binary sync issue)
- Critical for data consistency and deployment automation
2026-10-05 04:13:19 +08:00
Accusys 948b0f653b feat: implement register command for batch 3
**Implementation**:
- Uuid::new_v4() for file_uuid generation
- Local file path support only
- File existence check (exit 1 on failure)
- ffprobe metadata extraction
- Videos table insertion

**Specs**:
- videos.status: pending (from schema default)
- file_uuid: 32 chars, UNIQUE
- content_hash: no UNIQUE constraint

**Decision**: Use defaults from M4
2026-10-05 03:58:06 +08:00
Accusys 6d138024e4 fix: use as_str() for key_type in handlers.rs
Replace serde_json::to_string() with as_str() to store bare string.
2026-10-05 03:03:34 +08:00
Accusys 3ef6ccee7f fix: key_type stored as bare string instead of JSON string
**Problem**:
- key_type stored as "user" (with quotes, len=6)
- Future WHERE key_type = 'user' would silently fail

**Solution**:
- Added ApiKeyType::as_str() method
- Returns bare string: "system", "user", etc.
- handlers.rs:437 now uses as_str() instead of serde_json::to_string()

**Impact**:
- Existing test keys in test DBs can be safely ignored
- Production DB has no api_keys yet
- No code relies on JSON-quoted format
2026-10-05 03:01:42 +08:00
Accusys 0d5f5f4b22 fix: resolve api-key function signature mismatch
**問題**:
- main.rs 有舊的 handle_api_key stub
- 函數簽名不匹配

**修復**:
1. 刪除 main.rs:337-352 舊函數
2. 修改 main.rs:122 調用:
   - action 傳引用 (&action)
   - ttl 類型轉換 (ttl.map(|i| i as u64))
   - 添加 key_id 參數 (None)

**驗證**:
- ✅ 編譯成功
- ✅ 字串檢查通過
- ✅ 類型匹配正確
2026-10-05 02:34:50 +08:00
Accusys a535aa1b8d feat(cli): implement api-key create and list
**實作內容**:
- Create: 完整實作,生成 API key 並寫入 DB
- List: 完整實作,列表顯示所有 API keys
- Validate/Revoke/Rotate/Stats: 預留介面,回傳 exit code 1

**關鍵調整**:
- 權限寫死為 ["read","write"](預設值)
- key_type 使用 serde 序列化(JSON 字串格式)
- DB 寫入失敗回傳 Err(不再靜默成功)
- 錯誤處理完整,失敗時 exit code ≠ 0

**參考**:
- playground.rs:2862-2956
- postgres_db.rs:2928, 2992
- api_key/service.rs:66

**驗收標準**:
- api_keys 表新增記錄
- key_prefix 正確 (muser_ / msvc_ 等)
- exit code 為 0
2026-10-05 02:19:44 +08:00
Accusys bc441c1534 feat(runner): add schema_version skip logic
**目的**:
- 當 schema_migrations >= 42 筆時,跳過 migration 執行
- 支援 schema.sql 快速部署

**邏輯**:
- 檢查 schema_migrations 記錄數
- 如果 >= 42,表示已完整套用
- 記錄日誌並返回

**配合 M4**:
- schema.sql 已驗證可用
- Worker 可正常啟動
- 42 個 migration 標記已完成

**驗證**:
- M5Max128 測試通過
- Worker 啟動成功
2026-10-05 01:06:27 +08:00
Accusys 7c7cf60a12 feat(migration): remove hardcoded DDL, use migrations only
**重大變更**:
- 註解掉 postgres_db.rs:1075-1640 (570 行)
- 所有 schema 變更現在完全依賴 migration 文件

**實現**:
- 單一來源:migrations/*.sql
- 符合最佳實踐
- 易於維護和版本控制

**影響**:
- Server 啟動時只執行 migration 文件
- Worker 啟動時也執行 migration 文件
- Schema 完全由 migration 文件定義

**下一步**: 測試驗證所有表正確建立
2026-10-04 23:54:31 +08:00
Accusys 495e5e324a fix(migration): add dev schema support in migration runner
**修復**:
- postgres_db.rs:1695 添加 dev. schema 替換
- 支援 public. 和 dev. schema prefix 替換

**影響**:
- 修復 3 個 migration 失敗(010, 021, 024)
- 正確處理雙 schema 環境

**Ref**: M4 差異分析報告
2026-10-04 23:52:29 +08:00
Accusys bca83c2f26 fix(migration): rename 3002 to 002 for correct execution order
**問題** (M4 報告):
- 36/41 migration 失敗
- 3002 排在最後,基礎表未建立
- 導致 relation/column does not exist

**修復**:
- 重命名 3002_public_schema_pipeline_tables.sql → 002
- 確保基礎表在第 2 位建立

**預期**:
- 41/41 migration 成功
- videos.face_settings 欄位存在

**清理**:
- 移除錯誤提交的備份檔

Ref: docs_v1.0/M4_workspace/2026-10-04_B-4_Sorting_Fix.md
2026-10-04 22:41:10 +08:00
Accusys b83bb04496 fix(migration): deep fix for B-4 multi-statement and path issues
**問題** (M4 報告):
- 1. 多陳述句無法執行 (sqlx::query 限制)
- 2. 相對路徑 migrations/ (依賴 CWD)
- 3. Worker 路徑缺失
- 4. 欄位缺失 (face_settings, asr_status, completed_at)

**修復**:
- 使用 sqlx::raw_sql() 支持多陳述句
- 路徑改用 current_exe() 推導
- Worker 啟動時也執行 migration
- 新增 migration 039 補充缺失欄位

**文件**:
- src/core/db/postgres_db.rs: 修復 migration runner
- src/main.rs: 添加 worker migration
- migrations/039_add_missing_video_columns.sql: 新增缺失欄位

**測試**: 待 M5Max128 驗證

Ref: docs_v1.0/M4_workspace/2026-10-04_B-4_Deep_Fix_Plan.md
2026-10-04 22:13:15 +08:00
Accusys c1e3a2012f fix(migration): implement SQL file migration runner
- Add logic to read and execute .sql migration files
- Replace schema placeholders (public. -> current schema)
- Track applied migrations in schema_migrations table
- Support both public and dev schema environments
- Fixes B-4: 27/40 migrations failed on M5Max128

Ref: docs_v1.0/M4_workspace/2026-10-04_B-4_Migration_Fixed.md
2026-10-04 21:51:24 +08:00
Accusys 1c7e7481f6 fix: final docs.rs L11 path cleanup
Issue: Previous edit missed L11 hardcoded path

Solution: Use same env var + current_exe() pattern as L24

Verification: strings shows 0 dev paths in binary

D-4: ✅ Complete
2026-10-04 20:42:03 +08:00
Accusys 7ffb45c137 fix: remove final 3 hardcoded paths for D-4 compliance
Final cleanup:
1. main.rs:35 - Remove hardcoded .env fallback
   - Rationale: L30-34 already provide correct current_exe() resolution
   - Removes dev path, aligns with A-14.3 "禁止读取 dev 设定"

2. docs.rs:11,24 - Use current_exe() resolution
   - Replace hardcoded doc_wasm paths
   - Add MOMENTRY_DOCS_DIR env var support
   - Fallback to relative path

Result:
- All hardcoded dev paths removed from release binary
- D-4 Gate satisfied
- Zero momentry_core/nextorageai paths in source

Impact:
- Binary fully portable
- No dev environment assumptions
- All paths runtime-resolved
2026-10-04 20:40:27 +08:00
Accusys aa621b874c fix: D-4 hardcoded paths in release binary (critical)
Found 4 dev paths in momentry binary via strings:

1. pose.rs (2 paths) - CRITICAL
   - Line 250, 410: swift_pose path
   - Impact: processor execution path
   - Fix: Use path_utils::cli_dir() + relative path

2. docs.rs (2 paths) - MEDIUM
   - Line 11, 24: doc_wasm path
   - Impact: documentation service
   - Fix: cfg(debug_assertions) + env var

3. markbase_compat.rs (2 paths) - MEDIUM
   - Line 31, 58: Studio data path
   - Impact: SFTP service
   - Fix: MOMENTRY_STUDIO_DATA_DIR env + fallback

Verification:
- cargo check passes
- All paths now runtime-resolved or dev-only
- D-4 Gate should pass after rebuild
2026-10-04 20:22:34 +08:00
Accusys 1672a042af fix: G-4 (A-13) status consistency issue
Problem:
- GET /api/v1/files (list) returns DB status
- GET /api/v1/file/:uuid (detail) returns DB status
- DB status may be stale
- Results in inconsistency

Solution:
1. Add compute_file_status() helper function
   - Checks processing_status->>'phase'
   - Checks processor JSON files
   - Derives actual status

2. Fix get_file_detail:
   - Always use computed status
   - Ensures accuracy for single file queries

3. Fix list_files:
   - Add sync_status query parameter
   - sync_status=true: compute status for each file
   - sync_status=false (default): use DB status
   - Balances performance and accuracy

Verification: cargo check --lib passes

Impact:
- detail endpoint now returns accurate status
- list endpoint can optionally sync status
- Both endpoints use same derivation logic

G-4 status: ✅ Completed
2026-10-04 18:22:18 +08:00
Accusys 61b8fb3b52 feat: add models_dir() to path_utils (A-4.2 P3)
Purpose: Support health.rs models path resolution

Fallback: MOMENTRY_MODELS_DIR or relative to binary

Verification: cargo check --lib passes
2026-10-04 16:41:00 +08:00
Accusys cccb0aa9b9 fix: replace critical hardcoded paths (A-4.2 P3)
Issues: 4 remaining critical paths affecting release

Fixed:
- health.rs: models path -> path_utils::models_dir()
- config.rs: STORAGE_ROOT -> relative fallback
- storage/output_dir.rs: backup -> relative fallback
- tmdb/probe.rs: scripts -> path_utils::scripts_dir()

Verification: cargo check --lib passes

Impact: All paths now have portable fallbacks
2026-10-04 16:40:14 +08:00
Accusys 14bbae258b fix: resolve borrow error in scan.rs (A-4.2 P3)
Issue: demo_dir moved then borrowed

Solution: Use &demo_dir in read_dir()

Verification: cargo check --lib passes
2026-10-04 16:39:26 +08:00
Accusys 1e6226466c fix: complete scan.rs demo dir path cleanup (A-4.2 P3)
Issues: 2 hardcoded demo paths

Solution: Use MOMENTRY_SFTP_ROOT or relative fallback

Verification: cargo check --lib passes
2026-10-04 16:38:36 +08:00
Accusys b32a649496 fix: replace demo dir paths in scan.rs (A-4.2 P3)
Issues: 2 hardcoded demo paths

Solution: Use MOMENTRY_SFTP_ROOT or relative fallback

Verification: cargo check --lib passes
2026-10-04 16:38:16 +08:00
Accusys 036fc9f853 fix: replace hardcoded paths in job_worker.rs (A-4.2 P3)
Issues: 2 hardcoded output_dir paths

Solution: Use config::OUTPUT_DIR

Verification: cargo check --lib passes
2026-10-04 16:37:41 +08:00
Accusys 0afb90e26a fix: complete tools.rs path cleanup (A-4.2 P3)
Issues: 3 hardcoded paths

Solution: Use config::OUTPUT_DIR and path_utils::scripts_dir()

Verification: cargo check --lib passes, 0 hardcoded paths
2026-10-04 16:37:09 +08:00
Accusys 6c95404a30 fix: complete admin_config.rs path cleanup (A-4.2 P3)
Issues: 5 remaining hardcoded paths
- storage_root: /Users/accusys/momentry/var/sftpgo/data
- 4× paths in get_paths() fallback

Solution: Use relative paths and config constants
- storage_root: relative fallback
- output_dir: config::OUTPUT_DIR
- backup_dir: relative fallback
- scripts_dir: path_utils::scripts_dir()
- cli_dir: path_utils::cli_dir()

Verification: cargo check --lib passes, 0 hardcoded paths

Progress: admin_config.rs ✅✅, files.rs ✅, watcher.rs ✅, processing.rs ✅
2026-10-04 16:36:35 +08:00
Accusys 30ea384573 fix: complete processing.rs path cleanup (A-4.2 P3)
Issues: 4 hardcoded output_dir paths

Solution: Use config::OUTPUT_DIR throughout

Verification: cargo check --lib passes, 0 hardcoded paths

Progress: admin_config.rs ✅, files.rs ✅, watcher.rs ✅, processing.rs ✅
2026-10-04 16:32:30 +08:00
Accusys 3285cf7696 fix: complete processing.rs path cleanup (A-4.2 P3)
Issues: 4 hardcoded output_dir paths

Solution: Use config::OUTPUT_DIR throughout

Verification: cargo check --lib passes, 0 hardcoded paths

Progress: admin_config.rs ✅, files.rs ✅, watcher.rs ✅, processing.rs ✅
2026-10-04 16:32:09 +08:00
Accusys 1576b27528 fix: replace hardcoded paths in processing.rs (A-4.2 P3)
Issues: 4 hardcoded output_dir paths

Solution: Use config::OUTPUT_DIR

Verification: cargo check --lib passes

Progress: admin_config.rs ✅, files.rs ✅, watcher.rs ✅, processing.rs ✅
2026-10-04 16:31:26 +08:00
Accusys c55f664e47 fix: replace hardcoded paths in watcher.rs (A-4.2 P3)
Issues: 4 hardcoded fallback paths
- default_dir: /Users/accusys/momentry/var/sftpgo/data/demo
- 2× output_dir: /Users/accusys/momentry/output
- scripts_dir: /Users/accusys/momentry_core_0.1/scripts

Solution: Use config constants and relative paths
- MOMENTRY_SFTP_ROOT or relative fallback
- config::OUTPUT_DIR for output
- path_utils::scripts_dir() for scripts

Verification: cargo check --lib passes, 0 hardcoded paths

Progress: admin_config.rs ✅, files.rs ✅, watcher.rs ✅
2026-10-04 16:27:44 +08:00
Accusys 1166599f70 fix: replace all hardcoded paths in files.rs (A-4.2 P3)
Issues: 7 hardcoded fallback paths
- 5× output_dir: /Users/accusys/momentry/output
- 2× scripts_dir: /Users/accusys/momentry_core_0.1/scripts

Solution: Use config constants and path_utils
- config::OUTPUT_DIR for output paths
- path_utils::scripts_dir() for scripts paths

Changes:
- Replaced all unwrap_or_else fallbacks
- Unified path resolution

Verification: cargo check --lib passes, 0 hardcoded paths remaining

Progress: files.rs ✅, admin_config.rs ✅

Remaining: ~24 P3 locations in other files
2026-10-04 16:18:42 +08:00
Accusys b4dec14f8d fix: replace hardcoded fallback paths with relative paths (A-4.2 P3)
Issues: 4 fallback paths in admin_config.rs
- default_output_dir: /Users/accusys/momentry/output
- default_backup_dir: /Users/accusys/momentry/backup/momentry
- default_scripts_dir: /Users/accusys/momentry_core_0.1/tools/script
- default_cli_dir: /Users/accusys/momentry_core_0.1/tools/cli

Solution: Use current_exe() relative paths as fallback
- var/output, var/backup, tools/script, tools/cli
- Works on any machine without hardcoding

Changes:
- All 4 default functions now use relative paths
- Falls back to current_exe() sibling directories

Verification: cargo check --lib passes

Remaining: ~31 P3 locations in other files

References:
- A-4.2 P3 in Momentry_Release_Requirements_20261004.md v1.1
- G-3 gate condition
2026-10-04 16:17:18 +08:00
Accusys e0eb7b9ce8 fix: resolve P2 hardcoded paths to use runtime resolution (A-4.2 P2)
Issues: Direct hardcoded paths without fallback
- proxy.rs:108 - audio_track_probe.py
- tool_selector.rs:136 - output_dir
- ocr.rs:241 - swift_ocr binary
- files.rs:1190 - legacy output dirs

Impact: These paths don't exist on release machines

Solution:
1. proxy.rs: Use path_utils::scripts_dir()
2. tool_selector.rs: Use config::OUTPUT_DIR
3. ocr.rs: Use swift_processor_path() helper
4. face.rs: Make swift_processor_path() public
5. files.rs: Reduce duplicate legacy paths

Changes:
- src/core/proxy.rs: Resolve audio_track_probe.py
- src/core/processor/tool_selector.rs: Use OUTPUT_DIR from config
- src/core/processor/ocr.rs: Use swift_processor_path()
- src/core/processor/face.rs: Export swift_processor_path()
- src/api/files.rs: Deduplicate legacy paths

Verification: cargo check --lib passes

Remaining: P3 (unwrap_or_else type, ~89 locations)

References:
- A-4.2 P2 in Momentry_Release_Requirements_20261004.md v1.1
- G-3 gate condition
2026-10-04 16:06:41 +08:00
Accusys 2f5e2c1314 fix: resolve all P1 hardcoded model paths at runtime (A-4.2 P1)
Issues: 6 P1 locations with hardcoded model paths
- asr.rs:81 - whisper model
- scene_classification.rs:68 - resnet18 model
- qwen_vl_manager.rs:25,26 - Qwen model + mmproj
- rust_vad.rs:18 - silero_vad model
- facenet_embedding.swift:24 - already fixed (A-11)

Impact: Missing models cause silent degradation (A-12)
        No embeddings → TKG 0 nodes (020.mp4 root cause)

Solution: Use path_utils::resolve_asset_path for all model paths
- Resolves via MOMENTRY_MODELS_DIR env var
- Falls back to current_exe sibling
- Final fallback to models/ directory

Changes:
1. asr.rs: Resolve whisper model dir
2. scene_classification.rs: Resolve resnet18 model path
3. qwen_vl_manager.rs: Resolve Qwen model + mmproj paths
4. rust_vad.rs: Resolve silero_vad model via env or relative

Benefits:
- All P1 models now configurable via MOMENTRY_MODELS_DIR
- No more silent failures when models missing
- Models can be placed in release bundle

Verification:
- cargo check --lib passes
- cargo build --release --bin rust_vad passes

Next steps: Address P2 (41 locations) and P3 (35 locations)

References:
- A-4.2 P1 in Momentry_Release_Requirements_20261004.md v1.1
- A-11, A-12
- G-3 gate condition
2026-10-04 15:59:56 +08:00
Accusys 0d11c60163 fix: allow pipeline to complete with 0 results (A-10)
Issue: Pipeline stages never complete when result count = 0
Files: src/api/scan.rs (5 locations)

Root causes:
- L1357: tkg_nodes only marked complete if count > 0
- L1373: rule2_ingestion only if relationship_count > 0
- L1384:补救分支仍要求 tkg_node_count > 0
- L1412: vlm_summary only updated if vlm_total > 0
- L1432: face_dedup only checked if tkg_node_count > 0

Impact: When TKG has 0 nodes, 4 stages (weight 0.25) stay pending forever
        overall_progress stuck at 0.75

Solution:
1. TKG stages (nodes/edges/rule2): Always mark completed with count
2. VLM summary: Mark completed with "no traces" if vlm_total = 0
3. Face dedup: Check whenever processors_done, not just if nodes > 0
4. Add "no faces" / "no relationships" reasons for 0-result cases

Benefits:
- Distinguishes "completed with 0 results" from "not started"
- overall_progress can now reach 1.0 for all files
- Fixes G-2 gate condition

Verification: cargo check --lib passes

References:
- A-10 in Momentry_Release_Requirements_20261004.md v1.1
- G-2 in M5Max128_Portability_Install_Test_20261004.md
- 020.mp4 diagnosis: overall_progress stuck at 0.75
2026-10-04 15:56:14 +08:00
Accusys ad30742374 fix: integrate phase_completed into status logic (A-9)
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
2026-10-04 15:55:04 +08:00
Accusys 3399a137d8 fix: resolve FaceNet model path at runtime (A-4.2 P1, A-11, A-12)
Issues:
- facenet_embedding.swift:28 hardcoded model path
- face.rs:227-231 did not pass model path parameter
- face.rs:249-255 only logged warnings, causing silent degradation
- M4ProMini missing facenet512.mlpackage → embeddings all None → TKG 0 nodes

Changes:
1. facenet_embedding.swift:
   - Add --model option (default: models/facenet512.mlpackage)
   - Validate model file exists before loading
   - Print clear error message if missing

2. face.rs:
   - Use path_utils::resolve_asset_path for models dir
   - Pass --model argument to facenet_embedding
   - Validate model exists before running
   - Elevate errors from warn! to error! + bail!
   - Fail fast on embedding generation failure

Benefits:
- Runtime resolution via MOMENTRY_MODELS_DIR
- No silent degradation - missing model causes explicit error
- Clear error messages guide users to fix

Verification:
- cargo check --lib passes
- swift build -c release passes

Next steps:
- Add facenet512.mlpackage to release delivery (A-11 requirement 3)
- Update smoketest to verify embeddings != None (A-5.3)

References:
- A-4.2 P1 in Momentry_Release_Requirements_20261004.md v1.1
- A-11, A-12
- 020.mp4 diagnosis (appendix C)
2026-10-04 14:37:49 +08:00
Accusys d7df19e243 fix: remove cancelled 'pose' from required processors (A-8)
- Remove pose.json from required processor list in sync_file_status
- Pose was cancelled in the original plan, but still listed as required
- This caused status to stay in 'scanning' forever when pose.json is missing

Issue: 020.mp4 permanently showed 'Scanning' because pose.json was never generated
Root cause: all_consistent would never be true with missing pose.json
Solution: Remove pose from the required list

Verification: cargo check --lib passes

Next step: Implement configuration-driven processor list (A-8 requirement 2)

References:
- M4ProMini 020.mp4 diagnosis (appendix C)
- files.rs:1805-1813
- A-8 in Momentry_Release_Requirements_20261004.md v1.1
2026-10-04 14:32:03 +08:00
Accusys 1ec094571f docs: A-7 decision - re-scan as canonical API with auto_pipeline opt-in
- Decision: POST /api/v1/re-scan is canonical API
- Important: auto_pipeline=false by default (customer requirement)
- Provides manual control and safety over processing pipeline
- Includes workflow examples and Studio Team recommendations

Addresses: A-7 from Momentry_Release_Requirements_20261004.md
2026-10-04 13:51:50 +08:00
Accusys a3c3ed8dc1 refactor: eliminate all CARGO_MANIFEST_DIR compile-time dependencies (A-4)
- Add src/core/path_utils.rs with runtime path resolution helpers
- Replace all env!("CARGO_MANIFEST_DIR") with runtime resolution
- Priority: env var -> current_exe sibling -> dev fallback

Changes:
- executor.rs: scripts_dir(), cli_dir() (4 locations)
- face.rs: swift_processor_path()
- tool_selector.rs: swift_binary_path()
- thumbnail/mod.rs: script_path()

Issue: CARGO_MANIFEST_DIR expands to build machine path at compile time,
       breaking on binary-only release hosts.

Solution: Resolve paths at runtime in this order:
1. Explicit environment variable (MOMENTRY_SCRIPTS_DIR, MOMENTRY_CLI_DIR)
2. Sibling of current_exe (same directory as running binary)
3. Relative path fallback (dev machine)

Verified: cargo check --lib passes
2026-10-04 13:44:40 +08:00
Accusys f79292f867 fix: resolve rust_register/unregister at runtime for binary-only hosts
- Replace CARGO_MANIFEST_DIR compile-time constant with runtime resolution
- Priority: MOMENTRY_RUST_* env -> current_exe sibling -> target/release fallback
- Fixes sync-mode register/unregister on release machines (A-1)

Issue: env!("CARGO_MANIFEST_DIR") expands to build machine path at compile time,
       which doesn't exist on binary-only release hosts.

Solution: Resolve binary paths at runtime in this order:
1. MOMENTRY_RUST_REGISTER / MOMENTRY_RUST_UNREGISTER env (explicit override)
2. Sibling of current_exe (same directory as running momentry binary)
3. target/release fallback (dev machine)

Verified: M4ProMini deployment (2026-10-04)
2026-10-04 13:40:46 +08:00
Accusys 097b3721e8 fix: add face_cluster to auto-pipeline processors
The hardcoded processors array in create_monitor_job was missing
'face_cluster', causing jobs to never run face clustering and thus
never complete ingestion (face_cluster.json never created).

Successful jobs (e.g. 1250) have face_cluster in processors, but
newly created jobs (e.g. 1251) were missing it due to this hardcoded
array being incomplete.
2026-10-02 18:08:53 +08:00
Accusys ba71daf2c4 fix: store face embeddings to Qdrant in config-driven path
Config-driven swift/python branches in run_face_with_config were
saving face.json but not storing embeddings to Qdrant. This caused
TKG spawn to wait indefinitely for Qdrant face points that never
arrived, blocking ingestion completion.

The fallback hardcoded path had store_face_embeddings_to_qdrant
call, but config-driven path returned early without it.

Fix: call store_face_embeddings_to_qdrant after save_to_file in
both swift and python config-driven branches.
2026-10-02 17:23:44 +08:00