Extract _prepare_trimmed_messages() to prevent create_trimmed/acreate_trimmed drift#135
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
create_trimmedandacreate_trimmedboth calledtrimmed_messages_to_fitwith identical arguments and discarded the same return values — if the trim logic ever needs updating, both functions need the same edit_prepare_trimmed_messages(), a private pure function that both callers delegate toWhy it's safe
Pure extraction of identical code. Both functions produce the same
trimmed_messageslist as before. No public API changes.Test plan
_prepare_trimmed_messagesreturns the same list as the previous inlinetrimmed_messages_to_fitcallcreate_trimmedandacreate_trimmedstill pass trimmed messages tocompletions.createGenerated by Claude Code
Note
Low Risk
Pure refactor with identical trim parameters and outputs; no public API or runtime behavior changes.
Overview
Refactors
create_trimmedandacreate_trimmedinloop.pyso they no longer each inline the sametrimmed_messages_to_fitcall.A new private helper
_prepare_trimmed_messagesruns that trim step once (samemax_bytes/keep_recentdefaults) and returns only the message list; both completion helpers pass its result tocompletions.create. No public API or on-wire behavior change—only deduplication to avoid sync/async drift when trim logic changes.Reviewed by Cursor Bugbot for commit 35d7b12. Bugbot is set up for automated code reviews on this repo. Configure here.