Files
roboco/tests/unit/gateway/test_reassign_verb.py
T
3205443119 Fix: dependency spawn gate and cell ownership (#73)
* Cleanup + Missing greenlet error

* fix(messaging): persist a group's active-session pointer so posts reuse it

create_session and create_session_with_access_check set group.active_session_id
from session.id BEFORE the flush that materializes it — the id is a flush-time
uuid4 default, so the pointer was written as NULL and every post opened a fresh
session, fragmenting one conversation across many. Flush first, then link, the
same ordering the seed path already uses.

Two tests fabricated "two distinct sessions" by calling create_session twice on
one group, which only differed because of this bug; switch them to two groups so
they keep testing their real intent. Add a regression guard that the pointer is
actually persisted and a second create reuses the live session.

* fix(orchestrator): gate spawns on dependencies and keep cell tasks in their cell

The cross-task dependency check ran only on the dev dispatch path, so cell-PM,
Main-PM and board agents were spawned onto dependency-blocked tasks and flailed
unblock / escalate / notify against an unfinished upstream — climbing ownership
of cell work up to the board, which cannot drive it, and deadlocking the task.

- Move the dependency gate into the shared spawn readiness check so it covers
  every role, and auto-block the task so it leaves the pending pool until the
  upstream reaches a terminal state (then the existing auto-unblock revives it).
- Cell-ownership invariant: a backend/frontend/ux_ui task may only be worked or
  owned by its own cell. The readiness gate refuses a board or Main-PM spawn
  onto a cell task; reassign refuses and clears such an owner; and on
  dependency-clear a mis-owned cell task is re-homed to its cell's pending pool
  instead of reviving under an owner that cannot progress it.
- A dependency block is never a CEO signal: notify(target=ceo) is refused while
  the task is waiting on an unfinished upstream, with a remediate to idle and
  wait — the block clears on its own.

* Uploading images + Fixing pyproject.toml

* ++

* revert(orchestrator): drop the cell-ownership block pending a tooling audit

The cell-ownership invariant added earlier — a board / Main-PM role may never be
spawned onto or reassigned to a cell task, plus re-homing a mis-owned cell task
on dependency-clear — was too absolute. It forbids a higher role from stepping
in when something genuinely deeper is going on, and contradicts the existing
rule that main_pm may hold a task at awaiting_pm_review. The dependency spawn
gate already prevents the cascade that handed the board cell tasks; the deadlock
it guarded against will be addressed with a return-path approach after auditing
what tools the cell PMs actually need. Keeps the dependency gate and the CEO
dependency-block notify guard.

* docs(prompts): a dependency wait is wait-and-idle, not escalate

The cell-PM and Main-PM prompts told agents to escalate_up / retry unblock on a
blocked task without distinguishing a dependency wait (which auto-clears the
moment the upstream completes) from a real wedge — the source of the
escalate/unblock flail and the CEO-notification spam. Split the blocked-state
guidance: a cross-cell dependency wait = note + i_am_idle (do not escalate,
unblock, or notify the CEO); escalate only a genuinely broken upstream. Fix two
stale references to i_am_blocked, a developer-only verb the PMs do not have,
to escalate_up.

Correct the CLAUDE.md verb-surface table, which understated every role: it
listed 4 cell_pm verbs while the flow manifest derives the full set (11,
including unclaim and i_am_idle) from lifecycle.spec.intents_for_role.

* feat(gateway): cell_pm reassign verb — intra-cell developer hand-off

A cell PM can now hand a claimed/in_progress task to another developer in its
own cell without unclaim (which drops the work back to the pool and loses the
assignee). The branch is keyed to the task, so the work-in-progress is
preserved; the new dev is respawned to continue. Intra-cell only: the task must
be in the caller's cell and new_assignee must be a developer of that same cell.

Wired through every layer: the reassign IntentSpec (composes=(), cell_pm-only),
the choreographer verb + intra-cell guard, a reaper-safe
TaskService.reassign_active_claim (reseeds the claim heartbeat so the new dev
is not immediately reaped), the ReassignRequest schema, the cell_pm flow route,
and the MCP flow-server tool. Tracing-waived like unclaim (mechanical hand-off).
Regenerated lifecycle/verb artifacts; prompt + CLAUDE.md updated.

---------

Co-authored-by: Renn F <rennf93@users.noreply.github.com>
2026-06-06 22:10:48 +02:00

126 lines
4.0 KiB
Python

"""The cell_pm `reassign` verb — hand a claimed/in_progress task to another
developer in the caller's OWN cell, preserving the branch.
Covers the intra-cell guard (`Choreographer._validate_reassign`, using real
agents_config data) and the reaper-safe service write
(`TaskService.reassign_active_claim`).
"""
from __future__ import annotations
from unittest.mock import AsyncMock, MagicMock
from uuid import UUID, uuid4
import pytest
from roboco.models.base import TaskStatus
from roboco.seeds.initial_data import AGENT_UUIDS
from roboco.services.gateway.choreographer._impl import Choreographer
from roboco.services.task import TaskService
_BE_PM = UUID(AGENT_UUIDS["be-pm"])
def _task(team: str = "backend", status: str = "in_progress") -> MagicMock:
return MagicMock(team=MagicMock(value=team), status=MagicMock(value=status))
# ---------------------------------------------------------------------------
# _validate_reassign — intra-cell guard
# ---------------------------------------------------------------------------
def test_allows_same_cell_developer() -> None:
assert Choreographer._validate_reassign(_task(), _BE_PM, "be-dev-2") is None
def test_rejects_cross_cell_developer() -> None:
# fe-dev-1 is a frontend dev; a backend PM may not reassign to it.
env = Choreographer._validate_reassign(_task("backend"), _BE_PM, "fe-dev-1")
assert env is not None
assert env.error == "not_authorized"
def test_rejects_non_developer_target() -> None:
# be-qa is in the cell but is not a developer.
env = Choreographer._validate_reassign(_task("backend"), _BE_PM, "be-qa")
assert env is not None
assert env.error == "not_authorized"
def test_rejects_task_outside_callers_cell() -> None:
env = Choreographer._validate_reassign(_task("frontend"), _BE_PM, "be-dev-2")
assert env is not None
assert env.error == "not_authorized"
def test_rejects_non_active_status() -> None:
env = Choreographer._validate_reassign(
_task("backend", "awaiting_qa"), _BE_PM, "be-dev-2"
)
assert env is not None
assert env.error == "invalid_state"
def test_rejects_unknown_slug() -> None:
env = Choreographer._validate_reassign(_task("backend"), _BE_PM, "be-dev-99")
assert env is not None
assert env.error == "invalid_state"
def test_allows_claimed_status() -> None:
assert (
Choreographer._validate_reassign(
_task("backend", "claimed"), _BE_PM, "be-dev-1"
)
is None
)
# ---------------------------------------------------------------------------
# reassign_active_claim — reaper-safe service write
# ---------------------------------------------------------------------------
def _build_task(**over: object) -> MagicMock:
base: dict[str, object] = {
"id": uuid4(),
"status": TaskStatus.IN_PROGRESS,
"assigned_to": None,
"claimed_by": None,
"claimed_at": None,
"last_heartbeat_at": None,
"active_claimant_id": None,
}
base.update(over)
return MagicMock(**base)
def _service() -> TaskService:
session = MagicMock()
session.flush = AsyncMock()
return TaskService(session)
@pytest.mark.asyncio
async def test_reassign_active_claim_seeds_a_fresh_claim() -> None:
task = _build_task(status=TaskStatus.IN_PROGRESS)
svc = _service()
object.__setattr__(svc, "get", AsyncMock(return_value=task))
new_id = uuid4()
result = await svc.reassign_active_claim(task.id, new_id)
assert result is task
assert task.assigned_to == new_id
assert task.claimed_by == new_id
assert task.active_claimant_id == new_id
# Fresh claim window so the reaper doesn't treat the new dev as stale.
assert task.claimed_at is not None
assert task.last_heartbeat_at is not None
@pytest.mark.asyncio
async def test_reassign_active_claim_refuses_non_active_status() -> None:
task = _build_task(status=TaskStatus.AWAITING_QA)
svc = _service()
object.__setattr__(svc, "get", AsyncMock(return_value=task))
assert await svc.reassign_active_claim(task.id, uuid4()) is None