[Antigravity][Hooks] PreToolUse hook causes protojson syntax error on Python 3.9 and blocks all tool executions
Environment
- Host: Google Antigravity 2.0 / macOS (arm64)
- Default Python:
/usr/bin/python3(Python 3.9.6) - Plugin:
nowledge-mem-google-antigravity(commit9bb5f46) - Related Repo Issue: nowledge-co/nowledge-mem-google-antigravity#10
Problem Description
When running Google Antigravity with the Nowledge Mem plugin on macOS where /usr/bin/python3 is Python 3.9, calling any tool matched by PreToolUse (including run_command, call_mcp_tool) immediately aborts with:
failed to unmarshal result from hook jsonhook__nowledge-mem-hooks_PreToolUse_0_0 via protojson: {decision:ask}: proto: syntax error (line 1:2): invalid value decision
This prevents the agent from executing any terminal commands or calling MCP tools.
Root Cause Analysis
-
Python 3.9 PEP 604 Type Annotations: In
hooks/nmem_shared.py(line 33):_ACTIVE_WORKSPACE_ROOT: Path | None = NoneWithout
from __future__ import annotations, Python 3.9 raises:TypeError: unsupported operand type(s) for |: 'type' and 'NoneType'causing
python3 hooks/nmem_entrypoint.py gateto fail on startup. -
Shell Fallback Quoting in
hooks.json: Inhooks.json:"command": "python3 hooks/nmem_entrypoint.py gate || python hooks/nmem_entrypoint.py gate || echo {\"decision\":\"ask\"}"When the python commands fail, the shell executes
echo {"decision":"ask"}. Because outer quotes are missing, the shell strips quotes or expands braces, writing{decision:ask}(unquoted JSON keys) to stdout. Antigravity's Go runtime attempts to parse this viaprotojson.Unmarshal(), triggering a fatal syntax error.
Proposed Fixes
- Add
from __future__ import annotationstohooks/nmem_shared.py(and related entrypoint scripts). - Protect the fallback echo in
hooks.jsonwith single quotes to ensure valid JSON output:"command": "... || echo '{\"decision\":\"allow\"}'"
Thanks for the detailed report and root-cause analysis; it matched what we found.
The fix is merged into the plugin's main in nowledge-co/nowledge-mem-google-antigravity#11:
- the hooks now run on Python 3.9, including the macOS system
/usr/bin/python3; - the PreToolUse fallback prints valid JSON, so a hook that cannot run no longer aborts tool calls;
- CI now runs the hook tests on Python 3.9.
If you installed the plugin with git clone as in the README, update it and restart Antigravity:
git -C ~/.gemini/config/plugins/nowledge-mem pull
While the hooks were failing, Stop could not save your sessions. To bring them in, preview with nmem t sync --from antigravity, then run it again with --apply to import them.
Could you let us know whether tool calls work for you after updating?
@Ran-Xing a quick follow-up: the fix has been on the plugin's main since 2026-10-31 (nowledge-co/nowledge-mem-google-antigravity#11), and we have not heard back yet whether it works on your machine.
When you have a moment, please update the plugin and restart Antigravity:
git -C ~/.gemini/config/plugins/nowledge-mem pull
Then run any tool call that PreToolUse covers, for example run_command, and let us know whether it goes through. If it still fails, please paste the error line and the output of /usr/bin/python3 --version (no conversation content needed).
We will keep this open until you confirm.
git 已经是最新的了,请问你说的
然后运行 PreToolUse 涵盖的任何工具调用,例如
<toolcall>run_command,并告知我们是否成功。如果仍然失败,请粘贴错误信息和<toolcall>的输出/usr/bin/python3 --version(无需提供对话内容)。
是什么?
➜ ~ nmem t sync --from antigravity
Preview — 137 antigravity session(s). No changes made; re-run with --apply to import.
9cf03b01-a671-4573-b5e5-17626b63da3f (19 messages) /goal /teamwork /boost 1. 学习 paseo 前后端分离 2. 学习 cindy 使用 @anthropic-ai/claude-age...
! /Users/xr/.gemini/antigravity/brain/4cee0a61-0976-4a63-bc55-f17e6c38b835/.system_generated/logs/transcript.jsonl: Antigravity conversation has no human turn and its lineage is unknown
Mem syncs a conversation without a human turn only when Antigravity records which conversation delegated it. Antigravity's conversation_summaries.db is in WAL mode without its -wal and -shm files, which exist only while a program has the database open, and Mem does not open it without them.
! /Users/xr/.gemini/antigravity/brain/7ef83684-dce3-485e-92f1-3f4800502800/.system_generated/logs/transcript.jsonl: Antigravity conversation has no human turn and its lineage is unknown
Mem syncs a conversation without a human turn only when Antigravity records which conversation delegated it. Antigravity's conversation_summaries.db is in WAL mode without its -wal and -shm files, which exist only while a program has the database open, and Mem does not open it without them.
! /Users/xr/.gemini/antigravity/brain/745e1432-9a75-491b-8af3-18f4c3ab0822/.system_generated/logs/transcript.jsonl: Antigravity conversation has no human turn and its lineage is unknown
Mem syncs a conversation without a human turn only when Antigravity records which conversation delegated it. Antigravity's conversation_summaries.db is in WAL mode without its -wal and -shm files, which exist only while a program has the database open, and Mem does not open it without them.
! /Users/xr/.gemini/antigravity/brain/287aa0a2-c885-4cd0-85cf-8adc8973c416/.system_generated/logs/transcript.jsonl: Antigravity conversation has no human turn and its lineage is unknown
Mem syncs a conversation without a human turn only when Antigravity records which conversation delegated it. Antigravity's conversation_summaries.db is in WAL mode without its -wal and -shm files, which exist only while a program has the database open, and Mem does not open it without them.
! /Users/xr/.gemini/antigravity/brain/3ba7ce7b-aa1d-4c70-bb40-57207063393b/.system_generated/logs/transcript.jsonl: Antigravity conversation has no human turn and its lineage is unknown
Mem syncs a conversation without a human turn only when Antigravity records which conversation delegated it. Antigravity's conversation_summaries.db is in WAL mode without its -wal and -shm files, which exist only while a program has the database open, and Mem does not open it without them.
! /Users/xr/.gemini/antigravity/brain/4040d685-4425-491c-a2f3-5ceafcc7bf09/.system_generated/logs/transcript.jsonl: Antigravity conversation has no human turn and its lineage is unknown
Mem syncs a conversation without a human turn only when Antigravity records which conversation delegated it. Antigravity's conversation_summaries.db is in WAL mode without its -wal and -shm files, which exist only while a program has the database open, and Mem does not open it without them.
! /Users/xr/.gemini/antigravity/brain/c89bf529-f045-4de7-80dc-ad0a0e713514/.system_generated/logs/transcript.jsonl: Antigravity conversation has no human turn and its lineage is unknown
Mem syncs a conversation without a human turn only when Antigravity records which conversation delegated it. Antigravity's conversation_summaries.db is in WAL mode without its -wal and -shm files, which exist only while a program has the database open, and Mem does not open it without them.
! /Users/xr/.gemini/antigravity/brain/f0f4c76f-3250-4211-ad7f-24d5bbf95c6f/.system_generated/logs/transcript.jsonl: Antigravity conversation has no human turn and its lineage is unknown
Mem syncs a conversation without a human turn only when Antigravity records which conversation delegated it. Antigravity's conversation_summaries.db is in WAL mode without its -wal and -shm files, which exist only while a program has the database open, and Mem does not open it without them.
! /Users/xr/.gemini/antigravity/brain/de9d210e-6f2a-4aa8-a707-5ca64bb1b979/.system_generated/logs/transcript.jsonl: Antigravity conversation has no human turn and its lineage is unknown
Mem syncs a conversation without a human turn only when Antigravity records which conversation delegated it. Antigravity's conversation_summaries.db is in WAL mode without its -wal and -shm files, which exist only while a program has the database open, and Mem does not open it without them.
! /Users/xr/.gemini/antigravity/brain/662fdcf6-f6d5-4555-b741-6fca34385a3f/.system_generated/logs/transcript.jsonl: Antigravity conversation has no human turn and its lineage is unknown
Mem syncs a conversation without a human turn only when Antigravity records which conversation delegated it. Antigravity's conversation_summaries.db is in WAL mode without its -wal and -shm files, which exist only while a program has the database open, and Mem does not open it without them.
! /Users/xr/.gemini/antigravity/brain/7550ae2d-5c7d-48e6-bde1-e89f757d0a5b/.system_generated/logs/transcript.jsonl: Antigravity conversation has no human turn and its lineage is unknown
Mem syncs a conversation without a human turn only when Antigravity records which conversation delegated it. Antigravity's conversation_summaries.db is in WAL mode without its -wal and -shm files, which exist only while a program has the database open, and Mem does not open it without them.
! /Users/xr/.gemini/antigravity/brain/470f8f18-9501-4088-9efb-330771a6530e/.system_generated/logs/transcript.jsonl: Antigravity conversation has no human turn and its lineage is unknown
Mem syncs a conversation without a human turn only when Antigravity records which conversation delegated it. Antigravity's conversation_summaries.db is in WAL mode without its -wal and -shm files, which exist only while a program has the database open, and Mem does not open it without them.
! /Users/xr/.gemini/antigravity/brain/f1bdff44-e27f-4d9c-80a6-96e3c437ba3a/.system_generated/logs/transcript.jsonl: Antigravity conversation has no human turn and its lineage is unknown
Mem syncs a conversation without a human turn only when Antigravity records which conversation delegated it. Antigravity's conversation_summaries.db is in WAL mode without its -wal and -shm files, which exist only while a program has the database open, and Mem does not open it without them.
! /Users/xr/.gemini/antigravity/brain/0a33974c-26ec-453e-880e-327c029f1488/.system_generated/logs/transcript.jsonl: Antigravity conversation has no human turn and its lineage is unknown
Mem syncs a conversation without a human turn only when Antigravity records which conversation delegated it. Antigravity's conversation_summaries.db is in WAL mode without its -wal and -shm files, which exist only while a program has the database open, and Mem does not open it without them.
! /Users/xr/.gemini/antigravity/brain/5472df59-76c1-42ab-8957-41d798062991/.system_generated/logs/transcript.jsonl: Antigravity conversation has no human turn and its lineage is unknown
Mem syncs a conversation without a human turn only when Antigravity records which conversation delegated it. Antigravity's conversation_summaries.db is in WAL mode without its -wal and -shm files, which exist only while a program has the database open, and Mem does not open it without them.
0e8846cf-abeb-487e-8fb4-42d0f22171aa (5 messages) 把 cindy 的所有伙伴复制到 Bots 按照名字 创建文件夹
25d4e330-9111-4993-b243-b3b6a6a1858b (16 messages) Antigravity 还有记录
ca4c0d35-d059-414a-a039-9e5ab291dd65 (7 messages) 清理 agy 失效会话
7a0c5222-8d7a-4a71-a758-dbb6e1c90e71 (38 messages) 实现这个需求:https://github.com/makecindy/cindy/issues/8689#issuecomment-6612780022
... 117 more; use --json for full output
error: thread sync incomplete: 90 session(s) failed
➜ ~
@Ran-Xing 谢谢回复,上次那句确实写得太绕了,抱歉。
确认 hook 有没有修好,其实很简单:在 Antigravity 里开一个普通对话,让它在终端里执行一条命令,比如直接对它说「在终端里运行 echo hello」。如果命令正常执行,也没有再出现 failed to unmarshal result from hook ... via protojson 这行报错,就说明修好了。麻烦告诉我们结果就行。
如果想顺便确认插件确实是新版本,可以在终端运行下面这条命令,输出开头应当是 46022fe:
git -C ~/.gemini/config/plugins/nowledge-mem log -1 --format=%h
另外,谢谢你贴的同步结果、截图和附件,我们都看过了。失败的会话里有子代理会话,比如你截图里那个由另一个会话派出去的子任务,它们导入失败的原因在我们这边,不是你操作的问题。我们还在修,修好后会在这里告诉你。
有一件事能帮我们判断「开着 Antigravity 再同步」能不能解决:请在 Antigravity 开着的时候,在终端运行下面这条命令,把列出的文件名贴给我们。只要文件名,不需要任何对话内容。
ls ~/.gemini/antigravity/conversation_summaries.db*
是 46022fe
/Users/xr/.gemini/antigravity/conversation_summaries.db
/Users/xr/.gemini/antigravity/conversation_summaries.db-shm
/Users/xr/.gemini/antigravity/conversation_summaries.db-wal
/Users/xr/.gemini/antigravity/conversation_summaries.db.bak.1793785424
依旧导入不了,谢谢
@Ran-Xing 谢谢确认插件已经是 46022fe,也谢谢确认 Antigravity 打开时三个数据库文件都在。
你最后报告的子会话导入失败,需要看的是 Nowledge Mem CLI 版本。插件的 46022fe 对应这里最初的 Python hook 修复,子会话谱系识别则随 Nowledge Mem 0.10.112 发布(见 #954 的发布说明)。这两项更新是分开的。
如果已是 0.10.112 或更新,且预览仍有失败,麻烦只贴 nmem --version 和一个失败条目下的诊断原因即可,可以删掉路径、会话 ID 和对话内容。三个数据库文件存在这一点已经确认,无需再提供数据库或完整 transcript。我们会保留此贴跟踪你这边的实际结果。