IDEA的AI Assistant—Codex初始化失败、Node初始化失败:Failed to initialize ACP session. Error: Process cancelled、Reconnecting...

这两天开始接触到IDEA自带的ai chat,发现开通了他的AI Pro会员后,可以免费使用三种智能体,Codex、Claude Agent、Junie,而总是提示acp 初始化失败,一共遇到两种错误。

问题1、Node的npm初始化失败

Failed to initialize ACP session. Error: Process cancelled

Failed to initialize ACP process. Process terminated with exit code: -4058. Process output: npm warn Unknown env config "min-release-age". This will stop working in the next major version of npm. npm error code ENOENT npm error syscall open npm error path C:\Users\xxx\AppData\Local\JetBrains\IntelliJIdea2026.1\acp-agents\.runtimes\node\24.13.0\npm-cache\_npx\6722ddab116cb282\package.json npm error errno -4058

错误日志如上,idea提示我:

The agent runtime may be corrupted. 清除已下载的 ACP 运行时 and try again in the new chat.

If the issue persists, close the IDE, delete the C:\Users\xxx\AppData\Local\JetBrains\IntelliJIdea2026.1\acp-agents\.runtimes directory, and restart.The agent runtime may be corrupted. 清除已下载的 ACP 运行时 and try again in the new chat.

按照他说的没用,还是缺少**package.json。**好在之前处理管理后台,需要webpack打包,研究了node,不然还不知道怎么办。

解决办法 :缺什么自己补什么,我发现这个目录**acp-agents\.runtimes\node\24.13.0\npm-cache\_npx\6722ddab116cb282\,**已经下载好了node_modules,只是缺少package.json,不知道是因为网络墙的原因还是啥,反正可以自己补上,根据node_modules文件夹里面有哪些package给自己生成一个package.json出来,问了ai:node如何根据已经存在的node_modules,逆向生成package.json,他给我了一段代码:


const fs = require('fs');

const path = require('path');

const nodeModulesDir = path.join(__dirname, 'node_modules');

const dependencies = {};

function scan(dir) {

const items = fs.readdirSync(dir);

items.forEach(item => {

// 处理 @scope 目录

if (item.startsWith('@')) {

const scopeDir = path.join(dir, item);

if (fs.statSync(scopeDir).isDirectory()) {

const subItems = fs.readdirSync(scopeDir);

subItems.forEach(sub => {

const pkgPath = path.join(scopeDir, sub, 'package.json');

if (fs.existsSync(pkgPath)) {

const { name, version } = require(pkgPath);

dependenciesname = version;

}

});

}

} else {

const fullPath = path.join(dir, item);

// 过滤掉非目录文件(如 .bin, .package-lock.json)

if (fs.statSync(fullPath).isDirectory()) {

const pkgPath = path.join(fullPath, 'package.json');

if (fs.existsSync(pkgPath)) {

const { name, version } = require(pkgPath);

dependenciesname = version;

}

}

}

});

}

scan(nodeModulesDir);

const packageJson = {

name: "recovered-project",

version: "1.0.0",

description: "Recovered from node_modules",

main: "index.js",

scripts: { test: "echo \"Error: no test specified\" && exit 1" },

dependencies,

devDependencies: {}

};

fs.writeFileSync(

path.join(__dirname, 'package.json'),

JSON.stringify(packageJson, null, 2)

);

console.log(`✅ package.json 已生成,包含 ${Object.keys(dependencies).length} 个依赖`);


我们将上述代码复制,在目录acp-agents\.runtimes\node\24.13.0\npm-cache\_npx\6722ddab116cb282\ 下新建一个空白文件gen-package.js,然后将复制的内容粘贴进去,使用cmd在当前目录执行命令:node gen-package.js,就会生成package.json。该问题解决。如果你电脑本身没有安装全局性的node.js,那你就调用C:\Users\xxxAppData\Local\JetBrains\IntelliJIdea2026.1\acp-agents\.runtimes\node\24.13.0\bin目录下的node.exe,这个node和你全局安装的node不一样,此处的node是idea自己的ai chat安装的。

问题2、

Reconnecting... 1/5

Reconnecting... 2/5

Reconnecting... 3/5

Reconnecting... 4/5

Reconnecting... 5/5

unexpected status 503 Service Unavailable: Unknown error, url: http://127.0.0.1:50000/responses

解决办法: 当你看到http://127.0.0.1:xxxx/responses, 就知道,这肯定是走了代理,可是我明明用了vpn开了全局的,diea的设置里面http代理也是设置的自动检测代理,为什么ai没走我的系统代理?原因是他自己会新建一个代理走,但是咱们属于国内,走他那个代理,相当于不会翻出去,也就网络不通。所以咱们要修改codex的代理,C:\Users\xxx\.codex\目录下,有个.env文件,如果没有就自己新建,然后将以下内容复制进去,然后重启idea,问题解决。(注意:下面的1081是你自己的系统代理的端口号,改成自己的!!!)


HTTP_PROXY="http://127.0.0.1:1081"

HTTPS_PROXY="http://127.0.0.1:1081"

NO_PROXY="localhost,127.0.0.1,::1"