Skip to content

Recognize llama-server's context-overflow error - #656

Merged
zikajk merged 1 commit into
editor-code-assistant:masterfrom
netlogics:fix/llama-server-context-overflow-pattern
Oct 20, 2026
Merged

zikajk merged 1 commit into
editor-code-assistant:masterfrom
netlogics:fix/llama-server-context-overflow-pattern

Conversation

@netlogics

Copy link
Copy Markdown
Contributor

Recognize llama-server's context-overflow error

Summary

Auto compaction isn't triggered when a llama.cpp model's context window is exceeded.

Problem

When a provider rejects a prompt that exceeds the model's context window, ECA classifies the error with eca.llm-providers.errors/classify-error and, on :context-overflow, runs the automatic recovery path (prune-tool-results! auto-compact retry), as described in docs/config/context-management.md.

If no pattern matches, the error falls through to :unknown, so recovery never runs and the raw 400 is shown to the user instead.

llama.cpp's llama-server phrases the rejection as:

{"error":{"code":400,"message":"request (68183 tokens) exceeds the available context size (65536 tokens), try increasing it","type":"exceed_context_size_error","n_prompt_tokens":68183,"n_ctx":65536}}

The existing catch-all regex requires max/maximum/model right after exceeds the, so available doesn't match. Every llama-server wording since the message was introduced uses "exceeds the available context size", so none of them were recognized.

Changes

src/eca/llm_providers/errors.clj context-overflow-patterns:

  • Add available to the catch-all's alternation: exceeds? the? ?(?:available|max(?:imum)?|model).{0,20}(?:token|context).
  • Also match the error's type field, exceed_context_size_error, a stable identifier, so detection keeps working if llama.cpp rewords the message.

test/eca/llm_providers/errors_test.clj:

  • llama-server's full 400 body.
  • The type field on its own.
  • llama-server's earlier wording ("the request exceeds the available context size, try increasing it") with no body, i.e. the message-only path.
  • A guard against loosening the catch-all: Azure's rate-limit text ("exceeded token rate limit") must not classify as an overflow.

CHANGELOG.md:

  • Add an entry under ## Unreleased.

Testing

clojure -M:test --focus eca.llm-providers.errors-test
# 15 tests, 137 assertions, 0 failures.

Also checked against a live llama-server: an over-long prompt returns the 400 above on /v1/chat/completions and /v1/responses, streaming or not. The wording and type are the same in current ggml-org/llama.cpp master. That body classifies as :unknown on master and :context-overflow with this change.

Checklist

  • I added a entry in changelog under unreleased section.
  • This is not an AI slop.

🤖 Generated with ECA (Claude Code)

@zikajk zikajk left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Looks good!
Please, do the rebase and feel free to merge.

@netlogics
netlogics force-pushed the fix/llama-server-context-overflow-pattern branch from 633f62c to a7eed1d Compare October 20, 2026 17:57
llama-server rejects over-long prompts with a 400 saying the request
"exceeds the available context size". The catch-all in
context-overflow-patterns only accepted max/maximum/model after
"exceeds the", so the error classified as :unknown and auto-recovery
(prune, auto-compact, retry) never ran.

- add "available" to the catch-all's alternation
- also match the error's type field, "exceed_context_size_error", so
  detection keeps working if llama.cpp rewords the message

The catch-all keeps its existing shape. A looser "exceed ... token"
pattern would also match unrelated text such as Azure's "exceeded token
rate limit" message; a test guards against loosening it.

🤖 Generated with [Claude Code](https://claude.com/claude-code) (anthropic/claude-opus-5-5)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@netlogics
netlogics force-pushed the fix/llama-server-context-overflow-pattern branch from a7eed1d to f46c659 Compare October 20, 2026 18:15
@netlogics

Copy link
Copy Markdown
Contributor Author

Looks good! Please, do the rebase and feel free to merge.

Thanks for the review and approval @zikajk . I only have read access so I can't merge it myself. I reviewed the dev docs but apologies if I missed something.

@zikajk

zikajk commented Oct 20, 2026

Copy link
Copy Markdown
Member

Sorry, my bad @netlogics. Merged 🙂

@zikajk
zikajk merged commit fd545d9 into editor-code-assistant:master Oct 20, 2026
9 checks passed
@netlogics

Copy link
Copy Markdown
Contributor Author

Thanks

@netlogics
netlogics deleted the fix/llama-server-context-overflow-pattern branch October 20, 2026 23:09
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.

2 participants