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>
This commit is contained in:
Renzo F
2026-06-06 22:10:48 +02:00
committed by GitHub
co-authored by Renn F
parent 8596c72d9b
commit 3205443119
50 changed files with 1991 additions and 8482 deletions
@@ -2337,6 +2337,141 @@ class Choreographer:
context_briefing=briefing,
).with_introspection(task=after, role=role_str)
@staticmethod
def _validate_reassign(
t: Any, agent_id: UUID, new_assignee: str
) -> Envelope | None:
"""Intra-cell guard for ``reassign`` (verb body owns it — composes=()).
The task must be claimed/in_progress and in the caller's own cell, and
``new_assignee`` must be a developer of that same cell. Returns a
rejection envelope, or None when the hand-off is allowed.
"""
from roboco.agents_config import get_agent_role, get_agent_team
from roboco.seeds.initial_data import AGENT_UUIDS
caller_team = get_agent_team(str(agent_id))
task_team = getattr(t.team, "value", t.team)
status = str(getattr(t.status, "value", t.status))
if status not in ("claimed", "in_progress"):
return Envelope.invalid_state(
message=f"cannot reassign a task in status {status!r}",
remediate=(
"reassign only a claimed or in_progress task; review/terminal"
" states are owned by their lifecycle role"
),
context_briefing={},
)
if task_team is None or task_team != caller_team:
return Envelope.not_authorized(
message=f"task team {task_team!r} is not your cell ({caller_team!r})",
remediate="you can only reassign tasks inside your own cell",
context_briefing={},
)
if new_assignee not in AGENT_UUIDS:
return Envelope.invalid_state(
message=f"unknown agent slug {new_assignee!r}",
remediate=(
"new_assignee must be a developer slug in your cell, e.g. be-dev-2"
),
context_briefing={},
)
if get_agent_role(new_assignee) != "developer":
return Envelope.not_authorized(
message=f"{new_assignee!r} is not a developer",
remediate=(
"reassign hands work to a developer in your cell;"
" only dev slugs are valid"
),
context_briefing={},
)
if get_agent_team(new_assignee) != caller_team:
return Envelope.not_authorized(
message=f"{new_assignee!r} is not in your cell ({caller_team!r})",
remediate="reassign only to a developer in your own cell",
context_briefing={},
)
return None
async def reassign(
self, agent_id: UUID, task_id: UUID, new_assignee: str
) -> Envelope:
"""A cell PM hands a claimed/in_progress task to another dev in its cell.
Intra-cell only (see ``_validate_reassign``). The branch is keyed to the
task, not the agent, so it survives — the new developer continues the
work-in-progress and is respawned by the orchestrator.
"""
from roboco.seeds.initial_data import AGENT_UUIDS
t = await self.task.get(task_id)
briefing = await self._briefing_for(agent_id, task_id)
if t is None:
return await self._emit_rejection(
Envelope.not_found(message=f"task {task_id} not found"),
agent_id=agent_id,
task_id=task_id,
verb="reassign",
)
agent = await self.task.agent_for(agent_id)
role_str = str(agent.role) if agent is not None else "cell_pm"
try:
role = spec_module.Role(role_str)
except ValueError:
return await self._emit_rejection(
Envelope.not_authorized(
message=f"unknown role '{role_str}'",
remediate="role is not declared in the lifecycle spec",
context_briefing=briefing,
).with_introspection(task=t, role=role_str),
agent_id=agent_id,
task_id=task_id,
verb="reassign",
)
spec_ctx = spec_module.Context(
actor_id=agent_id,
actor_slug=getattr(agent, "slug", None) if agent is not None else None,
original_developer_slug=_extract_original_developer(t),
)
decision = spec_module.can_invoke_intent(role, "reassign", t, spec_ctx)
if not decision.allowed:
return await self._emit_rejection(
Envelope.from_decision(decision, briefing=briefing).with_introspection(
task=t, role=role_str
),
agent_id=agent_id,
task_id=task_id,
verb="reassign",
)
guard = self._validate_reassign(t, agent_id, new_assignee)
if guard is not None:
return await self._emit_rejection(
guard.with_introspection(task=t, role=role_str),
agent_id=agent_id,
task_id=task_id,
verb="reassign",
)
after = await self.task.reassign_active_claim(
task_id, UUID(AGENT_UUIDS[new_assignee])
)
if after is None:
return await self._emit_rejection(
Envelope.invalid_state(
message=f"cannot reassign from status {t.status}",
remediate="only a claimed / in_progress task can be reassigned",
context_briefing=briefing,
).with_introspection(task=t, role=role_str),
agent_id=agent_id,
task_id=task_id,
verb="reassign",
)
return Envelope.ok(
status=str(after.status),
task_id=str(task_id),
next=spec_module._INTENT_VERBS["reassign"].next_hint(after),
context_briefing=briefing,
).with_introspection(task=after, role=role_str)
async def resume(self, agent_id: UUID, task_id: UUID) -> Envelope:
"""Resume a paused task this agent owns; transitions paused → in_progress.