rtk-ai/rtk · error · anyhow::Error

negative event length: {}

Error message

negative event length: {}

What it means

Raised while skipping auxiliary binlog records (RECORD_NAME_VALUE_LIST / RECORD_PROJECT_IMPORT_ARCHIVE): the 7-bit-encoded length prefix read from the binary log was negative, meaning the file is corrupted or truncated and the reader cannot safely skip the payload. Not a user-input error — it signals a malformed .binlog file fed to parse_build/parse_test/parse_restore.

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 36788f6bd4)

Solutions

  1. Regenerate the binlog from a fresh, complete build
  2. Verify the file is a genuine .binlog (binlog magic) not a misnamed file
  3. Re-download/re-copy the artifact if it came from a network share or CI cache
  4. If the file opens in the MSBuild Structured Log Viewer, report the parsing bug
Defensive patterns

Strategy: try-catch

Try / catch

match parse_events_from_binlog(&path) {
    Ok(b) => use_events(&b),
    Err(e) if e.to_string().contains("negative event length") => {
        eprintln!("binlog corrupt or misaligned; regenerate the log");
    }
    Err(e) => return Err(e),
}

Prevention

When it happens

Trigger: parse_events_from_binlog's default record branch reads an event length that is negative, typically because an earlier record was misparsed, the payload was truncated, or the input is not a valid binlog.

Common situations: Parsing a partially written .binlog (build crashed); passing an unrelated binary file; version mismatch causing misread record boundaries; corrupted CI artifact.

Related errors


AI-assisted analysis of rtk-ai/rtk@36788f6bd4 (2026-09-03). Data as JSON: /api/errors/a8605193bd7ee486. Report an issue: GitHub.