fix: refine terminal preflight check to avoid false-positive PATH blocks on server

This commit is contained in:
2026-07-09 11:31:48 -04:00
parent f558b80cc8
commit 8d6d3cb014
+35 -28
View File
@@ -9457,35 +9457,42 @@ def gitea_resolve_task_capability(
resolved_cwd = os.environ.get("GITEA_ACTIVE_WORKTREE") or PROJECT_ROOT resolved_cwd = os.environ.get("GITEA_ACTIVE_WORKTREE") or PROJECT_ROOT
probe_res = native_mcp_preference.probe_terminal_spawn(resolved_cwd) probe_res = native_mcp_preference.probe_terminal_spawn(resolved_cwd)
if not probe_res["healthy"]: if not probe_res["healthy"]:
profile = get_profile() # Only block if the failure is due to a missing CWD, missing shell, or the circuit breaker is tripped.
h = host or (REMOTES.get(remote, {}).get("host") if remote in REMOTES else None) # Other failures (like missing executable in the MCP process's limited PATH) should not block the agent's shell capability.
username = _authenticated_username(h) if h else None is_real_blocker = (
next_safe_action = ( probe_res.get("error_type") in ("missing cwd", "missing shell")
"BLOCKED + DIAGNOSE: terminal-launcher-failure " or native_mcp_preference.shell_health_status().get("hard_stopped")
f"({probe_res['error_type']}): {probe_res['error_msg']}. "
"Do not attempt git/pytest finalization or unsafe fallbacks. "
"Run gitea_diagnose_terminal, emit blocked-diagnose-report, and stop."
) )
return { if is_real_blocker:
"requested_task": task, profile = get_profile()
"required_operation_permission": required_permission, h = host or (REMOTES.get(remote, {}).get("host") if remote in REMOTES else None)
"required_role_kind": required_role, username = _authenticated_username(h) if h else None
"active_profile": profile["profile_name"], next_safe_action = (
"active_identity": username, "BLOCKED + DIAGNOSE: terminal-launcher-failure "
"active_profile_allowed_operations": profile.get("allowed_operations") or [], f"({probe_res['error_type']}): {probe_res['error_msg']}. "
"allowed_in_current_session": False, "Do not attempt git/pytest finalization or unsafe fallbacks. "
"stop_required": True, "Run gitea_diagnose_terminal, emit blocked-diagnose-report, and stop."
"infra_stop": True, )
"blocked": True, return {
"blocked_reason": "BLOCKED + DIAGNOSE", "requested_task": task,
"terminal_launcher_unhealthy": True, "required_operation_permission": required_permission,
"terminal_launcher_diagnostics": probe_res, "required_role_kind": required_role,
"task_role_guidance": [next_safe_action], "active_profile": profile["profile_name"],
"matching_configured_profile": [], "active_identity": username,
"runtime_switching_supported": gitea_config.is_runtime_switching_enabled(), "active_profile_allowed_operations": profile.get("allowed_operations") or [],
"different_mcp_namespace_required": False, "allowed_in_current_session": False,
"exact_safe_next_action": next_safe_action, "stop_required": True,
} "infra_stop": True,
"blocked": True,
"blocked_reason": "BLOCKED + DIAGNOSE",
"terminal_launcher_unhealthy": True,
"terminal_launcher_diagnostics": probe_res,
"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, resolved_task=task) record_preflight_check("capability", required_role, resolved_task=task)