From 82fbe8a7ea42ed7f35a78080e02a815a041a34df Mon Sep 17 00:00:00 2001 From: M3gA-Mind Date: Wed, 15 Jul 2026 18:00:54 +0530 Subject: [PATCH] Resolve bounded o1/o3 mid-name segments to the 200K context window Segment-mode context matching only checked the first `/`- and `:`-delimited component's leading token, so an o-series id embedded mid-name (e.g. `ollama/mistral-for-o1-benchmark`) returned None. Scan the whole lowercased id for the pattern and accept any occurrence bounded by non-alphanumeric edges, so mid-name o1/o3 tokens resolve to 200K while substrings like `solo1-7b`, `proto3-chat`, and `octo3thing` stay unmatched. --- src/harness/model/mod.rs | 27 +++++++++++++++++++-------- src/harness/model/test.rs | 18 ++++++++++++++---- 2 files changed, 33 insertions(+), 12 deletions(-) diff --git a/src/harness/model/mod.rs b/src/harness/model/mod.rs index 6e5f58a..d906fbe 100644 --- a/src/harness/model/mod.rs +++ b/src/harness/model/mod.rs @@ -32,9 +32,11 @@ pub use types::*; enum ContextPatternMatch { /// Pattern may appear anywhere in the lowercased model id. Substring, - /// Pattern must be a complete segment delimited by common provider/id - /// separators. This avoids false positives for short model ids such as - /// `o1` and `o3`. + /// Pattern must appear as a bounded segment: delimited by a non-alphanumeric + /// boundary (or the string start/end) on both sides. This lets short o-series + /// ids such as `o1` and `o3` resolve even when embedded mid-name (e.g. + /// `ollama/mistral-for-o1-benchmark`) while avoiding false positives for + /// substrings such as `solo1-7b`, `proto3-chat`, or `octo3thing`. Segment, } @@ -75,11 +77,20 @@ fn matches_context_pattern(lower: &str, pattern: &str, mode: ContextPatternMatch match mode { ContextPatternMatch::Substring => lower.contains(pattern), ContextPatternMatch::Segment => { - let model_name = lower.rsplit(['/', ':']).next().unwrap_or(lower); - model_name - .split(['-', '_', '.']) - .next() - .is_some_and(|segment| segment == pattern) + // Match `pattern` as a bounded segment: every occurrence is accepted + // only when the byte before it and the byte after it are both + // non-alphanumeric (or absent at the string edge). Scanning the whole + // id — not just the final `/`- or `:`-delimited component — lets a + // token embedded mid-name (`ollama/mistral-for-o1-benchmark`) resolve, + // while the boundary guard keeps substrings like `solo1-7b`, + // `proto3-chat`, and `octo3thing` unmatched. + let bytes = lower.as_bytes(); + lower.match_indices(pattern).any(|(start, matched)| { + let before_ok = start == 0 || !bytes[start - 1].is_ascii_alphanumeric(); + let end = start + matched.len(); + let after_ok = end >= bytes.len() || !bytes[end].is_ascii_alphanumeric(); + before_ok && after_ok + }) } } } diff --git a/src/harness/model/test.rs b/src/harness/model/test.rs index 63e5036..bc163d4 100644 --- a/src/harness/model/test.rs +++ b/src/harness/model/test.rs @@ -120,6 +120,7 @@ fn context_window_patterns_cover_common_provider_families() { #[test] fn o1_o3_context_patterns_require_segment_boundaries() { + // Canonical o-series ids still resolve to the 200K reasoning window. assert_eq!(context_window_for_model_id("o1"), Some(200_000)); assert_eq!(context_window_for_model_id("o1-mini"), Some(200_000)); assert_eq!(context_window_for_model_id("o3-mini"), Some(200_000)); @@ -128,13 +129,22 @@ fn o1_o3_context_patterns_require_segment_boundaries() { Some(200_000) ); - assert_eq!(context_window_for_model_id("solo1-7b"), None); - assert_eq!(context_window_for_model_id("proto3-chat"), None); - assert_eq!(context_window_for_model_id("octo3thing"), None); + // A bounded o1/o3 token embedded mid-name resolves too: it is delimited by + // non-alphanumeric boundaries on both sides. assert_eq!( context_window_for_model_id("ollama/mistral-for-o1-benchmark"), - None + Some(200_000) + ); + assert_eq!( + context_window_for_model_id("vllm/qwen-o3-eval.bench"), + Some(200_000) ); + + // The boundary guard keeps o1/o3 substrings from over-matching. + assert_eq!(context_window_for_model_id("solo1-7b"), None); + assert_eq!(context_window_for_model_id("proto3-chat"), None); + assert_eq!(context_window_for_model_id("octo3thing"), None); + assert_eq!(context_window_for_model_id("totally-unknown-model"), None); } #[test]