The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(kanban): backfill legacy gateway notify subs to notify+wake on first migration
Teknium0818086c50c0
diff --git a/contributors/emails/[email protected] b/contributors/emails/[email protected]new file mode 100644index 00000000000..4236bbac665--- /dev/null+++ b/contributors/emails/[email protected]@@ -0,0 +1 @@+verybigdogdiff --git a/hermes_cli/kanban_db.py b/hermes_cli/kanban_db.pyindex a0b2211bfe4..b950320328b 100644--- a/hermes_cli/kanban_db.py+++ b/hermes_cli/kanban_db.py@@ -2689,6 +2689,19 @@ def _migrate_add_optional_columns(conn: sqlite3.Connection) -> None:"delivery_mode","delivery_mode TEXT NOT NULL DEFAULT 'notify'",)+ # Backfill: before this column existed, the notifier woke the+ # originating session unconditionally whenever the task carried a+ # session_id — every pre-existing gateway subscription had de+ # facto active wake. Defaulting them to plain 'notify' would+ # silently disable that behavior on upgrade. TUI/CLI rows keep+ # 'notify' (matching _maybe_auto_subscribe, which only requests+ # 'notify+wake' for gateway sessions). Runs ONLY on first-add of+ # the column, so a user's later explicit downgrade is never+ # overwritten by a re-migration.+ conn.execute(+ "UPDATE kanban_notify_subs SET delivery_mode = 'notify+wake' "+ "WHERE platform != 'tui'"+ )if "chat_type" not in notify_cols:_add_column_if_missing(conn,diff --git a/tests/hermes_cli/test_kanban_notify.py b/tests/hermes_cli/test_kanban_notify.pyindex 6a53fa16eba..b104d0f9eab 100644--- a/tests/hermes_cli/test_kanban_notify.py+++ b/tests/hermes_cli/test_kanban_notify.py@@ -869,3 +869,73 @@ async def test_notifier_artifact_delivery_skips_missing_files(kanban_home, tmp_p# Only the real file was uploaded.assert len(documents_uploaded) == 1assert "real.pdf" in documents_uploaded[0]+++# ---------------------------------------------------------------------------+# Migration backfill: pre-delivery_mode gateway subscriptions keep active wake.+#+# Before the delivery_mode column existed, the notifier woke the originating+# session unconditionally whenever the task carried a session_id — so every+# pre-existing gateway subscription had de facto active wake. The column's+# 'notify' DEFAULT alone would silently disable that on upgrade. The migration+# backfills first-add rows: gateway platforms -> 'notify+wake', tui -> 'notify'.+# ---------------------------------------------------------------------------+++def test_migration_backfills_legacy_gateway_subs_to_notify_wake(kanban_home):+ from hermes_cli.kanban_db import _migrate_add_optional_columns++ with kb.connect() as conn:+ task_id = kb.create_task(conn, title="legacy sub upgrade")+ # Simulate a pre-delivery_mode database: drop the column entirely,+ # then insert legacy-shaped rows (one gateway, one tui).+ conn.execute("ALTER TABLE kanban_notify_subs DROP COLUMN delivery_mode")+ conn.execute(+ "INSERT INTO kanban_notify_subs "+ "(task_id, platform, chat_id, thread_id, created_at) "+ "VALUES (?, 'telegram', 'legacy-chat', '', 1)",+ (task_id,),+ )+ conn.execute(+ "INSERT INTO kanban_notify_subs "+ "(task_id, platform, chat_id, thread_id, created_at) "+ "VALUES (?, 'tui', 'tui-session-1', '', 1)",+ (task_id,),+ )+ # Re-run the idempotent migration: first-add of delivery_mode must+ # backfill gateway rows to notify+wake and leave tui rows on notify.+ _migrate_add_optional_columns(conn)+ rows = {+ r["platform"]: r["delivery_mode"]+ for r in conn.execute(+ "SELECT platform, delivery_mode FROM kanban_notify_subs "+ "WHERE task_id = ?",+ (task_id,),+ )+ }+ assert rows["telegram"] == "notify+wake", (+ "Legacy gateway subscription lost active wake across the upgrade"+ )+ assert rows["tui"] == "notify"+++def test_migration_backfill_runs_only_on_first_add(kanban_home):+ from hermes_cli.kanban_db import _migrate_add_optional_columns++ with kb.connect() as conn:+ task_id = kb.create_task(conn, title="explicit downgrade survives")+ kb.add_notify_sub(+ conn,+ task_id=task_id,+ platform="telegram",+ chat_id="chat-x",+ delivery_mode="notify",+ )+ # Column already exists -> re-running the migration must NOT touch+ # the user's explicit 'notify' choice.+ _migrate_add_optional_columns(conn)+ row = conn.execute(+ "SELECT delivery_mode FROM kanban_notify_subs WHERE task_id = ?",+ (task_id,),+ ).fetchone()+ assert row["delivery_mode"] == "notify"