Skip to content

Conversation

@cte
Copy link
Collaborator

@cte cte commented Feb 24, 2025

Description

Fix truncation logic for models with maxTokens values above 40K (like Claude 3.7 Sonnet).

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

How Has This Been Tested?

Checklist:

  • My code follows the patterns of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation

Additional context

Related Issues

Reviewers


Important

Fixes sliding window logic in truncateConversation functions and adds tests for message truncation and token threshold handling.

  • Behavior:
    • Fixes sliding window logic in truncateConversation() and truncateConversationIfNeeded() in index.ts to correctly handle message truncation based on fraction and model context.
    • Adjusts buffer calculation in getMaxTokensForPromptCachingModels() and getMaxTokensForNonPromptCachingModels() to use modelInfo.maxTokens if available.
  • Tests:
    • Adds test cases in sliding-window.test.ts for truncateConversation() to verify message retention and removal logic.
    • Adds test cases for truncateConversationIfNeeded() to check token threshold handling for different model configurations.
  • Misc:
    • Adds handling for anthropic/claude-3.7-sonnet:beta model ID in ClineProvider.ts.

This description was created by Ellipsis for 6245aa7. It will automatically update as commits are pushed.

@cte cte requested a review from mrubens as a code owner February 24, 2025 23:11
@changeset-bot
Copy link

changeset-bot bot commented Feb 24, 2025

⚠️ No Changeset found

Latest commit: 6245aa7

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@cte cte changed the title Cte/sliding window fix Sliding window fix Feb 24, 2025
@dosubot dosubot bot added size:XS This PR changes 0-9 lines, ignoring generated files. bug Something isn't working labels Feb 24, 2025
@dosubot dosubot bot added the lgtm This PR has been approved by a maintainer label Feb 24, 2025
@dosubot dosubot bot added size:L This PR changes 100-499 lines, ignoring generated files. and removed size:XS This PR changes 0-9 lines, ignoring generated files. labels Feb 24, 2025
@cte cte merged commit 9a56e15 into main Feb 24, 2025
10 checks passed
@cte cte deleted the cte/sliding-window-fix branch February 24, 2025 23:42
import { ModelInfo } from "../../../shared/api"
import { truncateConversation, truncateConversationIfNeeded } from "../index"

describe("truncateConversation", () => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider adding tests for empty messages array to ensure truncate functions handle such edge cases gracefully.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working lgtm This PR has been approved by a maintainer size:L This PR changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants