JuliusBrussee/caveman · error

cachebench: invalid stable identity boundary

Error message

cachebench: invalid stable identity boundary

What it means

Raised in corpusStableIdentity when the stableCount boundary is invalid for the given message slice (e.g. stableCount == 0 or negative, or exceeding the number of messages available). The stable-prefix length must be a positive index within the conversation.

Solutions

  1. Clamp the stable segment count to [1, len(messages)] before computing identity
  2. Fix the stable-segment derivation logic that produced 0 or an out-of-range count
  3. Log the row/session where the boundary failed to locate the malformed conversation
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at cacheengine/cachebench/corpus.go:698 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of JuliusBrussee/caveman@766dce6b13 (2026-08-18). Data as JSON: /api/errors/b06a1ddc2462cfe5. Report an issue: GitHub.

Appendix: source

Thrown at cacheengine/cachebench/corpus.go:698

	}
	sort.SliceStable(requests, func(i, j int) bool { return requests[i].At.Before(requests[j].At) })
	return Trace{
		Provider: provider,
		Scenario: Scenario{Name: corpus.Metadata.Name, Turns: len(requests), AssumedTTL: 5 * time.Minute, Step: time.Second},
		Requests: requests, TokenBasis: counter.Name() + " estimate over normalized OpenAI messages",
		TimingBasis: TimingPerPartition,
	}, nil
}

func corpusStableIdentity(messages []CorpusMessage, stableCount int) (string, error) {
	if len(messages) == 0 {
		return "", errors.New("cachebench: empty stable identity")
	}
	if stableCount == 0 {
		stableCount = 1
	}
	if stableCount > len(messages) {
		return "", errors.New("cachebench: invalid stable identity boundary")
	}
	digest := sha256.New()
	encoder := json.NewEncoder(digest)
	encoder.SetEscapeHTML(false)
	for _, message := range messages[:stableCount] {
		if err := encoder.Encode(message); err != nil {
			return "", err
		}
	}
	return hex.EncodeToString(digest.Sum(nil)), nil
}

func corpusProviderBody(provider ProviderConfig, messages []CorpusMessage) ([]byte, error) {
	switch provider.Provider {
	case "openai":
		return json.Marshal(map[string]any{"model": provider.Model, "max_completion_tokens": 256, "messages": messages})
	case "anthropic":
		return anthropicCorpusBody(provider.Model, messages)

View on GitHub (pinned to 766dce6b13)