fix(gateway): 打通 executeSystemTool 链路,修复网关模式下 /memo 与 /remember 报 unsupported_action_in_gateway_mode#453
Conversation
- 新增 gateway.executeSystemTool 协议方法与 execute_system_tool 动作分发 - 打通 Gateway RuntimePort 到 runtime.ExecuteSystemTool 的桥接链路 - 将 RemoteRuntimeAdapter.ExecuteSystemTool 改为远程调用,并兼容旧网关 unsupported_action 降级 - 同步 ACL、指标方法白名单与相关单元测试覆盖
|
Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits. |
Codecov Report❌ Patch coverage is 📢 Thoughts on this report? Let us know! |
- 在网关层为 gateway.executeSystemTool 增加系统工具白名单,限制为 memo_* 工具 - 新增拒绝非白名单工具的单元测试,确保请求在网关层被拦截 - 补齐 README、gateway-rpc-api*、gateway-compatibility* 及相关设计/集成文档 - 更新网关 RPC 示例生成脚本并回填 reference 文档自动生成区块
- 新增 skills 相关网关 RPC:activate/deactivate/listSession/listAvailable,并贯通 TUI->Gateway->Runtime - gateway.executeSystemTool 增加系统工具白名单限制(仅 memo 相关工具)与回归测试 - 修复 gateway 测试桩缺失接口导致的编译失败,补齐 CLI/TUI/Gateway 测试覆盖 - 同步 README 与 Gateway 兼容性/RPC API/集成指南文档,更新自动示例生成脚本与测试
|
这次把 gateway.executeSystemTool 打通后,新 gateway 的 /memo happy path 已经能走通了,这部分方向没问题。 建议这里补一层面向用户的错误映射,而不是直接透传内部错误字符串。比较直接的做法是:在 memo 命令回调里对 errors.Is(err, tuiservices.ErrUnsupportedActionInGatewayMode) 做特判,统一转换成类似“当前连接的 gateway 版本暂不支持记忆命令,请升级 gateway 或切换到 local runtime”的可读提示;只有非该 sentinel 的错误再继续显示原始信息。这样既保留内部兼容分支的判定能力,也能把旧 gateway 场景的用户体验补完整。 |
|
@xgopilot 检查一遍该PR是否还在留旧网关兼容 |
- 删除 remote runtime adapter 的 method_not_found/unsupported_action 降级映射,改为直接透传 RPC 错误 - 修复 /memo 错误文案映射,避免向用户暴露 unsupported_action_in_gateway_mode 内部文本 - 在 skills registry 中新增 ~/.codex/skills 回退加载(当 ~/.neocode/skills 缺失时) - 补充 app/tui/services/tui/core 回归测试,并同步 skills 文档路径说明
|
/review 检查一遍有没有残留 |
There was a problem hiding this comment.
发现 2 个需要修复的问题(其余代码质量/性能/安全/文档检查未发现新增高风险问题):
-
internal/tui/core/app/skills_commands.go:156
normalizeSkillCommandError只匹配ErrUnsupportedActionInGatewayMode哨兵错误,但本 PR 已将 remote adapter 改为透传GatewayRPCError。当旧网关返回gateway_code=unsupported_action或method_not_found时,这里不会再映射为升级提示,用户会看到底层 RPC 错误文本,和预期的 UX 不一致。 -
internal/tui/core/app/update.go:3594
normalizeMemoCommandErrorMessage同样仍依赖哨兵或字符串unsupported_action_in_gateway_mode。但透传后的错误格式来自GatewayRPCError.Error()(例如包含unsupported_action),不会命中该分支,导致/memo在旧网关场景下无法显示预期的“请升级 gateway/client”提示。
建议:统一基于 errors.As(err, *GatewayRPCError) + GatewayCode/Code 做判定,避免继续依赖哨兵或脆弱的字符串包含匹配。
| @@ -154,7 +154,7 @@ func normalizeSkillCommandError(err error) error { | |||
| return nil | |||
| } | |||
| if errors.Is(err, tuiservices.ErrUnsupportedActionInGatewayMode) { | |||
There was a problem hiding this comment.
这里仅判断 ErrUnsupportedActionInGatewayMode。但本 PR 已把远端调用错误改为 GatewayRPCError 透传,旧网关的 unsupported_action/method_not_found 不会再进入该分支,最终把底层 RPC 错误直接暴露给用户。建议改为 errors.As(err, *GatewayRPCError) 并基于 GatewayCode/Code 判定后返回统一升级提示。
| return "memo command failed" | ||
| } | ||
| if errors.Is(err, tuiservices.ErrUnsupportedActionInGatewayMode) || | ||
| strings.Contains(strings.ToLower(strings.TrimSpace(err.Error())), "unsupported_action_in_gateway_mode") { |
There was a problem hiding this comment.
这个分支仍依赖 unsupported_action_in_gateway_mode 字符串。现在错误来源是 GatewayRPCError(例如 unsupported_action),通常不会包含该文本,导致 /memo 无法命中用户友好的升级提示。建议和 skills 命令共用同一套 GatewayRPCError 判定逻辑。
- 新增 isGatewayUnsupportedActionError,统一基于 GatewayRPCError(GatewayCode/Code) 判定 unsupported_action/method_not_found - /memo 与 /skills 复用同一判定逻辑,避免底层 RPC 错误文本直接暴露到 UI - 补充对应单测,覆盖 sentinel、unsupported_action 与 method_not_found 三类场景
背景与问题
在 Gateway 模式下,TUI 的
/memo与/remember <text>通过ExecuteSystemTool入口触发,但远端适配器此前直接返回unsupported_action_in_gateway_mode,导致命令无法执行。Closes #451
根因分析
RemoteRuntimeAdapter.ExecuteSystemTool未走网关 RPC,而是硬编码返回不支持。RuntimePort也未暴露对应能力,链路在 Gateway 处断开。主要改动
gateway.executeSystemToolexecute_system_toolRuntimePort.ExecuteSystemTool及桥接实现,接入 runtimeExecuteSystemToolgateway.executeSystemTool影响范围
internal/gateway/protocol/jsonrpc.gointernal/gateway/bootstrap.go、internal/gateway/contracts.go、internal/cli/gateway_runtime_bridge.gointernal/tui/services/remote_runtime_adapter.go测试验证
go test ./internal/gateway ./internal/tui/services ./internal/cli通过go test ./internal/gateway/launcher存在既有失败(与本 PR 无关,路径断言环境差异)go test ./...在当前环境执行超时,未完整跑完风险与回滚