Skip to content

AI agent skill that researches any topic across Reddit, X, YouTube, HN, Polymarket, and the web - then synthesizes a grounded summary

Salvage partial YouTube transcript on non-zero yt-dlp exit (#636)

SWAG489634b95b787bf
diff --git a/skills/last30days/scripts/lib/youtube_yt.py b/skills/last30days/scripts/lib/youtube_yt.py
index 05624ef4..811420eb 100644
--- a/skills/last30days/scripts/lib/youtube_yt.py
+++ b/skills/last30days/scripts/lib/youtube_yt.py
@@ -668,6 +668,18 @@ def _fetch_transcript_ytdlp(
# Genuine no-captions: return quietly (caller may still try direct).
return None
+ # Non-zero exit, but yt-dlp may have written a usable VTT before the
+ # failing language errored. With the default `--sub-lang en,es,pt`, an
+ # English video fetches `en` fine, then `es`/`pt` hit a 429 and yt-dlp
+ # exits non-zero — yet the `en` track is already on disk. A partial
+ # success is still a real transcript, so salvage any VTT before
+ # classifying this as an error (and, worse, retrying straight back into
+ # the same rate limit). This is the root cause of the 0/N transcript
+ # runs reported when every video had captions.
+ partial_vtt = _read_vtt(video_id, temp_dir)
+ if partial_vtt is not None:
+ return partial_vtt
+
# Non-zero exit == a real error worth classifying & surfacing.
stderr = (result.stderr or "").strip()
snippet = (stderr.splitlines()[-1][:200] if stderr
diff --git a/tests/test_youtube_yt.py b/tests/test_youtube_yt.py
index 9735473f..f4b136b5 100644
--- a/tests/test_youtube_yt.py
+++ b/tests/test_youtube_yt.py
@@ -154,6 +154,37 @@ class TestYtDlpSubLangs(unittest.TestCase):
self.assertIsNotNone(vtt)
self.assertIn("Hola mundo", vtt)
+ def test_partial_success_returns_vtt_despite_nonzero_exit(self):
+ """A non-zero yt-dlp exit must not discard a VTT already on disk.
+
+ Regression for the 0/N-transcripts bug: with the default
+ ``--sub-lang en,es,pt``, an English video fetches ``en`` successfully,
+ then ``es``/``pt`` hit a 429 and yt-dlp exits non-zero. The ``en``
+ track is already written and must be returned, not discarded (and not
+ retried back into the same rate limit).
+ """
+ with tempfile.TemporaryDirectory() as temp_dir:
+ (Path(temp_dir) / "abc123.en.vtt").write_text(
+ "WEBVTT\n\n00:00:00.000 --> 00:00:02.000\nThis is the english transcript.\n",
+ encoding="utf-8",
+ )
+ status: dict = {}
+ with mock.patch.object(youtube_yt, "is_ytdlp_installed", return_value=True), \
+ mock.patch.object(
+ youtube_yt.subproc,
+ "run_with_timeout",
+ return_value=self._fake_result(returncode=1),
+ ) as run_mock:
+ vtt = youtube_yt._fetch_transcript_ytdlp("abc123", temp_dir, status)
+
+ self.assertIsNotNone(vtt)
+ self.assertIn("english transcript", vtt)
+ self.assertNotIn("ytdlp_error", status)
+ # Salvage must short-circuit the retry loop: yt-dlp must not be called a
+ # second time when a partial VTT is already on disk (locks in the
+ # no-retry guarantee against a future salvage-after-retry regression).
+ self.assertEqual(run_mock.call_count, 1)
+
def test_vtt_matching_respects_non_default_priority(self):
"""When multiple tracks exist, the user-requested priority wins
over alphabetical order (regression for the Greptile review on #486)."""