fix(codemode): let the model recover from a wrong tool name in one retry - #50
Draft
kevoconnell wants to merge 2 commits into
Draft
kevoconnell wants to merge 2 commits into
kevoconnell wants to merge 2 commits into
Conversation
An unknown tool now names the closest real tool with its signature, and
the host can claim the name as one of its own tools, so opencode tells
the model that `tools.bedrock.find_registry_items` is the agent tool
`find-registry-items` and must be called directly. A call with no
arguments sends `{}` instead of failing. A parse error says where it is.
A caught tool failure stringifies to its message instead of
"[object Object]", which was silently discarding the error for the
common `catch (e) { return String(e) }` idiom.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
|
Thanks for your contribution! This PR doesn't have a linked issue. All PRs must reference an existing issue. Please:
See CONTRIBUTING.md for details. |
|
The following comment was made by an LLM, it may be inaccurate: |
…nknown tools inside resolve The error brand now lives with the other sandbox value types, and the intra-sandbox copy keeps a branded error as a leaf the way it keeps a Date or a Map, so the two per-site bypasses in String() and template literals go away. resolve takes the explain function directly instead of being wrapped in a try/catch that re-threw the same error with new suggestions. The parse position drops clamps for offsets that cannot occur. Co-Authored-By: Claude Fable 5.1 <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.
Issue for this PR
No issue here. It comes from root-causing the Replo agent-health card "CodeMode
executestill ~56% errors (repeat, day 6)". Companion PRs in andytown: replohq/andytown#27821 (tool contracts) and replohq/andytown#27824 (stale tool names in prompts, plus a CI lint for them).Type of change
What does this PR do?
When the model gets a tool name wrong inside a script, Code Mode tells it to go search. That costs a search call and then the real call, each a full model turn. Over 7 days of production sessions, about 150 of 541 failed scripts were "Unknown tool", and the wrong names were nearly always one step from a real one. Four changes, all about making the first failure carry its own fix:
tools.bedrock.find_registry_itemsnow answersDid you mean: tools.bedrock.registry_find_items(input: …): Promise<…>plus up to two other close paths. A namespace repeated in the name (bedrock.bedrock_generate_image, 55 of those failures) is dropped before ranking. The ranking is the search tool's own scoring, extracted intorankToolsand used by both. Suggestions come from the same search index as search, so a permission-hidden tool still cannot leak.tools.bedrock.set_project_contextfor the agent toolset-project-context). No search of the MCP catalog can fix that.CodeMode.maketakes an optionalunknownToolHint(path). opencode supplies it from the tool ids given to the model this turn (ctx.extra.toolIDs, set insession/tools.ts), comparing names with-and_folded, and answers "'set-project-context' is one of your regular tools, not a Code Mode tool. Call it directly, outside execute." The codemode package stays unaware of host tools, as its AGENTS.md asks.{}.tools.bedrock.list_sites()failed with "expects exactly one input object". The tool's schema still rejects a missing required field, and a second argument is still an error.(line 2, col 41) near: …, in the same format runtime errors use.And one interpreter bug:
String(e)on a caught tool failure returned"[object Object]". The intra-sandbox copy thatString()and template literals run their input through kept Date, Map, and the other sandbox values as leaves but not error values, so the symbol brand was gone beforecoerceToStringlooked.catch (e) { return String(e) }is the idiom models reach for, so the script "succeeded" and the model received no error text at all: 20 scripts in 18 projects in one week, including failed checkout setups. Error values are now kept as leaves like every other sandbox value, andcoerceToStringrenders themError: <message>like JavaScript, forString(e),`${e}`, and"" + e.How did you verify your code works?
packages/codemode:bun test273 pass,bun run typecheckclean, before and after a simplify pass (the pass folded the unknown-tool explanation intoresolve, moved the error brand next to the other sandbox value types, and deleted the two per-site brand bypasses). New filetest/recoverable-mistakes.test.tscovers each behavior above plus the two guards (a name nothing resembles still points at search; a second argument is still rejected).packages/opencode:bun test test/tool/code-mode.test.ts40 pass (two new cases: the closest-tool suggestion through the MCP catalog, and the regular-tool hint throughctx.extra.toolIDs),test/tool/task.test.tsandtest/tool/registry.test.tspass,bun run typecheckclean.Screenshots / recordings
Not a UI change.
Checklist
🤖 Generated with Claude Code
Summary by cubic
Fixes Code Mode’s recoverable-mistake handling so a wrong tool name, empty call, parse slip, or caught tool error carries its own correction instead of costing another model turn.
Bug Fixes
opencoderecognizes regular agent tools called inside a script and tells the model to call them directly.{}; missing required fields and extra arguments are still rejected.Error: <message>instead of[object Object].Migration
andytownmove.Written for commit 144ce86. Summary will update on new commits.