mirror of
https://github.com/rennf93/roboco.git
synced 2026-08-03 07:23:24 +02:00
[F018] claim_guards: treat blocked as active + broaden the guard lookup so a blocked dev can't double-claim
This commit is contained in:
@@ -3846,8 +3846,16 @@ class Choreographer:
|
||||
reality. Checkpoint failure is swallowed; it must never block the pause.
|
||||
"""
|
||||
in_progress = await self.task.list_in_progress_for_agent(agent_id)
|
||||
# F018: the lookup now also returns blocked tasks (so the claim guard
|
||||
# sees them). i_am_idle only auto-pauses genuinely in_progress tasks —
|
||||
# a blocked task is waiting on an external dep, not on the agent, so it
|
||||
# stays blocked (and isn't reported as paused for the agent to resume).
|
||||
from roboco.models.base import TaskStatus
|
||||
|
||||
paused_ids: list[str] = []
|
||||
for t in in_progress:
|
||||
if t.status != TaskStatus.IN_PROGRESS:
|
||||
continue
|
||||
await self.task.pause_for_agent(agent_id, t.id)
|
||||
paused_ids.append(str(t.id))
|
||||
await self._write_auto_pause_checkpoint(agent_id, t)
|
||||
|
||||
@@ -26,8 +26,13 @@ if TYPE_CHECKING:
|
||||
|
||||
# Statuses that count as "still actively worked" — pre-gateway
|
||||
# _helpers.py:check_blocking_tasks 134-152.
|
||||
#
|
||||
# F018: ``blocked`` is included — a blocked task is still owned by the dev and
|
||||
# ``unblock_with_restore`` resumes it to ``in_progress``. Excluding it let a dev
|
||||
# claim a second task while blocked, then end up with TWO ``in_progress``
|
||||
# tasks once the first was unblocked, violating the one-active-task invariant.
|
||||
_ACTIVE_BLOCKING_STATUSES: frozenset[str] = frozenset(
|
||||
{"claimed", "in_progress", "verifying"}
|
||||
{"claimed", "in_progress", "verifying", "blocked"}
|
||||
)
|
||||
|
||||
|
||||
|
||||
+11
-2
@@ -8184,12 +8184,21 @@ class TaskService(BaseService):
|
||||
return task
|
||||
|
||||
async def list_in_progress_for_agent(self, agent_id: UUID) -> list[TaskTable]:
|
||||
"""In-progress tasks currently assigned to the agent."""
|
||||
"""Tasks the agent is still on the hook for — in_progress OR blocked.
|
||||
|
||||
F018: ``blocked`` is included because a blocked task is still owned and
|
||||
``unblock_with_restore`` resumes it to ``in_progress``; the claim guard
|
||||
(``already_active_guard``) must see it or a dev could claim a second
|
||||
task while blocked and end up with two ``in_progress`` tasks once the
|
||||
first is unblocked. Callers that only want pausable (in_progress) tasks
|
||||
— the ``i_am_idle`` auto-pause path — filter on ``status`` themselves
|
||||
(``pause()`` no-ops on non-in_progress regardless).
|
||||
"""
|
||||
query = (
|
||||
select(TaskTable)
|
||||
.where(
|
||||
TaskTable.assigned_to == agent_id,
|
||||
TaskTable.status == TaskStatus.IN_PROGRESS,
|
||||
TaskTable.status.in_([TaskStatus.IN_PROGRESS, TaskStatus.BLOCKED]),
|
||||
)
|
||||
.order_by(TaskTable.priority, TaskTable.updated_at.desc())
|
||||
)
|
||||
|
||||
@@ -0,0 +1,57 @@
|
||||
"""F018 — ``already_active_guard`` must treat a ``blocked`` task as active.
|
||||
|
||||
``_ACTIVE_BLOCKING_STATUSES`` excluded ``blocked``, so a developer with a
|
||||
blocked task could claim a second task (the guard passed). When the blocked
|
||||
task was later unblocked via ``unblock_with_restore`` it resumed to
|
||||
``in_progress`` — leaving the dev silently holding TWO ``in_progress`` tasks,
|
||||
violating the one-active-task-per-dev invariant the guard exists to enforce.
|
||||
A blocked task is still owned and will resume to active, so it must block a
|
||||
new claim.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from unittest.mock import MagicMock
|
||||
from uuid import uuid4
|
||||
|
||||
from roboco.services.gateway.claim_guards import already_active_guard
|
||||
|
||||
|
||||
def _task(*, status: str) -> MagicMock:
|
||||
t = MagicMock()
|
||||
t.id = uuid4()
|
||||
t.status = status
|
||||
return t
|
||||
|
||||
|
||||
def test_already_active_guard_blocks_when_agent_has_blocked_task() -> None:
|
||||
"""A blocked task the dev still owns must block a new claim (F018)."""
|
||||
target_id = uuid4()
|
||||
blocked = _task(status="blocked")
|
||||
env = already_active_guard([blocked], target_id)
|
||||
assert env is not None
|
||||
assert env.error == "invalid_state"
|
||||
|
||||
|
||||
def test_already_active_guard_still_blocks_in_progress() -> None:
|
||||
"""Regression: the existing in_progress case still fires."""
|
||||
target_id = uuid4()
|
||||
in_progress = _task(status="in_progress")
|
||||
env = already_active_guard([in_progress], target_id)
|
||||
assert env is not None
|
||||
|
||||
|
||||
def test_already_active_guard_excludes_target_task_itself() -> None:
|
||||
"""Re-claiming/resuming the same blocked task must not self-block."""
|
||||
target_id = uuid4()
|
||||
blocked_self = MagicMock(id=target_id, status="blocked")
|
||||
env = already_active_guard([blocked_self], target_id)
|
||||
assert env is None
|
||||
|
||||
|
||||
def test_already_active_guard_passes_when_no_active_tasks() -> None:
|
||||
"""A dev with only terminal/backlog tasks may claim."""
|
||||
target_id = uuid4()
|
||||
others = [_task(status="completed"), _task(status="backlog")]
|
||||
env = already_active_guard(others, target_id)
|
||||
assert env is None
|
||||
Reference in New Issue
Block a user