Skip to content

fix(aliyun): give ROS template tools actionable input errors - #206

Open
ruanzhengxin-zhuxing wants to merge 1 commit into
mainfrom
harness/cfc4edce
Open

fix(aliyun): give ROS template tools actionable input errors#206
ruanzhengxin-zhuxing wants to merge 1 commit into
mainfrom
harness/cfc4edce

Conversation

@ruanzhengxin-zhuxing

Copy link
Copy Markdown
Collaborator

问题

ROS 模板工具(ros_validate_templateros_get_template_parameter_constraintsros_preview_templateros_estimate_template_cost)在输入有缺陷时返回的错误无法指导修复,导致 agent 首次失败后在不同工具上重复相同调用(会话证据:93851da3d55542baa2684387d4d5fc31f608eb3cc8944c95a81e901db47c1b2a3a0edeb1756b4e4fbf4e40689a1ee928)。

根因有两点:

  1. 本地 template_url 读取失败被误报为 body_file is invalid
    _execute_runtime_unattached 的 materialize 阶段通过 _read_body_file 读取本地模板;该函数把底层 OSError 包装成 ApiContractError("invalid_body_file"),而调用处只捕获 (OSError, UnicodeError),因此本应产出的 ROS1202 结构化预检诊断永远不会命中,错误最终渲染为 "body_file is invalid"。这些工具的输入 schema 里没有 body_file 字段,agent 无法把错误关联到 template_url

  2. 必填输入缺失只返回泛化 invalid_tool_input
    validate_delegated_tool_input 仅返回 bool,缺 parameters / stack_name 时错误不指明字段,也不给修复方向。

修改

  • aliyun_api.py:materialize 阶段同时捕获 ApiContractError,统一走 local_template_source_error,ROS 模板调用不再出现无法处理的 body_file 错误。
  • hooks/ros_validate.py:ROS1202 诊断区分读取失败 / 非 UTF-8 / 超过大小限制三种情形,并给出对应修复建议。
  • ros_template_tools.py:新增 delegated_tool_input_error,返回 missing_required_parameters:<names> 以点名缺失字段;validate_delegated_tool_input 复用它保持兼容。
  • runtime.py / aliyun_api.py:delegated 授权与执行路径改用带字段信息的错误码。
  • public_errors.py:缺失字段消息追加可执行指引(parameters 提示先用 ros_get_template_parameter_constraints 求解合法取值、stack_name 说明是工具参数、template_url 说明可接受的路径形式),并明确"先修复输入再调用,不要重复相同调用"。
  • i18n:6 个语言补齐译文并重新编译。

测试

  • 新增用例覆盖四个 ROS 工具在本地 template_url 不可读时返回 ROS1202(不含 body_file),以及缺 parameters / stack_name 时错误点名字段。
  • tests/tools/cloud/aliyun + tests/i18n:2185 passed。
  • 全量 pytest tests/:13277 passed, 4 skipped;另有 2 个失败(test_prepare_direct_binary_installer_reports_invalid_http_url_without_leaking_tokentest_latest_pipeline_sidecar_reads_nested_session_layout)在父提交上同样复现,属既有问题。
  • ruff checkty check src/ 均通过。

ROS template tools (ros_validate_template, ros_get_template_parameter_constraints,
ros_preview_template, ros_estimate_template_cost) failed with errors the agent
could not act on, so the same failing call was repeated across tools:

- An unreadable local template_url surfaced as "body_file is invalid" because
  _read_body_file raises ApiContractError, which the materialization step did not
  catch, bypassing the structured ROS1202 preflight diagnostic. These tools have
  no body_file input, so the error was unactionable.
- Missing required inputs collapsed into a generic invalid_tool_input message
  that did not name the offending field.

Now the materialization step maps ApiContractError to the ROS preflight report
(with distinct read/UTF-8/size guidance), and delegated input validation reports
the missing fields so the public error names parameters/stack_name/template_url
and tells the caller to fix the input instead of repeating the same call.
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.

1 participant