Skip to content

Commit 0618ec8

Browse files
committed
Fix: Handle claim_task error response in agent idle loop
1 parent a9c7100 commit 0618ec8

1 file changed

Lines changed: 5 additions & 1 deletion

File tree

agents/s11_autonomous_agents.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,8 @@ def claim_task(task_id: int, owner: str) -> str:
142142
if not path.exists():
143143
return f"Error: Task {task_id} not found"
144144
task = json.loads(path.read_text())
145+
if task.get("owner") or task.get("status") != "pending":
146+
return f"Error: Task {task_id} has already been claimed by someone else"
145147
task["owner"] = owner
146148
task["status"] = "in_progress"
147149
path.write_text(json.dumps(task, indent=2))
@@ -274,7 +276,9 @@ def _loop(self, name: str, role: str, prompt: str):
274276
unclaimed = scan_unclaimed_tasks()
275277
if unclaimed:
276278
task = unclaimed[0]
277-
claim_task(task["id"], name)
279+
result = claim_task(task["id"], name)
280+
if result.startswith("Error"):
281+
continue
278282
task_prompt = (
279283
f"<auto-claimed>Task #{task['id']}: {task['subject']}\n"
280284
f"{task.get('description', '')}</auto-claimed>"

0 commit comments

Comments
 (0)