Skip to content

fix(models): end the probe context ladder at the served context - #646

Merged
ion-alpha-dev merged 3 commits into
mainfrom
fix/probe-context-ladder-overflow
Nov 1, 2026
Merged

ion-alpha-dev merged 3 commits into
mainfrom
fix/probe-context-ladder-overflow

Conversation

@ion-alpha-dev

Copy link
Copy Markdown
Collaborator

What

flynn models probe now finishes when its context ladder reaches a prompt the server refuses as too long, and no longer stores a context larger than what it sent. The OpenAI-compatible client classifies a context-overflow refusal into a new exported error, llm.ErrContextOverflow, which the ladder treats as its end.

Why

On a machine where llama.cpp fits the context to the GPU, the server was started with 115456 tokens while the catalog advertises more. The ladder climbed past it, the server answered HTTP 400 "exceeds the available context size", and the probe returned that as fatal after about two minutes, so no profile was written and flynn init --local set no default. The prompt was also sized at 4 characters per token regardless of the tokenizer, so a pass at a rung was recorded as a length the prompt did not have.

How to verify

./dev/test ./llm/... ./internal/reliability/... ./cmd/flynn/... and ./dev/lint. The new tests are TestContextOverflowIsTyped and TestContextOverflowKeepsMessage (client classification for llama.cpp, vLLM and OpenAI wording, and that a 5xx or 429 is not reclassified), TestMeasureEffectiveContext* and TestContextCandidatesStopAtServedContext (ladder), and TestProbeSurvivesServedContextBelowAdvertised and TestServedContext (probe). Each fails when its cause is removed.

Live on Windows 11, RTX 4070 Ti 12 GB, llama.cpp b9813, gemma4:12b Q4_0 (with the handshake change from #645 applied locally): flynn models probe gemma4:12b completed in 166 seconds with tool calls, schema and instructions at 100% and a stored effective context of 65525 of 262144 advertised. The last rung (115200, inside the served 115456) was sent and the model did not recall the pass phrase, so the stored value is the 65536 rung as the server counted it.

Notes for reviewers

  • API: adds llm.ErrContextOverflow only. ./dev/apidiff on my machine also lists 51 incompatible changes unrelated to this diff (json.RawMessage reported as jsontext.Value), none touching this change.
  • The served context is read from llama.cpp's /props by a new helper in cmd/flynn/modelprobe_ctx.go. If it is unavailable the ladder ends at the server's refusal instead, so vLLM and other servers rely on the typed error alone.
  • probeAndStore keeps its signature and delegates to a new probeAndStoreWithin, to leave other tests that call it untouched.
  • Rungs after the first are sized from the token count the server reports for the first prompt. A server that reports no usage keeps the nominal sizing.

`flynn models probe` aborted after about two minutes when its context
ladder sent a prompt larger than the context the local server was
started with: llama.cpp answered HTTP 400 "exceeds the available
context size" and MeasureEffectiveContext returned that as fatal, so no
profile was written.

Three changes:

The OpenAI-compatible client now recognises a refusal for length (the
llama.cpp exceed_context_size_error type, vLLM's "maximum context
length", OpenAI's context_length_exceeded code) and wraps the new
llm.ErrContextOverflow around it, so callers use errors.Is rather than
matching message text. The error still prints as before.

MeasureEffectiveContext treats that error as the end of the ladder, the
same as a failed recall, and keeps the last length that passed. Any
other error still fails. It also sizes later rungs from the token count
the server reports for the first prompt (the filler runs near 3.5
characters per token, not the 4 assumed) and never stores more than the
server counted, so a pass is no longer overstated by about 14%.

The probe reads the served context from the server's /props and ends
the ladder there, less room for the answer.

Signed-off-by: Ion Alpha <[email protected]>
The declaration-comment length test fails on a doc comment of 15
lines or more. MeasureEffectiveContext was at 17; trim it to the
invariants a reader of go doc needs.

Signed-off-by: Ion Alpha <[email protected]>
@codecov

codecov Bot commented Oct 31, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 98.27586% with 1 line in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
cmd/flynn/modelprobe_ctx.go 95.00% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

@ion-alpha-dev
ion-alpha-dev merged commit b1ed000 into main Nov 1, 2026
32 checks passed
@ion-alpha-dev
ion-alpha-dev deleted the fix/probe-context-ladder-overflow branch November 1, 2026 07:35
@github-actions github-actions Bot locked and limited conversation to collaborators Nov 1, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant