Skip to content

The agent that grows with you

fix(kanban): point bare kanban_show/comment calls at kanban_list outside a worker

Brooklyn Nicholsond104a2005ae6
diff --git a/tests/tools/test_kanban_tools.py b/tests/tools/test_kanban_tools.py
index ec2ecbaa476..d295ff2205b 100644
--- a/tests/tools/test_kanban_tools.py
+++ b/tests/tools/test_kanban_tools.py
@@ -82,6 +82,65 @@ def test_show_defaults_to_env_task_id(worker_env):
assert "runs" in d
+def test_show_bare_call_outside_worker_returns_orientation_not_error(monkeypatch, worker_env):
+ """#91431: chat profiles with the kanban toolset call kanban_show bare to orient
+ themselves; with no dispatcher task in scope there is nothing to show, so the
+ answer must be a pointer to kanban_list — not an error naming an env var no
+ chat caller can set."""
+ monkeypatch.delenv("HERMES_KANBAN_TASK", raising=False)
+ from tools import kanban_tools as kt
+ out = json.loads(kt._handle_show({}))
+ assert "error" not in out, out
+ assert out.get("current_task") is None
+ assert "kanban_list" in out["hint"]
+
+
+def test_comment_bare_call_outside_worker_names_kanban_list(monkeypatch, worker_env):
+ """#91431 sibling: a comment cannot post without a target task, so a bare call
+ stays an error — but the error must point at kanban_list instead of the env."""
+ monkeypatch.delenv("HERMES_KANBAN_TASK", raising=False)
+ from tools import kanban_tools as kt
+ out = json.loads(kt._handle_comment({"body": "hello"}))
+ assert out.get("error"), out
+ assert "kanban_list" in out["error"]
+ assert "set HERMES_KANBAN_TASK" not in out["error"]
+
+
+def test_worker_tool_bare_call_outside_worker_error_is_actionable(monkeypatch, worker_env):
+ """#91431 sibling: the mutation/lifecycle tools still require a target, but the
+ rejection a non-worker receives must name what it can do (kanban_list), not the
+ env var it cannot set."""
+ monkeypatch.delenv("HERMES_KANBAN_TASK", raising=False)
+ from tools import kanban_tools as kt
+ for handler, name in ((kt._handle_heartbeat, "kanban_heartbeat"),
+ (kt._handle_attachments, "kanban_attachments")):
+ out = json.loads(handler({}))
+ assert out.get("error"), (name, out)
+ assert "kanban_list" in out["error"], (name, out)
+ assert "set HERMES_KANBAN_TASK" not in out["error"], (name, out)
+
+
+def test_kanban_task_id_descriptions_state_the_non_worker_case():
+ """#91431 contract: any task_id description that promises the HERMES_KANBAN_TASK
+ default must also say the default only exists for dispatcher-spawned workers —
+ an unqualified invite to omit the argument is what made chat profiles call bare."""
+ from tools import kanban_tools_schemas as kts
+
+ seen = []
+ for attr, schema in vars(kts).items():
+ if not (attr.startswith("KANBAN_") and attr.endswith("_SCHEMA")):
+ continue
+ desc = (schema["parameters"]["properties"].get("task_id") or {}).get("description") or ""
+ if "HERMES_KANBAN_TASK" not in desc:
+ continue
+ assert "worker" in desc, (
+ schema["name"], "env default promised without the non-worker case (#91431)")
+ assert "no default" in desc or "orientation" in desc, (
+ schema["name"], "must state what a non-worker bare call does (#91431)")
+ seen.append(schema["name"])
+ assert "kanban_show" in seen
+
+
def test_list_filters_tasks(monkeypatch, worker_env):
"""kanban_list gives orchestrators filtered board discovery."""
monkeypatch.delenv("HERMES_KANBAN_TASK", raising=False)
diff --git a/tools/kanban_tools.py b/tools/kanban_tools.py
index 5e81997a4ad..8c8c8b99079 100644
--- a/tools/kanban_tools.py
+++ b/tools/kanban_tools.py
@@ -197,9 +197,25 @@ def _default_task_id(arg: Optional[str]) -> Optional[str]:
def _require_task_id(args: dict) -> str:
+ """Resolve the target task or reject with a message the caller can act on.
+
+ The env default only exists for a dispatcher-spawned worker; every other
+ caller must name a task, so a rejection points at ``kanban_list`` instead of
+ an env var a chat caller cannot set (#91431).
+ """
tid = _default_task_id(args.get("task_id"))
- _check(tid, "task_id is required (or set HERMES_KANBAN_TASK in the env)")
- return tid
+ if tid:
+ return tid
+ if os.environ.get("HERMES_KANBAN_TASK"):
+ # Env task present but not usable here (delegate child / cron run beside
+ # a worker): it is not this session's to default to.
+ raise _Reject(
+ "task_id is required: this session does not own the inherited "
+ "HERMES_KANBAN_TASK, so it is not a valid default. Pass an explicit "
+ "task_id.")
+ raise _Reject(
+ "task_id is required: this session has no dispatcher-assigned task to "
+ "default to. Pass an explicit task_id; discover task ids with kanban_list.")
def _own_task_env(task_id: str, var: str) -> Optional[str]:
@@ -637,7 +653,18 @@ def inject_new_comments_from_env(agent: Any) -> bool:
@_kanban_handler("kanban_show")
def _handle_show(args: dict, **kw) -> str:
"""Full task state: row, parents, children, comments, runs, last 50 events."""
- tid = _require_task_id(args)
+ tid = _default_task_id(args.get("task_id"))
+ if not tid:
+ # No dispatcher task in scope and no explicit id: the caller asked "what
+ # should I be looking at". A chat profile cannot set HERMES_KANBAN_TASK,
+ # so an error naming the env var is dead end (#91431) — answer instead.
+ return json.dumps({
+ "current_task": None,
+ "hint": (
+ "No dispatcher-assigned task in this session, so there is no "
+ "task to show by default. Call kanban_list to see task ids on "
+ "the board, then kanban_show(task_id=<id>) for full state."),
+ })
with _board(args.get("board")) as (kb, conn):
task = _existing_task(kb, conn, tid)
return json.dumps({
@@ -915,8 +942,13 @@ def _handle_comment(args: dict, **kw) -> str:
"""Append a comment to a task's thread."""
_reject_delegated_child_mutation("kanban_comment")
tid = args.get("task_id")
- _check(tid, "task_id is required (use the current task id if that's what "
- "you mean — pulls from env but kept explicit here)")
+ if not tid:
+ # A comment writes to the board, so a bare call must stay an error — but
+ # point at kanban_list, not an env var a chat caller cannot set (#91431).
+ raise _Reject(
+ "task_id is required: comments are per-task and this session has no "
+ "dispatcher-assigned task to default to. Discover task ids with "
+ "kanban_list, or pass the task id you mean.")
body = _redact(_require_text(args, "body"))
# Author comes from the worker's runtime identity (``_persisted_identity``), never
# caller args: comments are injected into future workers' system prompts, so an
diff --git a/tools/kanban_tools_schemas.py b/tools/kanban_tools_schemas.py
index 090c752a019..8681b0076bc 100644
--- a/tools/kanban_tools_schemas.py
+++ b/tools/kanban_tools_schemas.py
@@ -4,8 +4,10 @@ from __future__ import annotations
from typing import Any
_DESC_TASK_ID_DEFAULT = (
- "Task id. If omitted, defaults to HERMES_KANBAN_TASK from the env "
- "(the task the dispatcher spawned you to work on)."
+ "Task id. If omitted, defaults to HERMES_KANBAN_TASK from the env — the "
+ "task the dispatcher spawned you to work on. That default only exists for "
+ "a dispatcher-spawned worker; any other caller has no default and must "
+ "pass an explicit task_id (use kanban_list to discover ids)."
)
_DESC_BOARD = (
@@ -48,7 +50,9 @@ KANBAN_SHOW_SCHEMA = _schema(
"and recent events. Use this to (re)orient yourself before "
"starting work, especially on retries. The response includes a "
"pre-formatted ``worker_context`` string suitable for inclusion "
- "verbatim in your reasoning."
+ "verbatim in your reasoning. Outside a dispatcher-spawned worker "
+ "there is no default task: a bare call returns a pointer to "
+ "``kanban_list`` instead of task state."
),
{
"task_id": _prop("string", _DESC_TASK_ID_DEFAULT),
@@ -320,7 +324,9 @@ KANBAN_COMMENT_SCHEMA = _schema(
{
"task_id": _prop("string", (
"Task id. Required (may be your own task or "
- "another's — comment threads are per-task)."
+ "another's — comment threads are per-task). Outside a "
+ "dispatcher-spawned worker there is no default; use "
+ "kanban_list to discover ids."
)),
"body": _prop("string", "Markdown-supported comment body."),
},