Skip to content

fix(tools): keep HY3 tool schemas inline - #1923

Merged
kevincodex1 merged 6 commits into
Twigpine:mainfrom
jatmn:fix/tencent-hy3-tool-calling
Jul 10, 2026
Merged

kevincodex1 merged 6 commits into
Twigpine:mainfrom
jatmn:fix/tencent-hy3-tool-calling

Conversation

@jatmn

@jatmn jatmn commented Jul 9, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

  • keep Tencent HY3 on the inline tool-schema path, avoiding the deferred TaskCreate schema loop reported in Tencent HY3 tool calling issues #1912
  • preserve that compatibility behavior when local tool-search feature flags add other unsupported models
  • correct HY3’s shared descriptor to its documented non-vision, 256K-context, 128K-output capabilities
  • recover HY3's OpenGateway text-form tool-call wrapper into executable OpenClaude tool uses

Root cause

HY3 does not reliably perform the extra ToolSearch discovery turn before invoking a deferred tool, so TaskCreate could be omitted from the request schema. Live OpenGateway validation also showed that, under OpenClaude's streamed request shape, HY3 emits <tool_call:...> text with named arguments instead of structured OpenAI tool_calls; the shim previously surfaced that text instead of executing the tool. The shim now supports both that gateway form and Tencent HY3's documented tagged <tool_call:opensource> / <arg_key:opensource> grammar.

Validation

  • bun test src/utils/toolSearch.test.ts src/integrations/tencent.test.ts src/integrations/index.test.ts
  • bun test src/services/api/openaiShim.xmlToolCalls.test.ts src/services/api/openaiShim.test.ts
  • bun run test:provider
  • bun run typecheck
  • bun run integrations:check
  • bun run security:pr-scan -- --base upstream/main --head HEAD
  • bun run build
  • node dist/cli.mjs --version

Live validation used a minimal, isolated TaskCreate prompt against OpenGateway HY3. The shim converted the returned textual wrapper into TaskCreate with the expected subject and description fields.

Final reviewed commit: d3170c5065a717b19a8ae995163e2b9b9e567b4a.

Fixes #1912

Summary by CodeRabbit

  • New Features
    • Enhanced compatibility with Tencent HY3 tool calls, including additional XML wrapper dialects and argument styles for both streamed and non-streamed responses.
  • Bug Fixes
    • Corrected Tencent HY3 capability reporting by disabling default vision support and marking tool reference support as unreliable.
    • Raised Tencent HY3 maximum output limit to 131,072 tokens.
    • Improved recovery of XML-formatted tool calls into structured tool-use content.
  • Tests
    • Added/expanded coverage for Tencent HY3 capabilities, catalog visibility, runtime limits, and tool-call recovery (including streaming edge cases).

@coderabbitai

coderabbitai Bot commented Jul 9, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: 51d4e934-0e1b-4d60-9b43-b9dcc4c21bf0

📥 Commits

Reviewing files that changed from the base of the PR and between 645e7b4 and 83ecf4f.

📒 Files selected for processing (5)
  • src/services/api/openaiShim.test.ts
  • src/services/api/openaiShim.ts
  • src/services/api/openaiShim.xmlToolCalls.test.ts
  • src/utils/toolSearch.test.ts
  • src/utils/toolSearch.ts
📜 Recent review details
⏰ Context from checks skipped due to timeout. (1)
  • GitHub Check: CodeRabbit / Review
🧰 Additional context used
📓 Path-based instructions (5)
**/*.{ts,tsx}

📄 CodeRabbit inference engine (AGENTS.md)

TypeScript code in this repository must use strict mode and ESM imports.

Files:

  • src/utils/toolSearch.test.ts
  • src/services/api/openaiShim.test.ts
  • src/utils/toolSearch.ts
  • src/services/api/openaiShim.xmlToolCalls.test.ts
  • src/services/api/openaiShim.ts
**

⚙️ CodeRabbit configuration file

**: # AGENTS.md - AI Agent Coding Guide

This guide is for AI coding agents working in the OpenClaude repository. Read it before changing code, and also follow CONTRIBUTING.md for contributor policy, PR expectations, review follow-up, and project scope.

Project Snapshot

OpenClaude is a coding-agent CLI for cloud and local model providers. It supports OpenAI-compatible APIs, Anthropic, Gemini, DeepSeek, Ollama, MCP, local backends, slash commands, tools, agents, and a React/Ink terminal UI.

The installed CLI runs on Node.js >=22.0.0. Bun is used for source builds, scripts, dependency management, and tests.

Work Style

  • Keep changes focused on one problem.
  • Prefer existing patterns in the file or nearby module.
  • Avoid unrelated formatting, renames, dependency changes, or broad rewrites.
  • Add or update tests when behavior changes.
  • Update docs when setup, commands, provider behavior, or user-facing behavior changes.
  • For new features, larger refactors, dependencies, or runtime changes, follow the issue-first guidance in CONTRIBUTING.md.

Stack And Conventions

  • TypeScript with strict mode and ESM imports.
  • React + Ink for terminal UI.
  • Bun lockfile and Bun scripts for development workflows.
  • Node runtime for the built CLI.

Common libraries and patterns:

  • chalk for terminal color.
  • commander for CLI argument parsing.
  • execa for child processes.
  • Existing service, provider, settings, permission, and UI patterns over new abstractions.

Repository Map

  • src/commands/ - slash and CLI command implementations.
  • src/components/ - React/Ink UI components.
  • src/services/ - API, MCP, OAuth, wiki, voice, and other service integrations.
  • src/tools/ - tool implementations.
  • src/utils/ - shared utilities.
  • src/integrations/ - provider and model integration metadata.
  • src/entrypoints/ - CLI, MCP, SDK, and generated public types.
  • src/tasks/ - local, remote, workflow, and monitor tas...

Files:

  • src/utils/toolSearch.test.ts
  • src/services/api/openaiShim.test.ts
  • src/utils/toolSearch.ts
  • src/services/api/openaiShim.xmlToolCalls.test.ts
  • src/services/api/openaiShim.ts
**/*

⚙️ CodeRabbit configuration file

**/*: Apply the OpenClaude maintainer review rubric from AGENTS.md. Review the current diff, not stale discussion context. Separate real blockers from suggestions. Do not request changes for vague style churn. Treat approval as merge-ready from CodeRabbit's side, pending required human review and GitHub Checks. If checks are failing or unavailable, say so clearly instead of implying the PR is fully ready.

Files:

  • src/utils/toolSearch.test.ts
  • src/services/api/openaiShim.test.ts
  • src/utils/toolSearch.ts
  • src/services/api/openaiShim.xmlToolCalls.test.ts
  • src/services/api/openaiShim.ts
{src/**/*.test.ts,src/**/*.test.tsx,tests/**,scripts/**/*.test.ts,vscode-extension/**/*.test.js}

⚙️ CodeRabbit configuration file

{src/**/*.test.ts,src/**/*.test.tsx,tests/**,scripts/**/*.test.ts,vscode-extension/**/*.test.js}: Review tests for meaningful coverage of the changed behavior, isolation of global/env/config state, async cleanup, fake timers, provider profile leaks, and Windows-compatible assumptions. Block when risky runtime changes lack focused regression coverage or tests assert implementation details while missing the user-visible behavior.

Files:

  • src/utils/toolSearch.test.ts
  • src/services/api/openaiShim.test.ts
  • src/services/api/openaiShim.xmlToolCalls.test.ts
{src/services/api/**,src/integrations/**,src/utils/model/**,src/utils/provider*.ts,src/commands/provider/**}

⚙️ CodeRabbit configuration file

{src/services/api/**,src/integrations/**,src/utils/model/**,src/utils/provider*.ts,src/commands/provider/**}: Review provider routing, model selection, env precedence, auth/token handling, OpenAI-compatible shims, retries, proxy behavior, and outbound HTTP behavior with high scrutiny. Block on silent default changes, hidden fallback expansion, credential reuse mistakes, hardcoded provider assumptions, or new network reach that is not intentional and documented.

Files:

  • src/services/api/openaiShim.test.ts
  • src/services/api/openaiShim.xmlToolCalls.test.ts
  • src/services/api/openaiShim.ts
🔇 Additional comments (9)
src/services/api/openaiShim.xmlToolCalls.test.ts (2)

276-298: Past fetch-restore concern is resolved — run() now wraps the override in try/finally.


133-211: LGTM!

Also applies to: 372-392, 431-507

src/utils/toolSearch.ts (2)

261-261: LGTM!

Also applies to: 284-287


245-246: 🎯 Functional Correctness

No additional Tencent HY3 variants to exclude
The repo only defines tencent/hy3 for Tencent, so the exact-match exception is sufficient here.

			> Likely an incorrect or invalid review comment.
src/utils/toolSearch.test.ts (1)

1-12: LGTM!

Also applies to: 56-85

src/services/api/openaiShim.ts (2)

1912-1914: LGTM!

Also applies to: 1921-1942, 1995-2054, 2401-2422, 2436-2440, 2455-2455, 2529-2529, 2934-2947, 3203-3206


1960-1994: 🎯 Functional Correctness

No change needed.

src/services/api/openaiShim.test.ts (2)

9921-9946: LGTM!

Also applies to: 10149-10190


10212-10222: 🎯 Functional Correctness

No issue here
The textDelta cast appears only once, and this snippet is syntactically valid.

			> Likely an incorrect or invalid review comment.

📝 Walkthrough

Walkthrough

Tencent HY3 capability metadata now disables vision and increases the output limit. Tool-search compatibility excludes HY3 tool references, while OpenAI-compatible conversion recovers HY3 XML tool calls in streaming and non-streaming responses.

Changes

Tencent HY3 compatibility and tool-call recovery

Layer / File(s) Summary
Model capabilities and compatibility rules
src/integrations/brands/tencent.ts, src/integrations/models/tencent.ts, src/integrations/tencent.test.ts, src/utils/toolSearch.ts, src/utils/toolSearch.test.ts
Tencent HY3 no longer advertises vision or tool-reference support, its maximum output token limit increases to 131_072, and capability, catalog, runtime-limit, and feature-flag behavior is tested.
HY3 XML parser support
src/services/api/openaiShim.ts, src/services/api/openaiShim.xmlToolCalls.test.ts
XML parsing adds Tencent HY3 wrappers, namespaced and inline arguments, zero-argument handling, tool-name validation, deduplication, and streaming opener detection.
Streaming and non-streaming recovery
src/services/api/openaiShim.ts, src/services/api/openaiShim.xmlToolCalls.test.ts, src/services/api/openaiShim.test.ts
Raw HY3 XML tool calls are converted into Anthropic tool-use blocks, removed from visible text, and recovered across split SSE chunks with JSON fallback coverage.

Estimated code review effort: 4 (Complex) | ~45 minutes

Possibly related PRs

Suggested labels: bug

Suggested reviewers: kevincodex1

🚥 Pre-merge checks | ✅ 5 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 71.43% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Risk Surface Disclosed ⚠️ Warning Touches provider routing/tool-search, but the PR review/description doesn’t explicitly call out the blast radius or whether it’s a blocker. Add a brief review note naming the affected surfaces (provider routing/tool-search/OpenAI shim) and stating whether the risk is merge-blocking or acceptable.
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title is concise and matches the PR’s HY3 tool-calling and schema behavior changes.
Description check ✅ Passed The description covers summary, root cause, validation, and the linked issue, so the template is effectively satisfied.
Linked Issues check ✅ Passed The changes address #1912 by restoring HY3 tool calling and inline schema behavior, matching the issue’s expected normal tool use.
Out of Scope Changes check ✅ Passed The changes stay focused on HY3 tool calling, descriptor metadata, and supporting shims, with no clear unrelated edits.
No Hidden Policy Change ✅ Passed Policy-adjacent changes are explicit: Tencent HY3 capability/tool-search gating is documented and tested, with no hidden telemetry, network, or permission-policy shift.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Comment @coderabbitai help to get the list of available commands.

@jatmn jatmn self-assigned this Jul 9, 2026
@jatmn jatmn added the enhancement New feature or request label Jul 9, 2026
@jatmn
jatmn force-pushed the fix/tencent-hy3-tool-calling branch from 1a5ea89 to d3170c5 Compare July 9, 2026 22:17

@coderabbitai coderabbitai Bot 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.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/services/api/openaiShim.xmlToolCalls.test.ts`:
- Around line 393-398: The test helper run() must restore globalThis.fetch after
each invocation to prevent stale SSE behavior leaking between tests. Wrap its
fetch override and execution in try/finally, restoring the original fetch in the
finally block, matching collectFallbackEvents cleanup; ensure restoration occurs
on both success and failure.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: 16b1dbb2-6ad4-47cd-a8ba-6b747b852bcd

📥 Commits

Reviewing files that changed from the base of the PR and between 87c457c and 645e7b4.

📒 Files selected for processing (8)
  • src/integrations/brands/tencent.ts
  • src/integrations/models/tencent.ts
  • src/integrations/tencent.test.ts
  • src/services/api/openaiShim.test.ts
  • src/services/api/openaiShim.ts
  • src/services/api/openaiShim.xmlToolCalls.test.ts
  • src/utils/toolSearch.test.ts
  • src/utils/toolSearch.ts
📜 Review details
⏰ Context from checks skipped due to timeout. (3)
  • GitHub Check: typecheck
  • GitHub Check: smoke-and-tests (22)
  • GitHub Check: smoke-and-tests (24.11.x)
🧰 Additional context used
📓 Path-based instructions (5)
**/*.{ts,tsx}

📄 CodeRabbit inference engine (AGENTS.md)

TypeScript code in this repository must use strict mode and ESM imports.

Files:

  • src/integrations/models/tencent.ts
  • src/integrations/tencent.test.ts
  • src/integrations/brands/tencent.ts
  • src/utils/toolSearch.test.ts
  • src/utils/toolSearch.ts
  • src/services/api/openaiShim.test.ts
  • src/services/api/openaiShim.xmlToolCalls.test.ts
  • src/services/api/openaiShim.ts
**

⚙️ CodeRabbit configuration file

**: # AGENTS.md - AI Agent Coding Guide

This guide is for AI coding agents working in the OpenClaude repository. Read it before changing code, and also follow CONTRIBUTING.md for contributor policy, PR expectations, review follow-up, and project scope.

Project Snapshot

OpenClaude is a coding-agent CLI for cloud and local model providers. It supports OpenAI-compatible APIs, Anthropic, Gemini, DeepSeek, Ollama, MCP, local backends, slash commands, tools, agents, and a React/Ink terminal UI.

The installed CLI runs on Node.js >=22.0.0. Bun is used for source builds, scripts, dependency management, and tests.

Work Style

  • Keep changes focused on one problem.
  • Prefer existing patterns in the file or nearby module.
  • Avoid unrelated formatting, renames, dependency changes, or broad rewrites.
  • Add or update tests when behavior changes.
  • Update docs when setup, commands, provider behavior, or user-facing behavior changes.
  • For new features, larger refactors, dependencies, or runtime changes, follow the issue-first guidance in CONTRIBUTING.md.

Stack And Conventions

  • TypeScript with strict mode and ESM imports.
  • React + Ink for terminal UI.
  • Bun lockfile and Bun scripts for development workflows.
  • Node runtime for the built CLI.

Common libraries and patterns:

  • chalk for terminal color.
  • commander for CLI argument parsing.
  • execa for child processes.
  • Existing service, provider, settings, permission, and UI patterns over new abstractions.

Repository Map

  • src/commands/ - slash and CLI command implementations.
  • src/components/ - React/Ink UI components.
  • src/services/ - API, MCP, OAuth, wiki, voice, and other service integrations.
  • src/tools/ - tool implementations.
  • src/utils/ - shared utilities.
  • src/integrations/ - provider and model integration metadata.
  • src/entrypoints/ - CLI, MCP, SDK, and generated public types.
  • src/tasks/ - local, remote, workflow, and monitor tas...

Files:

  • src/integrations/models/tencent.ts
  • src/integrations/tencent.test.ts
  • src/integrations/brands/tencent.ts
  • src/utils/toolSearch.test.ts
  • src/utils/toolSearch.ts
  • src/services/api/openaiShim.test.ts
  • src/services/api/openaiShim.xmlToolCalls.test.ts
  • src/services/api/openaiShim.ts
**/*

⚙️ CodeRabbit configuration file

**/*: Apply the OpenClaude maintainer review rubric from AGENTS.md. Review the current diff, not stale discussion context. Separate real blockers from suggestions. Do not request changes for vague style churn. Treat approval as merge-ready from CodeRabbit's side, pending required human review and GitHub Checks. If checks are failing or unavailable, say so clearly instead of implying the PR is fully ready.

Files:

  • src/integrations/models/tencent.ts
  • src/integrations/tencent.test.ts
  • src/integrations/brands/tencent.ts
  • src/utils/toolSearch.test.ts
  • src/utils/toolSearch.ts
  • src/services/api/openaiShim.test.ts
  • src/services/api/openaiShim.xmlToolCalls.test.ts
  • src/services/api/openaiShim.ts
{src/services/api/**,src/integrations/**,src/utils/model/**,src/utils/provider*.ts,src/commands/provider/**}

⚙️ CodeRabbit configuration file

{src/services/api/**,src/integrations/**,src/utils/model/**,src/utils/provider*.ts,src/commands/provider/**}: Review provider routing, model selection, env precedence, auth/token handling, OpenAI-compatible shims, retries, proxy behavior, and outbound HTTP behavior with high scrutiny. Block on silent default changes, hidden fallback expansion, credential reuse mistakes, hardcoded provider assumptions, or new network reach that is not intentional and documented.

Files:

  • src/integrations/models/tencent.ts
  • src/integrations/tencent.test.ts
  • src/integrations/brands/tencent.ts
  • src/services/api/openaiShim.test.ts
  • src/services/api/openaiShim.xmlToolCalls.test.ts
  • src/services/api/openaiShim.ts
{src/**/*.test.ts,src/**/*.test.tsx,tests/**,scripts/**/*.test.ts,vscode-extension/**/*.test.js}

⚙️ CodeRabbit configuration file

{src/**/*.test.ts,src/**/*.test.tsx,tests/**,scripts/**/*.test.ts,vscode-extension/**/*.test.js}: Review tests for meaningful coverage of the changed behavior, isolation of global/env/config state, async cleanup, fake timers, provider profile leaks, and Windows-compatible assumptions. Block when risky runtime changes lack focused regression coverage or tests assert implementation details while missing the user-visible behavior.

Files:

  • src/integrations/tencent.test.ts
  • src/utils/toolSearch.test.ts
  • src/services/api/openaiShim.test.ts
  • src/services/api/openaiShim.xmlToolCalls.test.ts
🔇 Additional comments (11)
src/integrations/brands/tencent.ts (1)

8-8: LGTM!

src/integrations/models/tencent.ts (1)

9-20: LGTM!

src/integrations/tencent.test.ts (1)

1-41: LGTM!

src/utils/toolSearch.ts (1)

242-265: LGTM!

src/utils/toolSearch.test.ts (1)

1-12: LGTM!

Also applies to: 57-83

src/services/api/openaiShim.ts (3)

1899-1907: 🔒 Security & Privacy

Do not treat syntax as authorization.

A literal assistant-text example such as <tool_call:call_1>TaskCreate</tool_call:call_1> passes this check and is converted into a tool_use; the current test only rejects examples whose extracted name contains invalid characters. Verify that downstream execution revalidates recovered names against the current authorized tool set, or add stronger gating before emitting executable calls.


1820-1851: LGTM!

Also applies to: 1865-1897, 1908-1935, 1954-1971, 1983-2037, 2391-2442, 2920-2920


1947-1951: 🎯 Functional Correctness

Duplicate identical XML tool calls are intentionally collapsed. The parser already deduplicates repeated name + args pairs, so this isn’t a bug.

			> Likely an incorrect or invalid review comment.
src/services/api/openaiShim.xmlToolCalls.test.ts (2)

10-15: LGTM!

Also applies to: 65-70, 133-201


393-398: 🎯 Functional Correctness

No model change needed here. The XML recovery path is content-driven, so these HY3 cases already exercise the Tencent-shaped stream handling; the request model only affects metadata.

			> Likely an incorrect or invalid review comment.
src/services/api/openaiShim.test.ts (1)

10148-10189: LGTM!

Comment thread src/services/api/openaiShim.xmlToolCalls.test.ts Outdated
coderabbitai[bot]
coderabbitai Bot previously approved these changes Jul 9, 2026
@jatmn
jatmn marked this pull request as ready for review July 9, 2026 23:55

@jatmn jatmn left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

@kevincodex1
kevincodex1 merged commit 64d164d into Twigpine:main Jul 10, 2026
6 checks passed
@jatmn
jatmn deleted the fix/tencent-hy3-tool-calling branch July 10, 2026 01:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Tencent HY3 tool calling issues

2 participants