Antigravity报错Agent execution terminated due to error的修复记录

想要给我的项目做反重力适配,没想到一打开就不断显示Agent execution terminated due to error. 翻了论坛佬的贴,依旧没解决问题。佬的贴在这→ Antigravity的进一步软封禁?从retry到429 Agent execution terminated due ...
Antigravity报错Agent execution terminated due to error的修复记录
Antigravity报错Agent execution terminated due to error的修复记录

想要给我的项目做反重力适配,没想到一打开就不断显示Agent execution terminated due to error.
翻了论坛佬的贴,依旧没解决问题。佬的贴在这→Antigravity的进一步软封禁?从retry到429 Agent execution terminated due to error.
足足排查了一上午,终于找到了问题,并且已经成功解决,发在这里希望能帮各位佬解决问题。

个人系统配置

Windows 11 + PowerShell + Antigravity CLI 1.0.0

整个排查过程

我一开始一开始看 CLI 日志(~/.gemini/antigravity-cli/log/cli-*.log)报错如下:
You are not logged into Antigravity
failed to get load code assist response
Failed to poll FetchAvailableModels

于是初步怀疑是Clash小黑猫的原因。于是清 oauth_creds.json、删 Windows Credential Manager 里的 token、设 HTTPS_PROXY 走代理、Invoke-WebRequest 测可达性,但依旧没有解决问题。
后来才注意到日志里 Auth succeedednot logged into Antigravity 在报错时会同时出现。然后我就让GPT哥帮我过滤了一下日志↓↓↓

Select-String -Path "$env:USERPROFILE\.gemini\antigravity-cli\log\cli-*.log" `
  -Pattern 'JSON hook|jsonhook__|agent executor error|was unexpected|not recognized|protojson' `
  -CaseSensitive:$false | Select-Object -Last 50

如果你像我一样搞过系统的hooks,那就可能会出现:

agent executor error: failed to call custom hook jsonhook__xxx_PreInvocation_0_0
& was unexpected at this time.
"node" is not recognized as an internal or external command

根本原因

agy 在 Windows 下执行hook不走PowerShell走cmd。cmd 不认 &,PATH 也未必有 node,hook 直接挂。
Antigravity 的设计是:PreInvocation hook 失败 → 整个 agent run 立刻被打断。TUI 不显示底层 hook 错误,只给你那一行通用红字。

屏幕截图 2026-05-21 113635

所以,我感觉这个报错实在是太宽泛了,Google实在是有点偷懒。这个报错的背后可能有多种原因 OAuth、网络、后端、workspace config、hook 命令格式、hook 输出不合法 JSON 之类的任何一种。那我这里贡献我自己的,因为hook设置导致失败的解决路径。

我的修复方案 (经5.5哥反复审核后分享给各位佬)

1)hook command 改成 PowerShell -EncodedCommand 调绝对路径 node.exe

powershell.exe -NoProfile -NonInteractive -ExecutionPolicy Bypass -EncodedCommand <base64>

base64 里塞真实命令,比如:

& 'C:\Program Files\nodejs\node.exe' 'D:/xxx/hook.js' 'PreInvocation'

生成 base64:

$s = "& 'C:\Program Files\nodejs\node.exe' 'D:/xxx/hook.js' 'PreInvocation'"
[Convert]::ToBase64String([Text.Encoding]::Unicode.GetBytes($s))

这样彻底绕开 cmd 和 PowerShell 的引号差异、空格路径、& 符号一系列坑。

2)hook 脚本本身一定要 fail-open

如果你的 hook 只是观察状态(上报本地服务、写 log 之类的活),任何本地异常都不该让 hook 返回非零或非法 JSON。catch 住所有异常,输出 fallback JSON 然后 exit 0:

main().catch(() => {
process.stdout.write(JSON.stringify({ decision: "ask" }) + "\n");
}).finally(() => process.exit(0));

3)修完验证

agy --print "ping"、

正常回响应就是修好了。

1 个帖子 - 1 位参与者

阅读完整话题

来源: LinuxDo 最新话题查看原文