fix: recompute infra_stop live on every capability resolve (#285)

Add assess_infra_stop() to scan git state and conflict markers on each
reviewer capability check, return the exact conflict path in responses,
and clear stale capability-stop terminal state once the worktree is clean.

Closes #285

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
This commit is contained in:
2026-07-07 00:21:18 -04:00
co-authored by Claude Opus 4.8
parent d6f4f936e3
commit 5af1b796ef
3 changed files with 172 additions and 53 deletions
+34 -24
View File
@@ -4905,30 +4905,40 @@ def gitea_resolve_task_capability(
required_permission = task_capability_map.required_permission(task)
required_role = task_capability_map.required_role(task)
if required_role == "reviewer" and role_session_router.check_mid_merge():
profile = get_profile()
h = host or (REMOTES.get(remote, {}).get("host") if remote in REMOTES else None)
username = _authenticated_username(h) if h else None
next_safe_action = (
"infra_stop: Unresolved merge conflict or mid-merge state detected in MCP runtime source. "
"Please resolve all conflicts manually, finish/abort the merge, restart the MCP server, and retry."
)
return {
"requested_task": task,
"required_operation_permission": required_permission,
"required_role_kind": required_role,
"active_profile": profile["profile_name"],
"active_identity": username,
"active_profile_allowed_operations": profile.get("allowed_operations") or [],
"allowed_in_current_session": False,
"stop_required": True,
"infra_stop": True,
"task_role_guidance": [next_safe_action],
"matching_configured_profile": [],
"runtime_switching_supported": gitea_config.is_runtime_switching_enabled(),
"different_mcp_namespace_required": False,
"exact_safe_next_action": next_safe_action,
}
infra_assessment = role_session_router.assess_infra_stop(PROJECT_ROOT)
if required_role == "reviewer":
if not infra_assessment["infra_stop"]:
capability_stop_terminal.clear()
last_route = role_session_router.last_route()
if last_route and last_route.get("route_result") == role_session_router.ROUTE_INFRA_STOP:
role_session_router.clear_route_state()
elif infra_assessment["infra_stop"]:
profile = get_profile()
h = host or (REMOTES.get(remote, {}).get("host") if remote in REMOTES else None)
username = _authenticated_username(h) if h else None
detail = "; ".join(infra_assessment.get("infra_stop_reasons") or [])
next_safe_action = (
"infra_stop: Unresolved merge conflict or mid-merge state detected in "
f"MCP runtime source ({detail}). Please resolve all conflicts manually, "
"finish/abort the merge, and retry."
)
return {
"requested_task": task,
"required_operation_permission": required_permission,
"required_role_kind": required_role,
"active_profile": profile["profile_name"],
"active_identity": username,
"active_profile_allowed_operations": profile.get("allowed_operations") or [],
"allowed_in_current_session": False,
"stop_required": True,
"infra_stop": True,
"infra_stop_assessment": infra_assessment,
"task_role_guidance": [next_safe_action],
"matching_configured_profile": [],
"runtime_switching_supported": gitea_config.is_runtime_switching_enabled(),
"different_mcp_namespace_required": False,
"exact_safe_next_action": next_safe_action,
}
record_preflight_check("capability", required_role)