fix(anthropic): tool_use/tool_result adjacency + OAuth claude-code/ UA (salvage #52145 #51948) - #268
Merged
Merged
Conversation
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
Batch salvage of two complementary
agent/anthropic_adapter.pyfixes, rebased onto currentmain. Both bugs confirmed still-present; disjoint regions, no conflict.Fixes
NousResearch#52145 (@fsaad1984) — enforce tool_use/tool_result adjacency in
_strip_orphaned_tool_blocksThe old logic collected tool_result ids across all user messages and kept any assistant
tool_usewhose id appeared anywhere. Anthropic requires eachtool_useto have itstool_resultin the immediately following user message — a stale match elsewhere in the transcript would keep a genuinely-orphanedtool_useand 400 the request. Rewritten to adjacency-checked two-pass logic: pass 1 strips atool_usewhose result isn't in the next user message; pass 2 removes results orphaned by pass 1.NousResearch#51948 (@DhivinX) — OAuth UA
claude-cli/→claude-code/Anthropic 404s the OAuth token endpoint for the
claude-cli/UA prefix (NousResearch#48534). Switched all three OAuth UA sites —build_anthropic_client(:820),refresh_anthropic_oauth_pure(:1048),run_hermes_oauth_login_pure(:1491) — toclaude-code/.Review follow-ups (mine)
A structured review of the salvage surfaced three test-quality issues, all fixed:
test_strips_tool_use_when_result_not_immediately_adjacent(the exact non-adjacent case the old global match got wrong) + an adjacent-pair control. Mutation-checked: reverting to a global match fails the non-adjacent test.test_token_exchange_ua_prefixfalse-failed on a comment (naive whole-function substring). Scoped it to actualUser-Agentheader lines, matching its sibling.test_token_refresh_ua_prefixwas vacuous — it bound to a wrapper (_refresh_oauth_token) with no HTTP call, so its assert never ran. Retargeted at the real refresh siterefresh_anthropic_oauth_pure. Mutation-checked: reverting :1048 now fails it.Verification
test_anthropic_adapter.pyhas ~15 pre-existing failures on currentmainin unrelated OAuth-token-resolution classes (TestResolveAnthropicToken/TestRefreshOauthToken/TestRunOauthSetupToken) — verified identical on cleanorigin/mainwith none of these changes applied. Not introduced by this PR.Closes NousResearch#52145. Closes NousResearch#51948.
Co-authored-by: fsaad1984 38867992+fsaad1984@users.noreply.github.com
Co-authored-by: DhivinX 20087092+DhivinX@users.noreply.github.com
Mirror-of: NousResearch#56263
NousResearch#56263