fix(kiro): recover native invoke tool calls and keep trailing system tools#146
Open
tonybase wants to merge 1 commit into
Open
fix(kiro): recover native invoke tool calls and keep trailing system tools#146tonybase wants to merge 1 commit into
tonybase wants to merge 1 commit into
Conversation
…tools The Kiro-backed model (AI_EDITOR origin) frequently emits tool calls as inline text in Claude's XML <invoke name="..."> format using Kiro IDE's own tool names instead of structured toolUseEvent events. Left as text, the client never sees a tool_use block, so no tool runs and the model starts hallucinating fake results. Add invoke recovery in both the buffered and streaming paths: - parse <invoke>/<parameter> blocks (antml: namespace tolerated) - map native names (grepSearch, readFile, fileSearch, listDirectory, writeFile, strReplaceEditor, executeBash, ...) onto client canonical tools (Grep, Read, Glob, Bash, Write, Edit) - emit recovered calls as tool_use blocks and override end_turn -> tool_use so the client runs them - InvokeStreamParser buffers partial tags across chunk boundaries Also normalize role:"system" messages placed inside the messages array (Claude Code mid-conversation-system beta), including a trailing system message, by rewriting them as user content wrapped in <system-reminder>. Without this the current user message is dropped and tool specs never attach, which is what triggers the text-format tool-call hallucination. Register new Kiro aliases and model defs: Sonnet 5, Opus 4.8, Fable 5. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The Kiro-backed model (AI_EDITOR origin) frequently emits tool calls as inline text in Claude's XML
<invoke name="...">format — using Kiro IDE's own tool names — instead of structuredtoolUseEventevents. Left as plain text, the client never sees atool_useblock, so no tool runs and the model starts hallucinating fake tool results. This PR recovers those calls and fixes the upstream condition that triggers them.Changes
Native
<invoke>tool-call recovery (kiro_claude_tools.go,kiro_executor.go)<invoke>/<parameter>blocks (antml:namespace tolerated), preserving JSON types for array/number params.readFile/fsRead/readMultipleFiles→ReadgrepSearch→Grep(withincludePattern→glob)fileSearch→GloblistDirectory→Bash(ls/ls -R)writeFile/fsWrite/createFile→WritestrReplaceEditor/editFile→EditexecuteBash/runCommand→BashparseEventStream) and streaming (streamToChannel) paths.InvokeStreamParserbuffers partial tags across chunk boundaries and flushes incomplete markup as text so nothing is dropped.end_turn→tool_usewhen calls are recovered, so the client actually runs them. Dedup is shared with the structured tool-use path.Trailing in-array system message normalization (
kiro_claude_request.go)mid-conversation-system-2026-04-07) can placerole:"system"messages inside the messages array, including as the final entry. Kiro has no system role, so these are rewritten as user content wrapped in<system-reminder>tags before merging.currentMessage.userInputMessageContextand the model, seeing no tools, hallucinates text-format tool calls (the root cause of the recovery above).New Kiro model aliases + definitions (
oauth_model_alias_defaults.go,model_definitions.go)Testing
gofmt -l internal/— cleango build ./cmd/server— passesgo test ./internal/translator/kiro/... ./internal/runtime/executor/... ./internal/config/... ./internal/registry/...— passeskiro_claude_tools_test.go(parse/map/stream), plusTestBuildKiroPayload_TrailingSystemMessageKeepsTools.🤖 Generated with Claude Code