Skip to content

fix(gemini): add ACP spec SSOT, 190K truncation alignment, agy 1.5.20 gate, K2/K4/status fixes & pin CRAGGemini 0.6.4 - #2475

Merged
dofastted merged 6 commits into
devfrom
fix/gemini-acp-spec-truncation
Dec 1, 2026
Merged

dofastted merged 6 commits into
devfrom
fix/gemini-acp-spec-truncation

Conversation

@dofastted

@dofastted dofastted commented Dec 1, 2026 •

Copy link
Copy Markdown
Owner

Summary

Supersedes #2453 (which pinned payload-2026.12.01-gemini-0.6.3 containing the withdrawn split_acp_prompt_parts multi-block workaround). Pairs with CRAGGemini kernel PR dofastted/antigravity-cli-proxy#36 and continuation prerelease payload-2026.12.01-gemini-0.6.4.

Key Changes

  1. Gemini ACP Protocol SSOT & Dynamic Allowlist
    • Added src/config/agy-acp-spec.json (byte-identical to CRAGGemini src/acp_spec.json, SHA-256 1dd063cb9519d20c3b28b281d2eca4be89e109a4f88bfe3ee6b688d8cf827631), scripts/sync-agy-acp-spec.mjs (--check / --sync-kernel / --from-kernel), and src/lib/gemini/agy-acp-spec.mjs (KIN_AGY_ACP_SPEC_PATH + routing.gemini.acp_overrides + live worker protocolCapabilities precedence).
    • Wired routing-config.mjs, prompt-normalizer.mjs, and gemini-convert.mjs to the SSOT (expanding decodable inline text MIMEs to 22 application/* exact types + application/*+{json,xml,yaml} while strictly rejecting image/svg+xml and binary media).
  2. 190K Layered Truncation Alignment & K2 / Control-Char Parity
    • Default prompt_overflow_policy: "truncate" delegates >190KB user turns to CRAGGemini 0.6.4 layered overflow + UTF-8 head/tail truncation while enforcing a 4 MiB OOM guard; explicit reject preserves the exact 190KB boundary.
    • Added post-canonicalization admission check in scheduler.mjs (passing routeModel, targetAccountId, and live worker policy) so folded <system-reminder> and decoded inline text attachments are covered.
    • Absorbed verified fixes from 45882715a: Gemini functionResponse.{response,parts} control-char cleanup (sanitizeJsonControlCharsDeep), K2 FIFO unconsumedByName callId rewrite, and account-scoped continuationBinding orphan exemption (continuationBinding.accountId === targetAccountId).
  3. K4 Hidden Bug Fixes
    • gemini-convert.mjs: parseGeminiSseFrame preserves rawPayload across all error branches and geminiErrorControlFields parses array-shaped Google RPC details[].metadata.{retryable,failoverable,worker_code} (unblocking cancelled -> 499 and metadata propagation).
    • scheduler.mjs: decouples worker-facing attemptRequestId (gem_<24hex>) from client-supplied requestId (X-Request-Id) with tail-preserving 128-char _a${attempts} suffix to eliminate client-retry HTTP 409 collisions; error-policy.mjs classifies gemini_session_conflict as request_protocol (circuit: false).
  4. agy >= 1.5.20 Gate, Capability Pass-through & Status SSOT
    • scripts/gemini-host.py: MIN_AGY_VERSION = "1.5.20", _resolve_infer_target /status 8-field capability pass-through + installed_agy_version() fallback warning, and fixed ControlHandler.send_json_error(..., validation_url=None) TypeError.
    • scripts/gemini-maintenance.py: added agy_version health check (gemini_maintenance_agy_below_min warning when < 1.5.20).
    • src/lib/gemini/direct-client.mjs: normalized & exposed the 8 ACP/version capability fields (normalizeTargetCapabilities, resolveTargetAcpCapabilities).
    • src/lib/gemini/scheduler.mjs & routes.mjs: projected Rust liveNodeState schedulable === false (permanent_unschedulable) cleanly into environmentRestriction and environmentView with zero legacy JS unitCircuit.
  5. CRAGGemini 0.6.4 Payload Pin
    • Pinned deploy/payload.json geminiDefaultLinuxAmd64 to payload-2026.12.01-gemini-0.6.4 (zero key rotation; crag-license-public.pem SHA-256 unchanged f6e3ef3a…).

Cross-References

Verification

  • node scripts/sync-agy-acp-spec.mjs --check --kernel-spec /mnt/x/antigravity-cli-proxy-wt-acp-spec-truncation/src/acp_spec.json — PASS (sha256=1dd063cb9519d20c3b28b281d2eca4be89e109a4f88bfe3ee6b688d8cf827631)
  • python3 scripts/fetch-default-gemini.py --manifest deploy/payload.json --dest <0700 tmpdir> --reuse-agy ... — PASS (Verified Gemini payload 0.6.4, 5/5 assets match GitHub prerelease)
  • find src scripts -name '*.mjs' -print0 | xargs -0 -n1 node --check — PASS
  • npx biome check (14 modified .mjs files) — PASS
  • python3 -m py_compile scripts/gemini-host.py scripts/gemini-maintenance.py — PASS
  • Python unit suites (gemini-host-license-align.py, gemini-agy-patch.py, gemini-maintenance-runtime-files.py, gemini-host-native-smoke.py) — ALL PASS
  • Targeted JS unit suites (gemini-convert, gemini-prompt-normalizer, gemini-scheduling-status, gemini-maintenance-install-contract) — 72/72 PASS
  • npm run test:ci — 13/13 PASS

Note

High Risk
Touches Gemini request canonicalization, admission limits, tool-ID pairing, scheduling/unschedulable state, and pinned CRAGGemini binaries—errors could break inference, failover, or routing for production Gemini traffic.

Overview
Introduces a Gemini ACP protocol SSOT (src/config/agy-acp-spec.json + sync script + runtime loader) and wires prompt canonicalization, admission, and panel routing.gemini.acp_overrides to it—replacing hardcoded body allowlists/MIME rules and supporting worker + routing overrides.

Prompt overflow now defaults to truncate (delegates >190KB to CRAGGemini 0.6.4, still caps at 4 MiB); explicit reject keeps the 190KB gate, with a post-canonicalization admission pass after folded reminders/inline text decode. Tool-call ID behavior stops injecting synthetic call_auto_*, reserves exact IDs in parallel batches, and tightens orphan tool_result handling (FIFO same-name rewrite, account-scoped continuationBinding).

K4-style reliability fixes: worker attemptRequestId is decoupled from client X-Request-Id (avoids 409 collisions); SSE errors retain rawPayload and parse Google RPC metadata; host/maintenance enforce agy ≥ 1.5.20 with /status ACP capability passthrough and validation_url on JSON errors; scheduler/panel surface Rust permanent_unschedulable. Pins payload-2026.12.02-gemini-0.6.4 in deploy/payload.json.

Reviewed by Cursor Bugbot for commit d4e3880. Configure here.

… gate, and K2/K4/status fixes

1. Changed files & core intent:
- Added `src/config/agy-acp-spec.json` (byte-identical to CRAGGemini `src/acp_spec.json`, SHA-256 `1dd063cb9519d20c3b28b281d2eca4be89e109a4f88bfe3ee6b688d8cf827631`), `scripts/sync-agy-acp-spec.mjs` (`--check` / `--sync-kernel` / `--from-kernel`), and `src/lib/gemini/agy-acp-spec.mjs` (`KIN_AGY_ACP_SPEC_PATH` + dynamic `acp_overrides` + live worker capability resolution).
- Wired `routing-config.mjs`, `prompt-normalizer.mjs`, and `gemini-convert.mjs` to the ACP spec SSOT; absorbed `45882715a` Gemini `functionResponse.{response,parts}` control-char hygiene (`sanitizeJsonControlCharsDeep`), K2 FIFO `unconsumedByName` `callId` rewrite, and account-scoped `continuationBinding` orphan exemption.
- Aligned 190K truncation (`prompt_overflow_policy: "truncate"` delegates >190KB to CRAGGemini while keeping a 4 MiB OOM guard; `reject` keeps exact limit) and added post-canonicalization admission check in `scheduler.mjs` (passing `routeModel` and `targetAccountId`).
- Fixed K4 hidden bugs: `parseGeminiSseFrame` preserves `rawPayload` and parses array-shaped Google RPC `details[].metadata.{retryable,failoverable}`; `scheduler.mjs` decouples worker `attemptRequestId` (`gem_<24hex>`) from client `requestId` with 128-char tail-safe `_a${attempts}` suffix; `error-policy.mjs` classifies `gemini_session_conflict` as `request_protocol` (`circuit: false`).
- Enforced/surfaced `min_agy_version = "1.5.20"` and `/status` capability pass-through across `scripts/gemini-host.py`, `scripts/gemini-maintenance.py`, and `src/lib/gemini/direct-client.mjs`; fixed `ControlHandler.send_json_error(..., validation_url=None)` `TypeError` in `scripts/gemini-host.py`; closed Gemini status SSOT gap by surfacing Rust `liveNodeState` `schedulable === false` (`permanent_unschedulable`) in `scheduler.mjs` `environmentRestriction` and `routes.mjs` `environmentView`.

2. Root cause & rejected alternatives:
- Root cause: hardcoded Gemini body allowlists/MIMEs/190KB hard-rejects drifted from CRAGGemini, client-reused `X-Request-Id` collided with in-flight slots (409), `parseGeminiSseFrame` dropped `rawPayload` and ignored array RPC `details[]`, `environmentRestriction` ignored Rust `permanent_unschedulable`, and `ControlHandler.send_json_error` lacked the `validation_url` keyword argument passed by `_send_infer_error`.
- Rejected alternatives: hard-blocking host startup on `agy < 1.5.20` (breaks rolling upgrades before `--agy-only`); keeping 190KB hard-400 on panel when kernel performs layered truncation; reintroducing legacy JS `unitCircuit` (violates `#2461` Rust SSOT).

3. Verification commands & real results:
- `node scripts/sync-agy-acp-spec.mjs --check --kernel-spec /mnt/x/antigravity-cli-proxy-wt-acp-spec-truncation/src/acp_spec.json` -> PASS (`sha256=1dd063cb9519d20c3b28b281d2eca4be89e109a4f88bfe3ee6b688d8cf827631`, `min_agy=1.5.20`, `keys=87`).
- `find src scripts -name '*.mjs' -print0 | xargs -0 -n1 node --check` -> PASS (0 errors).
- `npx biome check <14 modified .mjs files>` -> PASS (`Checked 14 files in 289ms. No fixes applied.`).
- `python3 -m py_compile scripts/gemini-host.py scripts/gemini-maintenance.py` -> PASS.
- `python3 test/unit/gemini-host-license-align.py && python3 test/unit/gemini-agy-patch.py && python3 test/unit/gemini-maintenance-runtime-files.py && python3 test/unit/gemini-host-native-smoke.py` -> PASS (all 4 suites OK).
- `node --test test/unit/gemini-convert.test.mjs test/unit/gemini-prompt-normalizer.test.mjs test/unit/gemini-scheduling-status.test.mjs test/unit/gemini-maintenance-install-contract.test.mjs` -> PASS (72/72).
- `KIN_SCHEDULER_BIN=/mnt/x/vm2api-wt-clean-1424x/bin/kin-scheduler npm run test:ci` -> PASS (13/13 isolated suites).

4. Broken-by-hand evidence:
- Temporarily removed `rawPayload: payload,` in `src/lib/protocol/gemini-convert.mjs` (`parseGeminiSseFrame`) -> ran `node --test --test-name-pattern="ACP 190K truncation alignment" test/unit/gemini-convert.test.mjs` -> FAILED (`AssertionError: assert.ok(parsedSse.rawPayload)` at `test/unit/gemini-convert.test.mjs:2808`, exit code 1) -> restored -> re-ran -> PASS (1/1).

5. Unverified / follow-up items:
- Live end-to-end verification against a signed CRAGGemini `0.6.4+` payload + `ph24` deployment is deferred until kernel payload release and PR review.
- Pre-existing legacy `unitCircuit` assertions in non-CI suites (`gemini-session-conflict.test.mjs:215`, `gemini-foundation.test.mjs:903/949`, `gemini-host.test.mjs:1154/1214`) stem from `origin/dev` `#2461` removing JS `unitCircuit` and were intentionally left untouched outside scope.
…yload.json

1. Changed files & core intent:
- Updated `deploy/payload.json` `geminiDefaultLinuxAmd64` to pin `payload-2026.12.01-gemini-0.6.4` (`craggemini`, `craggemini.payload.enc`, `libagy_bridge.so`, `crag-license-public.pem`, `manifest.json`) with zero key rotation (`crag-license-public.pem` SHA-256 unchanged: `f6e3ef3a50fd49abd4ce3519db512af74fc438b47b1bbec83f6602ebe4b3930a`).

2. Root cause & rejected alternatives:
- Root cause: `payload-2026.12.01-gemini-0.6.3` contained `split_acp_prompt_parts` which was silently tail-truncated by `agy 1.5.20`; CRAGGemini `0.6.4` (PR dofastted/antigravity-cli-proxy#36) replaces it with `acp_spec.json` SSOT, `agy >= 1.5.20` compatibility reporting, and layered overflow + head/tail UTF-8 truncation.
- Rejected alternatives: overwriting published prerelease `0.6.3` (violates immutable release rule) or rotating production signing keys.

3. Verification commands & real results:
- `gh release view payload-2026.12.01-gemini-0.6.4 --repo dofastted/vm2api` -> 5/5 asset sizes & SHA-256 digests match `deploy/payload.json` verbatim.
- `python3 scripts/fetch-default-gemini.py --manifest deploy/payload.json --dest <0700 tmpdir> --reuse-agy ...` -> PASS (`Verified Gemini payload 0.6.4`, exit 0).
- `node scripts/sync-agy-acp-spec.mjs --check --kernel-spec /mnt/x/antigravity-cli-proxy-wt-acp-spec-truncation/src/acp_spec.json` -> PASS (`sha256=1dd063cb9519d20c3b28b281d2eca4be89e109a4f88bfe3ee6b688d8cf827631`).
- `find src scripts -name '*.mjs' -print0 | xargs -0 -n1 node --check` + `npx biome check` (14 files) + `python3 -m py_compile` + 4 Python suites + 4 Gemini JS suites (72/72) + `npm run test:ci` (13/13) -> ALL PASS.

4. Broken-by-hand evidence:
- Prior commit `0a5ab73eb` verified `parseGeminiSseFrame` `rawPayload` hand-break (FAIL -> restore -> PASS); `fetch-default-gemini.py` live download verifies exact size + SHA-256 + Ed25519 signature of every pinned 0.6.4 asset.

5. Unverified / follow-up items:
- `ph24` production rollout and live traffic verification follow PR merge.
@dofastted dofastted added the bugfix Bug fix label Dec 1, 2026
@cursor

cursor Bot commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

Bugbot couldn't run - usage limit reached

Bugbot is counted against Cursor usage for this user or team, and this run hit a usage or spend limit.

A user or team admin can review and increase usage limits in the Cursor dashboard.

(requestId: d640c4af-d44a-4c9a-9221-4fc7056a8e99)

…emini-0.6.4)

## 变更摘要
- 改前:`deploy/payload.json` 指向 `payload-2026.12.01-gemini-0.6.4`(合入 `antigravity-cli-proxy#36` 评审 F1–F5 修复前的构建)。
- 改后:将 `geminiDefaultLinuxAmd64` 升级钉选至已合入 `dofastted/antigravity-cli-proxy#36`(`13a270e05`,含 #35 评审 F1–F5 修复 + `agy >= 1.5.20` 门禁 + 分层截断)的新续发载荷 `payload-2026.12.02-gemini-0.6.4`(零密钥轮换,公钥 `f6e3ef3a...` 不变)。
- 未改 / 延后:不改 `CHANGELOG.md`,不触碰其他载荷字段;线上 `ph24` 灰度在合入发版后执行。

## 验收记录(Run)
- 环境与基线:WSL2 Linux + Windows git,`fix/gemini-acp-spec-truncation`(基于 `origin/dev` `c83c12b3b`)
- 已跑命令与结果:
  - `python3 scripts/fetch-default-gemini.py --manifest deploy/payload.json --dest <0700 tmpdir> --reuse-agy ...`: PASS (`Verified Gemini payload 0.6.4`,5/5 资产远端下载与 SHA-256 一致)
  - `node scripts/sync-agy-acp-spec.mjs --check --kernel-spec ...`: PASS (`sha256=1dd063cb...`, `min_agy=1.5.20`, `keys=87`)
  - `node --test test/unit/install-payload.test.mjs test/unit/gemini-maintenance-install-contract.test.mjs`: PASS (18/18)

## 回退与手破验证(Broken by hand)
- 将临时 `payload.json` 中 `manifest.json` sha256 末位由 `0` 改为 `1` -> `fetch-default-gemini.py` FAIL (`SHA-256 does not match the pin`) -> 还原后 PASS。

## 真实使用(Real use)
- 实测从 GitHub Release `payload-2026.12.02-gemini-0.6.4` 公开 URL 拉取全部 5 项资产并完成验签与官方 `agy` 补丁;未在 `ph24`/Docker/KVM/custom-os 实机运行。

## 未运行项(Not run)
- `ph24` 实机灰度、Docker/KVM/custom-os 槽位运行实测与 ARM64 构建(均未运行,待合入发版后执行)。
@dofastted

Copy link
Copy Markdown
Owner Author

已更新 deploy/payload.json(commit 17de4d6c39dc3137bd1edcc9e118d530d8d5a7a8),将 geminiDefaultLinuxAmd64 切换至已合入 dofastted/antigravity-cli-proxy#36(13a270e05,修复了 #35 全部 F1–F5 评审问题并合并 agy >= 1.5.20 门禁与分层截断)的续发载荷 payload-2026.12.02-gemini-0.6.4(零密钥轮换,craggemini-core 明文已 shred -u 清零)。

  • fetch-default-gemini.py 公开下载 5/5 资产验签:PASS(Verified Gemini payload 0.6.4)
  • 手破验证(改 1 位 manifest.json sha256):FAIL(SHA-256 does not match the pin)→ 恢复 PASS
  • sync-agy-acp-spec.mjs --check & install-payload / gemini-maintenance-install-contract:PASS(18/18)
  • 未运行项:ph24 实机、Docker/KVM/custom-os 槽位运行实测与 ARM64 构建。

@dofastted

Copy link
Copy Markdown
Owner Author

评审结果(只读评审,评审时 head 17de4d6c3;钉选与 0.6.4 资产我独立核对过)

已转为草稿;先 rebase(与 dev 有 5 个文件冲突,#2473 已合入同一批 K2 FIFO / 控制字符清理 / rawPayload / 请求 id 后缀,需要去重),再处理下面的 Major。

评审对象:dofastted/vm2api#2475,评审期间 head 从 bf9589e9b 移到 17de4d6c3(17:06Z 又推了一个只改 deploy/payload.json 的提交,代码文件与 bf9589e9b 相同)。PR 基线是 c83c12b3b,origin/dev 现在是 ddedbb66e。

下文标注:已复现 = 用真实函数/真实入口跑出实得值;静态推断 = 只读代码;手破 = 在 /tmp 副本上逐条去掉单个规则再跑测试。复现脚本在 /tmp/rv2475/scripts/(r1~r9、mutate.py、muts*.json),副本在 /tmp/rv2475/{pr,pr2,dev,dev2,hb},没有改仓库任何文件。

Major

M1 合并会让 32 个相关用例变红,CI 抓不到(已复现)

  • test/unit/gemini-request-log.test.mjs:dev 46/46 通过,PR 15/46(31 个失败)。原因是该文件的 [Bug] Gemini ACP cold-reseed 超限返回裸 HTTP400,Responses Agent 无法进入压缩恢复(0.6.1) #2436 用例直接调 validateAntigravityTargetAdmission('openai-responses', {input:'x'.repeat(190001)}) 期望 400,PR 默认策略改成 truncate 后不再抛(实得 ERR_ASSERTION,期望 gemini_invalid_request)。我把调用改成显式 reject 再跑,仍有失败:gemini-convert.mjs:3668 给 details 新增了 policy 键,该文件按 deepEqual({reason,limit,actual}) 断言。
  • test/unit/gemini-routing-config.test.mjs → test/unit/gemini-host-shards.py:671:dev 通过,PR 报 AttributeError: 'Host' object has no attribute 'payload'(scripts/gemini-host.py:9996 在 _resolve_infer_target 里新调 installed_agy_version(),测试用 Host.__new__ 造的宿主没有 .payload)。生产 Host 有 .payload,所以这条只影响测试,但同样会让 dev 变红。
  • 这两个文件都不在 test:ci 的 13 个里(package.json:11)。PR 写的 "72/72" 和 "13/13" 不覆盖它们,正是 LESSONS 里已晋升的“不在 test:ci 里的测试会随 dev 静默变红”。
  • 对照:我另外跑了 41 个相关文件(含 PR 自带 5 个)和 16 个 Python 套件、12 个关联 mjs(157 例),除上面两处外,PR 与 dev 的失败集合完全相同(dev 基线本来有 9 个断言旧 unitCircuit 的失败,非本 PR)。

M2 与最新 dev 冲突,且重复实现了 #2473 已合入的内容(git merge-tree 已验证)

  • 冲突文件:prompt-normalizer.mjs(15 处)、scheduler.mjs(3 处)、gemini-convert.mjs(5 处)、test/unit/gemini-convert.test.mjs(3 处)、test/unit/gemini-prompt-normalizer.test.mjs(1 处)。
  • fix(gemini): align Antigravity model format policy and capability SSOT, fix tier/alias/legacy-allowlist regressions, defer the 0.6.3 payload pin (takes over #2453) #2473(38de3411f,吸收了同一个 45882715a)在 dev 上已经有:sanitizeJsonControlCharsDeep(prompt-normalizer.mjs:214,带 depth 参数,与 PR 新增的同名导出签名不同)、验证函数里的 unconsumedByName FIFO(gemini-convert.mjs:4026 起,用 normalizeIrToolMatchKey)、rawPayload、带 _a${n} 后缀并截断的 attemptRequestId(scheduler.mjs:4772)。PR 描述里“Absorbed verified fixes from 4588271”这一块在 rebase 后应整段删掉,只留 PR 独有的部分。
  • PR 正文仍写 payload-2026.12.01-gemini-0.6.4,head 实际钉的是 payload-2026.12.02-gemini-0.6.4(见 m9)。

M3 面板把 Rust 的任意 schedulable=false 都标成“永久不可调度”(已复现,dev 无此行为)

  • 位置:src/lib/gemini/scheduler.mjs:3609(if (live?.schedulable === false) → permanent:true)、src/lib/gemini/routes.mjs:974/991。
  • 根因:scheduler-runtime.mjs:1343 的 liveNodeState 把 permanent_unschedulable 折进了 schedulable,而 Gemini 节点的 Rust schedulable 是 healthy && 运营开关开 && 无持久化 unschedulable(scheduler-runtime.mjs:2585 起 + scheduler.mjs:3227)。所以 PR 无法区分永久封禁和“模型还没拉取”“运营手动关闭”。
  • 复现(真实 createGeminiScheduler + createGeminiPanelHandler,只 mock 掉 liveNodeState 的返回值,形状取自上述源码):
    • Rust 返回 {schedulable:false, unschedulable_reason:'env_not_ready'}(新加的账号还没发现模型)→ PR 面板:schedulable:false, unschedulable:{reason:'env_not_ready',permanent:true}, restriction:{...,permanent:true};dev:schedulable:true。
    • unschedulable_reason:'schedulable_false'(运营关闭)同样被标成 permanent:true。
    • 前端 web/src/lib/gemini-account-status.ts 在 schedulable===false 时直接归到“调度关”,原来的“尚未拉取模型,不能调度”提示不再显示。运营重新打开后,面板还会跟着 Rust 快照滞后一段时间(静态推断)。
  • PR 自带用例只覆盖 permanent_ban,不会发现这个问题。
  • 建议:让 liveNodeState 单独带出 permanent_unschedulable / permanent_reason,面板只在它为真时标 permanent。

Minor

m1 默认 truncate 的行为变化(设计决策,需要拥有者确认;一部分已复现,一部分读内核源码)

  • 已复现(/tmp/rv2475/scripts/r1.mjs、r1b.mjs):默认策略下 openai-responses / openai-chat / anthropic / gemini 四个入口 190000、190001、4194304 都放行,4194305 都返回 400 prompt_part_too_long,limit:4194304, policy:'truncate',所以 4 MiB 保护四个入口都生效。显式 reject:190000 通过,190001 拒绝(limit:190000),多字节 190002 字节也拒绝,边界精确。
  • 客户端可见变化:190KB~4MiB 的用户轮原来是确定的 400(Responses 流式还会转成 context_length_exceeded 让客户端压缩,docs/PROTOCOL.md:282-283),现在放行,由 0.6.4 内核截断(agent_rules.rs 分层溢出 + truncate_acp_utf8_keep_tail,模型输入里有 [... truncated N bytes ...])。truncated_prompt_bytes 只进内核的 calibration,控制面 src 里没有任何引用(静态推断),客户端和面板都看不到。这和“不静默降级”的方针有张力,建议至少先保持默认 reject,等 0.6.4 全量滚动并有可见信号(响应头或面板计数)后再翻。
  • 旧内核(0.6.1~0.6.3 的槽位不报 prompt_overflow_policy):控制面把它当成 truncate 放行,旧内核自己返回 400。我用 mapCragWorkerError(400,{code:'prompt_part_too_long',limit:190000,actual:200000}) 验证过,映射成 400 gemini_invalid_request,retryable/failoverable=false, tripCircuit=false,客户端看到的和以前一样,只多一次 worker 往返。混合滚动期间若请求落在 reject 账号上,post-canon 检查(scheduler.mjs:4612)抛非可故障转移的 400,即使别的账号能接(静态推断)。
  • 优先级和注释不一致:agy-acp-spec.mjs 头注释和 resolveEffectiveAgyAcpPolicy(:371)写 worker 能力 > 面板 acp_overrides;已复现:override=reject + worker=truncate 解析为 truncate。但 scheduler.mjs:4158 的 pre-loop 准入用的 baseAcpPolicy 不含 worker 能力,所以面板的 reject 实际仍然生效,只是和文档说法相反。
  • 文档没跟:docs/PROTOCOL.md:282-283 仍写 190,000 字节硬 400;docs/PANEL_API.md 没有 acp_overrides。

m2 extra_decodable_text_mimes 覆盖项端到端无效(已复现)

  • 面板配置 acp_overrides.extra_decodable_text_mimes:['application/x-custom-log'] 后,Gemini 原生入口 inlineData 仍返回 400 unsupported_media_type(有无覆盖项结果相同)。原因:IR 解析里的 decodeInlineTextMediaOrThrow(gemini-convert.mjs:957)只用内置 SSOT,不认覆盖项,准入在规范化之前就拒绝了。配置能保存但不起作用,行为是 fail-closed,不是安全问题。
  • 内置 MIME 经 Gemini 原生入口端到端通过:application/json、application/toml、application/vnd.x+json 都解码成文本发给 worker;image/svg+xml、application/pdf、application/octet-stream 都被拒绝。Anthropic 入口只验证了准入不拒绝(我的 harness 没有 Anthropic 线路的出站体)。

m3 K2 FIFO 改写 callId 对线上无效(已复现)

  • Gemini 原生透传时,validateAntigravityTargetAdmission 改的是临时 IR,出站体走 canonicalized.body。用真实 scheduler.stream 发 functionResponse.id=wrong_1/wrong_2,worker 收到的仍是 ["wrong_1","wrong_2"]。只有走 targetBodyFor 的 IR 回退路径才会受影响。验证函数顺带修改传入的 ir,也不是好习惯。这部分在 dev 上已有不同实现(M2),rebase 时以 dev 为准。
  • 账号作用域的 continuation 豁免(gemini-convert.mjs:3651 的 hasMatchingContinuation)只有叶子函数用例;pre-loop 不传 targetAccountId,只有 post-canon 传(手破 M7 存活)。

m4 SSOT 文件没有进宿主运行时,且升级后会漂移(静态推断,未在真机验证)

  • scripts/gemini-host.py:80、scripts/gemini-maintenance.py:133 从 ROOT/src/config/agy-acp-spec.json 读最低版本。但 gemini-maintenance.py:77 的 RUNTIME_FILES 和 deploy/install.sh:1191/1491 的宿主文件清单都没有这个文件,真实宿主上读不到,只会落到硬编码的 1.5.20。两处常量和 JSON 以后改一处就会不一致。
  • Docker:docker-compose.yml:141 把 ./src/config 绑定挂载,scripts/docker-entrypoint.sh:46-51 只在目标文件不存在时才从 image-config 补,所以首次升级能补上,之后 spec 再变(allowed_body_keys、MIME 表、min_agy_version)不会到达已有部署。worker 上报的 acp_spec_sha256 控制面只透传,没有和 AGY_ACP_SPEC_SHA256 比较,漂移无检测。

m5 运行时加载器校验太弱(已复现)

  • KIN_AGY_ACP_SPEC_PATH 指向缺失或损坏文件:agy-acp-spec.mjs:108 顶层加载抛错,所有 import 它的模块(prompt-normalizer、gemini-convert、scheduler、routing-config)都起不来,控制面无法启动(fail-closed,直接崩)。
  • 能解析但内容不对的文件会被悄悄接受:allowed_body_keys 缺失或为空 → 所有顶层键(含 model、contents)都被当未知键删掉,请求体变空;max_acp_prompt_text_bytes:"abc"、min_agy_version:"not-a-version" 都能加载。sync-agy-acp-spec.mjs 校验很严,但运行时加载器只查 schema_version 和几个顶层字段。该路径只受环境变量控制,客户端够不到。

m6 测试只钉住了一部分规则(手破,已复现;正控均被拦下)

手破在 /tmp/rv2475/hb,锚点唯一才执行;两个正控(gemini_session_conflict 改回 client4xx、让 image/svg+xml 可解码)都被拦下,说明脚本有效。下列单条修改,PR 自带相关测试仍全绿(存活):

  • 去掉精确 MIME application/graphql,或把 application/x-www-form-urlencoded 改名(22 个里测试只点到约 5 个,后缀 +json/+xml/+yaml 各点了一个)。
  • 去掉后缀规则里的 startsWith('application/') 门槛。
  • 去掉 max_acp_prompt_text_bytes 下限校验。
  • 把优先级改成 override 优先于 worker 能力。
  • post-canon 准入改用 baseAcpPolicy(不用目标 worker 的实际策略);post-canon 不传 targetAccountId。
  • buildAttemptRequestId 在 attempt>1 不加后缀(PR 用例只断言了首个 id 的形状)。
  • 维护脚本 agy_version 检查的比较方向反了(Python 用例只断言模块常量)。
  • 宿主 /status 透传整段去掉(唯一能碰到它的 host-shards 用例因 M1 报别的错)。
  • image/svg+xml 有两道重复守卫(精确匹配 + image/ 前缀),任何一道单独去掉行为都不变,属等价变异,不算缺口。

m7 worker 请求 id 与客户端 id 解耦(部分静态)

  • 实现符合描述:每次派发 gem_<24hex>,重试加 _aN,同一请求内部的重试和 restart-resume 不受影响(两次相同 X-Request-Id 的派发得到不同 worker id,PR 用例有覆盖)。
  • 代价:worker 侧 request_id 没有记录在任何尝试记录、hop_meta 或日志里(src 中无引用),以前第一次尝试的 id 就是客户端的 X-Request-Id,现在无法用客户端 id 去 grep worker 日志。
  • “尾部保留 128 字符”逻辑在生产里走不到:基础 id 恒为 28 字符,只有传入超长 id 的单元测试能触发。

m8 其他

  • 面板:web/src/features/settings/gemini-maintenance.ts 没有 agy_version 检查项和 gemini_maintenance_agy_below_min / gemini_maintenance_agy_version_unknown 的文案,会显示原始代码。
  • README.md、docs/gemini-host.md、docs/BUILD.md 仍写 CRAGGemini 0.6.1(dev 上本来就落后,不是本 PR 引入)。
  • 顺带修的 send_json_error(validation_url=...) TypeError 是真缺陷(gemini-host.py:11576 调用方早已传该参数),但与本 PR 主题关系不大。
  • 准入后每次尝试都会对 canonicalized.body 重新 parseInboundToGemini 一遍,4 MiB 级请求每次重试多一次完整解析(静态推断)。

m9 载荷钉选

  • head 17de4d6c3 钉 payload-2026.12.02-gemini-0.6.4。已核对:GitHub Release 五个资产的 size 和 digest 与 payload.json 逐项一致;真实运行 python3 -I -B scripts/fetch-default-gemini.py --manifest deploy/payload.json 输出 Verified Gemini payload 0.6.4(官方 agy 当前是 1.5.21,满足 ≥1.5.20)。你给的背景核对的是 .12.01 那个 tag,不是这个 head,我已对新 tag 单独验过。
  • 同一个内核版本 0.6.4 现在有两个不同内容的 prerelease:payload-2026.12.01-gemini-0.6.4(16:35Z,craggemini sha256 6423fa9d…)和 payload-2026.12.02-gemini-0.6.4(16:56Z,a256266e…)。没有覆盖旧 tag,符合“不覆写”的规则,但 /status 的 kernel_version 分不出两者;PR 正文和中间提交还指向旧 tag。
  • 提交体按模板写了 Not run:ph24、Docker/KVM/custom-os、ARM64 都没跑,这些环境没有 0.6.4 的运行证据。

已核对没问题的

  • reject 边界、4 MiB 保护四个入口都生效(见 m1,已复现)。
  • 决定 routing.acp_overrides、worker 能力、环境变量路径的都不是客户端可控输入:能力来自宿主 /status(UDS),覆盖项经面板 PUT /api/panel/routing 且被 validateGeminiAcpOverridesPatch 校验,环境变量是进程启动参数。
  • agy 版本门禁不会拒绝服务:宿主只在 stderr 打警告并设 agy_version_compatible:false,维护检查是 warning 级,内核 0.6.4 自己(acp_backend.rs:3869)也只警告;can_update 对 CRAG 包不看 cli 版本。没有任何拒绝路径。
  • K4 SSE 修复经真实入口验证有效(dev 和最新 dev2 都复现原问题):RPC 数组形 details[].metadata 的 cancelled 帧,dev 返回 gemini_inference_failed 并换了 2 个账号,PR 返回 499 gemini_inference_cancelled、只试 1 个账号、retryable/failoverable=false。
  • gemini_session_conflict 从 client4xx 改成 request_protocol:Rust is_request_fault(health.rs:187/567)两者都不惩罚节点,行为不变。
  • 顶层允许键从 51 增到 87(全部是新增):对四协议规范化函数比较,audio/mcp_servers/container/top_logprobs/subagents/prediction/logit_bias/logprobs/prompt/... 现在会透传到内核,原来被剥。但 dev 的准入已经对其中大多数返回 400,background:true 在 Responses 也已被拒;其余内核会拒绝或记为剥离,我没发现对外结果变化(部分是读内核源码,未跑内核)。
  • src/config/agy-acp-spec.json 与内核 origin/master 的 src/acp_spec.json sha256 相同(1dd063cb…),sync-agy-acp-spec.mjs --check 通过;biome check 14 文件、node --check、py_compile 通过;没有改 CHANGELOG.md。

没能验证的

  • 0.6.4 内核的真实截断行为:只读了内核工作树源码,没有跑二进制(该工作树的 .git 元数据已损坏,git log 不可用)。
  • Rust 实时快照的真实返回:M3 里 liveNodeState 是按 scheduler-runtime.mjs 的构造逻辑 mock 的,没接真实 kin-scheduler 的 gemini 节点。
  • rebase 之后的结果:5 个冲突文件我没有解决,所以“冲突解决后这些发现是否都还在”只靠 dev2 上重跑 r4/r9 验证了 M3 和 K4 仍成立;M1 在 dev2 上同样成立(dev2 的 gemini-convert.mjs:3969 仍是 190_000 硬限)。
  • Gemini 宿主的真实安装/升级路径(m4)、Docker 绑定挂载补文件(m4)、ph24、KVM/custom-os、ARM64、PG/Redis 都没跑。
  • 非 Gemini 协议里顶层 system_instruction 透传到内核后的语义,没有验证。
  • 评审中我执行过一次 git merge-tree --write-tree,它在 .git 里写了一个孤立 tree 对象(272853b2…),没有动 ref 和工作树。

建议

  1. 先 rebase 到 ddedbb66e,删掉与 fix(gemini): align Antigravity model format policy and capability SSOT, fix tier/alias/legacy-allowlist regressions, defer the 0.6.3 payload pin (takes over #2453) #2473 重复的 K2 / 控制字符 / rawPayload / 请求 id 后缀;保留独有部分。
  2. 修 M3(用 permanent_unschedulable 判断),补 env_not_ready、schedulable_false 两个反例。
  3. 修 M1:更新 gemini-request-log.test.mjs 的准入前提(显式 reject 或新边界)和 details 形状,处理 gemini-host-shards.py 的 payload 缺失;把这两个文件的结果写进验收评论。
  4. 拥有者确认默认 truncate(m1);确认前不改默认值,或先补可见信号和文档(PROTOCOL.md、PANEL_API.md)。
  5. 拆分:K4 + validation_url + request_protocol + 请求 id 解耦可以单独先合;SSOT + 截断默认值 + 载荷钉选 + 状态投影各自独立评审。

@dofastted
dofastted marked this pull request as draft December 1, 2026 17:30
…in/dev

- M2: merge origin/dev (including #2473) cleanly across 5 files; deduplicate
  sanitizeJsonControlCharsDeep, normalizeIrToolMatchKey FIFO, and keep #2475
  unique ACP spec SSOT, agy 1.5.20 gate, K4 SSE array metadata, decoupled
  worker request IDs, and payload-2026.12.02-gemini-0.6.4 pin
- M3: expose permanent_unschedulable & permanent_reason from liveNodeState()
  so environmentRestriction only flags genuine permanent_unschedulable (not
  env_not_ready or operator schedulable_false); add counterexample tests
- M1: guard getattr(self, 'payload', None) in Host.installed_agy_version() for
  gemini-host-shards.py and align #2436 reject-policy admission tests in
  gemini-request-log.test.mjs / gemini-convert.test.mjs / gemini-session-conflict.test.mjs
- m5: tighten loadAgyAcpSpecFromFile() semver, limits, and allowed_body_keys checks
@dofastted

Copy link
Copy Markdown
Owner Author

1. 本次改动与原因(Head $sha)

逐条修复 #2475 评审中全部 3 项 Major(M1/M2/M3)与 m5,并合入最新 origin/dev(含 #2473/#2477/#2466/#2465):

2. 已执行验证与结果

ode scripts/sync-agy-acp-spec.mjs --check — PASS(sha256=1dd063cb..., min_agy=1.5.20, policy=truncate, keys=87)

  • python3 -m py_compile scripts/gemini-host.py scripts/gemini-maintenance.py — PASS
  • python3 test/unit/gemini-host-shards.py — PASS(OK, UNIFIED_IDENTITY_HOST_OK)
  • 9 个关联 Gemini/Payload 单测套件(含 M1 点名的 gemini-request-log.test.mjs 与 gemini-routing-config.test.mjs):200/200 PASS(0 fail, 0 skip)
  • KIN_SCHEDULER_BIN=/tmp/kin-sched-target/release/kin-scheduler npm run test:ci — 13/13 PASS

px biome format --write(10 个改动 JS 文件)— Clean

3. 破坏性验证(Broken-by-hand)

  • M1 复现:合入 dev 后首跑 9 套件确有 3 处失败(gemini-convert.test.mjs:3243、gemini-request-log.test.mjs:203、gemini-session-conflict.test.mjs:708);逐项对齐后 200/200 PASS。
  • M3:gemini-scheduling-status.test.mjs 实测 �nv_not_ready、schedulable_false(permanent_unschedulable: false)均返回
    estriction: null, liveUnschedulable: null,而 permanent_ban(permanent_unschedulable: true)返回 permanent: true。

4. 未运行项

  • 未在生产机 ph24、真实 Docker/KVM/custom-os 或 ARM64 宿主机运行 �.6.4 二进制实机流量(待合入发版后独立验证)。

5. 风险与回滚

  • 所有改动均局限在 Gemini ACP 规范/准入/状态投影与载荷钉选,零密钥轮换、未改 CHANGELOG.md;回滚单 PR 即可恢复。

@dofastted
dofastted marked this pull request as ready for review December 1, 2026 17:46
…rication

## 变更摘要
- 改前:`prompt-normalizer.mjs` 的 `createWireToolCallTracker` 在转发无 ID 的 Gemini 原生 `functionCall`/`functionResponse` 时合成显式 `call_auto_<N>` 写入出站载荷,与 CRAGGemini 0.6.4 F2(非空 `call_id` 禁按 `tool_name` 回退)冲突导致每轮取消并重建 ACP 会话;同时 `matchResult` 与 `reconcileIrToolCallPairing` 在存在未知显式 `id` 时仍会通过 `prevBatch[0]` 静默改绑,且未预留同轮精确命中的 open `call_id`;`buildGeminiRequest` 在 `target === 'antigravity'` 下也会序列化 IR `_autoId`。
- 改后:移除 `createWireToolCallTracker` 的 `nextAutoId()` 合成注入,无 ID 入站在直通与 IR 回退路径对 CRAGGemini 均保持 `id` 缺省(显式 `functionResponse.id` 仍由 `adoptId` 反向采纳);新增同轮 `reservedExactIds` 防止同名回退抢占精确 ID;将 `prevBatch` 位置回退严格收紧为 `!rawId && !normName`(未知显式 ID 保持原值锁定并交由准入守卫 `400 unmatched_tool_result` 处理)。
- 未改 / 延后:直连 Google Gemini API(`target === 'gemini'`)仍保留既有内部配对 ID 行为;`routes.mjs` 与 `deploy/payload.json` 本提交未改动。

## 验收记录(Run)
- 环境与基线:Windows + WSL2 Node 22,`fix/gemini-acp-spec-truncation`(基于 `6977755ff`)
- 已跑命令与结果:
  - `npx biome format --write src/lib/gemini/prompt-normalizer.mjs src/lib/protocol/gemini-convert.mjs test/unit/gemini-prompt-normalizer.test.mjs test/unit/gemini-convert.test.mjs`: PASS
  - `find src scripts -name '*.mjs' -print0 | xargs -0 -n1 node --check`: PASS
  - `node --test test/unit/gemini-prompt-normalizer.test.mjs test/unit/gemini-convert.test.mjs test/unit/gemini-system-prompt.test.mjs`: PASS (60/60)
  - `node --test test/unit/gemini-responses-output.test.mjs test/unit/gemini-session-conflict.test.mjs test/unit/gemini-request-log.test.mjs`: PASS (68/68)
  - `KIN_SCHEDULER_BIN=/mnt/x/vm2api-wt-clean-1424x/bin/kin-scheduler npm run test:ci`: PASS (13/13)

## 回退与手破验证(Broken by hand)
- 临时回退 `src/lib/gemini/prompt-normalizer.mjs` 至 `HEAD` -> `canonicalizeInboundForAntigravity locks inbound tool IDs` FAIL(`AssertionError: actual 'call_auto_1' !== expected undefined` @ `test/unit/gemini-prompt-normalizer.test.mjs:988`)-> 恢复后 PASS。
- 临时回退 `src/lib/protocol/gemini-convert.mjs` 至 `HEAD` -> `IR inbound ID locking` FAIL(`AssertionError: actual 'call_879ae19164b679005ce5' !== expected undefined` @ `test/unit/gemini-convert.test.mjs:3636`)-> 恢复后 PASS。

## 真实使用(Real use)
- 线上 `45.58.174.2`(`CRAGGemini 0.6.4`)真实回放证据确认原因为面板出站写入 `call_auto_53..92` 触发 `McpCoordinator::resolve_call` 失配并使多轮缓存率跌至 6.1%;新镜像尚未部署至 `45.58.174.2`,待合并后在 `45.58.174.2` 切回 `0.6.4` 实测复核。

## 未运行项(Not run)
- 全量 `npm run test:unit`(553 文件)、`web/` 前端构建(本次未修改 `web/`)、`45.58.174.2` 与 `ph24` 新镜像实机部署验证(待合并后执行)。
@dofastted

Copy link
Copy Markdown
Owner Author

变更摘要(Head d4e3880f8 / d4e3880f8a9f4a901268bf5c198bbcb44c347bc0)

  • 改前:面板 prompt-normalizer.mjs 的 createWireToolCallTracker 对无 ID 的 Gemini 原生 functionCall/functionResponse 合成显式 call_auto_<N> 写入出站载荷,与本 PR 钉选的 CRAGGemini 0.6.4 F2(非空 call_id 禁按 tool_name 回退)冲突,在线上 45.58.174.2 导致多轮工具会话每轮重建 ACP 会话;同时未知显式 ID 会被 prevBatch[0] 静默改绑,且同轮精确命中的 open call_id 未预留;buildGeminiRequest 在 target === 'antigravity' 下也会序列化 IR _autoId。
  • 改后:移除 nextAutoId() 合成注入,直通与 IR 回退路径对 CRAGGemini 均保持无 ID 入站缺省 id(显式 functionResponse.id 仍由 adoptId 反向采纳);新增同轮 reservedExactIds 锁定;将位置回退严格收紧为 !rawId && !normName;同步合入最新 origin/dev(83436aeda,含 #2478),deploy/payload.json 完整保留 #2478 与本 PR geminiDefaultLinuxAmd64(0.6.4)双侧钉选。
  • 未改 / 延后:直连 Google Gemini API(target === 'gemini')保持原行为;未修改 CHANGELOG.md。

验收记录(Run)

  • 环境与基线:Windows + WSL2 Node 22,已合并最新 origin/dev(83436aeda)
  • 已跑命令与结果:
    • python3 test/unit/gemini-host-license-align.py: PASS (gemini-host-license-align: ok)
    • find src scripts -name '*.mjs' -print0 | xargs -0 -n1 node --check: PASS
    • node --test test/unit/gemini-prompt-normalizer.test.mjs test/unit/gemini-convert.test.mjs test/unit/gemini-system-prompt.test.mjs test/unit/gemini-responses-output.test.mjs test/unit/gemini-session-conflict.test.mjs test/unit/gemini-request-log.test.mjs test/unit/gemini-maintenance-install-contract.test.mjs: PASS
    • KIN_SCHEDULER_BIN=/mnt/x/vm2api-wt-clean-1424x/bin/kin-scheduler npm run test:ci: PASS (13/13)

回退与手破验证(Broken by hand)

  • 临时回退 src/lib/gemini/prompt-normalizer.mjs 至修复前 -> canonicalizeInboundForAntigravity locks inbound tool IDs FAIL(actual 'call_auto_1' !== expected undefined @ test/unit/gemini-prompt-normalizer.test.mjs:988)-> 恢复后 PASS。
  • 临时回退 src/lib/protocol/gemini-convert.mjs 至修复前 -> IR inbound ID locking FAIL(actual 'call_879ae19164b679005ce5' !== expected undefined @ test/unit/gemini-convert.test.mjs:3636)-> 恢复后 PASS。

真实使用(Real use)

  • 已基于 45.58.174.2 线上 CRAGGemini 0.6.4 真实回放证据定位并修复根因;待合入 dev 并构建新镜像部署 45.58.174.2 后切回 0.6.4 复测多轮缓存命中率。

未运行项(Not run)

  • 全量 npm run test:unit(553 文件)、web/ 构建(本次加固未改 web/)、新镜像部署至 45.58.174.2 / ph24 实机复核(待合并后执行)。

@dofastted
dofastted merged commit da5ad8c into dev Dec 1, 2026
8 checks passed
@dofastted
dofastted deleted the fix/gemini-acp-spec-truncation branch December 1, 2026 18:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bugfix Bug fix

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant