Merge pull request #490 from shareAI-lab/fix/s18-idle-poll-wtctx-update

fix(s18): update wt_ctx after idle_poll auto-claims a worktree task
This commit is contained in:
Yang Haoran
2026-07-29 01:27:46 +08:00
committed by GitHub

View File

@@ -440,8 +440,8 @@ def scan_unclaimed_tasks() -> list[dict]:
def idle_poll(agent_name: str, messages: list, def idle_poll(agent_name: str, messages: list,
name: str, role: str) -> str: name: str, role: str) -> tuple[str, str | None]:
"""Poll for 60s. Return 'work', 'shutdown', or 'timeout'.""" """Poll for 60s. Return (result, auto_claimed_task_id)."""
for _ in range(IDLE_TIMEOUT // IDLE_POLL_INTERVAL): for _ in range(IDLE_TIMEOUT // IDLE_POLL_INTERVAL):
time.sleep(IDLE_POLL_INTERVAL) time.sleep(IDLE_POLL_INTERVAL)
@@ -455,12 +455,12 @@ def idle_poll(agent_name: str, messages: list,
{"request_id": req_id, "approve": True}) {"request_id": req_id, "approve": True})
print(f" \033[35m[protocol] {name} approved shutdown " print(f" \033[35m[protocol] {name} approved shutdown "
f"in idle ({req_id})\033[0m") f"in idle ({req_id})\033[0m")
return "shutdown" return "shutdown", None
messages.append({"role": "user", messages.append({"role": "user",
"content": "<inbox>" + json.dumps(inbox) + "</inbox>"}) "content": "<inbox>" + json.dumps(inbox) + "</inbox>"})
print(f" \033[36m[idle] {name} found inbox messages\033[0m") print(f" \033[36m[idle] {name} found inbox messages\033[0m")
return "work" return "work", None
unclaimed = scan_unclaimed_tasks() unclaimed = scan_unclaimed_tasks()
if unclaimed: if unclaimed:
@@ -476,12 +476,12 @@ def idle_poll(agent_name: str, messages: list,
f"{task_data['subject']}{wt_info}</auto-claimed>"}) f"{task_data['subject']}{wt_info}</auto-claimed>"})
print(f" \033[32m[idle] {name} auto-claimed: " print(f" \033[32m[idle] {name} auto-claimed: "
f"{task_data['subject']}\033[0m") f"{task_data['subject']}\033[0m")
return "work" return "work", task_data["id"]
print(f" \033[33m[idle] {name} claim failed: " print(f" \033[33m[idle] {name} claim failed: "
f"{result}\033[0m") f"{result}\033[0m")
print(f" \033[31m[idle] {name} timeout ({IDLE_TIMEOUT}s)\033[0m") print(f" \033[31m[idle] {name} timeout ({IDLE_TIMEOUT}s)\033[0m")
return "timeout" return "timeout", None
# ── Teammate Thread (from s15 + s16 + s17 + s18) ── # ── Teammate Thread (from s15 + s16 + s17 + s18) ──
@@ -661,11 +661,17 @@ def spawn_teammate_thread(name: str, role: str, prompt: str) -> str:
break break
# IDLE phase # IDLE phase
idle_result = idle_poll(name, messages, name, role) idle_result, claimed_task_id = idle_poll(name, messages, name, role)
if idle_result == "shutdown": if idle_result == "shutdown":
break break
if idle_result == "timeout": if idle_result == "timeout":
break break
if idle_result == "work" and claimed_task_id:
task = load_task(claimed_task_id)
if task.get("worktree"):
wt_ctx["path"] = str(WORKTREES_DIR / task["worktree"])
else:
wt_ctx["path"] = None
# Summary # Summary
summary = "Done." summary = "Done."