Skip to content

fix(gateway): 打通 executeSystemTool 链路,修复网关模式下 /memo 与 /remember 报 unsupported_action_in_gateway_mode#453

Merged
phantom5099 merged 5 commits into1024XEngineer:mainfrom
pionxe:fix/gateway-memo-remember-support
Apr 26, 2026
Merged

fix(gateway): 打通 executeSystemTool 链路,修复网关模式下 /memo 与 /remember 报 unsupported_action_in_gateway_mode#453
phantom5099 merged 5 commits into1024XEngineer:mainfrom
pionxe:fix/gateway-memo-remember-support

Conversation

@pionxe
Copy link
Copy Markdown
Collaborator

@pionxe pionxe commented Apr 24, 2026

背景与问题

在 Gateway 模式下,TUI 的 /memo/remember <text> 通过 ExecuteSystemTool 入口触发,但远端适配器此前直接返回 unsupported_action_in_gateway_mode,导致命令无法执行。

Closes #451

根因分析

  • RemoteRuntimeAdapter.ExecuteSystemTool 未走网关 RPC,而是硬编码返回不支持。
  • 网关协议层缺少系统工具执行方法,RuntimePort 也未暴露对应能力,链路在 Gateway 处断开。

主要改动

  • 新增 JSON-RPC 方法:gateway.executeSystemTool
  • 新增网关动作:execute_system_tool
  • 新增 RuntimePort.ExecuteSystemTool 及桥接实现,接入 runtime ExecuteSystemTool
  • 更新 TUI 远端适配器:
    • 正常走 gateway.executeSystemTool
  • 同步 ACL 与 metrics 方法白名单
  • 补充协议层、分发层、桥接层、适配层与校验层测试

影响范围

  • Gateway 协议:internal/gateway/protocol/jsonrpc.go
  • Gateway 分发与运行时桥接:internal/gateway/bootstrap.gointernal/gateway/contracts.gointernal/cli/gateway_runtime_bridge.go
  • TUI 远端适配:internal/tui/services/remote_runtime_adapter.go
  • ACL/metrics/validate 与对应测试

测试验证

  • go test ./internal/gateway ./internal/tui/services ./internal/cli 通过
  • go test ./internal/gateway/launcher 存在既有失败(与本 PR 无关,路径断言环境差异)
  • go test ./... 在当前环境执行超时,未完整跑完

风险与回滚

  • 风险:新增 RPC 方法涉及网关协议扩展。
  • 回滚:可按提交回滚,恢复到原先“网关模式下系统工具不支持”的行为。

- 新增 gateway.executeSystemTool 协议方法与 execute_system_tool 动作分发

- 打通 Gateway RuntimePort 到 runtime.ExecuteSystemTool 的桥接链路

- 将 RemoteRuntimeAdapter.ExecuteSystemTool 改为远程调用,并兼容旧网关 unsupported_action 降级

- 同步 ACL、指标方法白名单与相关单元测试覆盖
@chatgpt-codex-connector
Copy link
Copy Markdown

Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits.
Credits must be used to enable repository wide code reviews.

@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 24, 2026

fennoai[bot]

This comment was marked as outdated.

pionxe added 2 commits April 25, 2026 00:41
- 在网关层为 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/集成指南文档,更新自动示例生成脚本与测试
@phantom5099
Copy link
Copy Markdown
Collaborator

这次把 gateway.executeSystemTool 打通后,新 gateway 的 /memo happy path 已经能走通了,这部分方向没问题。
但兼容旧 gateway 的降级链路还没有闭环到用户体验:RemoteRuntimeAdapter 仍会把 method_not_found / unsupported_action 降级成 ErrUnsupportedActionInGatewayMode,而 memo 命令路径在 internal/tui/core/app/update.go (line 3736) 这里还是直接把 err.Error() 回显给用户。这样一来,连接旧 gateway 时,用户仍然会看到 unsupported_action_in_gateway_mode 这个底层 sentinel,和 #451 里“不再向用户暴露该错误文本”的验收目标不一致。

建议这里补一层面向用户的错误映射,而不是直接透传内部错误字符串。比较直接的做法是:在 memo 命令回调里对 errors.Is(err, tuiservices.ErrUnsupportedActionInGatewayMode) 做特判,统一转换成类似“当前连接的 gateway 版本暂不支持记忆命令,请升级 gateway 或切换到 local runtime”的可读提示;只有非该 sentinel 的错误再继续显示原始信息。这样既保留内部兼容分支的判定能力,也能把旧 gateway 场景的用户体验补完整。

@phantom5099
Copy link
Copy Markdown
Collaborator

@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 文档路径说明
@phantom5099
Copy link
Copy Markdown
Collaborator

/review 检查一遍有没有残留

Copy link
Copy Markdown

@fennoai fennoai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

发现 2 个需要修复的问题(其余代码质量/性能/安全/文档检查未发现新增高风险问题):

  1. internal/tui/core/app/skills_commands.go:156
    normalizeSkillCommandError 只匹配 ErrUnsupportedActionInGatewayMode 哨兵错误,但本 PR 已将 remote adapter 改为透传 GatewayRPCError。当旧网关返回 gateway_code=unsupported_actionmethod_not_found 时,这里不会再映射为升级提示,用户会看到底层 RPC 错误文本,和预期的 UX 不一致。

  2. 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) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里仅判断 ErrUnsupportedActionInGatewayMode。但本 PR 已把远端调用错误改为 GatewayRPCError 透传,旧网关的 unsupported_action/method_not_found 不会再进入该分支,最终把底层 RPC 错误直接暴露给用户。建议改为 errors.As(err, *GatewayRPCError) 并基于 GatewayCode/Code 判定后返回统一升级提示。

Comment thread internal/tui/core/app/update.go Outdated
return "memo command failed"
}
if errors.Is(err, tuiservices.ErrUnsupportedActionInGatewayMode) ||
strings.Contains(strings.ToLower(strings.TrimSpace(err.Error())), "unsupported_action_in_gateway_mode") {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个分支仍依赖 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 三类场景
@phantom5099 phantom5099 merged commit d6b15ad into 1024XEngineer:main Apr 26, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Gateway 模式下 /memo/remember 不可用,导致记忆命令与默认链路不一致

2 participants