From 0ef20db9882838f37525311297a84b4ae4a879fc Mon Sep 17 00:00:00 2001 From: victorcavero14 Date: Sat, 26 Sep 2026 01:25:57 +0200 Subject: [PATCH] fix(dashboard): real log times, stage progress, cards that use the width Logs - Each job log line records when it arrived (app._TimedLog) and /api/status returns log_times; the dashboard showed new Date() on every render, so every line had the same, moving clock. - The cloud log view shows every stage: download %, early audio, transcription %, finding moments, layout, clips found, and per clip creating / framed / ready. Progress updates its own line instead of adding one per step. Lines glued to yt-dlp's \r progress bar (the parallel transcription prints onto it) are split, so its % shows again. "Found N clips" matched the old "viral clips" wording only. Result cards - The results grid only goes to two columns when each card gets ~600px (auto-fill) instead of at the xl breakpoint, where the side panel was squeezed and the copy buttons spilled out of the card. - Card actions take as many per row as fit. Co-Authored-By: Claude Opus 5.5 --- app.py | 52 +++++++++-- dashboard/src/App.jsx | 16 +++- dashboard/src/components/ResultCard.jsx | 6 +- log_view.py | 114 +++++++++++++++++++----- main.py | 2 + tests/test_log_view.py | 39 +++++++- 6 files changed, 187 insertions(+), 42 deletions(-) diff --git a/app.py b/app.py index e7a4f9a..710b40c 100644 --- a/app.py +++ b/app.py @@ -791,7 +791,7 @@ def _recover_jobs_from_disk(): owner = int(raw) if raw.isdigit() else (raw or None) jobs[job_id] = { 'status': 'completed', - 'logs': ["♻️ Job recovered from disk after server restart."], + 'logs': _TimedLog(["♻️ Job recovered from disk after server restart."]), 'output_dir': job_path, 'user_id': owner, 'result': {'clips': clips, 'cost_analysis': data.get('cost_analysis')}, @@ -1225,7 +1225,7 @@ def _resume_interrupted_jobs() -> set: jobs[job_id] = { 'status': 'queued', - 'logs': [f"♻️ Resuming your video after a server update (attempt {attempts})."], + 'logs': _TimedLog([f"♻️ Resuming your video after a server update (attempt {attempts})."]), 'cmd': m.get("cmd"), 'env': env, 'output_dir': job_path, @@ -2221,6 +2221,39 @@ _SENSITIVE_LOG_RE = re.compile( ) +class _TimedLog(list): + """A job's log lines plus the time each one arrived (``.times``). + + The dashboard used to stamp every line with the time it was RENDERED, so + all of them showed the same clock and it changed on every poll. + """ + + def __init__(self, lines=()): + super().__init__(lines) + self.times = [time.time()] * len(self) + + def append(self, line): + super().append(line) + self.times.append(time.time()) + + def extend(self, lines): + lines = list(lines) + super().extend(lines) + self.times.extend([time.time()] * len(lines)) + + +def _visible_logs_timed(logs): + """(lines, times) to surface to the client; see _visible_logs.""" + times = getattr(logs, "times", None) + if times is not None and len(times) != len(logs): + times = None + if not BILLING_ENABLED or DEBUG_LOGS: + return list(logs), list(times) if times is not None else None + from log_view import friendly_logs_timed + pairs = friendly_logs_timed(logs, times) + return [p[0] for p in pairs], ([p[1] for p in pairs] if times is not None else None) + + def _visible_logs(logs): """Logs to surface to the client. @@ -3050,7 +3083,7 @@ async def process_endpoint( # Enqueue Job jobs[job_id] = { 'status': 'queued', - 'logs': [f"Job {job_id} queued."], + 'logs': _TimedLog([f"Job {job_id} queued."]), 'cmd': cmd, 'env': env, 'output_dir': job_output_dir, @@ -3109,7 +3142,7 @@ def _job_view_from_disk(job_id): owner = m.get("user_id") return { 'status': 'processing' if alive else 'queued', - 'logs': ["♻️ The server was updated; your video continues on the new instance."], + 'logs': _TimedLog(["♻️ The server was updated; your video continues on the new instance."]), 'user_id': (int(owner) if isinstance(owner, str) and owner.isdigit() else owner), 'result': None, } @@ -3134,9 +3167,12 @@ async def get_status(job_id: str, request: Request): raise HTTPException(status_code=404, detail="Job not found") await _assert_job_owner(request, job) + _logs_view = _visible_logs_timed(job['logs']) return { "status": _presented_status(job_id, job), - "logs": _visible_logs(job['logs']), + "logs": _logs_view[0], + # When each line arrived (epoch seconds, parallel to "logs"), or None. + "log_times": _logs_view[1], "result": job.get('result'), # Position in line and a rough wait while the job is still queued. "queue": queue_snapshot(job_id), @@ -3436,7 +3472,7 @@ async def _restore_job_files(job_id: str, proj, user_id: str) -> bool: f"{_canonical_clip_file(job_dir, base_name, i)}") jobs[job_id] = { 'status': 'completed', - 'logs': ["♻️ Project restored from your library."], + 'logs': _TimedLog(["♻️ Project restored from your library."]), 'output_dir': job_dir, 'user_id': user_id, 'result': {'clips': clips, 'cost_analysis': data.get('cost_analysis')}, @@ -6690,7 +6726,7 @@ async def saasshorts_generate( saas_jobs[job_id] = { "user_id": await _owner_id(request), "status": "processing", - "logs": [f"Retrying job {job_id[:8]}... reusing cached assets from disk."], + "logs": _TimedLog([f"Retrying job {job_id[:8]}... reusing cached assets from disk."]), "result": None, "output_dir": job_output_dir, } @@ -6702,7 +6738,7 @@ async def saasshorts_generate( saas_jobs[job_id] = { "user_id": await _owner_id(request), "status": "processing", - "logs": ["SaaSShorts job started."], + "logs": _TimedLog(["SaaSShorts job started."]), "result": None, "output_dir": job_output_dir, } diff --git a/dashboard/src/App.jsx b/dashboard/src/App.jsx index 53a7d39..07c608b 100644 --- a/dashboard/src/App.jsx +++ b/dashboard/src/App.jsx @@ -346,6 +346,8 @@ function App() { // Pre-flight quality gate: { info: {max_height, min_height, cookies_invalid}, data } const [qualityGate, setQualityGate] = useState(null); const [logs, setLogs] = useState([]); + // When each server log line arrived (epoch s, parallel to logs), from /api/status. + const [logTimes, setLogTimes] = useState([]); // Collapsed on phones: the log tail is the least useful thing on a 360px // screen and it was pushing the actual clips a full scroll down. const [logsVisible, setLogsVisible] = useState(() => { @@ -509,6 +511,7 @@ function App() { setJobId(data.job_id); setResults(data.result || null); setLogs(['♻️ Project restored from your library.']); + setLogTimes([Date.now() / 1000]); setProcessingMedia(null); setQualityGate(null); setStatus('complete'); @@ -751,7 +754,10 @@ function App() { refreshMe(); } else { // Update logs if available - if (data.logs) setLogs(data.logs); + if (data.logs) { + setLogs(data.logs); + setLogTimes(data.log_times || []); + } } } catch (e) { console.error("Polling error", e); @@ -953,6 +959,7 @@ function App() { setStatus('processing'); setJobError(''); setLogs(["Starting process..."]); + setLogTimes([Date.now() / 1000]); setResults(null); // Studio handovers have no local media object; the preview switches to the // backend-served source once the job id is known. @@ -1100,6 +1107,7 @@ function App() { setJobId(null); setResults(null); setLogs([]); + setLogTimes([]); setProcessingMedia(null); setProjectState(null); setNoSource(false); @@ -2030,7 +2038,9 @@ function App() {
{logs.map((log, i) => (
- {new Date().toLocaleTimeString()} + + {logTimes[i] ? new Date(logTimes[i] * 1000).toLocaleTimeString() : ''} + {log}
))} @@ -2167,7 +2177,7 @@ function App() {
{results && results.clips && results.clips.length > 0 ? ( -
+
{rankedClips.map(({ clip, index: i }) => ( -
+
YOUTUBE

{clip.video_title_for_youtube_short || "Viral Short Video"} @@ -880,7 +880,7 @@ export default function ResultCard({ clip, index, jobId, durable, uploadPostKey,

-
+
TIKTOK · IG

{clip.video_description_for_tiktok || clip.video_description_for_instagram} @@ -911,7 +911,7 @@ export default function ResultCard({ clip, index, jobId, durable, uploadPostKey, )} {/* Actions Footer */} -

+
{onEditClip && (