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: preserve watchlist settings when saving research (#1206)

Ilia Alshanetskyf9048d80832c
diff --git a/changelog.d/+cr-011-watchlist-config.fixed.md b/changelog.d/+cr-011-watchlist-config.fixed.md
new file mode 100644
index 00000000..aaee20b7
--- /dev/null
+++ b/changelog.d/+cr-011-watchlist-config.fixed.md
@@ -0,0 +1 @@
+Saving research preserves an existing watchlist topic's custom queries and schedule.
diff --git a/skills/last30days/scripts/last30days.py b/skills/last30days/scripts/last30days.py
index e5957a6e..7190706f 100644
--- a/skills/last30days/scripts/last30days.py
+++ b/skills/last30days/scripts/last30days.py
@@ -640,7 +640,7 @@ def persist_report(report: schema.Report, store_db: Path | None = None) -> dict[
store.init_db()
if private_corpus:
store.ensure_private_db_files()
- topic_row = store.add_topic(report.topic)
+ topic_row = store.add_topic(report.topic, update_existing=False)
topic_id = topic_row["id"]
source_mode = ",".join(sorted(report.items_by_source)) or "v3"
run_id = store.record_run(topic_id, source_mode=source_mode, status="running")
diff --git a/skills/last30days/scripts/store.py b/skills/last30days/scripts/store.py
index 55faccc8..b7a04179 100644
--- a/skills/last30days/scripts/store.py
+++ b/skills/last30days/scripts/store.py
@@ -298,8 +298,10 @@ def add_topic(
name: str,
search_queries: Optional[List[str]] = None,
schedule: str = "0 8 * * *",
+ *,
+ update_existing: bool = True,
) -> Dict[str, Any]:
- """Add a topic to the watchlist. Returns the topic dict."""
+ """Add a topic, optionally preserving an existing topic's configuration."""
init_db()
conn = _connect()
try:
@@ -310,8 +312,9 @@ def add_topic(
ON CONFLICT(name) DO UPDATE SET
search_queries = excluded.search_queries,
schedule = excluded.schedule,
- updated_at = datetime('now')""",
- (name, queries_json, schedule),
+ updated_at = datetime('now')
+ WHERE ?""",
+ (name, queries_json, schedule, update_existing),
)
conn.commit()
row = conn.execute(
diff --git a/tests/test_store.py b/tests/test_store.py
index 777c9b0b..4e44c918 100644
--- a/tests/test_store.py
+++ b/tests/test_store.py
@@ -765,6 +765,47 @@ def test_add_topic_with_search_queries(temp_db):
assert json.loads(topic["search_queries"]) == ["query1", "query2"]
+def test_persist_report_preserves_existing_watchlist_settings(temp_db, sample_report):
+ import last30days as cli
+
+ topic = store.add_topic(
+ sample_report.topic,
+ search_queries=["custom research query"],
+ schedule="0 8 * * 1",
+ )
+ before = store.get_topic(sample_report.topic)
+
+ counts = cli.persist_report(sample_report, store_db=temp_db)
+
+ after = store.get_topic(sample_report.topic)
+ assert after == before
+ assert after["id"] == topic["id"]
+ assert counts["new"] > 0
+ assert store.get_new_findings(topic["id"])
+
+
+def test_persist_report_creates_a_missing_watchlist_topic(temp_db, sample_report):
+ import last30days as cli
+
+ assert store.get_topic(sample_report.topic) is None
+
+ counts = cli.persist_report(sample_report, store_db=temp_db)
+
+ topic = store.get_topic(sample_report.topic)
+ assert topic["schedule"] == "0 8 * * *"
+ assert counts["new"] > 0
+
+
+def test_add_topic_still_updates_explicit_watchlist_configuration(temp_db):
+ first = store.add_topic("Configured topic", search_queries=["old"], schedule="0 8 * * 1")
+
+ updated = store.add_topic("Configured topic", search_queries=["new"], schedule="0 9 * * 2")
+
+ assert updated["id"] == first["id"]
+ assert json.loads(updated["search_queries"]) == ["new"]
+ assert updated["schedule"] == "0 9 * * 2"
+
+
def test_remove_topic_cascades_findings(temp_db, sample_report):
"""Test that removing a topic deletes its findings and runs."""
topic = store.add_topic("Test Topic")