AI agent skill that researches any topic across Reddit, X, YouTube, HN, Polymarket, and the web - then synthesizes a grounded summary
Python ai-promptsai-skillblueskyclaudeclaude-codeclawhubdeep-researchhackernewsinstagramopenclawpolymarketrecencyredditresearchsocial-mediatiktoktrendstwitterweb-searchyoutube
fix: distinguish Instagram errors and preserve recovery advice (#1291)
Bhumika Gurav6a27fbca221d
diff --git a/changelog.d/1289.fixed.md b/changelog.d/1289.fixed.mdnew file mode 100644index 00000000..edc98e91--- /dev/null+++ b/changelog.d/1289.fixed.md@@ -0,0 +1 @@+Instagram nudge now distinguishes HTTP errors ("Bonus source failed: Instagram") from zero-result runs ("Bonus source unavailable: Instagram") instead of labelling both as "silent".diff --git a/skills/last30days/scripts/last30days.py b/skills/last30days/scripts/last30days.pyindex b5dc2463..11fc8c4d 100644--- a/skills/last30days/scripts/last30days.py+++ b/skills/last30days/scripts/last30days.py@@ -3238,6 +3238,7 @@ def _quality_research_results(report, diag, yt_fetch_stats):if (it.metadata.get("transcript_highlights") or it.metadata.get("transcript_snippet"))),"youtube_error": report.errors_by_source.get("youtube"),+ "instagram_error": report.errors_by_source.get("instagram"),"x_error": report.errors_by_source.get("x"),"x_degraded_error": x_degraded_error,"youtube_captions_disabled_count": sum(diff --git a/skills/last30days/scripts/lib/quality_nudge.py b/skills/last30days/scripts/lib/quality_nudge.pyindex 2796337e..3f62b1bc 100644--- a/skills/last30days/scripts/lib/quality_nudge.py+++ b/skills/last30days/scripts/lib/quality_nudge.py@@ -166,38 +166,39 @@ def _is_youtube_degraded(research_results: dict, threshold: float) -> bool:return (transcripts / eligible) < threshold-def _is_instagram_silent_failure(config: dict, research_results: dict) -> bool:- """Instagram is silently failing when SC is configured but the source- returned zero items. The canonical cause is SC's v2 reels endpoint- 500'ing on multi-token queries (it wraps Google Search and is documented- to be flaky there). Pre-fix the user got no signal at all - no Instagram- section in the brief, no error in the footer, just unexplained absence.+def _instagram_bonus_outcome(config: dict, research_results: dict) -> str | None:+ """Return the bonus-source outcome for Instagram, or None when not applicable.++ Returns:+ ``"errored"`` — SC is configured, the source ran, and it returned an error+ (e.g. HTTP 404 from the ScrapeCreators endpoint).+ ``"no_items"`` — SC is configured, the source ran with no error, but returned+ zero items (endpoint was live but had nothing for the query).+ ``None`` — SC not configured, source excluded, or source not run this+ invocation."""if not config.get("SCRAPECREATORS_API_KEY"):- return False # not configured — not a silent failure- # Honor EXCLUDE_SOURCES: a user who set EXCLUDE_SOURCES=instagram- # intentionally turned the source off, so a zero-item count is- # expected, not a silent failure. Mirror the canonical parsing- # pattern from pipeline.available_sources().+ return Noneexcluded = {s.strip().lower()for s in (config.get("EXCLUDE_SOURCES") or "").split(",")if s.strip()}- # Symmetric case: INCLUDE_SOURCES is an opt-in allowlist. If it is- # non-empty and does not name instagram, the source was intentionally- # filtered out, so a zero-item count is expected — not a silent failure.included = {s.strip().lower()for s in (config.get("INCLUDE_SOURCES") or "").split(",")if s.strip()}if "instagram" in excluded or (included and "instagram" not in included):- return False+ return Nonecount = research_results.get("instagram_items_count")if count is None:- return False # source not run this invocation- return int(count) == 0+ return None # source not run this invocation+ if int(count) == 0:+ if research_results.get("instagram_error"):+ return "errored"+ return "no_items"+ return Nonedef compute_quality_score(config: dict, research_results: dict) -> dict:@@ -210,8 +211,9 @@ def compute_quality_score(config: dict, research_results: dict) -> dict:``youtube_videos_count`` and ``youtube_transcripts_count`` enabledegraded-YouTube detection (transcript-fetch ratio below threshold,or fallback/provider data returned without local yt-dlp).- Optional key ``instagram_items_count`` enables silent-failure- detection for the bonus Instagram source. ``x_degraded_error``+ Optional keys ``instagram_items_count`` and ``instagram_error``+ enable failed/no-items detection for the bonus Instagram source.+ ``x_degraded_error``carries a failed xAI lane when another backend served X items.Returns:@@ -221,7 +223,7 @@ def compute_quality_score(config: dict, research_results: dict) -> dict:"core_missing": ["youtube"],"core_errored": [], # configured but errored at top level"core_degraded": [], # configured and returned items but quality below threshold- "bonus_errored": [], # bonus sources (Instagram, etc.) configured but silent+ "bonus_errored": [], # bonus sources (Instagram, etc.) configured but failed or returned no items"nudge_text": "..." or None if all sources healthy}"""@@ -281,10 +283,14 @@ def compute_quality_score(config: dict, research_results: dict) -> dict:if has_ytdlp and research_results.get("youtube_error"):core_errored.append("youtube")- # Bonus sources (Instagram, etc.): SC-key holders expect content from- # these but until now the pipeline fell silent on configured-but-zero.- if _is_instagram_silent_failure(config, research_results):- bonus_errored.append("instagram")+ # Bonus sources (Instagram, etc.): SC-key holders expect content but the+ # source can fail (HTTP 404) or return zero items without surfacing a+ # clear signal in the brief. Track both outcomes separately.+ _ig_outcome = _instagram_bonus_outcome(config, research_results)+ if _ig_outcome == "errored":+ bonus_errored.append("instagram:failed")+ elif _ig_outcome == "no_items":+ bonus_errored.append("instagram:no_items")scored_source_count = len(CORE_SOURCES) - len(optional_omitted)score_pct = int(len(core_active) / scored_source_count * 100)@@ -356,8 +362,22 @@ def _build_nudge_text(degraded_labels = ", ".join(SOURCE_LABELS[s] for s in core_degraded)lines.append(f"Degraded: {degraded_labels}.")if bonus_errored:- bonus_labels = ", ".join(s.capitalize() for s in bonus_errored)- lines.append(f"Bonus source silent: {bonus_labels}.")+ failed_sources = []+ unavailable_sources = []+ silent_sources = []+ for s in bonus_errored:+ if s == "instagram:failed":+ failed_sources.append("Instagram")+ elif s == "instagram:no_items":+ unavailable_sources.append("Instagram")+ else:+ silent_sources.append(s.capitalize())+ if failed_sources:+ lines.append(f"Bonus source failed: {', '.join(failed_sources)}.")+ if unavailable_sources:+ lines.append(f"Bonus source unavailable: {', '.join(unavailable_sources)}.")+ if silent_sources:+ lines.append(f"Bonus source silent: {', '.join(silent_sources)}.")lines.append("")# Free suggestions@@ -427,7 +447,7 @@ def _build_nudge_text(f"or {pip_update}.")- if "instagram" in bonus_errored:+ if "instagram:failed" in bonus_errored or "instagram:no_items" in bonus_errored:free_suggestions.append("Instagram returned 0 reels despite SC being configured. SC's ""v2 reels endpoint wraps Google Search and 500's frequently on "diff --git a/tests/test_quality_nudge.py b/tests/test_quality_nudge.pyindex 5c4c0de3..fc313466 100644--- a/tests/test_quality_nudge.py+++ b/tests/test_quality_nudge.py@@ -584,7 +584,7 @@ class TestInstagramSilentFailure:ytdlp_installed=True,result_overrides={"instagram_items_count": 0},)- assert "instagram" in q["bonus_errored"]+ assert q["bonus_errored"] == ["instagram:no_items"]assert q["nudge_text"] is not Noneassert "Instagram" in q["nudge_text"]@@ -594,7 +594,7 @@ class TestInstagramSilentFailure:ytdlp_installed=True,result_overrides={"instagram_items_count": 0},)- assert "instagram" not in q.get("bonus_errored", [])+ assert q["bonus_errored"] == []def test_nonzero_items_does_not_flag(self):q = _compute(@@ -605,9 +605,19 @@ class TestInstagramSilentFailure:ytdlp_installed=True,result_overrides={"instagram_items_count": 5},)- assert "instagram" not in q["bonus_errored"]+ assert q["bonus_errored"] == []assert q["nudge_text"] is None+ def test_nonzero_items_do_not_add_instagram_advice_to_other_nudges(self):+ q = _compute(+ config_overrides={"SCRAPECREATORS_API_KEY": "sc_key"},+ result_overrides={"instagram_items_count": 5},+ )+ assert q["bonus_errored"] == []+ assert "YouTube" in q["nudge_text"]+ assert "Instagram" not in q["nudge_text"]+ assert "single-word topic" not in q["nudge_text"]+def test_missing_key_means_source_did_not_run(self):q = _compute(config_overrides={@@ -616,23 +626,28 @@ class TestInstagramSilentFailure:},ytdlp_installed=True,)- assert "instagram" not in q["bonus_errored"]+ assert q["bonus_errored"] == []assert q["nudge_text"] is None- def test_nudge_text_explains_workaround(self):+ @pytest.mark.parametrize("error,outcome,label", [+ (None, "instagram:no_items", "Bonus source unavailable: Instagram."),+ ("HTTP 404", "instagram:failed", "Bonus source failed: Instagram."),+ ])+ def test_nudge_text_explains_workaround(self, error, outcome, label):q = _compute(config_overrides={"AUTH_TOKEN": "tok123","SCRAPECREATORS_API_KEY": "sc_key",},ytdlp_installed=True,- result_overrides={"instagram_items_count": 0},+ result_overrides={"instagram_items_count": 0, "instagram_error": error},)+ assert q["bonus_errored"] == [outcome]assert q["nudge_text"] is not None- text_lower = q["nudge_text"].lower()- assert "instagram" in text_lower- assert ("0 reels" in text_lower or "silent" in text_lower- or "hashtag" in text_lower)+ assert label in q["nudge_text"]+ assert "Instagram returned 0 reels" in q["nudge_text"]+ assert "retries with hashtag-form automatically" in q["nudge_text"]+ assert "Try a single-word topic" in q["nudge_text"]def test_bonus_errored_does_not_affect_core_score(self):q = _compute(@@ -644,9 +659,24 @@ class TestInstagramSilentFailure:result_overrides={"instagram_items_count": 0},)assert q["score_pct"] == 100- assert "instagram" in q["bonus_errored"]+ assert q["bonus_errored"] == ["instagram:no_items"]+ assert q["nudge_text"] is not None+ assert "Bonus source unavailable" in q["nudge_text"]++ def test_bonus_errored_instagram_http_error_emits_failed_label(self):+ """When instagram_error is set (HTTP error), nudge says 'Bonus source failed'."""+ q = _compute(+ config_overrides={+ "AUTH_TOKEN": "tok123",+ "SCRAPECREATORS_API_KEY": "sc_key",+ },+ ytdlp_installed=True,+ result_overrides={"instagram_items_count": 0, "instagram_error": "HTTP 404"},+ )+ assert q["bonus_errored"] == ["instagram:failed"]assert q["nudge_text"] is not None- assert "Bonus source silent" in q["nudge_text"]+ assert "Bonus source failed" in q["nudge_text"]+ assert "Instagram" in q["nudge_text"]def test_bonus_errored_field_always_present(self):q = _compute()@@ -667,7 +697,7 @@ class TestInstagramSilentFailure:ytdlp_installed=True,result_overrides={"instagram_items_count": 0},)- assert "instagram" not in q["bonus_errored"]+ assert q["bonus_errored"] == []assert q["nudge_text"] is Nonedef test_exclude_sources_multi_value_with_instagram(self):@@ -681,7 +711,7 @@ class TestInstagramSilentFailure:ytdlp_installed=True,result_overrides={"instagram_items_count": 0},)- assert "instagram" not in q["bonus_errored"]+ assert q["bonus_errored"] == []def test_exclude_sources_other_value_still_flags(self):"""EXCLUDE_SOURCES that does not mention instagram must not suppress@@ -696,7 +726,7 @@ class TestInstagramSilentFailure:ytdlp_installed=True,result_overrides={"instagram_items_count": 0},)- assert "instagram" in q["bonus_errored"]+ assert q["bonus_errored"] == ["instagram:no_items"]def test_include_sources_without_instagram_suppresses_silent_failure(self):"""User set INCLUDE_SOURCES to an opt-in allowlist that omits@@ -713,7 +743,7 @@ class TestInstagramSilentFailure:ytdlp_installed=True,result_overrides={"instagram_items_count": 0},)- assert "instagram" not in q["bonus_errored"]+ assert q["bonus_errored"] == []assert q["nudge_text"] is Nonedef test_include_sources_multi_value_without_instagram(self):@@ -727,7 +757,7 @@ class TestInstagramSilentFailure:ytdlp_installed=True,result_overrides={"instagram_items_count": 0},)- assert "instagram" not in q["bonus_errored"]+ assert q["bonus_errored"] == []def test_include_sources_with_instagram_still_flags(self):"""INCLUDE_SOURCES that explicitly names instagram must not suppress@@ -743,7 +773,7 @@ class TestInstagramSilentFailure:ytdlp_installed=True,result_overrides={"instagram_items_count": 0},)- assert "instagram" in q["bonus_errored"]+ assert q["bonus_errored"] == ["instagram:no_items"]def test_include_sources_empty_does_not_suppress(self):"""Empty/unset INCLUDE_SOURCES means no allowlist filter, so the@@ -758,7 +788,7 @@ class TestInstagramSilentFailure:ytdlp_installed=True,result_overrides={"instagram_items_count": 0},)- assert "instagram" in q["bonus_errored"]+ assert q["bonus_errored"] == ["instagram:no_items"]class TestBearerCredential: