@@ -7781,7 +7781,9 @@ impl LiveCli {
77817781 || error_str.contains("no parseable body")
77827782 || error_str.contains("exceed_context_size")
77837783 || error_str.contains("exceeds the available context size")
7784- || error_str.to_ascii_lowercase().contains("context size has been exceeded");
7784+ || error_str
7785+ .to_ascii_lowercase()
7786+ .contains("context size has been exceeded");
77857787
77867788 // Also treat "assistant stream produced no content" and reqwest decode failures
77877789 // as recoverable errors that may benefit from auto-compaction. Some backends (e.g.
@@ -7888,16 +7890,24 @@ impl LiveCli {
78887890 || retry_str.contains("no parseable body")
78897891 || retry_str.contains("exceed_context_size")
78907892 || retry_str.contains("exceeds the available context size")
7891- || retry_str.to_ascii_lowercase().contains("context size has been exceeded");
7892- let still_no_content = retry_str.contains("assistant stream produced no content")
7893+ || retry_str
7894+ .to_ascii_lowercase()
7895+ .contains("context size has been exceeded");
7896+ let still_no_content = retry_str
7897+ .contains("assistant stream produced no content")
78937898 || retry_str.contains("Failed to parse input at pos")
78947899 || retry_str.contains("error decoding response body");
78957900
7896- if (still_context_window || still_no_content) && round + 1 < max_compact_rounds {
7901+ if (still_context_window || still_no_content)
7902+ && round + 1 < max_compact_rounds
7903+ {
78977904 // If the retry error reveals the context window, adapt threshold.
7898- if let Some(window) = extract_context_window_tokens_from_error(&retry_str) {
7905+ if let Some(window) =
7906+ extract_context_window_tokens_from_error(&retry_str)
7907+ {
78997908 let threshold: u32 = (window as f64 * 0.7).round() as u32;
7900- new_runtime.set_auto_compaction_input_tokens_threshold(threshold);
7909+ new_runtime
7910+ .set_auto_compaction_input_tokens_threshold(threshold);
79017911 }
79027912
79037913 // The compacted session was still too large for the model's context.
@@ -12831,15 +12841,17 @@ fn extract_context_window_tokens_from_error(error_str: &str) -> Option<u32> {
1283112841 // Pattern: "(NNNNNN tokens)" appearing after context-size markers
1283212842 for line in error_str.lines() {
1283312843 let lowered = line.to_ascii_lowercase();
12834- if lowered.contains("context size") || lowered.contains("context length")
12844+ if lowered.contains("context size")
12845+ || lowered.contains("context length")
1283512846 || lowered.contains("context window")
1283612847 {
1283712848 // Try parenthesised form: (81920 tokens)
1283812849 if let Some(start) = lowered.find('(') {
1283912850 if let Some(end) = lowered.find(")") {
1284012851 if start < end {
1284112852 let inner = &line[start + 1..end];
12842- let digits: String = inner.chars().take_while(|c| c.is_ascii_digit()).collect();
12853+ let digits: String =
12854+ inner.chars().take_while(|c| c.is_ascii_digit()).collect();
1284312855 if let Ok(n) = digits.parse::<u32>() {
1284412856 if n > 1000 {
1284512857 return Some(n);
0 commit comments