Skip to content

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

fix(transcribe): send the skill User-Agent in _post_audio so Groq's Cloudflare edge stops returning 403 (#983) (#1036)

Terry Lie6d2d51f7bcf
diff --git a/changelog.d/+groq-transcribe-user-agent.fixed.md b/changelog.d/+groq-transcribe-user-agent.fixed.md
new file mode 100644
index 00000000..1a44d755
--- /dev/null
+++ b/changelog.d/+groq-transcribe-user-agent.fixed.md
@@ -0,0 +1 @@
+Audio transcription posts the skill's canonical User-Agent instead of Python-urllib, so Groq's Cloudflare edge no longer 403s the request with error 1010.
diff --git a/skills/last30days/scripts/lib/transcribe.py b/skills/last30days/scripts/lib/transcribe.py
index e470000d..dce0fd8c 100644
--- a/skills/last30days/scripts/lib/transcribe.py
+++ b/skills/last30days/scripts/lib/transcribe.py
@@ -24,7 +24,7 @@ import tempfile
from dataclasses import dataclass, field
from typing import Optional
-from . import env, health, subproc
+from . import env, health, http, log, subproc
# Whisper's documented upload ceiling. We compress to stay under it and chunk
# when a single clip still exceeds it.
@@ -177,7 +177,11 @@ def _transcribe_chunk(
for name, key in providers:
try:
text = _post_audio(name, path, key, timeout=timeout)
- except Exception: # noqa: BLE001 - any provider failure -> try the next
+ except Exception as exc: # noqa: BLE001 - any provider failure -> try the next
+ # Surface the failing provider + error (e.g. Groq's Cloudflare 403,
+ # "error code: 1010") under LAST30DAYS_DEBUG instead of silently
+ # degrading to an empty transcript (#983).
+ log.debug(f"transcribe: provider {name} failed on a chunk: {exc!r}")
text = None
if text is not None:
return text, name
@@ -214,6 +218,10 @@ def _post_audio(provider: str, path: str, api_key: str, timeout: float) -> Optio
headers={
"Authorization": f"Bearer {api_key}",
"Content-Type": f"multipart/form-data; boundary={boundary}",
+ # A plain-urllib UA is fingerprinted and 403'd by Cloudflare-style
+ # edges (Groq returns "error code: 1010", #983). Send the skill's
+ # canonical identity instead, same as lib/http.py's get/post.
+ "User-Agent": http.USER_AGENT,
},
method="POST",
)
diff --git a/tests/test_transcribe.py b/tests/test_transcribe.py
index 8e83a68e..f70867cd 100644
--- a/tests/test_transcribe.py
+++ b/tests/test_transcribe.py
@@ -2,7 +2,7 @@
from unittest import mock
-from lib import health, transcribe
+from lib import health, http, transcribe
class TestPrerequisites:
@@ -91,3 +91,58 @@ class TestTranscribeFlow:
result = transcribe.transcribe_media("https://x/v", {"GROQ_API_KEY": "k"})
assert result.ok is False
assert "all providers failed" in result.reason
+
+
+class TestPostAudioUserAgent:
+ """_post_audio must send a real User-Agent, not Python-urllib/3.x.
+
+ Groq's Cloudflare edge 403s the default urllib fingerprint with
+ "error code: 1010" (#983); a plain-urllib UA is a liability on every
+ provider this helper serves.
+ """
+
+ class _Resp:
+ def __enter__(self):
+ return self
+
+ def __exit__(self, *exc):
+ return False
+
+ def read(self):
+ return b'{"text": "hello"}'
+
+ def _capture_headers(self, tmp_path):
+ captured = {}
+
+ def _capture(req, timeout=None):
+ # urllib stores header keys capitalized ("User-agent").
+ captured.update({k.lower(): v for k, v in req.headers.items()})
+ return self._Resp()
+
+ audio = tmp_path / "audio.mp3"
+ audio.write_bytes(b"fake-audio")
+ with mock.patch("urllib.request.urlopen", side_effect=_capture):
+ transcribe._post_audio("groq", str(audio), "key", timeout=5.0)
+ return captured
+
+ def test_user_agent_is_canonical_skill_ua(self, tmp_path):
+ captured = self._capture_headers(tmp_path)
+ assert "user-agent" in captured
+ assert captured["user-agent"] == http.USER_AGENT
+
+ def test_user_agent_not_urllib_default(self, tmp_path):
+ captured = self._capture_headers(tmp_path)
+ assert not captured["user-agent"].startswith("Python-urllib")
+
+ def test_user_agent_sent_for_openai_too(self, tmp_path):
+ captured = {}
+
+ def _capture(req, timeout=None):
+ captured.update({k.lower(): v for k, v in req.headers.items()})
+ return self._Resp()
+
+ audio = tmp_path / "audio.mp3"
+ audio.write_bytes(b"fake-audio")
+ with mock.patch("urllib.request.urlopen", side_effect=_capture):
+ transcribe._post_audio("openai", str(audio), "key", timeout=5.0)
+ assert captured.get("user-agent") == http.USER_AGENT