Skip to content

The agent that grows with you

fix(kanban): name worker sessions from task title

KoNit-K56555f88dffd
diff --git a/agent/delegation_context.py b/agent/delegation_context.py
index 4ea7f895f0e..3e31fbedac5 100644
--- a/agent/delegation_context.py
+++ b/agent/delegation_context.py
@@ -20,7 +20,8 @@ _NON_DISPATCHER_OWNED_CONTEXT: ContextVar[bool] = ContextVar("hermes_non_dispatc
DELEGATED_CHILD_ENV_MARKER = "HERMES_DELEGATED_CHILD_CONTEXT"
KANBAN_ENV_KEYS: tuple[str, ...] = (
- "HERMES_KANBAN_TASK", "HERMES_KANBAN_RUN_ID", "HERMES_KANBAN_CLAIM_LOCK",
+ "HERMES_KANBAN_TASK", "HERMES_KANBAN_TASK_TITLE", "HERMES_KANBAN_RUN_ID",
+ "HERMES_KANBAN_CLAIM_LOCK",
"HERMES_KANBAN_GOAL_MODE", "HERMES_KANBAN_GOAL_MAX_TURNS",
)
diff --git a/agent/title_generator.py b/agent/title_generator.py
index 341f2171cd0..451ce8c4252 100644
--- a/agent/title_generator.py
+++ b/agent/title_generator.py
@@ -7,6 +7,7 @@ and neither replaces a name the user typed."""
import json
import logging
+import os
import re
from contextlib import suppress
from typing import Any, Callable, Optional
@@ -478,6 +479,21 @@ def maybe_auto_title(
"""Instant inline title, then a daemon-thread upgrade. Call at the START of a turn, before the model."""
if not session_db or not session_id or not user_message:
return
+ # The dispatcher gives workers the task's human-written title. It is both
+ # more useful than the synthetic worker opener and available without
+ # competing with the worker for an auxiliary model request. Keep the
+ # existing derived < llm < user precedence: a manual title still wins.
+ kanban_task_title = os.environ.get("HERMES_KANBAN_TASK_TITLE", "").strip()
+ if kanban_task_title:
+ try:
+ persisted = _persist_session_title(
+ session_db, session_id, kanban_task_title, source="llm"
+ )
+ if persisted:
+ _notify_title(title_callback, persisted, "llm", "Kanban task title")
+ except Exception:
+ logger.debug("Kanban task title failed", exc_info=True)
+ return
# History may be pre- or post-message. Skip only when BOTH past the opening turn AND named: count alone
# left a machinery-opened session nameless; title alone never titles on an old store.
user_msg_count = sum(1 for m in (conversation_history or []) if _is_real_user_turn(m))
diff --git a/hermes_cli/kanban_db_dispatch.py b/hermes_cli/kanban_db_dispatch.py
index 0a8327b2ae5..fdd5eb0a4e7 100644
--- a/hermes_cli/kanban_db_dispatch.py
+++ b/hermes_cli/kanban_db_dispatch.py
@@ -2327,6 +2327,7 @@ def _default_spawn(task: Task, workspace: str, *, board: Optional[str] = None) -
if task.tenant:
env["HERMES_TENANT"] = task.tenant
env["HERMES_KANBAN_TASK"] = task.id
+ env["HERMES_KANBAN_TASK_TITLE"] = task.title
env["HERMES_KANBAN_WORKSPACE"] = workspace
# Tag the session `kanban` so session-browsing surfaces filter it out by
# source instead of rendering one sidebar row per attempt.
diff --git a/tests/agent/test_title_generator.py b/tests/agent/test_title_generator.py
index 4e04feab951..eac9aa7cba3 100644
--- a/tests/agent/test_title_generator.py
+++ b/tests/agent/test_title_generator.py
@@ -356,6 +356,32 @@ class TestMaybeAutoTitle:
runtime_validator=None,
)
+ def test_kanban_worker_uses_task_title_without_background_llm(self, tmp_path, monkeypatch):
+ """A dispatcher-provided task title is the worker session title, not an LLM prompt."""
+ db = SessionDB(tmp_path / "state.db")
+ db.create_session(session_id="sess-1", source="kanban")
+ monkeypatch.setenv("HERMES_KANBAN_TASK_TITLE", "Fix flaky worker startup")
+
+ with patch("agent.title_generator.auto_title_session") as mock_auto:
+ maybe_auto_title(db, "sess-1", "work kanban task t_b21733fb", [])
+
+ assert db.get_session_title("sess-1") == "Fix flaky worker startup"
+ assert db.get_session_title_source("sess-1") == "llm"
+ mock_auto.assert_not_called()
+
+ def test_kanban_task_title_keeps_manual_title_precedence(self, tmp_path, monkeypatch):
+ db = SessionDB(tmp_path / "state.db")
+ db.create_session(session_id="sess-1", source="kanban")
+ db.set_session_title("sess-1", "Operator-selected title")
+ monkeypatch.setenv("HERMES_KANBAN_TASK_TITLE", "Fix flaky worker startup")
+
+ with patch("agent.title_generator.auto_title_session") as mock_auto:
+ maybe_auto_title(db, "sess-1", "work kanban task t_b21733fb", [])
+
+ assert db.get_session_title("sess-1") == "Operator-selected title"
+ assert db.get_session_title_source("sess-1") == "user"
+ mock_auto.assert_not_called()
+
def test_writes_instant_title_before_the_model_runs(self, tmp_path):
"""The derived title lands synchronously — no LLM, no waiting."""
db = SessionDB(tmp_path / "state.db")
diff --git a/tests/conftest.py b/tests/conftest.py
index 0fd5ef8e693..7eb78b0c039 100644
--- a/tests/conftest.py
+++ b/tests/conftest.py
@@ -312,6 +312,7 @@ _HERMES_BEHAVIORAL_VARS = frozenset({
"HERMES_KANBAN_WORKSPACES_ROOT",
"HERMES_KANBAN_LOGS_ROOT",
"HERMES_KANBAN_TASK",
+ "HERMES_KANBAN_TASK_TITLE",
"HERMES_KANBAN_WORKSPACE",
"HERMES_KANBAN_RUN_ID",
"HERMES_KANBAN_CLAIM_LOCK",
diff --git a/tests/hermes_cli/test_kanban_worker_session_source.py b/tests/hermes_cli/test_kanban_worker_session_source.py
index eae44b4615a..5b5293cfbaa 100644
--- a/tests/hermes_cli/test_kanban_worker_session_source.py
+++ b/tests/hermes_cli/test_kanban_worker_session_source.py
@@ -61,6 +61,7 @@ def test_worker_spawn_tags_session_source_kanban(monkeypatch, tmp_path):
kbd._default_spawn(task, workspace)
assert captured["env"]["HERMES_SESSION_SOURCE"] == "kanban"
+ assert captured["env"]["HERMES_KANBAN_TASK_TITLE"] == "ship it"
def test_kanban_rows_stay_out_of_the_session_list(db):