feat: declarative pipeline config, non-blocking Scene VLM, rust_asrx

Consolidated snapshot (previously WIP in working tree).

- core/pipeline_config: new module loading config/pipeline_flows.json as the
  source of truth for stage execution mode (parallel/blocking) and dependencies
- worker/job_worker: dispatch Scene VLM to a background task when the stage is
  declared parallel, unblocking the worker poll loop; resolve processor
  dependencies from pipeline_flows.json (fallback to built-in)
- config/pipeline_flows.json: asrx depends on [cut, asr]
- scripts/fix_stuck_jobs: fix UTC timezone comparison, raise default threshold
  to 6h, skip jobs with recent processor activity
- rust_asrx: Rust speaker diarization CLI + processor wiring
- processor metadata helper; fast_face_clustering script; file_progress pipeline
  API; scan API; VAD updates
This commit is contained in:
Accusys
2026-10-15 13:01:12 +08:00
parent 667e279768
commit 882e31ab96
76 changed files with 10117 additions and 300 deletions
@@ -0,0 +1,218 @@
---
title: Scene VLM Stats API
version: 1.0.0
date: 2026-10-14
author: Core Team
status: active
---
# Scene VLM Stats API
**Endpoint**: `/api/v1/file/{file_uuid}/scene-vlm-stats`
**Method**: `GET`
**Purpose**: 快速获取文件的 Scene VLM 统计数据
---
## Overview
**Scope**: File processing statistics
**Status**: Active
**Applicable to**: All registered files with Scene VLM processing
---
## Request
### Parameters
| Parameter | Type | Location | Required | Description |
|-----------|------|----------|----------|-------------|
| `file_uuid` | String | Path | Yes | File UUID |
### Example
```bash
curl http://localhost:3002/api/v1/file/dac75694ee550ff57d74f26391fcc751/scene-vlm-stats
```
---
## Response
### Success (200 OK)
```json
{
"total_scenes": 2,
"status": "completed",
"vlm_done": 2,
"vlm_total": 2
}
```
### Fields
| Field | Type | Description |
|-------|------|-------------|
| `total_scenes` | i64 | Total number of scenes detected |
| `status` | String | Scene VLM processing status (`pending`, `processing`, `completed`) |
| `vlm_done` | i64 | Number of scenes with VLM descriptions completed |
| `vlm_total` | i64 | Total scenes needing VLM processing |
### Default Response
If the file has no scenes file:
```json
{
"total_scenes": 0,
"status": "",
"vlm_done": 0,
"vlm_total": 0
}
```
---
## Performance
**Response Time**: < 10ms
**Why Fast**:
- Directly reads `{file_uuid}.scenes.json`
- No database queries
- No complex calculations
---
## Use Cases
### 1. UI Display
Display Scene VLM progress in Library view:
```typescript
const stats = await loadSceneVlmStats(fileUuid)
console.log(`${stats.vlm_done}/${stats.vlm_total} scenes completed`)
```
### 2. Performance Optimization
Replace expensive `get_file_stats` call:
- **Old**: `get_file_stats` - 100-500ms
- **New**: `scene-vlm-stats` - < 10ms
- **Improvement**: 10-50x faster
### 3. Real-time Updates
Poll for Scene VLM progress without heavy API load:
```typescript
setInterval(() => {
loadSceneVlmStats(fileUuid)
}, 5000)
```
---
## Implementation Details
### Backend
**File**: `src/api/scan.rs:1647`
**Logic**:
1. Check if `{file_uuid}.scenes.json` exists
2. Read JSON file
3. Parse and count scenes
4. Return statistics
**Code**:
```rust
async fn get_scene_vlm_stats(
Path(file_uuid): Path<String>,
) -> Result<Json<SceneVlmStats>, StatusCode> {
let scenes_path = format!("{}/{}.scenes.json", output_dir, file_uuid);
if !Path::new(&scenes_path).exists() {
return Ok(Json(SceneVlmStats::default()));
}
let scenes_json = std::fs::read_to_string(&scenes_path)?;
let scenes_data: Value = serde_json::from_str(&scenes_json)?;
// ... parse and return stats
}
```
---
## Error Handling
### File Not Found
**Status**: 200 OK
**Response**: Default values (all zeros)
### Parse Error
**Status**: 500 Internal Server Error
**Note**: Rare case, indicates corrupted JSON file
---
## Related APIs
- `GET /api/v1/file/{file_uuid}` - Full file info (slower)
- `GET /api/v1/file/{file_uuid}/processor-counts` - Processor counts
- `GET /api/v1/stats/file/{file_uuid}` - Detailed stats (slower)
---
## Best Practices
### 1. Use for Scene VLM Progress
**Recommended**: Use this API for Scene VLM progress display
**Avoid**: Using `get_file_stats` for simple Scene VLM stats
### 2. Caching
Frontend should cache results:
```typescript
if (fileStatsCache.value[fileUuid].scene_vlm) {
return fileStatsCache.value[fileUuid].scene_vlm
}
```
### 3. Error Handling
Always handle failures gracefully:
```typescript
try {
const stats = await loadSceneVlmStats(fileUuid)
} catch (e) {
console.warn('Scene VLM stats failed:', e)
// Use cached data or show 'Unknown'
}
```
---
## Version History
| Version | Date | Changes |
|---------|------|---------|
| 1.0.0 | 2026-10-14 | Initial API endpoint |
---
## Cross-References
- **Frontend Integration**: Studio team commit 3e7eba0
- **Test Script**: `momentry_studio/scripts/test_scene_vlm_api.sh`
- **Backend Code**: `src/api/scan.rs:1647`
---
**Last Updated**: 2026-10-14
@@ -0,0 +1,201 @@
---
title: Pipeline Progress API
version: 2.1.0
date: 2026-10-14
author: Core Team
status: implemented
---
# Pipeline Progress API
| Field | Value |
|-------|-------|
| Scope | Core HTTP API (axum) |
| Status | Implemented |
| Applicable to | Momentry Studio frontend, Core API consumers |
| Source | `/Users/accusys/momentry_core/src/api/file_progress.rs` |
| Config | `/Users/accusys/momentry_core/config/pipeline_flows.json` |
| Auth | Protected (session cookie, JWT, or API key) |
This document describes the phase-based pipeline progress API consumed by the
Studio frontend (`/Users/accusys/momentry_studio/src/store.ts`). All progress
values are normalized to the range **0.0 – 1.0** (the frontend multiplies by 100
for display).
> Note: an early design draft specified a richer 0–100 nested response
> (`progress.phases[]`). The implemented contract is the flat, 0–1 shape that
> Studio actually consumes. This document reflects the implementation.
---
## Endpoints
### 1. Get phase configuration (static)
`GET /api/v1/pipeline/phases`
Returns the phase/processor definition graph derived from
`/Users/accusys/momentry_core/config/pipeline_flows.json` (`phases` array plus
`flows.register.stages` for per-processor `weight` and `depends_on`).
```json
{
"phases": [
{
"name": "Foundation",
"weight": 0.15,
"processors": [
{ "name": "cut", "weight": 1.0, "depends_on": [] }
]
},
{
"name": "Core Processing",
"weight": 0.6,
"processors": [
{ "name": "asr", "weight": 0.35, "depends_on": [] },
{ "name": "face", "weight": 0.35, "depends_on": [] },
{ "name": "ocr", "weight": 0.3, "depends_on": [] }
]
},
{
"name": "Deep Analysis",
"weight": 0.2,
"processors": [
{ "name": "asrx", "weight": 0.4, "depends_on": ["asr"] },
{ "name": "scene", "weight": 0.35, "depends_on": ["cut"] },
{ "name": "face_cluster", "weight": 0.25, "depends_on": ["face"] }
]
},
{
"name": "Knowledge Building",
"weight": 0.05,
"processors": [
{ "name": "tkg", "weight": 1.0, "depends_on": ["asrx", "face_cluster"] }
]
}
]
}
```
- `name` is the phase key (`name_en` in config; falls back to Chinese `name`).
- Phase and processor `weight` are the `progress_weight` from config
(defaulting to `1.0` when absent).
### 2. Get per-file progress
`GET /api/v1/file/{file_uuid}/progress`
```json
{
"file_uuid": "9c77a341a1194167e8ff6a06816f1ff6",
"overall_progress": 0.486,
"current_phase": "Core Processing",
"phases": {
"Foundation": {
"status": "completed",
"progress": 1.0,
"processors": {
"cut": { "name": "cut", "status": "completed", "progress": 1.0 }
}
},
"Core Processing": {
"status": "running",
"progress": 0.56,
"processors": {
"asr": { "name": "asr", "status": "completed", "progress": 1.0 },
"face": { "name": "face", "status": "running", "progress": 0.6 },
"ocr": { "name": "ocr", "status": "pending", "progress": 0.0 }
}
}
}
}
```
- `overall_progress`: weighted sum of phase progress (0.0 – 1.0).
- `current_phase`: first phase (in config order) with `progress < 1.0`; `null`
when all phases are complete.
- `phases`: keyed by phase `name`. `status` is one of
`pending | running | completed | failed`. Processor-level `status` may also be
`skipped` (from `processor_results`).
- Unknown `file_uuid` returns HTTP 200 with `overall_progress: 0.0` and all
phases pending.
---
## Data Sources
| Source | Purpose |
|--------|---------|
| `videos.status`, `videos.processing_status` (JSONB) | File-level status; `processing_status.phase` (`PROCESSING`/`COMPLETED`) and `active_processors` decide applicability |
| Redis `{prefix}job:{file_uuid}:processor:{name}` (hash) | Real-time per-processor `status`, `current`, `total` |
| Postgres `processor_results` (`WHERE uuid = $1`, latest row per `processor`) | Terminal per-processor status |
| Redis `{prefix}progress:{file_uuid}:tkg` (JSON) | TKG progress (`overall_progress`, `phase`) |
| Redis `{prefix}progress:{file_uuid}:phase_hwm` (JSON) | Monotonic high-water mark per phase |
`{prefix}` is `MOMENTRY_REDIS_PREFIX` (`momentry:` in production).
---
## Progress Calculation
**Phase progress**
```
phase_progress = Σ(processor.weight × processor.progress) / Σ(processor.weight)
(over only "applicable" processors)
```
A processor is **applicable** when any of the following holds:
- the file is completed (`videos.status = completed` or `phase = COMPLETED`);
- the processor already produced a signal (Redis hash or `processor_results`);
- the processor is listed in `processing_status.active_processors`.
This prevents a phase from reporting 100% while sibling processors are still
pending, and prevents stalling on processors that never run for this job.
Processors with status `skipped` are treated as done (progress `1.0`).
**Overall progress**
```
overall_progress = Σ(phase.weight × phase.progress)
```
---
## Monotonic Guarantee
Each poll recomputes progress from scratch, so a naive implementation can
regress (e.g. a processor recount moving backwards). To prevent this, the API
stores a per-phase high-water mark in
`{prefix}progress:{file_uuid}:phase_hwm` and clamps every response so a phase
never decreases within a run. The high-water mark is cleared by the worker when
a new job starts
(`/Users/accusys/momentry_core/src/worker/job_worker.rs`).
---
## Example
```bash
curl -X GET "http://localhost:3002/api/v1/file/9c77a341a1194167e8ff6a06816f1ff6/progress" \
-H "Authorization: Bearer muser_..."
```
---
## Related Documents
- `/Users/accusys/momentry_core/config/pipeline_flows.json`
- `/Users/accusys/momentry_core/src/api/file_progress.rs`
- `/Users/accusys/momentry_core/docs_v1.0/OPERATIONS/Pipeline_Configuration_Guide.md`
- `/Users/accusys/momentry_core/AGENTS.md`
---
## Version History
| Version | Date | Change |
|---------|------|--------|
| 2.1.0 | 2026-10-14 | Rewritten to match implemented flat 0–1 contract (Studio-aligned); documented sources, calculation, and monotonic HWM |
| 2.0.0 | 2026-10-14 | Initial design (0–100 nested response) |