- executor.rs: Add cmd.env() for FACE_MIN_CONFIDENCE and FACE_MIN_SIZE in all 4 run methods
- face_processor.py: Pass os.environ to subprocess.Popen to inherit env vars
- Fixes multi-face detection issue where second face was being filtered out
- Tested: CONFIDENCE=0.5 preserves both faces (392 total), CONFIDENCE=0.75 filters second face (196 total), SIZE=100 filters small faces (201 total)
- 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
- 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)
- 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
- Force rebuilt all 37 traces for file 5e207a246fd6a2a65ee0a267440465ee
- Used select=eq(n\,frame) for VFR compatibility
- Each trace now uses best face (highest confidence) frame
- Created src/bin/backfill_trace_profiles.rs
- Queries Qdrant _faces once per file (optimized)
- Calculates avg confidence per trace
- Updates trace_profiles.avg_confidence and tkg_nodes.properties
- Backfilled 8250/9877 NULL traces (remaining 102 are edge cases without Qdrant data)
- tkg.rs: avg_confidence calculation moved to line 1207 (before props json)
- tkg.rs: Added 'avg_confidence' to props json (round4)
- schema.rs: ON CONFLICT DO UPDATE expanded to backfill start_frame, end_frame,
frame_count, key_frame, key_face, avg_confidence from tkg_nodes.properties
This fixes trace_profiles.avg_confidence always being NULL, and enables
automatic self-healing when upsert_trace_profile is called from any caller.
- 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
- 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.
- 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)
- ASR script used output_path.replace('.asr.json', '.cut.json') to find CUT file
- Executor passes output path with .tmp suffix (xxx.asr.json.tmp)
- This produced wrong path: xxx.cut.json.tmp (doesn't exist)
- Fix: use --uuid to construct CUT path from output_dir instead
- Also added executor Full command logging for debugging
Fixed IMG_9449 (1).MOV ASR failure: status changed from failed → completed
1. Per-job concurrency budget: add can_start_for_job() to ProcessorPool
so multiple files process in parallel instead of one job starving others.
Uses active_job_count to compute fair slot budget per job.
2. FaceCluster race condition: add face_traced.json existence check before
running face_cluster processor. face_traced.json is produced by P2
store_traced_faces.py which runs AFTER process_job completes, so
clustering was producing no_faces (0 clusters) despite having faces.
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.
The P3 Face Dedup trigger previously only logged when cluster_count !=
face_track_count without actually syncing labels. Now it calls
update_face_track_labels to:
- UPDATE tkg_nodes SET label = cluster_id for each trace
- UPSERT trace_profiles SET name = cluster_id
- Reset unclustered traces to default Person_N name
This matches what the manual 'Face Deduplication' button in Studio
already does via the cluster-agent API endpoint, ensuring the automatic
pipeline produces the same result without requiring manual intervention.
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
The PythonExecutor.run() hardcoded output_idx=1, which treats args[1] as
an output file path and rewrites it to .json.tmp. For scripts like
store_traced_faces.py that use --file-uuid (not an output path) at
position 1, this corrupted the UUID into a file path, causing the script
to fail with exit status 1 within 90ms.
- run_with_output_idx: output_idx changed from usize to Option<usize>
- run_with_output_idx_and_frames: same change
- run(): doc comment added, passes Some(1) for backward compatibility
- job_worker.rs: store_traced_faces.py and release_pack.py calls now
pass None for output_idx (no output path substitution)
- appearance.rs: passes Some(2) explicitly (output at index 2)
Verified: Gamma 8 file completed full pipeline with 24 face traces
and 185 TKG nodes.
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)
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}
Added Core API optimizations already deployed:
- Thumbnail API uses pre-cached key_face.jpg (8ms vs 500ms)
- Face-groups API supports ?include_trace_ids=false (-48% payload)
Updated Studio instructions to use these new endpoints.
1. Thumbnail API now checks trace/{tid}/key_face.jpg before ffmpeg
- First request: 8ms (read from disk) vs ~500ms (ffmpeg)
- All 2,451 trace thumbnails now served from pre-cached key_face.jpg
2. Face-groups API accepts ?include_trace_ids=false
- Default: includes trace_ids (32KB for Charade)
- With flag: excludes trace_ids (17KB, 48% reduction)
- Frontend can fetch full data only when user clicks into a group
Document for Studio team to implement lazy loading + concurrency increase
for face group thumbnail loading. Expected improvement: Charade load time
from ~76s to <2s.
Add async_mode option to POST /api/v1/unregister:
- async_mode=false (default): synchronous, waits for completion
- async_mode=true: spawns background task, returns immediately with job_id
Response now includes job_id field (None for sync mode).
Used by Studio when unregistering large files that take >30s
(e.g., 83K faces, 20K tkg_nodes).
run_with_frames / run_with_output_idx / run_with_output_idx_and_frames
had an inverted .tmp-file flow:
1. Before spawning, if the final .json existed it was renamed to .json.tmp
(the OLD output set aside as "tmp").
2. The script was passed the FINAL .json path, so it wrote fresh data there.
3. On success, .json.tmp (the OLD/empty file) was renamed back OVER the
fresh .json, discarding the new result.
For face clustering this meant the freshly-clustered 2-person result was
always overwritten by the stale/empty previous face_cluster.json, so the
cluster agent reported "0 clusters" and Face Deduplication matched nothing.
Fix: remove the bogus pre-rename and instead pass the .tmp path to the
script as its output argument, then promote .tmp -> .json only on success.
This guarantees the fresh result is what lands in the final file. Applied
identically to all three run_* helpers.
Verified on 9cbeb112 (FilmRiot): cluster-agent now returns 2 clusters /
17 traces and face_cluster.json contains the real clustering (was 0).
get_cluster_results_handler derived each group's trace_ids from
COALESCE(tp.properties, tn.properties)->>'trace_id'. Since
trace_profiles.properties is {} this was NULL -> fell back to 0 for
every row, so ALL groups reported trace_ids:[0] and collapsed to the
same representative trace.
Studio's People view renders groups from cluster-results, so every
group showed the same face (trace 0) and "Delete all" / "Merge" operated
on phantom data: batchDeleteGroups deleted trace 0 repeatedly and never
touched the real traces, which is why delete-all appeared to work but
left 16 groups behind and merge kept failing.
Now reads the real tp.trace_id (fallback tn.properties->>'trace_id'),
matching the face-groups fix in 4a480f46. Verified on 9cbeb112:
17 distinct traces now map correctly across 15 groups, no duplicate 0.
Two bugs broke Studio "Merge groups" on files where
trace_profiles.properties is empty {}:
1. get_face_groups_handler derived each group's trace_ids from
COALESCE(tp.properties, tn.properties)->>'trace_id'. Since
trace_profiles.properties is {} the value was NULL -> fell back to 0
for every row, so all groups reported trace_ids:[0] and group_uuid:None.
This corrupted Studio's group selection and caused the merge to fail
with "Target group cannot be in source_groups list" (the target name
collided with a corrupted source entry). Now reads the real
tp.trace_id (falling back to tn.properties->>'trace_id').
2. merge_groups_handler matched/updated tkg_nodes.label by the source
group NAME, which silently no-ops when tkg_nodes.label has drifted
out of sync with trace_profiles.name (e.g. after re-cluster), yielding
traces_merged:0. Rewrote it to resolve source trace_ids from
trace_profiles.name, then update both trace_profiles.name and
tkg_nodes.label by external_id=trace_{tid}, keeping both tables in
sync. Also defensively drops the target name from source_groups so a
client echoing the target no longer hard-fails.
Verified on file 9cbeb112 (FilmRiot): 17 groups now map to distinct
trace_ids 0-16; merge Person_4+Person_5 -> Person_0 yields
traces_merged:2 and updates both tp.name and tn.label. Test mutations
were reverted so the file is back to its original 17-group state.
Studio's "delete group" was calling hard_delete which physically removed
_faces points, tkg_nodes and trace_profiles (and silently failed to back
up to a non-existent _faces_trash collection, making undo impossible).
This permanently lost face groups and broke face-groups/cluster-results
(which are based on tkg_nodes) for any trace without a node row.
Changes:
- delete_trace hard-delete now means "restore to unassigned": keep
_faces/tkg_nodes/trace_profiles, only reset name to "Face Trace {id}".
Data is never destroyed so groups can be rebuilt and undo works.
- schema::ensure_face_track_node: create the face_track tkg_nodes row on
write so a trace that lost its node (old hard-delete) reappears in
face-groups/cluster-results (self-healing). Called from
update_trace_profile_handler, update_trace_profile_group_handler and
merge_groups_handler; the group handler also syncs tkg_nodes.label.
- restore_trace / undo_hard_delete_trace: when _faces_trash is empty
(new semantics), rebuild the named group from the operation snapshot
(tkg_nodes ON CONFLICT UPDATE + trace_profiles UPSERT) instead of 404.
Verified live on port 3002 (file bfba056f...): delete -> unassigned with
_faces preserved (4 points), rebuild group -> self-healing creates node
and group shows up, restore -> name restored to original. Also fixed the
pre-existing missing tkg_nodes row for trace 4621 via the same path.
- src/api/profile.rs: new get_cluster_results_handler
- Query param file_hash (Studio passes ?file_hash=)
- Builds face_groups from tkg_nodes + trace_profiles (same grouping as
face-groups handler) with group_id/cluster_id/name/trace_ids/
trace_count/representative_trace
- Scrolls _faces for the file, groups faces by frame into frames[]
- face_id = hex point id (matches identities.rs convention)
- timestamp = frame / fps (from videos table)
- cluster_id = group of the face's trace_id; unassigned faces skipped
- Response: { success, file_uuid, face_groups, frames } matching Studio
PeopleView.vue expected format
- profile.rs: single/group/merge_groups/undo all use upsert_trace_profile
- trace_agent_api.rs: hard delete/merge snapshot + delete trace_profiles
- cluster_agent.rs, job_worker.rs: background name writes use UPSERT
- schema.rs: upsert_trace_profile helper (backfill from tkg_nodes)
- Studio 3 API gaps documented (cluster-results/identity-matches/similar)
keyword_search and semantic_search used page_size (default 5)
instead of req.limit, so clients sending limit=N got only 5 results.
Now both handlers respect the limit parameter.
- trace_vlm_caption.py: use MOMENTRY_LLM_VISION_URL and MOMENTRY_LLM_VISION_MODEL
- scene_vlm_caption.py: use MOMENTRY_LLM_VISION_URL and MOMENTRY_LLM_VISION_MODEL
- Changed from Ollama /api/generate to OpenAI-compatible /v1/chat/completions format
- Added embedding server environment variables
- get_face_groups_handler: COALESCE(tp.name, tn.label) for name consistency
- sync_file_status: compare JSON vs pre_chunks (not chunk table)
- face consistency: compare frames.len() not total_faces
- cleanup 2 ghost records with NULL file_name/file_path
- replace identity_agent with face_dedup in pipeline stages
- remove identity_agent_api.rs and all references
- update required_processors to match actual processors
- update AGENTS.md with team responsibilities
- add Studio pipeline changes documentation
- Extract full frame at best confidence frame using ffmpeg
- Crop face region using average bbox coordinates
- Save to .faces/{file_uuid}/{trace_id}/key_frame.jpg and key_face.jpg
- TKG node properties store full file paths for UI display
- Supports future extension for cut representative frames
- FacePoint now includes confidence and point_id from Qdrant
- TKG build tracks best face (highest confidence) per trace
- key_frame = frame number of best face, key_face = Qdrant point ID
- Every face trace now has representative frame and face for UI display
- tkg.rs: use trace_N as primary external_id, delete duplicate face_track_N nodes
- trace_agent_api.rs: add POST /trace/:id/restore to undo soft delete
- ensure 1:1 mapping: each trace has exactly one TKG node with full profile
- Add Qdrant count verification before TKG build
- Wait up to 30 seconds for Qdrant to have all face embeddings
- Prevents race condition where TKG reads incomplete data
- Add count_points method to QdrantDb
- Check face.json status before waiting for face_traced.json
- If status='no_faces', spawn TKG immediately (no face_track nodes)
- If status='has_faces', wait for face_traced.json
- Prevents infinite wait when video has no faces
- Add check for face_traced.json existence before spawning TKG build
- Prevents race condition where TKG reads Qdrant before trace_id is written
- Logs clearly when waiting and when proceeding
- Add POST /api/v1/file/:file_uuid/cluster-agent endpoint for on-demand face clustering
- Fix OCR chunks being labeled as ASRX: use ChunkType.as_str() instead of {:?}
- Rule 1 now deletes old chunks before re-inserting to avoid stale data
- Add fallback face_traced.json when store_traced_faces.py fails
- ingestion_complete now handles status='error' to unblock jobs
- VLM describe tool now uses trace_id with pre-extracted face crops