The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(kanban): coerce foreign timestamp values when reading task/run/event rows
liuhao1024d56e357556fc
diff --git a/hermes_cli/kanban_db.py b/hermes_cli/kanban_db.pyindex b0d8915f71a..55066f1afa8 100644--- a/hermes_cli/kanban_db.py+++ b/hermes_cli/kanban_db.py@@ -689,9 +689,9 @@ class Task:# Columns every schema version has (KeyError if the SELECT omitted them)._TASK_REQUIRED_COLUMNS = ("id", "title", "body", "assignee", "status", "priority", "created_by",- "workspace_kind", "workspace_path", "claim_lock", "claim_expires",+ "workspace_kind", "workspace_path", "claim_lock",)-_TASK_EPOCH_COLUMNS = ("created_at", "started_at", "completed_at")+_TASK_EPOCH_COLUMNS = ("created_at", "started_at", "completed_at", "claim_expires")# Later-added columns read as NULL when absent from the row._TASK_OPTIONAL_COLUMNS = ("branch_name", "project_id", "tenant", "result", "idempotency_key", "worker_pid",@@ -731,13 +731,12 @@ class Run:return cls(**{col: _lossy_text(row[col]) for col in (- "task_id", "profile", "step_key", "status", "claim_lock", "claim_expires",- "worker_pid", "max_runtime_seconds", "last_heartbeat_at", "outcome", "summary", "error",+ "task_id", "profile", "step_key", "status", "claim_lock",+ "worker_pid", "max_runtime_seconds", "outcome", "summary", "error",)},- id=int(row["id"]),- started_at=int(row["started_at"]),- ended_at=_opt_int(row["ended_at"]),+ **{col: _to_epoch(row[col]) for col in ("claim_expires", "last_heartbeat_at", "ended_at")},+ id=int(row["id"]), started_at=_to_epoch(row["started_at"]) or 0,metadata=_json_or(_lossy_text(row["metadata"])),)@@ -754,7 +753,7 @@ class Comment:def from_row(cls, r: sqlite3.Row) -> Comment:return cls(id=r["id"], task_id=r["task_id"], author=_lossy_text(r["author"]),- body=_lossy_text(r["body"]), created_at=r["created_at"],+ body=_lossy_text(r["body"]), created_at=_to_epoch(r["created_at"]) or 0,)@@ -776,7 +775,7 @@ class Attachment:return cls(id=r["id"], task_id=r["task_id"], filename=r["filename"],stored_path=r["stored_path"], content_type=r["content_type"],- size=r["size"] or 0, uploaded_by=r["uploaded_by"], created_at=r["created_at"],+ size=r["size"] or 0, uploaded_by=r["uploaded_by"], created_at=_to_epoch(r["created_at"]) or 0,)@@ -794,7 +793,8 @@ class Event:run_id = _row_get(row, "run_id")return cls(id=row["id"], task_id=row["task_id"], kind=_lossy_text(row["kind"]),- payload=_json_or(_lossy_text(row["payload"])), created_at=row["created_at"], run_id=_opt_int(run_id),+ payload=_json_or(_lossy_text(row["payload"])), created_at=_to_epoch(row["created_at"]) or 0,+ run_id=_opt_int(run_id),)@@ -4102,7 +4102,7 @@ def _ctx_role_history(lines: list[str], conn: sqlite3.Connection, task: Task, nofor row in role_rows:first = _first_line(row["summary"], 200) or "(no summary)"lines.append(- f"- {row['id']} — {row['title']} ({_ctx_stamp(int(row['ended_at']), now)}): {first}"+ f"- {row['id']} — {row['title']} ({_ctx_stamp(_to_epoch(row['ended_at']) or 0, now)}): {first}")lines.append("")diff --git a/hermes_cli/kanban_db_dispatch.py b/hermes_cli/kanban_db_dispatch.pyindex 1bb3044bfa7..38ae835875a 100644--- a/hermes_cli/kanban_db_dispatch.py+++ b/hermes_cli/kanban_db_dispatch.py@@ -1566,16 +1566,16 @@ def check_respawn_guard().fetchone()if latest_run is not None and latest_run["outcome"] == "spawn_failed":if rl_cooldown > 0 and _kb._json_dict(latest_run["metadata"]).get("infrastructure"):- ended_at = latest_run["ended_at"]- if ended_at is not None and (now - int(ended_at)) < rl_cooldown:+ ended_at = _kb._to_epoch(latest_run["ended_at"])+ if ended_at is not None and (now - ended_at) < rl_cooldown:return "infrastructure_cooldown"if latest_run is not None and latest_run["outcome"] == "rate_limited":if rl_cooldown <= 0:# Cooldown disabled — respawn immediately, skipping blocker_auth so# the stamped rate-limit text doesn't re-trap the task.return None- ended_at = latest_run["ended_at"]- if ended_at is not None and (now - int(ended_at)) < rl_cooldown:+ ended_at = _kb._to_epoch(latest_run["ended_at"])+ if ended_at is not None and (now - ended_at) < rl_cooldown:return "rate_limit_cooldown"# Cooldown elapsed — return early so blocker_auth doesn't catch the# stamped rate-limit text; this path intentionally retries forever@@ -1608,7 +1608,7 @@ def check_respawn_guard((task_id, cutoff),).fetchone()if recent_completed:- completed_at = int(recent_completed["ended_at"] or 0)+ completed_at = _kb._to_epoch(recent_completed["ended_at"]) or 0requeued_after = conn.execute("SELECT 1 FROM task_events ""WHERE task_id = ? AND created_at >= ? "diff --git a/tests/hermes_cli/test_kanban_cli.py b/tests/hermes_cli/test_kanban_cli.pyindex 1eee380f3d2..109de962497 100644--- a/tests/hermes_cli/test_kanban_cli.py+++ b/tests/hermes_cli/test_kanban_cli.py@@ -111,6 +111,32 @@ def test_kanban_show_text_renders_legacy_iso_completed_at(kanban_home):assert "completed: 2026-09-30 14:22" in " ".join(output.split())+def test_show_survives_iso_strings_in_integer_timestamp_columns(kanban_home):+ """`kanban show` must not crash on ISO-8601 strings written into the+ INTEGER timestamp columns of tasks / task_runs / task_events by raw SQL+ outside the mutators (#97455): both output modes stay readable and serve+ epoch ints instead of raising ``invalid literal for int()``."""+ iso_utc = "2026-08-28T14:35:22+00:00"+ iso_z = "2026-08-28T16:58:56.613Z"+ with kbc.connect_closing() as conn:+ task_id = kb.create_task(conn, title="corrupted card", assignee="alice")+ assert kb.claim_task(conn, task_id)+ assert kb.complete_task(conn, task_id, summary="done")+ conn.execute("UPDATE task_runs SET ended_at = ? WHERE task_id = ?", (iso_utc, task_id))+ conn.execute("UPDATE tasks SET completed_at = ? WHERE id = ?", (iso_z, task_id))+ conn.execute("UPDATE task_events SET created_at = ? WHERE task_id = ?", (iso_z, task_id))+ conn.commit()++ output = kc.run_slash(f"show {task_id}")+ assert f"Task {task_id}: corrupted card" in output+ assert "invalid literal" not in output++ payload = json.loads(kc.run_slash(f"show {task_id} --json"))+ assert payload["task"]["id"] == task_id+ assert payload["runs"] and all(isinstance(r["ended_at"], int) for r in payload["runs"])+ assert payload["events"] and all(isinstance(e["created_at"], int) for e in payload["events"])++def test_kanban_edit_updates_documented_task_fields(kanban_home):with kbc.connect_closing() as conn:task_id = kb.create_task(conn, title="old title", body="old body", priority=2)