Repository navigation
Conversation
klarkxy
left a comment
There was a problem hiding this comment.
Reviewed via Gemini App · Model: Gemini · Commit:
e94164bf578aedd913c55327bc239c291b590a99
整体评估
本 PR 围绕本地 CLI 原生搜索与媒体生成(Codex / Grok / MiniMax 搜索、Codex app-server 生图、Grok 生图与视频)构建了完整的防重放扣费状态机、O_NOFOLLOW + 容器头尾安全交付管线与离线故障注入测试。由于 main 分支已合入中心 Hub 重构 #42(20a0882a),且关联 PR #47 已将本 PR 的原生搜索部分迁移适配至 Hub 架构,当前分支处于结构性冲突状态(mergeable_state: "dirty")。建议不直接对 #39 强行解冲突合入,而是在 #47 合入后,基于 Hub 鉴权框架单独拆分迁移本 PR 独有的原生图片/视频媒体能力,并在迁移时一并修复以下查出的逻辑缺陷。
1. 建议修复(逻辑缺陷 / 契约违背)
-
Grok/MiniMax(
AcpAdapter)与 Codex 搜索在子进程退出未确认时静默清除 PID 并放行续接,违背退出保护契约- 位置:
src/agent_bridge/adapters/acp.py:1861-1879、src/agent_bridge/adapters/codex.py:283-309、src/agent_bridge/registry.py:1189-1208 - 触发场景:
processes.py的reap_subprocess在杀进程超时后内部吞掉TimeoutError返回,此时proc.returncode仍为None。但AcpAdapter.shutdown与CodexAdapter(非生图分支)未检查returncode is None,无条件调用drop_pid、清空session.pid并返回正常结束,导致Registry._run_task误判pending=False并允许previous_call_id并发恢复仍在后台残留的会话。 - 具体修改建议:与
codex_image.py:340-342对齐,当内部能力会话子进程returncode is None时保留pids.json与存活句柄并抛出未确认退出异常,维持pending=True阻断续接。
- 位置:
-
取消挂起的 Codex 生图任务时,
Registry.cancel_task因未捕获前置adapter.cancel抛错而短路跳过状态收敛- 位置:
src/agent_bridge/registry.py:1747-1754、src/agent_bridge/codex_image.py:312-318, 352-364 - 触发场景:当
codex app-server未在 2 秒内退出时,image.cancel()直接抛出RuntimeError,导致Registry.cancel_task在执行bg.cancel()前异常中断(后台任务保持running);且CodexImageTurn.run的except asyncio.CancelledError:中await self.cancel()抛错也会跳过后续finish_job(..., status="uncertain")。 - 具体修改建议:在
Registry.cancel_task中用try/except包裹await adapter.cancel(session)确保继续执行bg.cancel();在CodexImageTurn.run的取消分支中用try/finally保证job先收敛落盘为"uncertain"。
- 位置:
-
Codex 搜索事件(
codex exec --json)动作分类缺陷导致无action字段的web_search误判为web_fetch或触发工具名变更报错- 位置:
src/agent_bridge/adapters/codex.py:188-194、src/agent_bridge/native_results.py:28-30、src/agent_bridge/capabilities.py:224-228 - 触发场景:当
item.completed收到不含嵌套action字典的{"type": "web_search", ...}事件时,codex.py:193将其归类为"web_fetch",导致validate_capability_output因缺少"web_search"将成功搜索判败;若item.started先带空action: {}(记为"web_fetch")而item.completed带action: {"type": "search"},observe_call会抛出ValueError("native capability tool identity changed")。 - 具体修改建议:仅在动作类型已确定或
item.completed时记录调用,当action is None时对web_search事件默认归为"web_search",仅对明确的open_page/find_in_page归为"web_fetch"。
- 位置:
-
checked_path向上遍历越过受控根目录,在 macOS/private/tmp软链或 Windows 8.3 短路径/挂载点下导致计费生成后交付失败- 位置:
src/agent_bridge/output_files.py:21-39、src/agent_bridge/codex_image.py:182-185, 245-262、src/agent_bridge/acp_results.py:62-69, 195-196 - 触发场景:
checked_path对[absolute, *absolute.parents]一路检查到文件系统根,只要$HOME、/tmp(macOS/tmp -> /private/tmp)或上层挂载卷含系统软链/0x400重解析点即无条件拒绝;且CodexImageTurn校验时用了.resolve()、产物比对却用未解析的.absolute()(WindowsRUNNER~1短路径必不相等),AcpNativeResults.__init__捕获前置目录异常仅置setup_error = True而不阻断远端扣费请求发送。 - 具体修改建议:先将受控基准根
boundary = root.resolve()规范化,仅对boundary内部相对子路径拦截软链与重解析点;CodexImageTurn统一基于规范化路径比对;AcpNativeResults对目录配置错误在发送session/prompt前直接报错中止。
- 位置:
2. 建议改进(边界条件 / 健壮性)
- 避免
_validate_native_files在只读查询路径无条件写盘并冲掉task.checkpoint_error(src/agent_bridge/registry.py:1060-1064, 1730-1731、src/agent_bridge/capabilities.py:151-156):仅在确实剔除了失效文件且not task.checkpoint_error时尝试写盘并捕获OSError,防止get_capability_result因磁盘满报错崩溃。 - 封堵 ACP 异步通知回调中
64/256工具调用上限后的违规工具漏检(src/agent_bridge/acp_results.py:94-107、src/agent_bridge/native_results.py:32-34):超出上限或检测到禁用工具时在Task上设置显式违规标志并取消当前prompt_task。 - 修正
_lexical_reference中normpath前置导致的..穿越段折叠放行(src/agent_bridge/registry.py:613-652):在执行os.path.normpath之前先检查原始路径分段是否包含".."并对齐请求指纹去重规则。
Adds
call_capability,get_capability_result, andcancel_capabilityfor native search and media operations through existing local worker CLIs. Callers receive native sources, verified workspace-relative output files, and explicit job/durability status without managing worker sessions.Supported integrations:
The integration validates reference images and delivered files, persists native evidence, deduplicates retained requests across restarts, and supports explicit continuation of successful compatible calls. Native calls require durable state before provider execution. Results remain pending through worker cleanup; unconfirmed process exits retain worker/PID evidence and block continuation. No automatic generation resubmission occurs.
Scope is limited to search/media tools and their supporting adapters, result handling, documentation, and tests. This branch is based directly on upstream
5560e06; it does not include fork TaskNode metadata, orchestration rules, configuration defaults, diagnostic schemas, or private acceptance logs. Existing upstream request fingerprints, async result/persistence contracts, permissions, environment filtering, and ordinary dispatch behavior are preserved.Validation on Windows / CPython 3.12.11:
An earlier full run encountered a transient Windows file-replacement denial in an unchanged upstream configuration test. All 28 configuration tests passed independently, followed by the clean full run reported above; configuration/persistence source files were not changed for that failure.
This verification made no real provider calls and did not upgrade a shared installation. Native operation counts are observed after execution rather than enforced as a provider-side billing/execution budget. Account availability and broader live-provider acceptance remain environment-specific.