Commit Graph

246 Commits

Author SHA1 Message Date
Accusys 5f9ddd2d02 fix: change async_mode default to false for register API
問題:
- Library 卡片 register 不成功
- 前端未傳遞 async_mode 參數
- API 默認異步模式,返回警告
- file_uuid 為空,前端無法使用

根本原因:
1. 前端調用 API 時未指定 async_mode
2. API 默認 async_mode=true (異步)
3. 異步模式返回空 file_uuid
4. Worker health key 未更新,顯示警告

解決方案:
- 修改 async_mode 默認值從 true 改為 false
- 前端現在默認使用同步模式
- 立即返回完整信息(file_uuid, duration, etc.)

測試結果:
- ✅ 同步模式 (默認): 立即返回 UUID 和元數據
- ✅ 異步模式 (明確指定): 正常排隊處理

影響:
- Studio (LibraryView): 現使用同步模式
- Portal (client.ts): 現使用同步模式

優勢:
- ✅ 快速響應 (~1秒)
- ✅ 完整信息返回
- ✅ 無警告
- ✅ 開發測試友好

注意:
- ⚠️ 行為變更: 默認從異步改為同步
- ⚠️ 生產環境建議明確指定 async_mode=true

待解決:
- Worker health key 更新問題

文檔:
- docs_v1.0/M4_workspace/2026-09-28_register_issue_analysis.md

狀態: ✅ 已修復
2026-09-28 20:20:41 +08:00
Accusys efd6f4372e feat: integrate rust_register and rust_unregister into API
新增功能:
- API 支持 sync/async 模式切換
- 同步模式直接調用 rust_register / rust_unregister
- 異步模式通過 Worker 執行

修改:
1. UnregisterRequest 添加 async_mode 參數
2. RegisterFileRequest 添加 async_mode 參數
3. unregister() 函數支持雙模式
4. register_file() 函數支持雙模式

API 使用:
```bash
# 同步模式
POST /api/v1/unregister
{"file_uuid": "...", "async_mode": false}

POST /api/v1/files/register
{"file_path": "...", "async_mode": false}

# 異步模式
POST /api/v1/unregister
{"file_uuid": "...", "async_mode": true}

POST /api/v1/files/register
{"file_path": "...", "async_mode": true}
```

測試結果:
- ✅ Unregister 同步模式: 通過
- ✅ Unregister 異步模式: 通過
- ✅ Register 同步模式: 通過
- ✅ Register 異步模式: 通過

性能:
- 同步 Register: ~1s
- 同步 Unregister: ~2s
- 異步模式: 立即返回

優勢:
- 開發測試: 同步模式快速反饋
- 生產環境: 異步模式不阻塞

文檔:
- docs_v1.0/M4_workspace/2026-09-28_api_rust_integration_test.md

狀態: ✅ 測試通過,生產就緒
2026-09-28 19:41:40 +08:00
Accusys ecb209633a feat: implement Re-scan API (partial)
實現內容:
1. 新增 ReScanRequest 和 ReScanResponse 結構體
2. 實現 re_scan API 函數
3. 添加路由 POST /api/v1/re-scan
4. 修改 process_register_command 添加 auto_pipeline_override 支持

測試結果:
- ✅ Re-scan API 可用
- ✅ Command 創建成功
- ✅ Force unregister 正確執行
- ❌ Monitor Job 未自動創建(需要進一步修復)

已知問題:
- register_single_file 在 force unregister 後仍返回 already_exists=true
- 導致 auto_pipeline 條件判斷失敗

下一步:
- 修改 register_single_file 修復 already_exists 標志
- 或在 process_register_command 中添加 force_unregister_executed 標志
2026-09-27 14:29:23 +08:00
Accusys 357e585399 fix: Face processor now saves status and total_faces to face.json 2026-09-26 23:06:11 +08:00
Accusys 55fcbf107d feat: add is_registered field to FileItem API
- Add is_registered field to FileItem struct
- Set is_registered based on status != 'pending'
- Fixes Library card display issue (frontend expects is_registered field)

Related: FaceNet CoreML integration testing completed successfully
2026-09-26 21:27:47 +08:00
Accusys 31d1b4050f fix: correct face detection threshold defaults
- Changed min_confidence from 50.0 to 0.5 (Vision uses 0.0-1.0 range)
- Changed min_size from 32 to 1 (was filtering out all small faces)
- Changed min_capture_quality from 25.0 to 0.25
- Fixes issue where all videos showed 0 faces detected

Root cause: admin_config.rs used wrong defaults (50.0/32) instead of
config.rs constants (0.5/1), causing Vision framework to filter out
ALL faces because confidence threshold exceeded valid range.

Verified: IMG_9449 now correctly detects 191 faces (was 0).
2026-09-18 02:42:21 +08:00
Accusys e4b8ddab94 fix: People Search 移除 VLM 文本搜索,只搜索 name 字段
- 移除 search_persons_internal 和 search_people_by_query 中的 VLM 文本搜索
- 避免匹配 'watermark', 'landmark', 'market' 等 VLM 描述文本
- People Search 現在只搜索 tp.name(人物名字)
- VLM 相關搜索應使用 Semantic Search API
2026-09-18 01:08:36 +08:00
Accusys c34b7b9ea0 feat: add force parameter to re-scan API for proper output file cleanup
Problem: Re-scan (/api/v1/file/:file_uuid/process) only deleted processor_results from DB,
but not output files. Worker checks if output file exists and skips re-processing,
resulting in stale/incorrect results persisting.

Solution:
- Add 'force' parameter to ProcessRequest struct (default: false)
- When force=true, delete all output files before re-processing
- Worker will then re-run processors from scratch

Changes:
- src/api/processing.rs:
  - Added 'force: bool' to ProcessRequest
  - Added delete_output_files_for_uuid() helper function
  - Modified trigger_processing() to delete output files when force=true

API usage:
POST /api/v1/file/:file_uuid/process
{
  "processors": ["face","ocr",...],
  "force": true
}

Note: Build currently fails due to unrelated uncommitted admin_config changes.
Those should be fixed separately.
2026-09-17 22:34:44 +08:00
Accusys 474a5bee99 refactor: remove YOLO processor and dependencies
- Delete YOLO processor implementation (src/core/processor/yolo.rs)
- Remove YOLO from processing pipeline and worker
- Clean up YOLO-related code across multiple modules
- Add migration 033_remove_yolo.sql

YOLO functionality removed as part of architecture simplification
2026-09-17 16:56:25 +08:00
Accusys 8b53384059 fix: VLM semantic search enrich + cleanup debug logging 2026-08-25 16:43:56 +08:00
Accusys 771115b42b fix: VLM enrich handle nullable start_frame/end_frame 2026-08-25 16:41:37 +08:00
Accusys b5de4f6745 debug: log VLM enrich query details 2026-08-25 16:39:37 +08:00
Accusys e2c352d502 debug: log qdrant search errors 2026-08-25 16:35:59 +08:00
Accusys d981e0a6fe debug: more semantic search logging 2026-08-25 13:08:02 +08:00
Accusys c3367b47b1 debug: add VLM enrich logging 2026-08-25 10:12:46 +08:00
Accusys 44ad6ac213 fix: VLM semantic search chunk_id parsing (off-by-one error) 2026-08-25 10:02:21 +08:00
Accusys 8a34dcb8f2 fix: VLM re-embedding support + API checks vlm_embedding
- vlm_summary now skips VLM call if description exists, but still generates embedding + Qdrant
- API endpoint checks both vlm_description AND vlm_embedding before saying 'already done'
- Fixed point_id hash generation (was creating 0, now properly hashes)
2026-08-25 08:11:48 +08:00
Accusys 29f14e83c4 feat: VLM summary vector storage in Qdrant for semantic search
- Add upsert_vlm_embedding to QdrantDb with trace_id in payload
- chunk_id format: {file_uuid}_t{trace_id_hex} for search enrichment
- Update enrich_vlm_from_pg to extract trace_id from chunk_id
- VLM summary now searchable via semantic search with source_type=vlm
2026-08-25 02:57:18 +08:00
Accusys b2378a219b fix: pipeline stats API now shows VLM summary progress
- Added trace_profiles query to compute vlm_done/vlm_total
- vlm_summary stage now shows actual progress (e.g. 312/4829)
- Status shows 'running' while in progress, 'completed' when done
2026-08-24 19:40:00 +08:00
Accusys 9f12e835b8 feat: add TraceArtifacts phase + VLM waits for all key_frame.jpg
- Add TraceArtifacts phase to TkgPhase enum (phase 18)
- Report progress as key_frame.jpg/key_face.jpg are created
- VLM trigger now polls until ALL key_frame.jpg files exist
  (was: started after TKG build, before artifacts were ready)
- Add iron rule to AGENTS.md: ask before removing data

Tested: Gamma 8 (27 traces) → 27/27 VLM summaries completed
2026-08-24 19:13:11 +08:00
Accusys cce30ffacb revert: remove auto-create monitor_job in register
Register should only write videos table, not automatically create
monitor jobs. This violates the design principle that register does
not trigger deep scan.

The auto-pipeline (triggered only for new files with auto_pipeline_enabled)
handles job creation separately. Re-scan via processing API will handle
job creation when needed.
2026-08-23 02:44:48 +08:00
Accusys b8b8f2d6af fix: register creates monitor_job with full pipeline after unregister
When a file is re-registered after unregister, the monitor_job is
missing. The register function now checks if a job exists and creates
one with full pipeline processors (cut, asr, asrx, ocr, face,
face_cluster) if missing.

This ensures re-scan after unregister triggers the complete pipeline
including face detection → TKG → VLM summary (P5).
2026-08-22 23:51:10 +08:00
Accusys 11d210ee55 feat: add VLM summary progress to scan status API
- Add VlmSummaryStats { total, done } to FileStatsResponse
- Query trace_profiles for vlm_description count
- Endpoint: GET /api/v1/stats/file/:uuid returns vlm_summary field
- Response: { "vlm_summary": { "total": 22, "done": 22 } }
2026-08-22 17:03:09 +08:00
Accusys 054545bccd feat: VLM summary vector search integration
- Add vlm_point_id column to trace_profiles (stores Qdrant point ID)
- Add upsert_chunk_embedding_u64 to QdrantDb (numeric ID support)
- Add chunk_id to VLM payload in Qdrant for search enrichment
- Update enrich_from_pg to fallback to VLM lookup when chunk not found
- Add /api/v1/file/:uuid/vlm-summary endpoint for manual trigger
- Fix VLM point_id: use u64 hash instead of string (Qdrant requirement)
- Fix VLM timeout: was 0 (immediate timeout), now 120s

Verified: semantic search returns [vlm] results with proper enrichment
2026-08-22 12:10:47 +08:00
Accusys 6d7b477b31 fix: TKG key frame/face selection uses best-confidence — match frontend label
- tkg.rs: key_frame/key_face/best_bbox now use best-confidence frame
  (was cq_best capture-quality) so thumbnails agree with trace_agent_api
  best_face_frame / [F..] labels
- keep cq_best_quality as trace-level stat only
- add backfill_trace_dirs + skip_existing resume mode
- trace_agent_api.rs regenerate-thumbnail: use strict > tie-break (reduce)
  matching list_traces_sorted so equal-confidence frames pick the same one
2026-08-20 01:27:35 +08:00
Accusys dda0b7cc7f feat: expose face artifact completion counts (trace_profile/key_frame/key_face) in scan + traces APIs 2026-08-16 23:09:12 +08:00
Accusys 39e9ce4c3b fix: add min_capture_quality to FaceFilterSettings + trace profile fixes
- Add min_capture_quality to FaceFilterSettings (file_profile.rs)
- Fix store_traced_faces.py: load embeddings from Qdrant with_vector=True
- Fix face_tracker.py: force new traces when frame_gap > 30
- Fix backfill_trace_profiles.py: key_frame select=eq(n,N), bbox scaling, best_frame
- Add best_frame to FaceTraceProfile (Rust + Python)
- Fix min_capture_quality persistence in file-profile API
2026-08-13 10:12:21 +08:00
Accusys e88f066d65 fix: update trigger_processing face defaults to Apple Vision (0.5/1)
Hard-coded 0.75/64 in trigger_processing API was overriding the new
Apple Vision defaults when re-triggering processing. Now uses 0.5/1
consistently.
2026-08-12 09:49:59 +08:00
Accusys c1e158a368 fix: trace-profile API SQL errors (missing FROM alias + null decoding)
Two pre-existing bugs broke rename/get operations:

1. schema.rs: DO UPDATE referenced 'tp' alias from LEFT JOIN which is
   invisible in ON CONFLICT scope → 'missing FROM-clause entry for table tp'
   Fix: use {tp_table}.column instead of tp.column

2. profile.rs: SELECT tp.properties / tn.properties can be NULL when no
   trace_profile row exists but decoder expected non-optional Value
   → 'unexpected null; try decoding as an Option'
   Fix: decode as Option<serde_json::Value> and handle None in merge logic
2026-08-12 05:51:12 +08:00
Accusys 59ca6cdf83 feat: add regenerate trace thumbnail endpoint with bbox clamping
- validator::clamp_crop: clamp crop rect to frame dims (fixes OOB shift)
- tkg.rs: use clamp_crop in key_face crop paths (root-cause fix)
- trace_agent_api: POST /api/v1/file/:file_uuid/trace/:trace_id/regenerate-thumbnail
- docs: 26_trace_thumbnail_regenerate.md for Studio team
2026-08-12 03:04:19 +08:00
Accusys aa28bf93fb fix: resolve merge silent failure by fixing upsert_trace_profile SQL and backfilling data
- Fixed upsert_trace_profile() SQL: changed trace_profiles.xxx to tp.xxx in ON CONFLICT DO UPDATE
  to fix invalid reference to FROM-clause entry error
- Fixed cluster_agent.rs error handling: replaced 'let _ =' with proper error logging
- Created migration script to backfill trace_profiles from tkg_nodes for existing files
- Migration successfully inserted 98 missing trace_profiles records
- Verified merge now works correctly: traces_merged > 0 instead of silent no-op

This fixes both the rename 500 error and the merge silent failure, as they share
the same root cause in upsert_trace_profile() SQL.
2026-08-10 01:42:34 +08:00
Accusys d6f45683a0 fix: resolve trace-profile UPSERT SQL error and face-filter route syntax
- Fixed upsert_trace_profile() SQL: replaced scalar subqueries with LEFT JOIN
  to properly reference trace_profiles table in backfill logic
- Fixed face_filter routes: changed {file_uuid} to :file_uuid syntax for
  axum 0.7.9 compatibility
- Both fixes resolve HTTP 500 errors in rename and 404 errors in face filter
2026-08-09 23:41:11 +08:00
Accusys a3eba898e2 fix: update face filter API routes to avoid conflicts with identity_api
Changed routes to use /face-filter/ prefix to avoid conflicts:
- /api/v1/file/{uuid}/face-filter/faces
- /api/v1/file/{uuid}/face-filter/{faceId}/report
- /api/v1/file/{uuid}/face-filter/apply
- /api/v1/file/{uuid}/face-filter/stats
- /api/v1/file/{uuid}/face-filter/rules
2026-08-09 22:34:12 +08:00
Accusys dfa515f249 feat: add bbox_size field for frontend filtering
- Database: Added bbox_size column (min(width, height)) to face_filter_features
- API: Updated all endpoints to include bbox_size in responses
- Documentation: Added bbox_size explanation and frontend filtering examples
- Maintains current Swift implementation calculation method
- Enables efficient frontend filtering without backend threshold

This allows the frontend to do real-time filtering using bbox_size
while the backend pre-computes and stores the value.
2026-08-09 19:05:09 +08:00
Accusys 9b6750b85e feat: implement face filter API for GUI filtering mechanism
- Database schema: face_filter_features and filter_rules tables
- Core engine: FilterEngine with 4 filter rules (landmark, mediapipe, embedding, temporal)
- API endpoints:
  - GET /faces - Get faces with filtering
  - GET /face/{id}/filter-report - Get filter report for single face
  - POST /faces/filter - Apply filter rules
  - GET /filter-stats - Get filter statistics
  - GET/POST /filter-rules - Manage filter rules
- API documentation for Studio team with examples
- Based on FaceNet analysis results from WD and KOBA videos
2026-08-09 17:11:07 +08:00
Accusys 658f509500 fix: pass face_settings to create_monitor_job in register and process endpoints
- files.rs: register_file now converts FaceSettings to json and passes to create_monitor_job
- processing.rs: ProcessRequest now includes face_settings field
- processing.rs: trigger_processing now passes face_settings to create_monitor_job and updates existing jobs
- docs: updated API examples to use correct endpoints (/api/v1/files/register and /api/v1/files/:uuid/process)
2026-08-08 22:16:06 +08:00
Accusys 8d83d9f217 fix: replace dev schema defaults with public
- schema.rs: Change DATABASE_SCHEMA default from 'dev' to 'public'
- rule2_ingest.rs, files.rs, tools.rs, scan.rs: Same schema default fix
- files.rs, watcher.rs, processing.rs: Change output_dev to output
- identities.rs: Change API schema parameter default from 'dev' to 'public'
- postgres_db.rs: Add face_settings column to SELECT query (fix ColumnIndexOutOfBounds panic)

This fixes worker not processing jobs due to missing dev schema.
2026-08-08 17:35:23 +08:00
Accusys 606f4ce5be feat: add per-file face_settings (min_confidence, min_size) support
- DB: Added face_settings jsonb column to monitor_jobs
- API: RegisterFileRequest accepts face_settings
- DB: create_monitor_job accepts and stores face_settings
- MonitorJob struct includes face_settings field
- Swift face processor will read from FACE_MIN_CONFIDENCE and FACE_MIN_SIZE env vars
2026-08-08 04:17:05 +08:00
Accusys c184711bfc fix: thumbnail cache headers - no-cache + ETag for browser revalidation
- Changed Cache-Control from 'public, max-age=86400' to 'no-cache, must-revalidate'
- Added ETag header (sha256 hash of image bytes)
- Browser will revalidate on each request
- If file unchanged → 304 Not Modified (save bandwidth)
- If file changed → 200 with new image
- Applied to all thumbnail endpoints (trace, face, chunk, live extraction)
2026-08-08 02:13:14 +08:00
Accusys 1d3638649b fix: trace-thumbnail cache-control changed to no-cache for testing
- Changed from 'public, max-age=86400' to 'no-cache'
- Allows immediate verification of rebuilt key_face.jpg files
- Can be changed back to max-age=300 after verification
2026-08-07 19:28:50 +08:00
Accusys 64f5e3f543 feat: add request logging middleware for all API calls
- Added request_logger middleware in middleware.rs
- Logs every API request with method, path, and query string
- Logs every API response with status code and duration
- Skips health checks and static files to reduce noise
- Error responses (4xx/5xx) logged at warn/error level
- Added to server router as global middleware
2026-08-06 09:50:20 +08:00
Accusys 23c6f63742 feat: add face search API at trace level for People page FS filtering
- GET /api/v1/file/:file_uuid/faces/search
- q parameter: trace_id substring, frame fall-through, range overlap, name substring
- binding filter: assigned/unassigned
- min_confidence filter
- Pagination with page/page_size
- Response includes trace_id, file_uuid, file_name, name, start_frame, end_frame, frame_count, thumbnail_url
- SQL-based filtering with indexes on name/file_uuid for performance
2026-08-05 21:40:07 +08:00
Accusys a6d705abf1 fix: VFR frame extraction - use select=eq(n) instead of -ss frame/fps
- tkg.rs key_frame: select=eq(n\,best_frame) instead of -ss frame/fps
- tkg.rs retry: same fix for need_retry block
- tools.rs agent frame: select=eq(n\,frame_number)
- media_api.rs segment video: select=between(n\,sf\,ef-1) for frame mode

VFR videos (r_frame_rate != actual fps) now get correct frames.
CFR videos unaffected: select=eq(n) produces same result as -ss frame/fps.

Fixes: face card / face-detail thumbnail mismatch for VFR files.
2026-08-05 12:36:25 +08:00
Accusys 2117ca60b8 fix: trace thumbnail now uses trace_profile key_face.jpg for consistency
- Thumbnail endpoint was using select_rep_face (blurdetect) which could pick
  a different frame than the trace_profile's key_frame/key_face
- This caused mismatch between Face Detail modal and thumbnail in trace list
- Fix: add Step 1.5 to check trace_profile's key_face.jpg before falling back
  to select_rep_face
- Ensures thumbnail always matches what Face Detail modal shows

Verified: trace_21 thumbnail now matches key_face.jpg (same hash)
2026-08-05 02:42:38 +08:00
Accusys 3d13a06bd9 feat: face fix deployment + trace_* regeneration + executor stderr filter fix
- swift_face.swift: frame rounding (.rounded()), conf 0.75, min_size 64
- trace_* directories regenerated for KOBA (37 traces, start_frame 5307)
- executor.rs: stderr filter now logs all non-empty stderr (was discarding)
- VAD not skippable in ASRX (main_fixed.py Step 2 always runs)
- Step 2.5 sentence boundary refinement added
- Cluster agent async endpoints + similarity transparency
- Keyword search: relationship text extraction, priority ordering
- Face fix handoff doc for Studio team
2026-08-05 00:13:50 +08:00
Accusys c5c1b08ffd feat: add trigger source and reason logging to unregister
Now all unregister operations log:
- source: who triggered it (api, studio, watcher, auto-cleanup, etc.)
- reason: why it was triggered (manual, failed-processing, duplicate, etc.)

Also adds proper ERROR logging for failures:
- Transaction commit failures
- Redis client creation failures
- Qdrant deletion failures

This allows tracking which operations caused file deletion and
identifying failures that were previously silent.
2026-08-03 08:55:44 +08:00
Accusys 975c72eb49 fix: add trace_profiles deletion to unregister
trace_profiles was missing from the unregister cleanup, leaving orphaned
records when files were unregistered. This caused data inconsistency:
- trace_profiles remained while Qdrant _faces and TKG nodes were deleted
- Studio could show stale face groups pointing to non-existent data

Changes:
- Added trace_profiles_table to both unregister functions
- Added delete_safe! call to delete trace_profiles by file_uuid
- Updated log message to include trace_profiles count

Verified: Cleaned up 24 orphaned records for a4442006be2d401a7e22ed8ff29da772
2026-08-03 07:17:40 +08:00
Accusys e22393d577 feat: permanent trace delete (mode:delete) + best-face fields in /traces
- delete_trace: add mode:'delete' → permanent removal (Qdrant points,
  trace_profiles, tkg_nodes, on-disk files), no undo/history written
- list_unassigned_traces: exclude status=deleted (REQ-2), consistent
  with /traces endpoint
- /traces: return real best_face_id/frame/confidence/bbox (highest
  confidence face per trace) instead of start_frame/avg_confidence
- docs: Studio delete Core req + FS detail fix patch + handoff v2
2026-08-02 14:18:44 +08:00
Accusys 8eb130959c fix: keep user-named single-trace groups in face-groups
Single-trace groups with auto-generated names (Person_N) are filtered
to unassigned, but user-named groups are kept even with 1 trace.

This fixes the issue where moving traces one-by-one to a new group
caused them to disappear from the UI.

Before: trace → 'NewGroup' → filtered → unassigned (FS disappeared)
After:  trace → 'NewGroup' → shown as group (FS visible)
2026-08-01 06:24:00 +08:00
Accusys 57f542fdad perf: add /api/v1/trace-thumb/:uuid/:tid endpoint
Direct access to trace key_face.jpg — simpler URL, faster routing.
Response: ~8ms (read from disk, no ffmpeg).

Studio can use: /api/v1/trace-thumb/{file_uuid}/{trace_id}
Instead of: /api/v1/face-thumbnail?uuid={uuid}&trace_id={tid}&frame={frame}
2026-08-01 02:28:15 +08:00