rtk-ai/rtk · error · anyhow::Error
negative event length
Error message
negative event length: {} What it means
For any record type not specifically handled, the parser reads a 7-bit-encoded signed event length; a negative value means the byte stream is corrupt or the parser has lost synchronization with the record boundaries. Since a length-prefixed payload cannot have negative size, the parser bails before calling read_exact, which would otherwise receive a negative-cast usize.
Solutions
- Regenerate the binlog: re-run `dotnet build -bl:build.binlog` with a current SDK.
- Verify file integrity — compare size/checksum against the CI artifact; a truncated file explains mid-record corruption.
- Ensure the input path really is a binlog and was produced by MSBuild (check gzip header and version >= 18).
- If it happens on intact logs, audit the record-type switch so unknown records keep the stream aligned.
Defensive patterns
Strategy: try-catch
Validate before calling
// ensure the file is complete: no concurrent writer, gzip stream ends cleanly
let mut d = flate2::read::GzDecoder::new(std::fs::File::open(path)?);
let mut payload = Vec::new();
d.read_to_end(&mut payload)?;
if !d.header().map(|h| h.extra().is_some()).unwrap_or(true) || d.status().is_err() {
bail!("binlog gzip stream is truncated");
} Try / catch
if let Err(e) = parse_result {
if e.to_string().contains("negative event length") {
eprintln!("binlog stream corrupted or truncated; re-run dotnet build -bl");
return regenerate_binlog();
}
return Err(e);
} Prevention
- Wait for the build process to fully exit before consuming its binlog
- Detect truncation: gzip decode errors or sizes far below expected indicate partial writes
- Run binlog-producing builds on storage with sufficient free space
- Avoid pointing the tool at arbitrary .gz files; only parse MSBuild-produced -bl output
When it happens
Trigger: The _ catch-all arm of the record loop in parse_events_from_binlog decodes read_7bit_i32() and gets len < 0 — caused by offset drift after an unknown/misparsed record type, truncation mid-record, or decoding arbitrary bytes as a binlog.
Common situations: A build killed mid-write leaving a truncated tail record; a binlog from a newer/older MSBuild whose record layout differs and desynchronizes the parser; pointing the tool at a random gzip file renamed to .binlog.
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
- negative record length
- Failed to parse binlog at
- Failed to parse binlog at
- invalid 7-bit encoded integer
- legacy dictionary format is unsupported
AI-assisted analysis of rtk-ai/rtk@0924356b4c (2026-09-19).
Data as JSON: /api/errors/a8605193bd7ee486.
Report an issue: GitHub.
Appendix: source
Thrown at src/cmds/dotnet/binlog.rs:364
parsed.string_records.push(text);
}
RECORD_NAME_VALUE_LIST | RECORD_PROJECT_IMPORT_ARCHIVE => {
let len = reader
.read_7bit_i32()
.context("failed to read record length")?;
if len < 0 {
anyhow::bail!("negative record length: {}", len);
}
reader
.skip(len as usize)
.context("failed to skip auxiliary record payload")?;
}
_ => {
let len = reader
.read_7bit_i32()
.context("failed to read event length")?;
if len < 0 {
anyhow::bail!("negative event length: {}", len);
}
let payload = reader
.read_exact(len as usize)
.context("failed to read event payload")?;
let mut event_reader = BinReader::new(payload);
let _ =
parse_event_record(kind, &mut event_reader, file_format_version, &mut parsed);
}
}
}
Ok(parsed)
}
fn parse_event_record(
kind: i32,
reader: &mut BinReader<'_>,View on GitHub (pinned to 0924356b4c)