Skip to content

fix(tools): enforce per-request tool declarations - #1841

Merged
lizhengfeng101 merged 5 commits into
alibaba:mainfrom
chaojixinren:fix-scan-remove-diff-tool
Nov 12, 2026
Merged

lizhengfeng101 merged 5 commits into
alibaba:mainfrom
chaojixinren:fix-scan-remove-diff-tool

Conversation

@chaojixinren

@chaojixinren chaojixinren commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

Description

Scan omitted file_read_diff from the model's tool definitions but could still execute it through the shared registry and return whole-file contents. Registered tools were executable even when the current request did not declare them.

Validate tool calls against the definitions sent in that request before invoking providers or special task_done/code_comment actions. Undeclared tools return the existing tool-unavailable response. Keep the shared registry and remove scan's whole-file diff injection. The restricted grace round uses its own declarations; explicitly advertised MCP tools remain available, and tool_references grant no execution permission.

Type of Change

  • Bug fix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Refactoring (no functional changes)
  • Documentation update
  • CI / Build / Tooling

How Has This Been Tested?

  • make check and the full make test suite with race detection pass.

  • make coverage passes at 91.6% (90% required).

  • The manual_e2e retry-report tests pass.

  • ocr review --audience agent --background ... reviewed both changed production files and reported zero findings.

  • Regression tests cover registered but undeclared providers, empty declarations, special actions, phase restrictions, and actual MCP registration and execution through a local server.

  • The scan entry-point regression still rejects file_read_diff; a review-loop integration test preserves diff access and old/new comparison reads.

  • A temporary Go overlay removing the guard makes all five targeted regression tests fail, while the advertised MCP case continues to pass.

  • make test passes locally

  • Manual testing (describe below)

Checklist

  • My code follows the project's coding style (go fmt, go vet)
  • I have performed a self-review of my code
  • I have added tests that prove my fix is effective or my feature works
  • New and existing unit tests pass locally with my changes
  • I have updated the documentation accordingly (if applicable)
  • I have signed the CLA
  • I did not use AI/LLM to create this PR, or I disclosed the tool/model below and reviewed its output; I did not attribute commits to AI and will answer maintainer questions and review comments myself without AI/LLM.

AI disclosure: OpenAI Codex (GPT-6 and GPT-6 Astra) assisted with implementation, tests, and this description. OCR used deepseek-flash for automated code review. No AI attribution trailers were added to the commit.

- Separate review and scan tool registries.
- Remove scan's full-file fallback for file_read_diff.
- Verify scan rejects diff calls and budget tests read files successfully.
@github-actions

Copy link
Copy Markdown
Contributor

✅ OpenCodeReview: Review complete: 0 finding(s) across 3 selected item(s).

@chaojixinren
chaojixinren marked this pull request as ready for review October 28, 2026 15:56
@Qiyuanqiii

Copy link
Copy Markdown
Contributor

同步最新的 main,然后重新触发 CI即可

@NanaseInori NanaseInori left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Reviewed the complete eight-file diff and existing discussion. The rationale is supported by the old scan initialization: file_read_diff was absent from the advertised definitions but remained executable through the shared registry, with full file bodies injected as a fallback. Removing that fallback and registering only scan's actual providers closes that inconsistency.

The review registry retains its diff provider and its existing call sites. The scan entry point now uses the independent registry; its HTTP regression deliberately returns an unadvertised file_read_diff call and checks the unavailable-tool result in the next request. The budget fixtures now create real files, use file_read, and assert both an executed read and no tool failures, so they cannot pass merely because an unavailable tool consumed a round. No blocking defect found.

The related changes are complementary: #1836 improves missing-path diagnostics in the diff tool, while #1898 moves advertised tool bindings into templates. Neither removes this scan execution provider. I am not treating the template lists as an execution sandbox.

Approval is based on source and regression-test inspection. I did not independently run make check, the race suite, the manual_e2e tests, or a live-model review.

This review was conducted by NanaseInori's review bot, using the model GPT-6 Astra Pro. If you need a human review, please manually @NanaseInori.

@lizhengfeng101

Copy link
Copy Markdown
Contributor

Thanks for addressing this inconsistency. Given the recent tool refactoring in #1898, I'd prefer to use this PR to make the task's tool declarations constrain execution as well, rather than introduce a separate hard-coded scan registry.

Currently, the template determines which tool definitions are sent to the model, but runtime dispatch independently looks up providers in the registry. That leaves registered-but-unadvertised tools executable if the model calls them anyway.

Could you adjust the implementation along these lines?

  • Keep the removal of injectScanContentMap; scan should not populate a diff provider with whole-file contents.
  • Avoid adding buildScanToolRegistry. A shared provider registry is fine, provided registration alone does not authorize execution for a task.
  • At the shared execution boundary, check each requested tool against the tool definitions actually sent in that model request. Return the existing tool-unavailable response for undeclared tools, without executing the provider or performing special tool actions.
  • Use the correct tool set for each phase, including the restricted grace round, rather than always checking the main task's tools. Preserve explicitly exposed MCP tools and account for task_done; tool_references must not grant execution permission.

Please add regression coverage showing that a registered-but-undeclared tool is rejected without invoking its provider, while declared tools still execute. Keep the scan rejection test and verify that review retains diff access and the comparison-side reading behavior introduced in #1903. The phase-specific restrictions and MCP handling should also be covered where applicable.

This is a requested design adjustment, not a claim that the current patch breaks supported workflows. It broadens the fix into the shared execution path, so the corresponding tests matter; unrelated registry or construction refactors can stay out of scope.

AI disclosure: This comment was drafted with OpenAI Codex at the maintainer's request.

@chaojixinren chaojixinren changed the title fix(scan): remove diff tool registration fix(tools): enforce per-request tool declarations Nov 12, 2026
@chaojixinren

Copy link
Copy Markdown
Contributor Author

Thanks for addressing this inconsistency. Given the recent tool refactoring in #1898, I'd prefer to use this PR to make the task's tool declarations constrain execution as well, rather than introduce a separate hard-coded scan registry.

Currently, the template determines which tool definitions are sent to the model, but runtime dispatch independently looks up providers in the registry. That leaves registered-but-unadvertised tools executable if the model calls them anyway.

Could you adjust the implementation along these lines?

  • Keep the removal of injectScanContentMap; scan should not populate a diff provider with whole-file contents.
  • Avoid adding buildScanToolRegistry. A shared provider registry is fine, provided registration alone does not authorize execution for a task.
  • At the shared execution boundary, check each requested tool against the tool definitions actually sent in that model request. Return the existing tool-unavailable response for undeclared tools, without executing the provider or performing special tool actions.
  • Use the correct tool set for each phase, including the restricted grace round, rather than always checking the main task's tools. Preserve explicitly exposed MCP tools and account for task_done; tool_references must not grant execution permission.

Please add regression coverage showing that a registered-but-undeclared tool is rejected without invoking its provider, while declared tools still execute. Keep the scan rejection test and verify that review retains diff access and the comparison-side reading behavior introduced in #1903. The phase-specific restrictions and MCP handling should also be covered where applicable.

This is a requested design adjustment, not a claim that the current patch breaks supported workflows. It broadens the fix into the shared execution path, so the corresponding tests matter; unrelated registry or construction refactors can stay out of scope.

AI disclosure: This comment was drafted with OpenAI Codex at the maintainer's request.

@lizhengfeng101 done

@lizhengfeng101 lizhengfeng101 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM

@lizhengfeng101
lizhengfeng101 merged commit 43638b5 into alibaba:main Nov 12, 2026
12 checks passed
@chaojixinren
chaojixinren deleted the fix-scan-remove-diff-tool branch November 13, 2026 00:20
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.

4 participants