Commit Graph

696 Commits

Author SHA1 Message Date
Accusys d95857dcc7 refactor: Face Cluster prefer Rust binary, remove global switch
- Remove MOMENTRY_USE_RUST_PROCESSORS from .env
- Face Cluster now tries Rust binary first, falls back to Python
- Appearance and Pose keep using Python (not needed currently)
- Simpler configuration: no global switch needed
2026-09-20 20:48:32 +08:00
Accusys ebee351523 refactor: enable Rust processors and remove appearance_processor.py
- Set MOMENTRY_USE_RUST_PROCESSORS=true in .env
- Remove scripts/appearance_processor.py (Rust binary replaces it)
- Update AGENTS.md with Rust Processors configuration
- Rust binaries available: rust_face_cluster, rust_appearance, rust_pose
- All Rust processors A/B tested and verified against Python versions
2026-09-20 20:12:43 +08:00
Accusys 93c8760788 fix: prevent VLM panic by using try_read instead of blocking_read
** Problem:
- get_face_filter_defaults() used blocking_read() in sync context
- Caused panic: 'Cannot block the current thread from within a runtime'
- VLM generation repeatedly failed with panic

** Root Cause:
- admin_config.rs:473: ADMIN_CONFIG.config.blocking_read()
- Called from FileProfile::defaults() which runs in async context
- Tokio runtime doesn't allow blocking operations

** Fix:
- Replace blocking_read() with try_read()
- Fall back to hardcoded defaults if config is locked
- Non-blocking, safe for async context

** Impact:
- VLM summaries now generate successfully
- No more panics in VLM processing
- Job 779 VLM generation now working
2026-09-18 05:38:40 +08:00
Accusys 73c59449fe fix: prioritize environment variables over config for face detection thresholds
** Problem:
- Worker set FACE_MIN_CONFIDENCE=0.5 via std::env::set_var()
- But Python subprocess received FACE_MIN_CONFIDENCE=0.4 (from config)
- get_face_settings() prioritized admin config over environment variables

** Root Cause:
- Line 17-21: Config checked first, env var as fallback
- Worker's runtime override was ignored

** Fix:
- Reversed priority: Environment variable > Admin config
- Now reads FACE_MIN_CONFIDENCE from env first
- Falls back to config only if env var not set

** Impact:
- Worker can override face thresholds at runtime
- UI 'Deep Scan' will use correct thresholds (0.5, 1)
- Allows per-job threshold customization

** Note:
- Binary built at 05:11
- All jobs currently completed
- Requires new job to test (no active jobs available)
2026-09-18 05:12:54 +08:00
Accusys 3aaaf36ff6 fix: processor status timestamps and admin config defaults
** Problem 1: started_at not set
- update_processor_result() ignored started_at/completed_at parameters
- Only updated 'status' field, leaving timestamps as None
- Caused false 'running' state detection

** Problem 2: AdminConfig missing fields
- admin_config.json missing required fields (updated_at, paths, etc.)
- JSON parsing failed, caused panic on worker startup
- Lazy instance poisoned, all processors failed

** Fix:
1. update_processor_result now sets timestamps automatically:
   - Running -> started_at = CURRENT_TIMESTAMP
   - Completed/Failed -> completed_at = CURRENT_TIMESTAMP

2. Added #[serde(default)] to all AdminConfig fields
   - Allows partial config files
   - Missing fields get default values

** Impact:
- Processor status now accurately tracked
- Worker can start with minimal config
- UI 'Deep Scan' deadlock resolved
2026-09-18 05:00:59 +08:00
Accusys a8edc43a3f docs: add complete delivery package with full file paths
- Lists all modified files with absolute paths
- Includes step-by-step instructions for Studio team
- Documents commits and expected results
- Provides troubleshooting guidance
2026-09-18 04:21:49 +08:00
Accusys 51c86a22f4 docs: add Studio team handoff documents for worker deadlock fix
** Purpose:
- Provide clear deployment instructions for Studio team
- Document the fix and required actions
- Enable quick verification steps

** Files Added:
- docs_v1.0/STUDIO_TEAM/2026-09-18_worker_deadlock_fix_handoff.md
- docs_v1.0/STUDIO_TEAM/README.md

** Key Points:
- Code fix committed (0fe09af)
- Worker binary needs rebuild
- Studio team should rebuild and redeploy
- Verification steps included
2026-09-18 04:21:20 +08:00
Accusys 2c1618ef06 docs: add worker running deadlock fix report 2026-09-18 03:55:14 +08:00
Accusys 0fe09afdb6 fix: prevent 'running' status deadlock in worker
** Problem:
- Worker set processor status to 'running' BEFORE checking capacity
- If capacity limit reached, processor was skipped but status stuck at 'running'
- Worker would skip processors with 'running' status on next poll (deadlock)

** Root Cause:
- Line 591-600: update_processor_progress(..., 'running')
- Line 1434: check capacity (TOO LATE!)
- Result: status='running' but processor never started

** Fix:
- Move capacity check BEFORE setting 'running' status
- If capacity limit reached, mark as 'skipped' immediately
- Prevents 'running' status from being set when processor won't actually run

** Impact:
- Fixes UI 'Deep Scan' deadlock issue
- Workers will no longer get stuck in infinite loop
- Processor status will accurately reflect actual state

** Files Changed:
- src/worker/job_worker.rs: Moved capacity check to line 591-592
- Removed duplicate capacity check at line 1464-1493
2026-09-18 03:53:39 +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 9ffbfeb6c5 feat: OCR resolution optimization - native resolution up to 1920px
- Replace fixed 320px downscale with smart resolution handling
- Videos <= 1920px: use native resolution (no downscale)
- Videos > 1920px: downscale to 1920px width
- Improves OCR quality for small text, subtitles, and scene text

Before: All videos scaled to 320px → poor OCR for small text
After: 1080p/720p videos use native resolution, 4K scales to 1920px

Verified: swift_ocr binary builds and runs correctly
- 720x890 video: native resolution (no scaling)
- 1920x1080 video: native resolution (at threshold)
- Detects video width and applies conditional scaling

Note: PaddleOCR fallback (ocr_processor_mps.py) already uses native resolution
2026-09-17 22:18:33 +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 791c782606 fix: search_bm25 NUMERIC→f64 decode panic + rerank UTF-8 truncation
- postgres_db.rs: CAST source_weight to ::float8 (NUMERIC→FLOAT8)
- rerank.rs: char-based truncation for UTF-8 safety
- Both fixes prevent tokio worker panics that killed search requests

Bug root causes:
- keyword/BM25: sqlx decode f64 from NUMERIC panicked at postgres_db.rs:3758
- llm-smart: &text[..100] byte slice panicked at rerank.rs:52 on Chinese text

Verified: both /api/v1/search/keyword and /api/v1/search/llm-smart now return 200
2026-09-17 16:55:48 +08:00
Accusys e25c279eeb feat: port face clustering to Rust (rust_face_cluster) with A/B gating
- rust_face_cluster: seed-leader + agglomerative clustering port of
  fast_face_clustering_processor.py (Qdrant _faces scroll, trace aggregation,
  auto speaker bind, strict 2dp rounding parity)
- A/B verified vs Python on same Qdrant snapshot: both methods match on
  cluster membership/trace_id/confidence (leader + agglomerative)
- face_clustering.rs: USE_RUST_PROCESSORS switch with Python fallback
- executor.rs: run_rust_with_output_idx_and_frames (+ QDRANT env passthrough)
- appearance/pose: re-use rust runner path (previous migration)
- verify_face_cluster.py / verify_pose.py / verify_appearance.py: A/B harness
2026-09-16 21:50:07 +08:00
Accusys 362a735a91 feat: add VLM model logging before processing
- Add info log in vlm_summary.rs showing VLM model name
- Add print statements in Python VLM scripts showing model name
- Applies to: trace_vlm_caption.py, scene_vlm_caption.py, interval_vlm_caption.py
2026-08-27 20:16:08 +08:00
Accusys d8e4033741 docs: update LLM config to gemma-4-12b-it (chat/summary server on port 8080) 2026-08-27 17:26:02 +08:00
Accusys 20f5974b52 feat: Rule 3 moment chunks — 10s windows with 1-2 key frames
- Add ChunkType::Moment to types.rs
- Add moment_interval to FileProfile (configurable, default 10s)
- Create rule3_moment.rs: reads trace_profile.json, groups by time window,
  selects 1-2 diverse key frames using Jaccard similarity on VLM text
- Embed moment chunks into Qdrant using trace VLM embeddings
- Wire into worker: triggers after VLM completes, blocks job completion
- Add moment_chunks progress stage (weight: 0.01)
2026-08-26 02:37:47 +08:00
Accusys 8732c3e0a4 fix: VLM blocking in worker — job waits for all traces to have VLM description
Problem: vlm_done_bool=true was hardcoded, so job completed immediately
without waiting for VLM generation. After re-scan, trace_profile.json
showed vlm_summary: null.

Fix: Query trace_profiles to check VLM completion status before
marking all_ok=true. Job now blocks until vlm_done_count >= vlm_total.
2026-08-25 21:50:54 +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 2bbbf1950d fix: integrate VLM into worker poll loop for auto-resume
- Move VLM trigger from TKG spawn to worker poll loop
- Each poll checks if VLM is incomplete and key_frames are ready
- If VLM was interrupted (server restart), next poll will restart it
- Removed duplicate VLM spawn from TKG block
2026-08-24 21:34:31 +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 d29b4804af fix: P5 VLM trigger after Face Dedup + sync label to on-disk JSON
- Move P5 VLM trigger from TKG block to Face Dedup block
  (trace_profiles DB is written by update_face_track_labels, not TKG)
- Update on-disk trace_profile.json label when Face Dedup updates names
- Add output_dir and redis_clone to Face Dedup spawn scope

Pipeline flow:
  Face → P2 Tracing → P3 Cluster → update_face_track_labels
    → DB trace_profiles + on-disk JSON updated
    → P5 VLM triggered with verified trace count
2026-08-23 15:21:43 +08:00
Accusys ff9fb9a4ca fix: make VLM non-blocking in ingestion check
VLM summary was blocking job completion, causing jobs created before
P5 deployment to be stuck forever (vlm=false, all_ok=false).

Now VLM logs progress but doesn't block: vlm_done_bool always true.
This allows older jobs to complete while VLM can be triggered
separately via API.
2026-08-23 03:10:58 +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 58d80e34c6 fix: move P5 verify inside TKG spawn — guarantee DB committed before VLM
verify_traces_ready now runs synchronously after build_tkg().await
completes, not inside a separate spawned task. This guarantees the
DB transaction from TKG is fully committed before VLM checks for data.

Before: TKG spawn → P5 spawn (race: P5 may run before TKG DB commit)
After:  TKG spawn → build_tkg() await → verify → spawn VLM (sequential)
2026-08-22 22:36:14 +08:00
Accusys 906243fdc1 refactor: replace P5 polling with JOIN-based verification + timeout
B: Replace wait_for_traces polling with verify_traces_ready
   - Uses JOIN query: trace_profiles INNER JOIN tkg_nodes
   - Ensures trace_profiles data is consistent with TKG before VLM runs
   - Single query instead of 30 retry attempts

C: Add 5-minute timeout to VLM generation
   - tokio::time::timeout(300s) prevents worker from hanging
   - Logs completion stats or timeout error

This fixes the root cause: P5 no longer polls blindly waiting for
TKG to finish. The JOIN query only returns rows when both
trace_profiles AND tkg_nodes face_track entries exist.
2026-08-22 22:17:21 +08:00
Accusys 165af40f3c fix: upsert_trace_profile preserves VLM fields on conflict
The ON CONFLICT DO UPDATE clause was missing vlm_* columns, causing
Face Cluster (P3) label sync to overwrite and lose VLM data.

Added COALESCE preservation for:
  vlm_description, vlm_clothing, vlm_tags, vlm_location, vlm_setting,
  vlm_lighting, vlm_weather, vlm_hand_objects, vlm_has_plants,
  vlm_has_animals, vlm_background, vlm_bg_tags, vlm_model,
  vlm_embedding, vlm_point_id
2026-08-22 17:27:56 +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 978b2b338b fix: P5 race condition — poll for trace_profiles before VLM generation
- Add wait_for_traces() helper: polls trace_profiles table every 2s
  up to 60s, returning when rows appear (TKG may still be writing)
- Replace one-shot face_count query in both P5 triggers (has_face +
  no-face paths) with polling
- Verified: 22/22 traces summarized for 9df18017, semantic search
  returns 10 VLM results with sim 0.601-0.696
2026-08-22 16:17:30 +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 476a31ecc6 feat: P5 VLM Summary pipeline integration + trace_profile vlm_summary field
- Add src/core/processor/vlm_summary.rs: VLM + Embedding pipeline stage
  * Reads key_frame.jpg → Ollama llava:7b → vlm_description
  * Writes DB (vlm_description, vlm_model, vlm_embedding) + on-disk JSON
  * EmbeddingGemma → Qdrant upsert (chunk_type=vlm_summary)
  * Non-blocking: errors logged, does not prevent job completion
  * Redis progress tracking: vlm_summary stage N/M traces

- Add src/bin/backfill_trace_vlm.rs: manual backfill binary
  * Supports --file-uuid, --force, --limit flags
  * Concurrency: 2 parallel VLM calls

- Add vlm_embedding JSONB column to trace_profiles (schema + migration)
- Add vlm_summary field to FaceTraceProfile struct
- Add P5 trigger in job_worker.rs (has_face + no-face paths)
- Add VLM monitoring to ingestion_complete() (non-blocking)
- Update .env / .env.development: VISION_URL → Ollama 11434
2026-08-22 09:52:04 +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 efa17d4b62 fix: preserve integers in trace_profile.json — no more .0 suffix on trace_id/frame/bbox 2026-08-16 23:41:15 +08:00
Accusys 78eb4fb8d9 docs: studio team guide — face_artifacts completion counts (new API fields) 2026-08-16 23:14:10 +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 e2b9999cba fix: run-server-3002.sh restart — exec replaced stop's process, start never ran 2026-08-16 14:09:10 +08:00
Accusys 7c9c3ded42 feat: opt-in face trace quality filter (min_trace_len/min_confidence, default off) 2026-08-16 09:36:23 +08:00
Accusys 2466a41eb8 perf: cut face_traced Qdrant I/O — merge trace-count scan (B1) + batch 1000 (B2) 2026-08-16 09:27:46 +08:00