{"repo":"NousResearch/hermes-agent","public_id":"8568","display_label":"Background task visibility and status indicators","summary":"These items address the lack of observable state for background tasks, including a status bar indicator for running tasks and a proposed namespace for background task observability in the CLI.","subsystem":"hermes_cli","kind":"feature","counts":{"members":4,"open_issues":0,"open_issues_distinct":0,"open_prs":1,"closed_issues":1,"merged_prs":1,"attempt_prs":2},"landed_fix":{"status":"merged_to_main","basis":"structural","pr":27175,"merged_at":"2026-05-16T23:51:29+00:00"},"resolution":{"state":"unresolved","by":null},"freshness":{"state":"stale","last_verified_at":"2026-05-16T23:51:29+00:00","is_stale":true},"grouping":{"backbone":"STRUCTURAL_SPANNING","link_density":0.5},"fix_edges":[{"issue_number":8568,"pr_number":27175,"tier":"verified","basis":"superseded_ref","confidence":0.9,"recoverable_from_timeline":false,"pr_merged_at":"2026-05-16T23:51:29+00:00"}],"members":[{"kind":"issue","number":8568,"title":"[Bug]: Background tasks have no observable state — no logs, no file list, no session context for foreground agent","url":null,"state":"closed"},{"kind":"pr","number":8592,"title":"feat(cli): background task observability and /bg namespace","url":null,"state":"closed","close_reason":{"refs":[{"kind":"pr","value":"#27175","number":27175},{"kind":"pr","value":"#8568","number":8568}],"category":"superseded_by_pr","implication":"superseded"},"merged":false},{"kind":"pr","number":27175,"title":"feat(cli): show ▶ N indicator in status bar for running /background tasks","url":null,"state":"merged","close_reason":{"category":"merged"},"merged":true,"is_fix_pr":true,"fix_tier":"verified","files_changed":["cli.py","tests/cli/test_cli_background_status_indicator.py"],"fix_hunks":[{"file":"cli.py","hunks":["@@ -3113,8 +3113,19 @@ def _get_status_bar_snapshot(self) -> Dict[str, Any]:\n             \"session_total_tokens\": 0,\n             \"session_api_calls\": 0,\n             \"compressions\": 0,\n+            \"active_background_tasks\": 0,\n         }\n \n+        # Count live /background tasks. The dict entry is removed in the\n+        # task thread's finally block, so len() reflects truly-running tasks.\n+        # len() on a CPython dict is atomic; safe to read without a lock.\n+        try:\n+            bg_tasks = getattr(self, \"_background_tasks\", None)\n+            if bg_tasks:\n+                snapshot[\"active_background_tasks\"] = len(bg_tasks)\n+        except Exception:\n+            pass\n+\n         if not agent:\n             return snapshot\n ","@@ -3350,6 +3361,9 @@ def _build_status_bar_text(self, width: Optional[int] = None) -> str:\n                 compressions = snapshot.get(\"compressions\", 0)\n                 if compressions:\n                     parts.append(f\"🗜️ {compressions}\")\n+                bg_count = snapshot.get(\"active_background_tasks\", 0)\n+                if bg_count:\n+                    parts.append(f\"▶ {bg_count}\")\n                 parts.append(duration_label)\n                 if yolo_active:\n                     parts.append(\"⚠ YOLO\")","@@ -3366,6 +3380,9 @@ def _build_status_bar_text(self, width: Optional[int] = None) -> str:\n             parts = [f\"⚕ {snapshot['model_short']}\", context_label, percent_label]\n             if compressions:\n                 parts.append(f\"🗜️ {compressions}\")\n+            bg_count = snapshot.get(\"active_background_tasks\", 0)\n+            if bg_count:\n+                parts.append(f\"▶ {bg_count}\")\n             parts.append(duration_label)\n             prompt_elapsed = snapshot.get(\"prompt_elapsed\")\n             if prompt_elapsed:","@@ -3406,6 +3423,7 @@ def _get_status_bar_fragments(self):\n                 percent_label = f\"{percent}%\" if percent is not None else \"--\"\n                 if width < 76:\n                     compressions = snapshot.get(\"compressions\", 0)\n+                    bg_count = snapshot.get(\"active_background_tasks\", 0)\n                     frags = [\n                         (\"class:status-bar\", \" ⚕ \"),\n                         (\"class:status-bar-strong\", snapshot[\"model_short\"]),","@@ -3415,6 +3433,9 @@ def _get_status_bar_fragments(self):\n                     if compressions:\n                         frags.append((\"class:status-bar-dim\", \" · \"))\n                         frags.append((self._compression_count_style(compressions), f\"🗜️ {compressions}\"))\n+                    if bg_count:\n+                        frags.append((\"class:status-bar-dim\", \" · \"))\n+                        frags.append((\"class:status-bar-strong\", f\"▶ {bg_count}\"))\n                     frags.extend([\n                         (\"class:status-bar-dim\", \" · \"),\n                         (\"class:status-bar-dim\", duration_label),","@@ -3433,6 +3454,7 @@ def _get_status_bar_fragments(self):\n \n                     bar_style = self._status_bar_context_style(percent)\n                     compressions = snapshot.get(\"compressions\", 0)\n+                    bg_count = snapshot.get(\"active_background_tasks\", 0)\n                     frags = [\n                         (\"class:status-bar\", \" ⚕ \"),\n                         (\"class:status-bar-strong\", snapshot[\"model_short\"]),","@@ -3446,6 +3468,9 @@ def _get_status_bar_fragments(self):\n                     if compressions:\n                         frags.append((\"class:status-bar-dim\", \" │ \"))\n                         frags.append((self._compression_count_style(compressions), f\"🗜️ {compressions}\"))\n+                    if bg_count:\n+                        frags.append((\"class:status-bar-dim\", \" │ \"))\n+                        frags.append((\"class:status-bar-strong\", f\"▶ {bg_count}\"))\n                     frags.extend([\n                         (\"class:status-bar-dim\", \" │ \"),\n                         (\"class:status-bar-dim\", duration_label),"]},{"file":"tests/cli/test_cli_background_status_indicator.py","hunks":["@@ -0,0 +1,104 @@\n+\"\"\"Tests for the /background indicator in the CLI status bar.\n+\n+The classic prompt_toolkit status bar shows `▶ N` when N tasks launched via\n+`/background` are still running. Source of truth is `self._background_tasks`\n+(a Dict[str, threading.Thread]); entries are removed in the task thread's\n+finally block, so len() reflects truly-running tasks.\n+\"\"\"\n+\n+import threading\n+from datetime import datetime\n+\n+from cli import HermesCLI\n+\n+\n+def _stub_thread() -> threading.Thread:\n+    \"\"\"Return a Thread instance that's never started — pure dict-value stand-in.\"\"\"\n+    return threading.Thread(target=lambda: None)\n+\n+\n+def _make_cli():\n+    \"\"\"Bare-metal HermesCLI for snapshot/build tests (no __init__ side effects).\"\"\"\n+    cli_obj = HermesCLI.__new__(HermesCLI)\n+    cli_obj.model = \"anthropic/claude-opus-4.6\"\n+    cli_obj.agent = None\n+    cli_obj._background_tasks = {}\n+    # The snapshot reads session_start to compute duration; supply a stub.\n+    cli_obj.session_start = datetime.now()\n+    return cli_obj\n+\n+\n+def test_snapshot_reports_zero_when_no_background_tasks():\n+    cli_obj = _make_cli()\n+    snap = cli_obj._get_status_bar_snapshot()\n+    assert snap[\"active_background_tasks\"] == 0\n+\n+\n+def test_snapshot_counts_live_background_tasks():\n+    cli_obj = _make_cli()\n+    cli_obj._background_tasks = {\"bg_a\": _stub_thread(), \"bg_b\": _stub_thread()}\n+    snap = cli_obj._get_status_bar_snapshot()\n+    assert snap[\"active_background_tasks\"] == 2\n+\n+\n+def test_snapshot_safe_when_background_tasks_attr_missing():\n+    \"\"\"Older HermesCLI instances (tests with __new__, etc.) may lack the attr.\"\"\"\n+    cli_obj = HermesCLI.__new__(HermesCLI)\n+    cli_obj.model = \"x\"\n+    cli_obj.agent = None\n+    cli_obj.session_start = datetime.now()\n+    # No _background_tasks at all — must not raise.\n+    snap = cli_obj._get_status_bar_snapshot()\n+    assert snap[\"active_background_tasks\"] == 0\n+\n+\n+def test_plain_text_status_omits_indicator_when_idle():\n+    cli_obj = _make_cli()\n+    text = cli_obj._build_status_bar_text(width=80)\n+    assert \"▶\" not in text\n+\n+\n+def test_plain_text_status_shows_indicator_when_active():\n+    cli_obj = _make_cli()\n+    cli_obj._background_tasks = {\"bg_a\": _stub_thread()}\n+    text = cli_obj._build_status_bar_text(width=80)\n+    assert \"▶ 1\" in text\n+\n+\n+def test_plain_text_status_shows_higher_count():\n+    cli_obj = _make_cli()\n+    cli_obj._background_tasks = {\n+        \"a\": _stub_thread(),\n+        \"b\": _stub_thread(),\n+        \"c\": _stub_thread(),\n+    }\n+    text = cli_obj._build_status_bar_text(width=80)\n+    assert \"▶ 3\" in text\n+\n+\n+def test_narrow_width_omits_bg_indicator():\n+    \"\"\"The narrow tier (<52) is already cramped — bg is secondary, drop it.\"\"\"\n+    cli_obj = _make_cli()\n+    cli_obj._background_tasks = {\"bg_a\": _stub_thread()}\n+    text = cli_obj._build_status_bar_text(width=40)\n+    assert \"▶\" not in text\n+\n+\n+def test_fragments_include_bg_segment_when_active():\n+    cli_obj = _make_cli()\n+    cli_obj._background_tasks = {\"a\": _stub_thread(), \"b\": _stub_thread()}\n+    cli_obj._status_bar_visible = True\n+    # _get_status_bar_fragments asks _get_tui_terminal_width(); stub it wide.\n+    cli_obj._get_tui_terminal_width = lambda: 120  # type: ignore[method-assign]\n+    frags = cli_obj._get_status_bar_fragments()\n+    rendered = \"\".join(text for _style, text in frags)\n+    assert \"▶ 2\" in rendered\n+\n+\n+def test_fragments_omit_bg_segment_when_idle():\n+    cli_obj = _make_cli()\n+    cli_obj._status_bar_visible = True\n+    cli_obj._get_tui_terminal_width = lambda: 120  # type: ignore[method-assign]\n+    frags = cli_obj._get_status_bar_fragments()\n+    rendered = \"\".join(text for _style, text in frags)\n+    assert \"▶\" not in rendered\n"]}]},{"kind":"pr","number":139826,"title":"fix(cli): /agents lists the /bg background sessions of this process","url":null,"state":"open","close_reason":{"category":"silent_close","implication":"active"},"merged":false}],"trust":{"default_tier":"verified","includes_suggested":false}}