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(pipeline): stop adding jobs to host-supplied query plans (#1258)

Matt Van Horn15a137ffce0f
diff --git a/changelog.d/+host-plan-jobs.fixed.md b/changelog.d/+host-plan-jobs.fixed.md
new file mode 100644
index 00000000..a5cca192
--- /dev/null
+++ b/changelog.d/+host-plan-jobs.fixed.md
@@ -0,0 +1 @@
+A host-supplied query plan now searches only the sources it names: company topics no longer get an unrequested jobs lane added to it. A plan that names jobs keeps jobs on any topic, and hiring-signals mode with a host plan runs the jobs lane instead of failing with "No available planned sources remain".
diff --git a/skills/last30days/scripts/lib/pipeline.py b/skills/last30days/scripts/lib/pipeline.py
index 46ed4243..2f67f43f 100644
--- a/skills/last30days/scripts/lib/pipeline.py
+++ b/skills/last30days/scripts/lib/pipeline.py
@@ -2308,6 +2308,10 @@ def run(
# assign it (eligible_sources = available ∩ capabilities).
config["_financial_topic"] = stocktwits.is_financial_topic(topic)
+ # A host-supplied plan's source lists are final: company-topic jobs is an
+ # automatic lane only for engine-planned runs.
+ host_plan = external_plan is not None
+ auto_company_jobs = not host_plan and _company_topic_likely(topic)
if mock:
runtime = providers.mock_runtime(config, depth)
reasoning_provider = None
@@ -2316,7 +2320,7 @@ def run(
available.append("corpus")
if not corpus_enabled and not corpus_requested:
available = [source for source in available if source != "corpus"]
- if not requested_sources and not hiring_signals_mode and not _company_topic_likely(topic):
+ if not requested_sources and not hiring_signals_mode and not auto_company_jobs:
available = [source for source in available if source != "jobs"]
else:
runtime, reasoning_provider = providers.resolve_runtime(config, depth)
@@ -2338,9 +2342,17 @@ def run(
available.append("grounding")
if (
hiring_signals_mode
- or (not requested_sources and _company_topic_likely(topic))
+ or (not requested_sources and auto_company_jobs)
) and "jobs" not in available:
available.append("jobs")
+ if (
+ host_plan
+ and not requested_sources
+ and "jobs" not in available
+ and "jobs" not in excluded_sources
+ and _external_plan_names_source(external_plan, "jobs")
+ ):
+ available.append("jobs")
if hiring_signals_mode:
config = dict(config)
config["_hiring_signals_mode"] = True
@@ -2357,6 +2369,15 @@ def run(
# External plan provided (e.g., from Claude Code via --plan flag).
# Explicit input is a contract: validate it before permissive sanitization.
planner.validate_external_plan(external_plan)
+ if hiring_signals_mode:
+ # Hiring-signals mode always runs the jobs lane. Add it before
+ # sanitizing: with a jobs-only source set, sanitize would drop every
+ # subquery that does not already name jobs.
+ external_plan = copy.deepcopy(external_plan)
+ for subquery in external_plan["subqueries"]:
+ sources = subquery.setdefault("sources", [])
+ if isinstance(sources, list) and "jobs" not in sources:
+ sources.append("jobs")
plan = planner._sanitize_plan(
external_plan, topic, available, planner_requested_sources, depth,
honor_plan_sources=True,
@@ -2395,9 +2416,10 @@ def run(
for sq in plan.subqueries:
if "grounding" not in sq.sources:
sq.sources.append("grounding")
- if "drill-mode" not in plan.notes:
+ if "drill-mode" not in plan.notes and (not host_plan or hiring_signals_mode):
# Drill plans re-fetch only the sources that contributed to the matched
- # cluster; the company-topic jobs injection must not widen that set.
+ # cluster, and host plans name their final source set; the company-topic
+ # jobs injection must not widen either.
_ensure_jobs_in_plan(plan, available, explicit=hiring_signals_mode, topic=topic)
_ensure_devto_in_plan(plan, available)
if "corpus" in available and plan.subqueries:
@@ -3735,6 +3757,20 @@ def _ensure_devto_in_plan(plan: schema.QueryPlan, available: list[str]) -> None:
plan.source_weights = planner._normalize_weights(plan.source_weights)
+def _external_plan_names_source(external_plan: Any, source: str) -> bool:
+ if not isinstance(external_plan, dict):
+ return False
+ subqueries = external_plan.get("subqueries")
+ if not isinstance(subqueries, list):
+ return False
+ return any(
+ isinstance(subquery, dict)
+ and isinstance(subquery.get("sources"), list)
+ and source in subquery["sources"]
+ for subquery in subqueries
+ )
+
+
def _ensure_jobs_in_plan(
plan: schema.QueryPlan,
available: list[str],
diff --git a/tests/test_drill_mode.py b/tests/test_drill_mode.py
index 21b3b06b..846933d1 100644
--- a/tests/test_drill_mode.py
+++ b/tests/test_drill_mode.py
@@ -477,7 +477,7 @@ def test_drill_plan_does_not_gain_jobs_via_company_topic(monkeypatch, drill):
as_of_date="2026-07-10",
)
- expected = {"youtube"} if drill else {"youtube", "jobs"}
+ expected = {"youtube"}
assert report.query_plan.subqueries
assert all(set(subquery.sources) == expected for subquery in report.query_plan.subqueries)
diff --git a/tests/test_external_plan_source_contract.py b/tests/test_external_plan_source_contract.py
index 08c0b372..ca618407 100644
--- a/tests/test_external_plan_source_contract.py
+++ b/tests/test_external_plan_source_contract.py
@@ -53,3 +53,66 @@ def test_internal_empty_intersection_retains_fallback():
plan_with(["instagram"]), "test topic", ["reddit", "hackernews"], None, "default",
)
assert plan.subqueries[0].sources == ["reddit", "hackernews"]
+
+
+def _run_with_plan(topic, plan, **kwargs):
+ with patch.object(pipeline, "_retrieve_stream", return_value=([], {})) as retrieve:
+ report = pipeline.run(
+ topic=topic, config={}, mock=True, web_backend="none",
+ depth="default", external_plan=plan, **kwargs,
+ )
+ return report, {call.kwargs["source"] for call in retrieve.call_args_list}
+
+
+def test_host_plan_on_company_topic_does_not_gain_jobs():
+ report, fetched = _run_with_plan(
+ "Listen Labs", plan_with(["reddit", "youtube"], ["hackernews"]),
+ )
+ assert [sq.sources for sq in report.query_plan.subqueries] == [
+ ["reddit", "youtube"], ["hackernews"],
+ ]
+ assert "jobs" not in fetched
+ assert "jobs" not in report.source_status
+
+
+def test_host_plan_naming_jobs_keeps_it_on_non_company_topic():
+ report, fetched = _run_with_plan(
+ "test topic", plan_with(["reddit", "jobs"], ["hackernews"]),
+ )
+ assert [sq.sources for sq in report.query_plan.subqueries] == [
+ ["reddit", "jobs"], ["hackernews"],
+ ]
+ assert "jobs" in fetched
+
+
+def test_host_plan_naming_jobs_does_not_override_excluded_jobs():
+ with patch.object(pipeline, "_retrieve_stream", return_value=([], {})) as retrieve:
+ report = pipeline.run(
+ topic="test topic", config={"EXCLUDE_SOURCES": "jobs"}, mock=True,
+ web_backend="none", depth="default",
+ external_plan=plan_with(["reddit", "jobs"], ["hackernews"]),
+ )
+ fetched = {call.kwargs["source"] for call in retrieve.call_args_list}
+ assert [sq.sources for sq in report.query_plan.subqueries] == [
+ ["reddit"], ["hackernews"],
+ ]
+ assert "jobs" not in fetched
+
+
+def test_hiring_mode_adds_jobs_to_host_plan_without_it():
+ report, fetched = _run_with_plan(
+ "Listen Labs", plan_with(["reddit"], ["hackernews"]),
+ hiring_signals_mode=True,
+ )
+ assert len(report.query_plan.subqueries) == 2
+ assert all("jobs" in sq.sources for sq in report.query_plan.subqueries)
+ assert "jobs" in fetched
+
+
+def test_hiring_mode_does_not_duplicate_jobs_already_in_host_plan():
+ report, _ = _run_with_plan(
+ "Listen Labs", plan_with(["reddit", "jobs"], ["jobs"]),
+ hiring_signals_mode=True,
+ )
+ assert len(report.query_plan.subqueries) == 2
+ assert all(sq.sources.count("jobs") == 1 for sq in report.query_plan.subqueries)