Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions hermes_cli/kanban_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -4614,8 +4614,14 @@ def complete_task(

``summary`` and ``metadata`` are stored on the closing run (if any)
and surfaced to downstream children via :func:`build_worker_context`.
When ``summary`` is omitted we fall back to ``result`` so single-run
callers do not have to pass both. ``metadata`` is a free-form dict
When ``summary`` is omitted we fall back to ``result`` — and when
``result`` is omitted we fall back to ``summary`` — so single-run
callers do not have to pass both. The result backfill is what keeps
a successful worker handoff visible on the task row itself
(``tasks.result``) when the worker completed via the run protocol
with only a summary and posted no completion comment (#t_343e914f:
tasks done + task_runs.summary populated + tasks.result NULL).
``metadata`` is a free-form dict
(e.g. ``{"changed_files": [...], "tests_run": [...]}``) — workers
are encouraged to use it for structured handoff facts.

Expand Down Expand Up @@ -4666,6 +4672,12 @@ def complete_task(
metadata = _merge_completion_prose_artifacts(
conn, task_id, metadata, summary=summary, result=result,
)
# Backfill tasks.result from the handoff summary when the worker only
# passed summary (the common run-protocol shape). Without this the task
# closes with result=NULL and the summary is only reachable via the run
# row — dashboard/notifier paths that read tasks.result show nothing.
if result is None and summary is not None:

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

summary and result are intentionally distinct on current main: the tool schema directs workers to use the run-level summary, while result is a legacy task-row field. Dashboard, CLI, and notifier consumers already surface the summary. Please retain that distinction unless this is explicitly re-scoped as a cross-surface contract change.

result = summary
with write_txn(conn):
if expected_run_id is None:
cur = conn.execute(
Expand Down
46 changes: 46 additions & 0 deletions tests/hermes_cli/test_kanban_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -4959,3 +4959,49 @@ def test_bare_connect_does_not_close_on_context_exit(tmp_path):
# Still usable after with-block exit (the leak).
conn.execute("SELECT 1").fetchone()
conn.close() # explicit close to avoid leaking THIS test


def test_complete_task_backfills_result_from_summary(kanban_home):
"""Summary-only worker completions remain visible on the task row."""
with kb.connect() as conn:
tid = kb.create_task(conn, title="summary-only", assignee="worker")
kb.claim_task(conn, tid)

assert kb.complete_task(conn, tid, summary="rich worker handoff")

task = kb.get_task(conn, tid)
assert task is not None
assert task.result == "rich worker handoff"
run = conn.execute(
"SELECT summary FROM task_runs WHERE task_id=? AND outcome='completed'",
(tid,),
).fetchone()
assert run is not None
assert run["summary"] == "rich worker handoff"


def test_complete_task_keeps_explicit_result_when_summary_differs(kanban_home):
"""The reverse fallback must not overwrite an explicit task result."""
with kb.connect() as conn:
tid = kb.create_task(conn, title="explicit-result", assignee="worker")
kb.claim_task(conn, tid)

assert kb.complete_task(
conn, tid, result="short result", summary="long handoff",
)

task = kb.get_task(conn, tid)
assert task is not None
assert task.result == "short result"


def test_complete_task_backfills_result_without_active_run(kanban_home):
"""Manual completion's synthesized run uses the same reverse fallback."""
with kb.connect() as conn:
tid = kb.create_task(conn, title="manual-summary", assignee="worker")

assert kb.complete_task(conn, tid, summary="manual handoff")

task = kb.get_task(conn, tid)
assert task is not None
assert task.result == "manual handoff"
8 changes: 4 additions & 4 deletions tests/plugins/test_kanban_dashboard_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -2446,8 +2446,8 @@ def test_task_detail_exposes_result_and_latest_summary_separately(client):
assert "final_result" not in data


def test_task_detail_exposes_latest_summary_when_result_is_empty(client):
"""Summary-only completions remain available to the drawer fallback."""
def test_task_detail_persists_summary_as_result(client):
"""Summary-only completions remain available on the task row."""
conn = kb.connect()
task_id = kb.create_task(conn, title="Task with only run summary")
kb.claim_task(conn, task_id)
Expand All @@ -2458,7 +2458,7 @@ def test_task_detail_exposes_latest_summary_when_result_is_empty(client):
assert r.status_code == 200
data = r.json()["task"]
assert data["status"] == "done"
assert not data["result"]
assert data["result"] == "Report written to /output/report.md"
assert data["latest_summary"] == "Report written to /output/report.md"


Expand Down Expand Up @@ -2519,7 +2519,7 @@ def test_task_detail_includes_child_result_summaries(client):
"title": "Collect sources",
"status": "done",
"latest_summary": "Collected five primary sources.",
"result": None,
"result": "Collected five primary sources.",
}
]

Expand Down
Loading