docs(ai): record that MLX context overflow is undetectable - #1277
Open
albertoelopez wants to merge 1 commit into
Open
docs(ai): record that MLX context overflow is undetectable#1277albertoelopez wants to merge 1 commit into
albertoelopez wants to merge 1 commit into
Conversation
mlx_lm.server neither rejects nor truncates an oversized prompt. It prefills the whole thing past the model's max_position_embeddings until Metal reports insufficient memory, then the server process aborts, so the client sees a dropped connection rather than a provider error. None of the three cases in isContextOverflow can see that. Document the behaviour alongside the other unreliable backends and add a regression test keeping transport failures unclassified, so a future change does not try to "support MLX" with a socket-error pattern that would misclassify every server crash and network fault. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Rb4AjM3nPgiG18V6RN3XYF
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
mlx_lm.servercannot have a context-overflow pattern, and this documents why so nobody tries to add one.Given a prompt beyond the model's context it does not reject, error, or truncate. It prefills the entire prompt past the model's own
max_position_embeddingsuntil the GPU runs out of memory, then the server process aborts mid-request:The client observes a dropped connection, so none of the three cases in
isContextOverflowapply: there is noerrorMessageto match, nousageto compare against the context window, and no length stop.Changes
overflow.tsalongside the other backends, in both the provider list and the "Unreliable detection" section.fetch failed,terminated,socket hang up,ECONNRESET,ECONNREFUSED) stay unclassified.[Unreleased].The tests are the point. A dropped socket is not evidence of overflow — it is equally consistent with a server crash or a network fault — so matching one to "support MLX" would misclassify every such failure. The tests make that regression fail loudly.
No behaviour changes;
isContextOverflowis untouched.Reproduction
Measured against
mlx_lm.server0.31.3 servingmlx-community/Qwen3-14B-4bit(max_position_embeddings40960) on an M4 / 24 GB, sending a ~50k-token prompt. The crash is memory-bound, so the exact threshold varies with host memory, but the failure mode does not: MLX never reports overflow.The practical mitigation is configuration rather than detection — declare a
contextWindowthe host can actually hold so compaction runs before the limit is reached. Note that aKeepAlivelaunchd agent restarts the server after such a crash, which makes it easy to miss.Testing
packages/ai:npx tsx ../../node_modules/vitest/dist/cli.js --run test/overflow.test.ts— 14 passednpm run checkfrom the repo root — cleanNote
Document that MLX context overflow is undetectable in
isContextOverflowmlx_lm.serveraborts the process on context overflow rather than returning an error, making overflow undetectable via response inspection.fetch failed,socket hang up,ECONNRESET, etc.) are not classified as context overflow.Macroscope summarized cea8555.