Repository navigation
fix(failure): read a trailing context limit after a multi-byte character - #141
shaurya703 wants to merge 1 commit into
Conversation
parse_context_limit_from_error falls back to the number right before
"maximum context length" (the Mistral shape). trailing_number found the
character before the digits with rfind and started the digits at
index + 1, which lands inside that character when it is multi-byte. A
message such as "too large for model with\u{a0}32768 maximum context
length" or one with a CJK character before the number panicked on the
slice instead of returning the limit.
Step past the whole preceding character with its UTF-8 length.
Tiny Sweeper reviewReviewed head: Verdict: Ready for maintainer review · Priority: none Diagnostics and supporting detailsFull summaryPull request purpose (title): fix(failure): read a trailing context limit after a multi-byte character. Tiny Sweeper completed its review; deterministic results follow. Review snapshot
Completeness: Complete What changed`trailing_number` in the context-limit parser replaces its `rfind`-based byte offset with a reverse `char_indices()` scan that advances by the matched character's `len_utf8()`, preserving the `map_or(0, ...)` fallback for all-digit/comma input and leaving the downstream `trim_start_matches(',')`/parse handling unchanged. Messages that previously panicked on a non-char-boundary slice now return the stated limit. A new unit test in the sibling tests file exercises a no-break space and a CJK character before the number, both expected to parse as `Some(32_768)`. Features
TestsNo supported feature-to-test mapping was produced. Test execution is not inferred. FindingsNo active actionable findings. Before mergeNone. Agent review detailscritique
security
tests
commits
description
Evidence and run details
|
|
Important
This repository does not receive automatic reviews because it has fewer than 10 stars.
|
Summary
parse_context_limit_from_errorpanics when a multi-byte character comes right before the number in the "<N> maximum context length" (Mistral) shape.Bug. Reproduction on current
main:The same happens when a CJK character precedes the number (
"…模型32768 maximum context length"). This runs on provider overflow error bodies throughmodel::discover::record_overflow_error, so a provider error with that wording crashes the caller instead of recording the window.Root cause.
trailing_numberfinds the last non-digit character withrfindand starts the digit run atindex + 1. That is one byte past the start of the character, so a no-break space (2 bytes) or CJK character (3 bytes) leaves the slice start inside it.Fix. Walk
char_indices()from the end and start atindex + character.len_utf8().Related issue
None. Found while reading the overflow-error parsers.
API or behavior changes
None. Messages that used to panic now return the stated limit.
Validation
cargo fmt --all -- --check: cleancargo clippy -p tinyinference-llm --all-targets --all-features -- -D warnings: cleancargo test -p tinyinference-llm --all-features: all pass (873 lib tests). The new test panics without the fix.Tests
failure::context_limit::tests::parses_trailing_limit_after_a_multibyte_charactercovers a no-break space and a CJK character before the number, and expectsSome(32_768)for both.Documentation
Not needed.
Checklist
#[allow(...)],#[ignore], or relaxed lints.envcontents in the diff or the description