Skip to content

The agent that grows with you

fix(kanban): read the worker's card title from the board instead of a new env var

teknium1c12a3397b163
diff --git a/agent/delegation_context.py b/agent/delegation_context.py
index 3e31fbedac5..4ea7f895f0e 100644
--- a/agent/delegation_context.py
+++ b/agent/delegation_context.py
@@ -20,8 +20,7 @@ _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_TASK_TITLE", "HERMES_KANBAN_RUN_ID",
- "HERMES_KANBAN_CLAIM_LOCK",
+ "HERMES_KANBAN_TASK", "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 451ce8c4252..9c62f91096e 100644
--- a/agent/title_generator.py
+++ b/agent/title_generator.py
@@ -466,6 +466,22 @@ def _session_is_untitled(session_db, session_id: str) -> bool:
return False
+def _kanban_task_title() -> Optional[str]:
+ """Kanban worker: the card's title, or ``Kanban task <id>`` when the board can't be read; None elsewhere."""
+ task_id = (os.environ.get("HERMES_KANBAN_TASK") or "").strip()
+ if not task_id:
+ return None
+ try:
+ from hermes_cli import kanban_db, kanban_db_connect
+ with kanban_db_connect.connect_closing() as conn:
+ task = kanban_db.get_task(conn, task_id)
+ title = (task.title or "").strip() if task is not None else ""
+ except Exception:
+ logger.debug("Kanban task %s unreadable; naming the session after its id", task_id, exc_info=True)
+ title = ""
+ return title or f"Kanban task {task_id}"
+
+
def maybe_auto_title(
session_db,
session_id: str,
@@ -479,25 +495,22 @@ 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))
- if (user_msg_count > 1 and not _session_is_untitled(session_db, session_id)) or not is_titleable_user_message(user_message):
+ if user_msg_count > 1 and not _session_is_untitled(session_db, session_id):
+ return
+ kanban_title = _kanban_task_title()
+ if kanban_title:
+ # The card already carries a human-written name; an auxiliary model call per spawned worker
+ # only competes with the worker for capacity (#111166). Final (``llm``) authority: nothing
+ # upgrades it later, and a manual ``/title`` still wins inside ``set_auto_title``.
+ with suppress(Exception):
+ persisted = _persist_session_title(session_db, session_id, kanban_title, source="llm")
+ if persisted:
+ _notify_title(title_callback, persisted, "llm", "Kanban task title")
+ return
+ if not is_titleable_user_message(user_message):
return
if not _auto_title_enabled(): # config read after the cheap guards so the file isn't touched every turn
logger.debug("Auto-title skipped: auxiliary.title_generation.enabled=false")
diff --git a/hermes_cli/kanban_db_dispatch.py b/hermes_cli/kanban_db_dispatch.py
index fdd5eb0a4e7..0a8327b2ae5 100644
--- a/hermes_cli/kanban_db_dispatch.py
+++ b/hermes_cli/kanban_db_dispatch.py
@@ -2327,7 +2327,6 @@ 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 eac9aa7cba3..15b16c39332 100644
--- a/tests/agent/test_title_generator.py
+++ b/tests/agent/test_title_generator.py
@@ -356,30 +356,33 @@ 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."""
+ def test_kanban_worker_is_named_after_its_card_without_the_llm_thread(self, tmp_path, monkeypatch):
+ """A worker's session takes the board card's title synchronously; no auxiliary model call (#111166)."""
+ from hermes_cli import kanban_db, kanban_db_connect
+
+ with kanban_db_connect.connect_closing(board="default") as conn:
+ task_id = kanban_db.create_task(conn, title="Fix flaky worker startup", board="default")
+ conn.commit()
+ monkeypatch.setenv("HERMES_KANBAN_TASK", task_id)
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", [])
+ maybe_auto_title(db, "sess-1", f"work kanban task {task_id}", [])
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):
+ def test_kanban_worker_with_unreadable_card_falls_back_to_the_task_id(self, tmp_path, monkeypatch):
+ monkeypatch.setenv("HERMES_KANBAN_TASK", "t_missing")
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", [])
+ maybe_auto_title(db, "sess-1", "work kanban task t_missing", [])
- assert db.get_session_title("sess-1") == "Operator-selected title"
- assert db.get_session_title_source("sess-1") == "user"
+ assert db.get_session_title("sess-1") == "Kanban task t_missing"
mock_auto.assert_not_called()
def test_writes_instant_title_before_the_model_runs(self, tmp_path):
diff --git a/tests/conftest.py b/tests/conftest.py
index 7eb78b0c039..0fd5ef8e693 100644
--- a/tests/conftest.py
+++ b/tests/conftest.py
@@ -312,7 +312,6 @@ _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 5b5293cfbaa..eae44b4615a 100644
--- a/tests/hermes_cli/test_kanban_worker_session_source.py
+++ b/tests/hermes_cli/test_kanban_worker_session_source.py
@@ -61,7 +61,6 @@ 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):