docs: trace_profile UPSERT fixes + Studio face group API gap analysis
- 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)
This commit is contained in:
@@ -0,0 +1,197 @@
|
||||
# Studio Face Group API 斷點對照
|
||||
|
||||
**Date:** 2026-07-31
|
||||
**Status:** Analysis Report
|
||||
**Author:** OpenCode
|
||||
**Scope:** Studio (`momentry_studio`) 依賴 Core 的 face group 相關 API 斷點分析
|
||||
|
||||
---
|
||||
|
||||
## 一、背景
|
||||
|
||||
Core 完成 trace_profiles UPSERT 修復後(`2026-07-31_trace_profile_upsert_fix_plan.md`),
|
||||
確認 rename/undo/delete/restore 的 API contract 完全相容,Studio 端不需要改動。
|
||||
|
||||
但調查過程中發現 Studio 的 **face group 顯示流程** 存在三個既存斷點
|
||||
(與本次 UPSERT 修復無關,先前調查已記錄):
|
||||
|
||||
| # | Studio 呼叫 | Core 端點 | 狀態 |
|
||||
|---|-------------|-----------|------|
|
||||
| 1 | `get_cluster_results` | `GET /api/v1/cluster-results?file_hash=` | ❌ 404 (Core 無此端點) |
|
||||
| 2 | `get_identity_matches` | `GET /api/v1/identity-matches?file_hash=` | ❌ 404 (Core 無此端點) |
|
||||
| 3 | `get_similar_face_groups` | `GET /api/v1/file/:file_uuid/face-groups/similar` | ⚠️ 逾時 (183K points 全量 scroll) |
|
||||
|
||||
---
|
||||
|
||||
## 二、斷點 1:`cluster-results`(影響最大)
|
||||
|
||||
### Studio 端呼叫
|
||||
|
||||
- `momentry_studio/src/api/index.ts:471-473`
|
||||
```typescript
|
||||
case 'get_cluster_results': {
|
||||
return { url: `/api/v1/cluster-results?file_hash=${a.fileHash}`, method: 'GET' }
|
||||
}
|
||||
```
|
||||
|
||||
- `momentry_studio/src/views/PeopleView.vue:848-976` `loadClusterResults()`:
|
||||
- 入口:`faceGroups` computed(line 624-658)依賴 `clusterResults`
|
||||
- 選檔、cluster 完成後、rename 後都會重新 load
|
||||
- 回傳需含 `face_groups` 或 `clusters` 陣列 + `frames` 陣列
|
||||
|
||||
### Studio 預期回應格式(PeopleView.vue:864-893)
|
||||
|
||||
```jsonc
|
||||
{
|
||||
"face_groups": [ // 或 "clusters"
|
||||
{
|
||||
"group_id": 1, // 沒有時 fallback 用 cluster_id
|
||||
"cluster_id": "c01", // 可選,統一用 group_id
|
||||
"name": "Person_1",
|
||||
"trace_ids": [12, 34],
|
||||
"trace_count": 2,
|
||||
"representative_trace": 12
|
||||
}
|
||||
],
|
||||
"frames": [ // 每個 group 的 member_faces / face_count 來源
|
||||
{
|
||||
"frame": 100,
|
||||
"timestamp": 3.33,
|
||||
"faces": [
|
||||
{ "face_id": "face_12", "confidence": 0.9, "cluster_id": "c01" }
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
- Studio 對每個 group 會填 `member_faces`、`face_count`(line 889-893)
|
||||
- group 沒有 `name` 時 fallback 為 `group NN`(line 641)
|
||||
|
||||
### Core 現況
|
||||
|
||||
Core 完全沒有 `cluster-results` 端點(`grep cluster-results src/` 無結果)。
|
||||
|
||||
**可替代方案**:Core 已有 `GET /api/v1/file/:file_uuid/face-groups`
|
||||
(`src/api/profile.rs:1325`),回應:
|
||||
```jsonc
|
||||
{
|
||||
"success": true,
|
||||
"file_uuid": "...",
|
||||
"face_groups": [
|
||||
{
|
||||
"group_id": 1,
|
||||
"name": "Person_1",
|
||||
"trace_ids": [12, 34],
|
||||
"trace_count": 2,
|
||||
"representative_trace": 12,
|
||||
"editable": true
|
||||
}
|
||||
],
|
||||
"total_groups": 1,
|
||||
"unassigned_traces": [99]
|
||||
}
|
||||
```
|
||||
|
||||
差異:
|
||||
| 欄位 | Studio 預期 (`cluster-results`) | Core (`face-groups`) |
|
||||
|------|-------------------------------|----------------------|
|
||||
| group 列表 | `face_groups` | `face_groups` ✅ |
|
||||
| `cluster_id` | 可選(fallback 用 group_id) | 無 → Studio 會用 `group_id` ✅ |
|
||||
| `trace_ids` | 需要 | 有 ✅ |
|
||||
| `representative_trace` | 需要 | 有 ✅ |
|
||||
| `frames[]` / `member_faces` | 需要(顯示成員臉) | ❌ 無 |
|
||||
| `unassigned_traces` | 未用 | 有(額外) |
|
||||
|
||||
→ **缺 `frames[]`** 是主要差距。Studio 用它建立 `member_faces`(點擊 group 顯示成員臉)。
|
||||
|
||||
---
|
||||
|
||||
## 三、斷點 2:`identity-matches`
|
||||
|
||||
### Studio 端呼叫
|
||||
|
||||
- `momentry_studio/src/api/index.ts:465-467`
|
||||
```typescript
|
||||
case 'get_identity_matches': {
|
||||
return { url: `/api/v1/identity-matches?file_hash=${a.fileHash}`, method: 'GET' }
|
||||
}
|
||||
```
|
||||
|
||||
- `momentry_studio/src/views/PeopleView.vue:943-970`:抓 TMDB identity 建議,
|
||||
對每個 cluster 統計 trace → suggestion 的 `group_uuid` 映射,取最高頻者設為
|
||||
`c.tmdb_name` / `c.tmdb_uuid` / `c.tmdb_count`。
|
||||
|
||||
### Studio 預期回應格式(PeopleView.vue:945-946)
|
||||
|
||||
```jsonc
|
||||
{
|
||||
"suggestions": {
|
||||
"12": { "group_uuid": "tmdb-xxx", "name": "Alice" }, // key = trace_id (string)
|
||||
"34": { "group_uuid": "tmdb-xxx", "name": "Alice" }
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### Core 現況
|
||||
|
||||
Core 無此端點。若無法提供,**影響有限**:Studio 已用 `try/catch` 包住
|
||||
(line 970 `catch { /* no identity matches available */ }`),
|
||||
404 時只是 TMDB 名稱建議不顯示,不阻斷 face group 流程。
|
||||
|
||||
---
|
||||
|
||||
## 四、斷點 3:`face-groups/similar`(逾時)
|
||||
|
||||
### Studio 端呼叫
|
||||
|
||||
- `momentry_studio/src/api/index.ts:474-480`
|
||||
```typescript
|
||||
case 'get_similar_face_groups': {
|
||||
const params = new URLSearchParams()
|
||||
if (a.traceIds) params.set('trace_ids', String(a.traceIds))
|
||||
if (a.topK) params.set('top_k', String(a.topK))
|
||||
if (a.minScore) params.set('min_score', String(a.minScore))
|
||||
return { url: `/api/v1/file/${a.fileUuid}/face-groups/similar?${params.toString()}`, method: 'GET' }
|
||||
}
|
||||
```
|
||||
|
||||
### Core 現況
|
||||
|
||||
Core 有端點(`src/api/profile.rs:1329`,handler `get_similar_group_handler`),
|
||||
回應格式:
|
||||
```jsonc
|
||||
{
|
||||
"success": true,
|
||||
"file_uuid": "...",
|
||||
"suggestions": [
|
||||
{ "group_name": "Person_1", "score": 0.91, "matched_trace_id": 12 }
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
**問題**:handler 對 source trace 的 `_faces` 做全量 scroll(183K points),
|
||||
實測逾時。屬效能問題,非格式問題。
|
||||
|
||||
---
|
||||
|
||||
## 五、建議(角色分工待確認)
|
||||
|
||||
> **注意**:`momentry_studio/` 屬 Studio team 負責,Core team 不可直接改;
|
||||
> Core route 新增屬 API 設計決策,不應由實作方單方面決定(見 AGENTS.md)。
|
||||
|
||||
| 方案 | 做法 | 負責方 |
|
||||
|------|------|--------|
|
||||
| A | Core 新增 `GET /api/v1/cluster-results` alias → 轉發 `face-groups` + 附 `frames[]` | Core (需使用者/路由設計拍板) |
|
||||
| B | Studio 改用 `GET /file/:file_uuid/face-groups` + 另行組 `frames[]` | Studio team |
|
||||
| C | 暫緩,僅記錄。cluster-results 404 時 face group 列表不顯示 | 維持現狀 |
|
||||
|
||||
`identity-matches` 影響最小(已 try/catch),`similar` 為效能問題需 Core 優化 scroll。
|
||||
|
||||
---
|
||||
|
||||
## 六、Version History
|
||||
|
||||
| Version | Date | Author | Changes |
|
||||
|---------|------|--------|---------|
|
||||
| 1.0 | 2026-07-31 | OpenCode | Initial analysis report |
|
||||
Reference in New Issue
Block a user