Repository navigation
run_serve: refuse over-context prompts with CONTEXT_EXCEEDED instead of silently truncating - #2104
Conversation
|
Thanks for this. The API-mode half is right: a The interactive half changes what Either of these would work:
A test would help too: the tiny oracle model ( It stays out of today's batch (#2284) for that reason only. |
|
Went with option (a): the refusal stays in both arms, and What changed (pushed as 918a979):
On the gateway half: I checked, and no change was needed. Test evidence, with the tiny oracle from
|
|
Thanks, this does what was asked: One thing before it goes in: no workflow sets With that it goes into the next batch. |
|
I used Codex to put together a small CI change for this PR. The Linux job already generates Commit cd c
python3 tests/test_glm_oracle.py
COLI_ORACLE_FIXTURE="$PWD/glm_tiny" python3 -m unittest -v tests.test_run_serve_context_exceededThe local CPU run passed all 17 oracle checks and all four serving-context tests, with none skipped. Running the serving tests without the fixture variable skipped all four. The generated fixture was 2.46 MB. The checks used CPU-only PyTorch 2.14.1, Transformers 5.20.2 and Safetensors 0.8.0, with model downloads disabled. GitHub Actions has not run for this commit yet. You're welcome to cherry-pick it into this PR. |
|
Done: the Linux efficiency job now runs the four run_serve context-refusal tests right after the oracle checks, with COLI_ORACLE_FIXTURE pointed at the generated glm_tiny (commit 402e8d1). Verified the step parses as valid YAML and the test module collects all four (they skip cleanly without the fixture, as expected on a box with no built engine). The workflow run on the new head should exercise them for real. |
|
Thanks for putting this together, and for the local verification numbers. Applied the equivalent change to this PR (commit 402e8d1), crediting your patch bherald/colibri@049edad1 in the commit message. Only tweak is a slightly shorter comment line in the step. |
…of silently truncating The legacy run_serve path (coli chat and the \x02PROMPT pre-mux API mode) encoded prompts with a hard tok_encode cap and no overflow signal, so an over-long prompt was silently cut and answered from the truncated text -- the exact JustVugg#401 field failure the mux path already refuses loudly. Mirror the mux_submit pattern in both run_serve arms: encode into a maxctx-1 buffer purely to detect overflow (a full buffer means the prompt does not fit) and refuse. The legacy protocol has no ERROR frame, so a refusal is an empty answer plus a STAT line carrying CONTEXT_EXCEEDED as a seventh token (coli's STAT regex matches the first fields and ignores the rest) and a stderr line naming the cause. The interactive arm additionally detects a clipped 64KB render via the snprintf return value and refuses rather than answering from clipped text; a conversation history that no longer fits is refused with a hint to \x02RESET instead of being silently wiped and restarted. Fixes JustVugg#2097 Signed-off-by: Varshith Puli <pulivarshit@gmail.com>
Follow-up to the JustVugg#2097 refusal: the interactive arm refused over-context turns with an empty answer and the reason only on the engine's stderr, which coli chat drains to a temp log and never shows, so users saw empty answers with no hint to :reset. Keep the refusal in both arms (option a), and make it visible: - The engine now appends the refusal cause to the STAT line (PROMPT_TOO_LONG, HISTORY_FULL, RENDER_CLIPPED), next to the CONTEXT_EXCEEDED token the previous commit added. Existing STAT parsers match the leading fields and ignore the rest, so the frame stays compatible. - coli chat's stream_turn reads the token and the chat loop prints the reason with the hint that fixes it: :reset for a full history, a shorter prompt or larger CTX for an over-long turn, smaller chunks for a clipped render. Tests: c/tests/test_run_serve_context_exceeded.py drives the real engine (SERVE=1) against the tiny GLM oracle at CTX=64 and asserts the refusal STAT in the interactive arm, the \x02PROMPT API arm, the HISTORY_FULL cause on a filled conversation, and that a fitting prompt is still answered. c/tests/test_chat_context_exceeded.py runs the real cmd_chat against a fake refusing engine and asserts the user-facing message for each cause spelling (and for an older engine with no cause token). No gateway change: openai_server.py only speaks the mux protocol (SERVE_BATCH=1); the legacy \x02PROMPT arm has no gateway consumer, and the mux CONTEXT_EXCEEDED ERROR already maps to HTTP 400. Signed-off-by: Varshith Puli <pulivarshit@gmail.com>
…ny fixture The Linux efficiency job generates glm_tiny but never set COLI_ORACLE_FIXTURE, so the four run_serve context-refusal tests always skipped in CI and a regression there would pass silently. Run them after the oracle checks, reusing the same fixture, as requested in review. Based on bherald's patch (bherald/colibri@049edad1), applied with a small comment tweak.
402e8d1 to
5227865
Compare
|
Heads up: rebased onto current dev to clear a conflict (dev added the MTP draft-gate step right after the oracle step in the meantime). The serving-context test step is preserved after the oracle checks, ahead of the new MTP step. CI is running on the new head 5227865. |
Fixes #2097
What was wrong
The legacy
run_servepath (coli chatand the\x02PROMPTpre-mux API mode) encoded prompts with a hardtok_encodecap and no overflow signal. An over-long prompt was silently cut to the cap and the engine generated a normal-looking answer from the truncated text -- the exact #401 field failure the mux path already refuses loudly. The interactive arm additionally clipped rendered turns at the 64 KBbufand, when the conversation filled the context, silently wiped history (len=0) and restarted from a clamped prompt.What the fix does
Mirrors the
mux_submitpattern in bothrun_servearms: encode into amaxctx-1buffer purely to detect overflow (a full buffer means the prompt does not fit) and refuse instead of generating from cut text.\x02PROMPTarm: over-context prompts are refused rather than truncated.snprintfreturn value), and when the conversation history no longer fits -- the old silent history wipe is gone; the stderr message points at\x02RESET.The legacy protocol has no ERROR frame, so a refusal is an empty answer plus a
STATline carryingCONTEXT_EXCEEDEDas a seventh token (coli's STAT regex matches the first fields and ignores the rest) and a stderr line naming the cause and the remedy (raiseCTX, shorten the prompt). This matches how every sibling engine and the mux path refuse.docs/serve_protocol.mddocuments the new refusal contract.coli_serve_budget()was checked and doesn't fit here -- it computes a generation budget from a known prompt size, not overflow detection.Verification
make -C c colibribuilds clean under the repo's flags (-Wall -Wextra), no new warnings.tmp/raw, restoreg_temp/g_nuc, leavehist/len/KV untouched (a refused turn corrupts no state), and thehist+lenmemcpystays within bounds on the accepted path (len+k <= maxctx-9-g_draft).snprintftruncation-detection idiom (fits / overflows / exact-fit cases) behaves as coded.maxctx-2tokens is accepted with near-zero generation room, same asmux_submit) mirrors the mux path.