Hmbown/CodeWhale · info
event recovery chunk length fits u64
Error message
event recovery chunk length fits u64
What it means
Panic from `u64::try_from(chunk_len)` where `chunk_len` is the usize chunk length just computed (bounded by the 8 KiB buffer). Conversion to u64 cannot fail for any chunk the previous line produced; the expect asserts the recovery loop's internal sizing invariant.
Solutions
- No action needed; keep the expect as a documented invariant
- If chunk sizing changes, re-verify the bound before the try_from
Defensive patterns
Strategy: validation
Validate before calling
// chunk_len <= 8192 by construction, so u64::try_from always succeeds
Prevention
- Derive chunk_len only from the bounded buffer length
- Keep the usize→u64 round trip in one function so bounds stay provable
When it happens
Trigger: Unreachable with the current 8 KiB chunking; only a refactor producing chunk_len > u64::MAX (impossible for usize-derived values on supported targets) would fire it.
Common situations: Refactors that change the chunk-size source without revalidating the usize→u64 round trip.
Understand the failure class
Background: "value must be between 0 and 1" / "out of range" / "must not be negative" errors: fixing range-validation failures across open-source libraries — this error's family across 42 libraries.
Related errors
- event recovery chunk length fits usize
- event recovery buffer fits u64
- event recovery newline index fits u64
- hardcoded project MCP state path is valid
- hardcoded project notes state path is valid
AI-assisted analysis of Hmbown/CodeWhale@73e0f67d83 (2026-09-22).
Data as JSON: /api/errors/978b10ba3c7e1702.
Report an issue: GitHub.
Appendix: source
Thrown at crates/tui/src/runtime_threads.rs:14024
if len == 0 {
return Ok(());
}
file.seek(SeekFrom::End(-1))?;
let mut last = [0_u8; 1];
file.read_exact(&mut last)?;
if last[0] == b'\n' {
return Ok(());
}
let mut search_end = len;
let mut truncate_at = 0_u64;
let mut buffer = [0_u8; 8 * 1024];
let buffer_len = u64::try_from(buffer.len()).expect("event recovery buffer fits u64");
while search_end > 0 {
let chunk_len = usize::try_from(search_end.min(buffer_len))
.expect("event recovery chunk length fits usize");
let chunk_len_u64 = u64::try_from(chunk_len).expect("event recovery chunk length fits u64");
let chunk_start = search_end - chunk_len_u64;
file.seek(SeekFrom::Start(chunk_start))?;
file.read_exact(&mut buffer[..chunk_len])?;
if let Some(index) = buffer[..chunk_len].iter().rposition(|byte| *byte == b'\n') {
truncate_at = chunk_start
+ u64::try_from(index).expect("event recovery newline index fits u64")
+ 1;
break;
}
search_end = chunk_start;
}
file.set_len(truncate_at)
.with_context(|| format!("Failed to truncate torn tail in {}", path.display()))?;
file.sync_all()
.with_context(|| format!("Failed to sync repaired {}", path.display()))?;
tracing::warn!(
path = %path.display(),View on GitHub (pinned to 73e0f67d83)