MCPcopy Create free account
hub / github.com/ChrisFeldmeier/OpenCodeRust / is_overflow

Method is_overflow

crates/opencode-session/src/compaction.rs:203–230  ·  view source on GitHub ↗

Check whether the conversation has overflowed the context window. Mirrors TS `isOverflow`. The `total` field on `TokenUsage` is used first; if it is zero we fall back to summing the individual fields (input + output + cache_read + cache_write) -- matching the TS `input.tokens.total || input.tokens.input + ...` logic.

(&self, usage: &TokenUsage, limits: &ModelLimits)

Source from the content-addressed store, hash-verified

201 /// (input + output + cache_read + cache_write) -- matching the TS
202 /// `input.tokens.total || input.tokens.input + ...` logic.
203 pub fn is_overflow(&self, usage: &TokenUsage, limits: &ModelLimits) -> bool {
204 if !self.config.auto {
205 return false;
206 }
207
208 if limits.context == 0 {
209 return false;
210 }
211
212 // TS: const count = input.tokens.total || input.tokens.input + ...
213 let count = if usage.total > 0 {
214 usage.total
215 } else {
216 usage.input + usage.output + usage.cache_read + usage.cache_write
217 };
218
219 let reserved = self
220 .config
221 .reserved
222 .unwrap_or_else(|| COMPACTION_BUFFER.min(limits.max_output));
223
224 let usable = limits
225 .max_input
226 .map(|input| input.saturating_sub(reserved))
227 .unwrap_or_else(|| limits.context.saturating_sub(limits.max_output));
228
229 count >= usable
230 }
231
232 pub fn estimate_tokens(text: &str) -> u64 {
233 let char_count = text.chars().count() as u64;

Callers 2

should_compactMethod · 0.45
process_streamMethod · 0.45

Calls

no outgoing calls

Tested by

no test coverage detected