mirror of
https://github.com/rennf93/roboco.git
synced 2026-08-03 07:23:24 +02:00
* feat(gateway): claim-scoped context briefing — heavy sections only on context-acquisition verbs
* feat(gateway): cap unbounded LLM-facing payloads — embedded diffs, notification bodies, handoff journal content, north star
* feat(mcp): role-scope the optimal server's tool groups; index management becomes dev/test-only
* feat(mcp): cap per-result content on kb/error/learning search, mentor sources, rag citations
* refactor(gateway): extract heavy-briefing sections + clip helper to keep xenon ranks
* feat(orchestrator): cross-tick cooldown for notification-triggered spawns
* feat(usage,orchestrator): scope spawn-waste to anthropic sessions; cap agent Bash output via settings env
* docs: claim-scoped briefing, payload caps, optimal role-scoping, notification-spawn cooldown
* test(mcp): type the mixed-item cap fixture explicitly
* fix(orchestrator): lazy-init the notification-spawn cooldown store
* fix(lifecycle): admin-override claim reconciliation + PM request_changes verb (S6 postmortem B3+B4)
B3 — admin_set_status now reconciles claim ownership when leaving BLOCKED:
review/queue targets clear claimed_by/claimed_at/active_claimant_id and
consume the pre-block snapshot (a stale escalation claim was stranding the
next claimant: give_me_work handed the task out while note() bounced
not_authorized — the live b8fe0494 wedge). The pending/in_progress restore
path also syncs active_claimant_id, and a REST PATCH unassign releases the
claim with it.
B4 — new PM verb request_changes: awaiting_pm_review -> needs_revision with
concrete issues. The PM previously had no reject at merge review (only
complete/escalate), so an AC/scope violation looped i_am_blocked->escalate
4x live. Full vertical: lifecycle transition + ActionSpec + IntentSpec,
TaskService.request_changes (routes like a QA fail — original dev for a
leaf, revision PM for assembled; issues appended to dev_notes), verb-runner
compose, choreographer verb (spec gate + non-empty issues + soup check +
a2a delivery of the reject reason), HTTP routes on both PM flows, MCP tool,
journal:decision tracing, PM prompts, regenerated lifecycle artifacts.
* fix(panel): stop scorecard fetches for fallback-roster placeholder ids
useAgents() serves the static AGENT_ROSTER (ids "1".."22") while agent
definitions load; the Scorecards tab fetched a member scorecard per row
immediately, firing 22 guaranteed-422 requests per refetch cycle. Through
the browser's per-origin connection limit those queued every metrics-page
query behind them (~10s of skeletons on every tab). Gate the fetch on a
real member id (agent UUID or the "ceo" alias).
* Upgraded uv.lock
* fix(sequencing): declared deps become real edges + full loop-breaker coverage + assembled-branch freshness (S6 postmortem B1/B2/B6 + breaker)
B1a — code delegations REQUIRE a collision surface: new TASK_AT_DELEGATE
completeness spec (conditional FieldRequirement, when=('task_type','code'))
enforced at the gateway delegate gate. A no-surface code sibling is
'parallel to everything' by analyzer design, which is how two devs ran the
CEO's explicitly-ordered work out of order (f3e1afc5: seq#1 started before
seq#0, zero dependency edges). PM prompts updated; REST/manual creation
(TASK_AT_CREATE) unchanged.
B1b — the CEO's declared 'Depends on' lists become real edges: DraftSurface
gains declared_depends_on; SequencingService.analyze unions declared edges
(validated: self/out-of-range rejected) with the derived collision rules,
cycle-checked by the existing toposort. confirm_live_batch/preview_batch
map each draft's depends_on through (string indices coerced); intake tool
doc + prompter role prompt instruct verbatim copying. The live S6 root got
1 of its 3 declared in-batch edges and started alongside still-running R3.
Breaker coverage — the progress-aware respawn circuit breaker
(_pm_respawn_should_gate: strike counting, status-advance reset,
tracing-gap budget, DB durability, one-shot CEO notification) was consulted
by only 3 spawn paths; the doc/QA/dev/PR-review/PR-gate/revision/board
paths spawned unguarded at fixed cadence (the 26-respawn fe-doc loop,
~$7.20). Now consulted at every task-keyed spawn site (14 total).
B2 — assembled-branch freshness: submit_up/submit_root auto-sync the
assembled branch when it has fallen behind its base (children are terminal
at submit time, so the rebase is safe; master is never written). A rebase
conflict is a hard reject naming the files instead of a blind re-review —
kills the needs_revision↔awaiting_pr_review ping-pong of re-submitting a
stale head. Leaf i_am_done already had the behind-base gate; claim-time
fetch-fresh cut already existed.
B6 — documenter revision-pass loop: the awaiting_documentation bail
rejections (i_am_blocked/unclaim) now name the actual exit (i_documented
re-affirm) and the documenter prompt gets an explicit revision-pass rule.
* fix(orchestration): assembly-integrity gate + dispatcher heartbeat (incidents #11, #1)
Assembly integrity — submit_up/submit_root refuse when a completed child's
commits are not patch-present in the assembled branch (git cherry —
rebase-safe; branch pruned after merge or any git error fails open). Live
incident #11: a completed revert subtask's merge was lost from the cell
branch and the review gate re-flagged the exact violation the revert fixed,
spawning another revision cycle.
Dispatcher heartbeat — a dispatcher.alive audit row every 5 minutes from
the dispatch loop. The 2026-07-01 outage was 4h25m of fleet-wide silence
with no way to distinguish 'loop dead' from 'no work'; the loop's stdout
died with the container while audit_log survives. CHANGELOG for tonight's
full sweep included.
* style: ruff format for the orchestration sweep
* refactor(gateway): fold the assembled-submit guards + trim complexity under the xenon gate
_assembled_submit_guards combines the #11 integrity check and B2 freshen for
submit_up/submit_root; lifecycle's invalid-source remediate and git's
per-child cherry probe extracted into helpers. Test harnesses built via
__new__ stub the respawn tracker (the breaker now runs on their paths).
---------
Co-authored-by: Renn F <rennf93@users.noreply.github.com>
305 lines
11 KiB
Python
305 lines
11 KiB
Python
"""Board agents (Product Owner + Head of Marketing) review board-team tasks.
|
|
|
|
- A board/coordination task is a TWO-reviewer gate: BOTH the Product Owner and
|
|
the Head of Marketing must review it before it reaches the CEO. Each reviewer
|
|
is dispatched ONCE — board roles have no verb to claim/plan/delegate/complete,
|
|
so a respawn cannot advance the task and would just loop.
|
|
- Once BOTH reviewers have finished, the orchestrator hands the review to the
|
|
CEO: it flags the (still-pending) task ``board_review_complete`` so the CEO's
|
|
Approve & Start button appears, and emits exactly one formal CEO notification
|
|
so the handoff is an actionable signal, not buried channel chatter.
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
from contextlib import asynccontextmanager
|
|
from typing import TYPE_CHECKING, Any, cast
|
|
from unittest.mock import AsyncMock, patch
|
|
from uuid import uuid4
|
|
|
|
import pytest
|
|
|
|
if TYPE_CHECKING:
|
|
from collections.abc import AsyncIterator
|
|
|
|
import httpx
|
|
from roboco.runtime.orchestrator import AgentOrchestrator
|
|
|
|
|
|
def _make_orch() -> AgentOrchestrator:
|
|
orch = AgentOrchestrator.__new__(AgentOrchestrator)
|
|
cast("Any", orch)._pm_respawn_tracker = {}
|
|
cast("Any", orch)._schedule_respawn_persist = lambda *_a, **_k: None
|
|
orch._instances = {}
|
|
orch._board_dispatched = set()
|
|
orch._board_review_ceo_notified = set()
|
|
return orch
|
|
|
|
|
|
def _board_task(assigned_to: str) -> dict[str, Any]:
|
|
return {
|
|
"id": str(uuid4()),
|
|
"status": "pending",
|
|
"team": "board",
|
|
"title": "Strategic feature",
|
|
"description": "A board-level task to review and shape.",
|
|
"assigned_to": assigned_to,
|
|
}
|
|
|
|
|
|
def _patch_handoff_db(task_svc: AsyncMock) -> tuple[Any, Any]:
|
|
"""Patch the DB context + TaskService the handoff opens to flag the task.
|
|
|
|
Returns a tuple of context managers for the caller's ``with`` block so the
|
|
direct-call tests exercise the real handoff body without touching a DB.
|
|
"""
|
|
|
|
@asynccontextmanager
|
|
async def _fake_ctx() -> AsyncIterator[AsyncMock]:
|
|
yield AsyncMock()
|
|
|
|
return (
|
|
patch("roboco.db.base.get_db_context", _fake_ctx),
|
|
patch("roboco.services.task.TaskService", return_value=task_svc),
|
|
)
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_both_board_agents_dispatched_for_board_task() -> None:
|
|
"""A board task must dispatch BOTH the PO and the Head of Marketing — the
|
|
review is a two-reviewer gate, not a single-assignee claim."""
|
|
orch = _make_orch()
|
|
task = _board_task("product-owner")
|
|
with (
|
|
patch.object(orch, "_is_agent_active", return_value=False),
|
|
patch.object(orch, "_task_git_context", return_value=None),
|
|
patch.object(
|
|
orch,
|
|
"_maybe_handoff_board_review_to_ceo",
|
|
new=AsyncMock(),
|
|
),
|
|
patch.object(orch, "spawn_agent", new=AsyncMock()) as spawn,
|
|
):
|
|
await orch._handle_board_assigned_task(task, "product-owner")
|
|
|
|
dispatched = {call.kwargs["agent_id"] for call in spawn.await_args_list}
|
|
assert dispatched == {"product-owner", "head-marketing"}
|
|
for call in spawn.await_args_list:
|
|
assert call.kwargs["task_id"] == task["id"]
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_each_board_agent_spawned_only_once() -> None:
|
|
"""Board roles have no progression verb — a re-tick must NOT respawn."""
|
|
orch = _make_orch()
|
|
task = _board_task("head-marketing")
|
|
with (
|
|
patch.object(orch, "_is_agent_active", return_value=False),
|
|
patch.object(orch, "_task_git_context", return_value=None),
|
|
patch.object(
|
|
orch,
|
|
"_maybe_handoff_board_review_to_ceo",
|
|
new=AsyncMock(),
|
|
),
|
|
patch.object(orch, "spawn_agent", new=AsyncMock()) as spawn,
|
|
):
|
|
await orch._handle_board_assigned_task(task, "head-marketing")
|
|
# Second tick: still pending — must not respawn either reviewer.
|
|
await orch._handle_board_assigned_task(task, "head-marketing")
|
|
|
|
dispatched = [call.kwargs["agent_id"] for call in spawn.await_args_list]
|
|
assert sorted(dispatched) == ["head-marketing", "product-owner"]
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_board_handler_skips_active_reviewer_but_dispatches_other() -> None:
|
|
"""An already-running reviewer is skipped; the other is still dispatched."""
|
|
orch = _make_orch()
|
|
task = _board_task("product-owner")
|
|
|
|
def _active(slug: str) -> bool:
|
|
return slug == "product-owner"
|
|
|
|
with (
|
|
patch.object(orch, "_is_agent_active", side_effect=_active),
|
|
patch.object(orch, "_task_git_context", return_value=None),
|
|
patch.object(
|
|
orch,
|
|
"_maybe_handoff_board_review_to_ceo",
|
|
new=AsyncMock(),
|
|
),
|
|
patch.object(orch, "spawn_agent", new=AsyncMock()) as spawn,
|
|
):
|
|
await orch._handle_board_assigned_task(task, "product-owner")
|
|
|
|
dispatched = {call.kwargs["agent_id"] for call in spawn.await_args_list}
|
|
assert dispatched == {"head-marketing"}
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_board_handler_ignores_non_board_assignee() -> None:
|
|
orch = _make_orch()
|
|
task = _board_task("be-pm")
|
|
with (
|
|
patch.object(orch, "_is_agent_active", return_value=False),
|
|
patch.object(orch, "spawn_agent", new=AsyncMock()) as spawn,
|
|
):
|
|
await orch._handle_board_assigned_task(task, "be-pm")
|
|
spawn.assert_not_awaited()
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_unassigned_board_task_dispatches_both_via_board_handler() -> None:
|
|
"""An UNASSIGNED board task must route through the board handler so BOTH
|
|
reviewers are dispatched — not claimed + single-spawned for the PO only.
|
|
The task stays unclaimed for the CEO's Approve & Start."""
|
|
orch = _make_orch()
|
|
task = {
|
|
"id": str(uuid4()),
|
|
"status": "pending",
|
|
"team": "board",
|
|
"task_type": "code",
|
|
"title": "Strategic feature",
|
|
"description": "A board-level task to review and shape.",
|
|
"assigned_to": None,
|
|
}
|
|
client = cast("httpx.AsyncClient", object())
|
|
with (
|
|
patch.object(orch, "_is_agent_active", return_value=False),
|
|
patch.object(orch, "_task_git_context", return_value=None),
|
|
patch.object(
|
|
orch,
|
|
"_maybe_handoff_board_review_to_ceo",
|
|
new=AsyncMock(),
|
|
),
|
|
patch.object(
|
|
orch, "_claim_task_for_agent", new=AsyncMock(return_value=True)
|
|
) as claim,
|
|
patch.object(orch, "spawn_agent", new=AsyncMock()) as spawn,
|
|
):
|
|
await orch._route_unassigned_pm_task(client, task)
|
|
|
|
# Board work is a two-reviewer gate, not a claim — never claimed here.
|
|
claim.assert_not_awaited()
|
|
dispatched = {call.kwargs["agent_id"] for call in spawn.await_args_list}
|
|
assert dispatched == {"product-owner", "head-marketing"}
|
|
|
|
|
|
def test_board_review_complete_requires_both_reviewers_idle() -> None:
|
|
"""Review is complete only when BOTH reviewers are dispatched AND idle."""
|
|
orch = _make_orch()
|
|
task_id = str(uuid4())
|
|
|
|
with patch.object(orch, "_is_agent_active", return_value=False):
|
|
# Neither dispatched yet.
|
|
assert orch._board_review_complete(task_id) is False
|
|
# Only PO dispatched.
|
|
orch._board_dispatched.add(("product-owner", task_id))
|
|
assert orch._board_review_complete(task_id) is False
|
|
# Both dispatched and idle.
|
|
orch._board_dispatched.add(("head-marketing", task_id))
|
|
assert orch._board_review_complete(task_id) is True
|
|
|
|
|
|
def test_board_review_not_complete_while_a_reviewer_active() -> None:
|
|
orch = _make_orch()
|
|
task_id = str(uuid4())
|
|
orch._board_dispatched.add(("product-owner", task_id))
|
|
orch._board_dispatched.add(("head-marketing", task_id))
|
|
|
|
with patch.object(
|
|
orch, "_is_agent_active", side_effect=lambda s: s == "head-marketing"
|
|
):
|
|
# HoM still running its review — not done yet.
|
|
assert orch._board_review_complete(task_id) is False
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_ceo_handoff_once_when_board_review_complete() -> None:
|
|
"""When both reviewers finish, the handoff flags the task board-reviewed and
|
|
fires exactly one CEO notification."""
|
|
orch = _make_orch()
|
|
task_id = str(uuid4())
|
|
orch._board_dispatched.add(("product-owner", task_id))
|
|
orch._board_dispatched.add(("head-marketing", task_id))
|
|
|
|
svc = AsyncMock()
|
|
task_svc = AsyncMock()
|
|
db_ctx, task_ctx = _patch_handoff_db(task_svc)
|
|
with (
|
|
patch.object(orch, "_is_agent_active", return_value=False),
|
|
patch("roboco.services.notification.NotificationService", return_value=svc),
|
|
db_ctx,
|
|
task_ctx,
|
|
):
|
|
await orch._maybe_handoff_board_review_to_ceo(task_id)
|
|
# Second tick: already handed off — must not re-emit.
|
|
await orch._maybe_handoff_board_review_to_ceo(task_id)
|
|
|
|
task_svc.mark_board_review_complete.assert_awaited_once()
|
|
svc.send_board_review_complete_notification.assert_awaited_once_with(
|
|
task_id=task_id
|
|
)
|
|
assert task_id in orch._board_review_ceo_notified
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_ceo_not_handed_off_while_review_incomplete() -> None:
|
|
"""No flag and no CEO notification until BOTH reviewers are done."""
|
|
orch = _make_orch()
|
|
task_id = str(uuid4())
|
|
# Only PO has been dispatched/finished.
|
|
orch._board_dispatched.add(("product-owner", task_id))
|
|
|
|
svc = AsyncMock()
|
|
task_svc = AsyncMock()
|
|
db_ctx, task_ctx = _patch_handoff_db(task_svc)
|
|
with (
|
|
patch.object(orch, "_is_agent_active", return_value=False),
|
|
patch("roboco.services.notification.NotificationService", return_value=svc),
|
|
db_ctx,
|
|
task_ctx,
|
|
):
|
|
await orch._maybe_handoff_board_review_to_ceo(task_id)
|
|
|
|
task_svc.mark_board_review_complete.assert_not_awaited()
|
|
svc.send_board_review_complete_notification.assert_not_awaited()
|
|
assert task_id not in orch._board_review_ceo_notified
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_ceo_handoff_failure_allows_retry() -> None:
|
|
"""A handoff failure clears the one-shot guard so a later tick retries."""
|
|
orch = _make_orch()
|
|
task_id = str(uuid4())
|
|
orch._board_dispatched.add(("product-owner", task_id))
|
|
orch._board_dispatched.add(("head-marketing", task_id))
|
|
|
|
svc = AsyncMock()
|
|
svc.send_board_review_complete_notification.side_effect = RuntimeError("db down")
|
|
task_svc = AsyncMock()
|
|
db_ctx, task_ctx = _patch_handoff_db(task_svc)
|
|
with (
|
|
patch.object(orch, "_is_agent_active", return_value=False),
|
|
patch("roboco.services.notification.NotificationService", return_value=svc),
|
|
db_ctx,
|
|
task_ctx,
|
|
):
|
|
await orch._maybe_handoff_board_review_to_ceo(task_id)
|
|
|
|
# Guard cleared so a later, healthy tick can re-run the handoff.
|
|
assert task_id not in orch._board_review_ceo_notified
|
|
|
|
|
|
def test_board_review_prompt_names_both_reviewers_and_board_verbs() -> None:
|
|
"""The prompt must steer board agents to their real verbs (triage / note /
|
|
say / i_am_idle), make the PO+HoM pair-review model explicit, and away from
|
|
claim/plan/delegate they do not have."""
|
|
orch = _make_orch()
|
|
prompt = orch._build_board_prompt(_board_task("product-owner"))
|
|
assert "triage()" in prompt
|
|
assert "note(" in prompt
|
|
assert "i_am_idle()" in prompt
|
|
assert "Product Owner" in prompt and "Head of Marketing" in prompt
|
|
assert "do NOT" in prompt.lower() or "do not" in prompt.lower()
|