Skip to content

Extract _prepare_trimmed_messages() to prevent create_trimmed/acreate_trimmed drift#135

Merged
dhruvbatra merged 1 commit into
mainfrom
claude/cool-brahmagupta-oz7i2a
Jun 16, 2026
Merged

Extract _prepare_trimmed_messages() to prevent create_trimmed/acreate_trimmed drift#135
dhruvbatra merged 1 commit into
mainfrom
claude/cool-brahmagupta-oz7i2a

Conversation

@dhruvbatra

@dhruvbatra dhruvbatra commented Jun 16, 2026

Copy link
Copy Markdown
Contributor

Summary

  • create_trimmed and acreate_trimmed both called trimmed_messages_to_fit with identical arguments and discarded the same return values — if the trim logic ever needs updating, both functions need the same edit
  • Extracted the shared trim step into _prepare_trimmed_messages(), a private pure function that both callers delegate to
  • No behavioral change — identical on-wire messages, same parameters

Why it's safe

Pure extraction of identical code. Both functions produce the same trimmed_messages list as before. No public API changes.

Test plan

  • Verify _prepare_trimmed_messages returns the same list as the previous inline trimmed_messages_to_fit call
  • create_trimmed and acreate_trimmed still pass trimmed messages to completions.create

Generated by Claude Code


Note

Low Risk
Pure refactor with identical trim parameters and outputs; no public API or runtime behavior changes.

Overview
Refactors create_trimmed and acreate_trimmed in loop.py so they no longer each inline the same trimmed_messages_to_fit call.

A new private helper _prepare_trimmed_messages runs that trim step once (same max_bytes / keep_recent defaults) and returns only the message list; both completion helpers pass its result to completions.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.

@dhruvbatra dhruvbatra merged commit b62ef5a into main Jun 16, 2026
9 checks passed
@dhruvbatra dhruvbatra deleted the claude/cool-brahmagupta-oz7i2a branch June 16, 2026 20:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant