Skip to content

fix(context): align isItemTooBig budget with the message compiler#12515

Open
MukundaKatta wants to merge 1 commit into
continuedev:mainfrom
MukundaKatta:fix/file-context-item-too-big
Open

fix(context): align isItemTooBig budget with the message compiler#12515
MukundaKatta wants to merge 1 commit into
continuedev:mainfrom
MukundaKatta:fix/file-context-item-too-big

Conversation

@MukundaKatta
Copy link
Copy Markdown

@MukundaKatta MukundaKatta commented May 29, 2026

Description

@file rejects items that @CurrentFile accepts. Core.isItemTooBig reserves the full maxTokens (contextLength - maxTokens) when deciding whether a context item fits, but compileChatMessages only reserves min(MIN_RESPONSE_TOKENS, maxTokens) plus the counting safety buffer. On small context windows, or on models with no known completion limit where maxTokens defaults to 4096, a single file looks too big even though the compiler would include it. @CurrentFile skips isItemTooBig entirely, which is why it was unaffected.

This pulls the compiler's budget into getAvailableInputTokens and uses it in both places so the check matches what actually gets sent.

Fixes #12165

Checklist

  • I've read the contributing guide
  • The relevant docs, if any, have been updated or created
  • The relevant tests, if any, have been updated or created

Tests

Added a getAvailableInputTokens unit test block in core/llm/countTokens.test.ts: one case for a small window with the default 4096 maxTokens, one for when maxTokens is below the minimum response allowance. The core/llm/countTokens Jest suite passes.


Summary by cubic

Aligns context-size checks with the message compiler so @file no longer gets rejected when the compiler would include it. Uses the compiler’s input budget (safety buffer + minimum response allowance) instead of reserving the full maxTokens, fixing false “too big” results on small windows and models with unknown completion limits.

  • Bug Fixes
    • Added getAvailableInputTokens(contextLength, maxTokens) to mirror compiler budgeting (safety buffer + min(1000, maxTokens)).
    • Updated Core.isItemTooBig to use it; @file now matches @CurrentFile.
    • Added unit tests for small-window and low-maxTokens scenarios.

Written for commit 6e5827b. Summary will update on new commits.

Review in cubic

isItemTooBig reserved the full configured maxTokens when deciding whether
a context item fits, but compileChatMessages only reserves
min(MIN_RESPONSE_TOKENS, maxTokens) plus the counting safety buffer. On
small context windows, or on models with no known completion limit (where
maxTokens defaults to 4096), this made a single @file item look too big to
include even though the compiler would have accepted it.

Extract the compiler's budget into getAvailableInputTokens and use it in
both places so the "too big" check matches what actually gets sent.

Fixes continuedev#12165
@MukundaKatta MukundaKatta requested a review from a team as a code owner May 29, 2026 02:44
@dosubot dosubot Bot added the size:M This PR changes 30-99 lines, ignoring generated files. label May 29, 2026
@github-actions
Copy link
Copy Markdown
Contributor


Thank you for your submission, we really appreciate it. Like many open-source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution. You can sign the CLA by just posting a Pull Request Comment same as the below format.


I have read the CLA Document and I hereby sign the CLA


You can retrigger this bot by commenting recheck in this Pull Request. Posted by the CLA Assistant Lite bot.

Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai Bot left a comment

Choose a reason for hiding this comment

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

No issues found across 3 files

Re-trigger cubic

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

Labels

size:M This PR changes 30-99 lines, ignoring generated files.

Projects

Status: Todo

Development

Successfully merging this pull request may close these issues.

@file applies the wrong context lenght limit but @CurrentFile works fine.

1 participant