feat(mcp): detect and withhold a tool-call-free reasoning-loop reply - #131
Merged
Conversation
…114) A live run today (bar mode via a "thinking" model, opencode's kimi-k2.7-code) burned its whole step budget on a ~36,000-character reply that was pure self-narration ("OK. Let's go. Now. Done. I'll output now...") with zero real tool calls. bridge.outcome_of_steps returned that text as a normal, completed reply — a caller had no signal the run had degenerated rather than succeeded. Scoped this to lex-code rather than lex-llm: true mid-generation cancellation would need lex-llm to expose an abort, and would be moot for MCP specifically anyway — make_handler already calls iter.to_list on the whole run_loop before any Step is visible here, so the full (wasted) generation has already happened by the time detection could run. What's fully in scope on lex-code's side: never hand the raw ramble back as if it were a real answer. is_degenerate_ramble(steps) flags a turn with zero StepToolExec steps whose final StepDone text exceeds 8,000 characters — picked well below today's 36,000-character failure and comfortably above the longest genuine final answers seen live this session (a few thousand characters). make_handler now checks this before handing off to bridge.outcome_of_steps, replacing a flagged reply with an explicit "[degenerate response detected...]" message naming the character count and pointing at LEX_CODE_PROVIDER_<MODE> as the fix. Verified with constructed Step lists covering the three cases that matter: a long zero-tool-call reply (flagged), a short zero-tool-call reply — e.g. plain chat with no work to do — (not flagged, avoiding a false positive on legitimate short answers), and a long reply that DID call a tool (not flagged, since tool use is itself evidence of real work regardless of final text length). Also live-tested a normal short MCP request end to end afterward to confirm an ordinary reply still passes through unchanged. Fixes #114 Co-Authored-By: Claude Sonnet 5 <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
Fixes #114
Test plan
🤖 Generated with Claude Code