fix(kanban): align worker terminal timeout with task runtime
This commit is contained in:
@@ -2679,6 +2679,124 @@ def test_default_spawn_auto_loads_kanban_worker_skill(kanban_home, monkeypatch):
|
||||
assert env.get("HERMES_PROFILE") == "some-profile"
|
||||
|
||||
|
||||
def test_default_spawn_raises_terminal_timeout_to_task_runtime(kanban_home, monkeypatch):
|
||||
"""A task runtime cap should raise the worker's terminal default.
|
||||
|
||||
This is worker-scoped env only: normal CLI/gateway terminal settings stay
|
||||
untouched, but long kanban tasks no longer inherit a short generic
|
||||
TERMINAL_TIMEOUT that kills their foreground command first.
|
||||
"""
|
||||
captured = {}
|
||||
|
||||
class FakeProc:
|
||||
pid = 123
|
||||
|
||||
def fake_popen(cmd, **kwargs):
|
||||
captured["env"] = kwargs.get("env", {})
|
||||
return FakeProc()
|
||||
|
||||
monkeypatch.setattr("subprocess.Popen", fake_popen)
|
||||
monkeypatch.setenv("TERMINAL_TIMEOUT", "180")
|
||||
monkeypatch.delenv("TERMINAL_MAX_FOREGROUND_TIMEOUT", raising=False)
|
||||
|
||||
conn = kb.connect()
|
||||
try:
|
||||
tid = kb.create_task(
|
||||
conn,
|
||||
title="long worker",
|
||||
assignee="ops",
|
||||
max_runtime_seconds=3600,
|
||||
)
|
||||
task = kb.get_task(conn, tid)
|
||||
workspace = kb.resolve_workspace(task)
|
||||
kb._default_spawn(task, str(workspace))
|
||||
finally:
|
||||
conn.close()
|
||||
|
||||
assert captured["env"]["TERMINAL_TIMEOUT"] == "3570"
|
||||
assert captured["env"]["TERMINAL_MAX_FOREGROUND_TIMEOUT"] == "3570"
|
||||
assert os.environ["TERMINAL_TIMEOUT"] == "180"
|
||||
|
||||
|
||||
def test_default_spawn_preserves_longer_terminal_timeout(kanban_home, monkeypatch):
|
||||
"""Kanban should never lower an explicitly larger terminal timeout."""
|
||||
captured = {}
|
||||
|
||||
class FakeProc:
|
||||
pid = 124
|
||||
|
||||
def fake_popen(cmd, **kwargs):
|
||||
captured["env"] = kwargs.get("env", {})
|
||||
return FakeProc()
|
||||
|
||||
monkeypatch.setattr("subprocess.Popen", fake_popen)
|
||||
monkeypatch.setenv("TERMINAL_TIMEOUT", "7200")
|
||||
monkeypatch.setenv("TERMINAL_MAX_FOREGROUND_TIMEOUT", "7200")
|
||||
|
||||
conn = kb.connect()
|
||||
try:
|
||||
tid = kb.create_task(
|
||||
conn,
|
||||
title="already tuned",
|
||||
assignee="ops",
|
||||
max_runtime_seconds=3600,
|
||||
)
|
||||
task = kb.get_task(conn, tid)
|
||||
workspace = kb.resolve_workspace(task)
|
||||
kb._default_spawn(task, str(workspace))
|
||||
finally:
|
||||
conn.close()
|
||||
|
||||
assert captured["env"]["TERMINAL_TIMEOUT"] == "7200"
|
||||
assert captured["env"]["TERMINAL_MAX_FOREGROUND_TIMEOUT"] == "7200"
|
||||
|
||||
|
||||
def test_default_spawn_leaves_terminal_timeout_without_runtime_cap(kanban_home, monkeypatch):
|
||||
"""Uncapped tasks keep the existing terminal timeout behavior."""
|
||||
captured = {}
|
||||
|
||||
class FakeProc:
|
||||
pid = 125
|
||||
|
||||
def fake_popen(cmd, **kwargs):
|
||||
captured["env"] = kwargs.get("env", {})
|
||||
return FakeProc()
|
||||
|
||||
monkeypatch.setattr("subprocess.Popen", fake_popen)
|
||||
monkeypatch.setenv("TERMINAL_TIMEOUT", "180")
|
||||
monkeypatch.delenv("TERMINAL_MAX_FOREGROUND_TIMEOUT", raising=False)
|
||||
|
||||
conn = kb.connect()
|
||||
try:
|
||||
tid = kb.create_task(conn, title="uncapped", assignee="ops")
|
||||
task = kb.get_task(conn, tid)
|
||||
workspace = kb.resolve_workspace(task)
|
||||
kb._default_spawn(task, str(workspace))
|
||||
finally:
|
||||
conn.close()
|
||||
|
||||
assert captured["env"]["TERMINAL_TIMEOUT"] == "180"
|
||||
assert "TERMINAL_MAX_FOREGROUND_TIMEOUT" not in captured["env"]
|
||||
|
||||
|
||||
def test_build_worker_context_includes_runtime_timeout_budget(kanban_home, monkeypatch):
|
||||
monkeypatch.setenv("TERMINAL_TIMEOUT", "180")
|
||||
conn = kb.connect()
|
||||
try:
|
||||
tid = kb.create_task(
|
||||
conn,
|
||||
title="long context",
|
||||
assignee="ops",
|
||||
max_runtime_seconds=3600,
|
||||
)
|
||||
ctx = kb.build_worker_context(conn, tid)
|
||||
finally:
|
||||
conn.close()
|
||||
|
||||
assert "Max runtime: 3600s" in ctx
|
||||
assert "Terminal timeout: 3570s" in ctx
|
||||
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# Per-task force-loaded skills
|
||||
|
||||
Reference in New Issue
Block a user