fix(llm, cli, anthropic): Bound provider rebuild loop and heal turns - #920
Merged
Conversation
Anthropic rejects a thinking block whenever any thinking or redacted-thinking block in the latest assistant message was rewritten, not only when a signature goes stale. The repair now recognizes both rejection messages and, when the offending block sits in the latest assistant turn, downgrades every thinking block in that message in one patch set instead of one block per round. Anthropic requires that message's thinking blocks to come back unchanged as a whole, so patching one block at a time left the message half-rewritten and the next request failed the same way. A conversation already left in that half-rewritten state is now healed by the same patch. Earlier turns keep their narrower, single-block repair since they carry no such constraint. A provider that keeps asking to rebuild the request without actually fixing anything could previously loop forever, resending the full conversation each time. `jp query` now refuses a rebuild unless the preceding patch changed the stream in a way guaranteed to make progress (`PatchAction::shrinks_stream`), and caps consecutive rebuilds within a turn at 10. Hitting either limit aborts the turn with an error instead of looping, after flushing whatever was already streamed so no partial response is lost. The counter resets once a turn streams a successful event, so later, unrelated repairs are not penalized by an earlier one. Signed-off-by: Jean Mertz <git@jeanmertz.com>
Signed-off-by: Jean Mertz <git@jeanmertz.com>
Signed-off-by: Jean Mertz <git@jeanmertz.com>
Signed-off-by: Jean Mertz <git@jeanmertz.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.
Anthropic rejects a thinking block whenever any thinking or redacted-thinking block in the latest assistant message was rewritten, not only when a signature goes stale. The repair now recognizes both rejection messages and, when the offending block sits in the latest assistant turn, downgrades every thinking block in that message in one patch set instead of one block per round. Anthropic requires that message's thinking blocks to come back unchanged as a whole, so patching one block at a time left the message half-rewritten and the next request failed the same way. A conversation already left in that half-rewritten state is now healed by the same patch. Earlier turns keep their narrower, single-block repair since they carry no such constraint.
A provider that keeps asking to rebuild the request without actually fixing anything could previously loop forever, resending the full conversation each time.
jp querynow refuses a rebuild unless the preceding patch changed the stream in a way guaranteed to make progress (PatchAction::shrinks_stream), and caps consecutive rebuilds within a turn at 10. Hitting either limit aborts the turn with an error instead of looping, after flushing whatever was already streamed so no partial response is lost. The counter resets once a turn streams a successful event, so later, unrelated repairs are not penalized by an earlier one.