JuliusBrussee/caveman · error

cachebench: session %q row %d: %w

Error message

cachebench: session %q row %d: %w

What it means

While building the CorpusSummary, converting a row's messages into prefix segments (corpusPrefix) failed for the given session and row index. The wrapper adds session ID and row index so the failing row can be located in the source corpus; the '%w' clause carries the underlying prefix-construction error.

Source

Thrown at cacheengine/cachebench/corpus.go:550

	summary := CorpusSummary{
		Name: corpus.Metadata.Name, License: corpus.Metadata.License, Revision: corpus.Metadata.Revision,
		SHA256: corpus.SHA256, Sessions: len(sessions), Requests: len(corpus.Rows), Sources: map[string]int{},
		RetainedBytes: corpus.Bytes,
		TokenBasis:    counter.Name() + " estimate over canonical message JSON",
	}
	if summary.RetainedBytes == 0 {
		summary.RetainedBytes = corpusRetainedBytes(corpus.Rows)
	}
	turns := make([]int, 0, len(sessions))
	for _, id := range order {
		session := sessions[id]
		turns = append(turns, len(session.Rows))
		summary.Sources[corpusSource(id)]++
		var previous []PrefixSegment
		for index, row := range session.Rows {
			prefix, err := corpusPrefix(row.Input, counter)
			if err != nil {
				return CorpusSummary{}, fmt.Errorf("cachebench: session %q row %d: %w", id, index, err)
			}
			eligible := prefixTokens(prefix)
			summary.EstimatedInputTokens += int64(eligible)
			if index > 0 {
				reused := commonPrefixTokens(previous, prefix)
				summary.EstimatedReusableTokens += int64(reused)
				if reused > 0 {
					summary.OpportunityRequestHitRate++
				}
				if len(prefix) > len(previous) && samePrefix(previous, prefix) {
					summary.StrictPrefixExtensions++
				} else {
					summary.MutatedOrCompactedTransitions++
				}
			}
			previous = prefix
		}
	}

View on GitHub (pinned to 27d5a3981a)

Solutions

  1. Inspect the wrapped error to identify what corpusPrefix rejected.
  2. Flatten array-form content to plain strings when exporting the corpus.
  3. Re-generate the corpus with the same tool version used for summarization.
  4. Exclude the reported session/row from the corpus if it is not representative.
Defensive patterns

Strategy: try-catch

Validate before calling

for i, row := range session.Rows {
	if _, err := corpusPrefix(row.Input, counter); err != nil {
		return fmt.Errorf("preflight: session %q row %d: %w", id, i, err)
	}
}

Try / catch

summary, err := SummarizeCorpus(corpus)
if err != nil {
	var target *CorpusRow
	if strings.Contains(err.Error(), "cachebench: session") {
		// extract session/row from message, fix corpus, retry once
	}
	return err
}

Prevention

When it happens

Trigger: Calling the corpus summarization path over a loaded corpus where corpusPrefix(row.Input, counter) errors for some row — typically content that passed structural validation but cannot be turned into a PrefixSegment (e.g. non-text content shapes unsupported by the tokenizer/segmenter).

Common situations: Multimodal or array-form content in messages that the prefix extractor does not handle; corpus produced by a newer exporter whose content format the summarizer version cannot segment.

Related errors


AI-assisted analysis of JuliusBrussee/caveman@27d5a3981a (2026-08-15). Data as JSON: /api/errors/1fe0b410a21a8b8b. Report an issue: GitHub.