fix(gateway): bounded fail-open evidence assembly + PM decision transient-failure bypass

Evidence-assembly git legs (diff, changed-files, branch fetch, advisory
conventions run) ran unbounded inside claim_review / claim_doc_task /
claim_gate_review / evidence() / i_am_done's envelope build, so a slow
clone turned the whole verb into a silent 120s FlowVerbTimeout 504.
Each leg now runs through run_bounded_leg under a shared LegBudget
(evidence_assembly_timeout_seconds, 45s total): a timed-out leg — both
asyncio TimeoutError and git's own GitTimeoutError — degrades into an
evidence_gaps note on the envelope instead of hanging the verb, while
non-timeout git errors still propagate. The advisory conventions run
gets an inner-only timeout (conventions_validator_advisory_timeout_
seconds, 30s) threaded down to the subprocess so it is never orphaned
by an outer cancel; the fail-closed i_am_done/pr_pass conventions
gates keep their hardcoded 120s.

_ensure_pm_decision now reports a PmDecisionOutcome: a transient DB
failure recording the PM's decision journal (e.g. lock timeout under
load) no longer launders into a journal:decision gate rejection that
escalates and BLOCKS the task — the verb's own rationale satisfies the
gate with a structured warning, across all seven PM verbs.

Also: repo-wide ruff realignment to the lockfile-pinned ruff (8
format-only diffs, 14 UP038 isinstance conversions) that a transiently
newer venv ruff had masked.

Gate: 15474 passed, 459 skipped; ruff/mypy/xenon/vulture/bandit/
pip-audit/deptry/import-linter/foundation-check all green.
This commit is contained in:
Renn F
2026-07-31 13:56:19 +02:00
parent ef8849b0cd
commit ce4d02b3c2
41 changed files with 2160 additions and 138 deletions
-21
View File
@@ -325,7 +325,6 @@ async def test_send_message_with_task_id_response(a2a_route_client: dict) -> Non
async def test_send_message_response_invalid_task_id(
a2a_route_client: dict,
) -> None:
client = a2a_route_client["client"]
with patch("roboco.api.routes.a2a.A2AService") as mock_service_cls:
instance = AsyncMock()
@@ -352,7 +351,6 @@ async def test_send_message_response_invalid_task_id(
async def test_send_message_response_task_not_found(
a2a_route_client: dict,
) -> None:
client = a2a_route_client["client"]
with patch("roboco.api.routes.a2a.A2AService") as mock_service_cls:
instance = AsyncMock()
@@ -379,7 +377,6 @@ async def test_send_message_response_task_not_found(
async def test_send_message_create_notification_success(
a2a_route_client: dict,
) -> None:
client = a2a_route_client["client"]
with patch("roboco.api.routes.a2a.A2AService") as mock_service_cls:
instance = AsyncMock()
@@ -403,7 +400,6 @@ async def test_send_message_create_notification_success(
@pytest.mark.asyncio
async def test_send_message_permission_error(a2a_route_client: dict) -> None:
client = a2a_route_client["client"]
with patch("roboco.api.routes.a2a.A2AService") as mock_service_cls:
instance = AsyncMock()
@@ -427,7 +423,6 @@ async def test_send_message_permission_error(a2a_route_client: dict) -> None:
@pytest.mark.asyncio
async def test_send_message_value_error(a2a_route_client: dict) -> None:
client = a2a_route_client["client"]
with patch("roboco.api.routes.a2a.A2AService") as mock_service_cls:
instance = AsyncMock()
@@ -454,7 +449,6 @@ async def test_send_message_value_error(a2a_route_client: dict) -> None:
@pytest.mark.asyncio
async def test_cancel_task_success(a2a_route_client: dict) -> None:
a2a_task = A2ATask.model_validate(
{
"id": str(a2a_route_client["task"].id),
@@ -484,7 +478,6 @@ async def test_cancel_task_success(a2a_route_client: dict) -> None:
@pytest.mark.asyncio
async def test_cancel_task_already_terminal(a2a_route_client: dict) -> None:
client = a2a_route_client["client"]
_set_pm_context(a2a_route_client["app"], a2a_route_client["dev"])
with patch("roboco.api.routes.a2a.A2AService") as mock_service_cls:
@@ -502,7 +495,6 @@ async def test_cancel_task_already_terminal(a2a_route_client: dict) -> None:
@pytest.mark.asyncio
async def test_cancel_task_not_found(a2a_route_client: dict) -> None:
client = a2a_route_client["client"]
_set_pm_context(a2a_route_client["app"], a2a_route_client["dev"])
with patch("roboco.api.routes.a2a.A2AService") as mock_service_cls:
@@ -638,7 +630,6 @@ async def test_send_message_uses_authenticated_identity_not_client_from_agent(
async def test_chat_create_conversation_access_denied(
a2a_route_client: dict,
) -> None:
client = a2a_route_client["client"]
with patch("roboco.api.routes.a2a.A2AService") as mock_service_cls:
instance = AsyncMock()
@@ -667,7 +658,6 @@ async def test_chat_create_conversation_access_denied(
async def test_chat_create_conversation_success(
a2a_route_client: dict,
) -> None:
client = a2a_route_client["client"]
conv_id = uuid4()
with patch("roboco.api.routes.a2a.A2AService") as mock_service_cls:
@@ -707,7 +697,6 @@ async def test_chat_create_conversation_success(
async def test_chat_create_conversation_refresh_failed(
a2a_route_client: dict,
) -> None:
client = a2a_route_client["client"]
with patch("roboco.api.routes.a2a.A2AService") as mock_service_cls:
instance = AsyncMock()
@@ -744,7 +733,6 @@ async def test_chat_create_conversation_refresh_failed(
@pytest.mark.asyncio
async def test_get_conversation_not_found(a2a_route_client: dict) -> None:
client = a2a_route_client["client"]
with patch("roboco.api.routes.a2a.A2AService") as mock_service_cls:
instance = AsyncMock()
@@ -758,7 +746,6 @@ async def test_get_conversation_not_found(a2a_route_client: dict) -> None:
@pytest.mark.asyncio
async def test_get_conversation_success(a2a_route_client: dict) -> None:
client = a2a_route_client["client"]
conv_id = uuid4()
with patch("roboco.api.routes.a2a.A2AService") as mock_service_cls:
@@ -790,7 +777,6 @@ async def test_get_conversation_success(a2a_route_client: dict) -> None:
async def test_close_conversation_value_error(
a2a_route_client: dict,
) -> None:
client = a2a_route_client["client"]
with patch("roboco.api.routes.a2a.A2AService") as mock_service_cls:
instance = AsyncMock()
@@ -806,7 +792,6 @@ async def test_close_conversation_value_error(
@pytest.mark.asyncio
async def test_close_conversation_success(a2a_route_client: dict) -> None:
client = a2a_route_client["client"]
with patch("roboco.api.routes.a2a.A2AService") as mock_service_cls:
instance = AsyncMock()
@@ -822,7 +807,6 @@ async def test_close_conversation_success(a2a_route_client: dict) -> None:
@pytest.mark.asyncio
async def test_list_chat_messages(a2a_route_client: dict) -> None:
client = a2a_route_client["client"]
msg = SimpleNamespace(
id=uuid4(),
@@ -853,7 +837,6 @@ async def test_list_chat_messages(a2a_route_client: dict) -> None:
async def test_send_chat_message_value_error(
a2a_route_client: dict,
) -> None:
client = a2a_route_client["client"]
with patch("roboco.api.routes.a2a.A2AService") as mock_service_cls:
instance = AsyncMock()
@@ -869,7 +852,6 @@ async def test_send_chat_message_value_error(
@pytest.mark.asyncio
async def test_send_chat_message_success(a2a_route_client: dict) -> None:
client = a2a_route_client["client"]
msg = SimpleNamespace(
id=uuid4(),
@@ -926,7 +908,6 @@ async def test_send_chat_message_over_budget_returns_403(
@pytest.mark.asyncio
async def test_mark_read(a2a_route_client: dict) -> None:
client = a2a_route_client["client"]
with patch("roboco.api.routes.a2a.A2AService") as mock_service_cls:
instance = AsyncMock()
@@ -941,7 +922,6 @@ async def test_mark_read(a2a_route_client: dict) -> None:
@pytest.mark.asyncio
async def test_get_task_conversations(a2a_route_client: dict) -> None:
client = a2a_route_client["client"]
with patch("roboco.api.routes.a2a.A2AService") as mock_service_cls:
instance = AsyncMock()
@@ -956,7 +936,6 @@ async def test_get_task_conversations(a2a_route_client: dict) -> None:
@pytest.mark.asyncio
async def test_chat_list_with_status_filter(a2a_route_client: dict) -> None:
client = a2a_route_client["client"]
with patch("roboco.api.routes.a2a.A2AService") as mock_service_cls:
instance = AsyncMock()
@@ -18,7 +18,7 @@ def _enclosing_function(tree: ast.AST, lineno: int) -> str | None:
candidate: str | None = None
candidate_start = -1
for node in ast.walk(tree):
if isinstance(node, (ast.AsyncFunctionDef, ast.FunctionDef)):
if isinstance(node, ast.AsyncFunctionDef | ast.FunctionDef):
start = node.lineno
end = getattr(node, "end_lineno", None) or start
if start <= lineno <= end and start > candidate_start:
@@ -884,7 +884,6 @@ async def test_soft_block_task_for_agent_full_flow(
db_session: AsyncSession,
monkeypatch: pytest.MonkeyPatch,
) -> None:
svc = task_setup["svc"]
task = await svc.create(_req(task_setup))
task.assigned_to = task_setup["agent_id"]
@@ -929,7 +928,6 @@ async def test_soft_block_task_for_agent_full_flow(
async def test_docs_complete_for_task_invokes_notification(
task_setup: dict, db_session: AsyncSession, monkeypatch: pytest.MonkeyPatch
) -> None:
svc = task_setup["svc"]
doc = AgentTable(
id=uuid4(),
@@ -988,7 +986,6 @@ async def test_docs_complete_for_task_invokes_notification(
async def test_escalate_to_ceo_for_agent_invokes_notification(
task_setup: dict, db_session: AsyncSession, monkeypatch: pytest.MonkeyPatch
) -> None:
svc = task_setup["svc"]
pm = AgentTable(
id=uuid4(),
@@ -1054,7 +1051,6 @@ async def test_escalate_to_ceo_for_agent_invokes_notification(
async def test_claim_task_for_agent_commits_and_returns(
task_setup: dict, db_session: AsyncSession, monkeypatch: pytest.MonkeyPatch
) -> None:
svc = task_setup["svc"]
task = await svc.create(_req(task_setup))
task.branch_name = "feature/backend/x"
@@ -1088,7 +1084,6 @@ async def test_claim_task_for_agent_commits_and_returns(
async def test_complete_task_for_agent_commits(
task_setup: dict, db_session: AsyncSession, monkeypatch: pytest.MonkeyPatch
) -> None:
svc = task_setup["svc"]
pm = AgentTable(
id=uuid4(),
@@ -1138,7 +1133,6 @@ async def test_complete_task_for_agent_commits(
async def test_substitute_task_for_agent_runs_update(
task_setup: dict, db_session: AsyncSession, monkeypatch: pytest.MonkeyPatch
) -> None:
svc = task_setup["svc"]
task = await svc.create(_req(task_setup))
task.assigned_to = task_setup["agent_id"]
-4
View File
@@ -1182,7 +1182,6 @@ async def test_unblock_task_not_blocked_returns_400(task_client: dict) -> None:
@pytest.mark.asyncio
async def test_unblock_task_forbidden(task_client: dict) -> None:
other = await _seed_agent(task_client)
task = _seed_task(task_client, status=TaskStatus.BLOCKED, assigned_to=other.id)
await task_client["db"].flush()
@@ -1615,7 +1614,6 @@ async def test_activate_unknown_returns_4xx(task_client: dict) -> None:
@pytest.mark.asyncio
async def test_activate_developer_forbidden(task_client: dict) -> None:
app = task_client["client"]._transport.app
async def _override_agent() -> AgentContext:
@@ -1668,7 +1666,6 @@ async def test_get_team_tasks_unauthorized(task_client: dict) -> None:
async def test_get_task_stats_by_team_developer_forbidden(
task_client: dict,
) -> None:
app = task_client["client"]._transport.app
async def _override_agent() -> AgentContext:
@@ -1779,7 +1776,6 @@ async def test_delete_task_forbidden_non_creator(task_client: dict) -> None:
@pytest.mark.asyncio
async def test_cancel_developer_forbidden(task_client: dict) -> None:
task = _seed_task(task_client)
await task_client["db"].flush()
app = task_client["client"]._transport.app