fix: MCP server SQL uses correct column names (video_id, not pipeline_run_id)

This commit is contained in:
jlightner 2026-04-03 03:05:59 +00:00
parent 6375ce667e
commit f27c18b555

View file

@ -608,14 +608,13 @@ def recent_events(limit: int = 20, video_id: str = "", stage: str = "") -> str:
pe.prompt_tokens, pe.completion_tokens, pe.duration_ms,
pe.created_at, sv.filename
FROM pipeline_events pe
LEFT JOIN pipeline_runs pr ON pe.pipeline_run_id = pr.id
LEFT JOIN source_videos sv ON pr.source_video_id = sv.id
LEFT JOIN source_videos sv ON pe.video_id = sv.id
"""
conditions = []
params: list = []
if video_id:
conditions.append("pr.source_video_id = %s")
conditions.append("pe.video_id = %s")
params.append(video_id)
if stage:
conditions.append("pe.stage = %s")
@ -640,12 +639,11 @@ def token_usage(video_id: str = "", stage: str = "") -> str:
coalesce(sum(pe.completion_tokens), 0) as total_completion_tokens,
coalesce(sum(pe.prompt_tokens), 0) + coalesce(sum(pe.completion_tokens), 0) as total_tokens
FROM pipeline_events pe
LEFT JOIN pipeline_runs pr ON pe.pipeline_run_id = pr.id
WHERE pe.event_type = 'llm_call'
"""
params: list = []
if video_id:
sql += " AND pr.source_video_id = %s"
sql += " AND pe.video_id = %s"
params.append(video_id)
if stage:
sql += " AND pe.stage = %s"
@ -662,16 +660,15 @@ def token_usage(video_id: str = "", stage: str = "") -> str:
def processing_times(limit: int = 10) -> str:
"""Processing duration for recent pipeline runs (start to last event)."""
rows = _query("""
SELECT pr.id, sv.filename, c.name as creator,
SELECT pe.video_id, sv.filename, c.name as creator,
min(pe.created_at) as started_at,
max(pe.created_at) as finished_at,
EXTRACT(EPOCH FROM (max(pe.created_at) - min(pe.created_at)))::int as duration_seconds,
count(pe.id) as event_count
FROM pipeline_runs pr
JOIN source_videos sv ON pr.source_video_id = sv.id
FROM pipeline_events pe
JOIN source_videos sv ON pe.video_id = sv.id
LEFT JOIN creators c ON sv.creator_id = c.id
JOIN pipeline_events pe ON pe.pipeline_run_id = pr.id
GROUP BY pr.id, sv.filename, c.name
GROUP BY pe.video_id, sv.filename, c.name
ORDER BY max(pe.created_at) DESC
LIMIT %s
""", (limit,))