Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/context-overflow-recovery.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@kilocode/cli": patch
---

Recover from provider context-limit errors by compacting and retrying when the provider reports the request exceeded the model's context length.
4 changes: 4 additions & 0 deletions packages/llm/src/provider-error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ const patterns = [
/model_context_window_exceeded/i,
/too many tokens/i,
/token limit exceeded/i,
// kilocode_change start - providers/gateways report over-long requests as
// "<N> tokens long and exceeds this model's context length of <M> tokens"
/exceeds (?:this|the) model'?s (?:(?:maximum|max) )?context length(?: of [\d,]+ tokens?)?/i,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

it's all good but I wonder if that translates well in terms of i18n ... the , for thousands is not universally common so that:

  • why do we have a thousand separator at all?
  • once we answer previous point, should we add all other thousand separators in there too?

not a blocker, rather a question, and once answered, I'll approve

// kilocode_change end
]

// kilocode_change start - keep transient token throttles retryable
Expand Down
4 changes: 4 additions & 0 deletions packages/llm/test/provider-error.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ describe("provider error classification", () => {
"Prompt has 5,958,968 tokens, but the configured context size is 256,000 tokens",
"Too many tokens",
"Token limit exceeded",
// kilocode_change start - gateway/provider wording seen in production
"The request is 280913 tokens long and exceeds this model's context length of 262144 tokens.",
"[Nex AGI] The request is 282364 tokens long and exceeds this model's context length of 262144 tokens.",
// kilocode_change end
]

expect(messages.every(isContextOverflow)).toBe(true)
Expand Down
Loading