Skip to content

fix(amp): preserve lowercase glob tool name#2766

Open
edlsh wants to merge 1 commit intorouter-for-me:devfrom
edlsh:fix/amp-glob-tool-casing
Open

fix(amp): preserve lowercase glob tool name#2766
edlsh wants to merge 1 commit intorouter-for-me:devfrom
edlsh:fix/amp-glob-tool-casing

Conversation

@edlsh
Copy link
Copy Markdown
Contributor

@edlsh edlsh commented Apr 13, 2026

Summary

  • normalize known Amp tool names in rewritten responses
  • preserve the lowercase glob name that Amp expects instead of rewriting it to Glob
  • add regression coverage for normalized and untouched tool names

Testing

  • go test ./internal/api/modules/amp
  • go test ./...
  • go build -o test-output ./cmd/server && rm test-output

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces tool name normalization to ensure compatibility with Amp's case-sensitive tool whitelist. It adds a mapping of canonical tool names and a function to update tool names in both streaming and non-streaming API responses. Unit tests were added to verify the normalization logic. Feedback was provided regarding an optimization in the streaming logic to reduce redundant JSON parsing when accessing content_block fields.

Comment on lines +158 to +160
if gjson.GetBytes(data, "content_block.type").String() == "tool_use" {
name := gjson.GetBytes(data, "content_block.name").String()
if canonical, ok := ampCanonicalToolNames[strings.ToLower(name)]; ok && name != canonical {
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.

medium

The code performs redundant JSON parsing by calling gjson.GetBytes twice for the same content_block object. It is more efficient to retrieve the content_block once and then use Get on the resulting gjson.Result to access its fields. This is particularly relevant in streaming mode where this logic is executed for every chunk.

	// Streaming: content_block.name in content_block_start events
	contentBlock := gjson.GetBytes(data, "content_block")
	if contentBlock.Get("type").String() == "tool_use" {
		name := contentBlock.Get("name").String()

Copy link
Copy Markdown
Collaborator

@luispater luispater left a comment

Choose a reason for hiding this comment

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

Summary

This PR normalizes known Amp tool names in rewritten Anthropic-style responses, while explicitly preserving the lowercase glob tool name that Amp expects. It adds focused unit coverage for normalized and untouched tool names.

Key findings

  • Correctness: Normalization is applied to both non-streaming content[].name tool_use blocks and streaming content_block_start (content_block.name).
  • Compatibility: glob remains lowercase (and mixed/upper-case variants will normalize to glob).
  • Safety: Unknown tool names are left untouched.

Test plan

  • Not run locally (per review constraints; no PR checkout).
  • CI is green; PR description reports running:
    • go test ./internal/api/modules/amp
    • go test ./...
    • go build -o test-output ./cmd/server && rm test-output

Non-blocking suggestion

  • Add a unit test asserting Glob/GLOB becomes glob to lock in the key casing nuance.

This is an automated Codex review result and still requires manual verification by a human reviewer.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants