diff --git a/src/daemon/spawner.py b/src/daemon/spawner.py index 8ee8a62..1d45bf2 100644 --- a/src/daemon/spawner.py +++ b/src/daemon/spawner.py @@ -1294,6 +1294,22 @@ curl -X POST http://{api_host}:{api_port}/api/projects/{project_id}/tasks/{task_ if result["status"] in ("done", "timeout"): result["lock_pid_alive"] = False result["lock_expired"] = True + # running + lock 超时 >30分钟 > 视为 idle,允许 dispatch + elif result["status"] == "running" and result["lock_pid_alive"]: + try: + lock_data = json.loads(lock_path.read_text()) + created_at_str = lock_data.get("createdAt", "") + if created_at_str: + from datetime import datetime as _dt, timezone as _tz + created_dt = _dt.fromisoformat(created_at_str.replace("Z", "+00:00")) + elapsed = (_dt.now(_tz.utc) - created_dt).total_seconds() + if elapsed > 1800: # 30 minutes + result["lock_pid_alive"] = False + result["lock_expired"] = True + logger.info("Lock expired for %s: running + lock age %.0fs > 1800s", + agent_id, elapsed) + except Exception: + pass except Exception: pass