fix: preserve task stop intent and guard remote execution boundaries

This commit is contained in:
Xin Wang
2026-10-23 19:53:17 +08:00
parent 8ac75a1873
commit 89c3bad58e
16 changed files with 199 additions and 20 deletions
@@ -101,10 +101,17 @@ class TaskService:
task_id = message.payload["task_id"]
self._jobs[message.job_id] = task_id
record = await self.get(task_id)
if record.status == "cancel_requested":
await self._stop_record(record)
return {"task_id": task_id}
executor = self.executor_factory(record.connection, record.secrets)
resume = bool(record.remote_handle)
try:
if not resume:
outstanding = await self.repository.list(active=True)
if any(other.id != task_id and other.remote_handle for other in outstanding):
await self.repository.patch(task_id, status="failed", summary="另一远端任务尚未结束,请先核查或停止该任务;本任务未提交到远端")
return {"task_id": task_id}
handle = await executor.prepare()
record = await self.repository.patch(task_id, remote_handle=handle)
last_event = None