multica-ai/multica · warning

runtime provider counts do not match runtime_count

Error message

runtime provider counts do not match runtime_count

What it means

The final cross-check in validateClientUsageRuntime: the sum of all per-provider counts in provider_summary must equal runtime_count exactly. The summary is meant to be a complete partition of the runtimes by provider, not a top-N; if the buckets do not add up to the whole, the report is self-contradictory and rejected. This runs after per-entry validation, so counts are already known non-negative and bounded.

Source

Thrown at server/internal/handler/client_usage.go:216

	if probe.RuntimeCount == nil || probe.ProviderSummary == nil || probe.OnlineCount == nil || probe.OfflineCount == nil {
		return validatedRuntimeProbe{}, errors.New("successful runtime probes require all counts")
	}
	if *probe.RuntimeCount < 0 || *probe.RuntimeCount > 1000 || *probe.OnlineCount < 0 || *probe.OfflineCount < 0 || *probe.OnlineCount+*probe.OfflineCount != *probe.RuntimeCount {
		return validatedRuntimeProbe{}, errors.New("invalid runtime counts")
	}
	if len(probe.ProviderSummary) > 32 {
		return validatedRuntimeProbe{}, errors.New("too many runtime providers")
	}
	var providerTotal int64
	for provider, count := range probe.ProviderSummary {
		if !providerNamePattern.MatchString(provider) || count < 0 || count > 1000 {
			return validatedRuntimeProbe{}, errors.New("invalid runtime provider summary")
		}
		providerTotal += int64(count)
	}
	if providerTotal != int64(*probe.RuntimeCount) {
		return validatedRuntimeProbe{}, errors.New("runtime provider counts do not match runtime_count")
	}
	summary, err := json.Marshal(probe.ProviderSummary)
	if err != nil {
		return validatedRuntimeProbe{}, errors.New("invalid runtime provider summary")
	}
	validated.RuntimeCount = pgtype.Int4{Int32: *probe.RuntimeCount, Valid: true}
	validated.ProviderSummary = summary
	validated.OnlineCount = pgtype.Int4{Int32: *probe.OnlineCount, Valid: true}
	validated.OfflineCount = pgtype.Int4{Int32: *probe.OfflineCount, Valid: true}
	return validated, nil
}

View on GitHub (pinned to 2c0912b6ec)

Solutions

  1. Derive both the total and the per-provider map from one snapshot so they partition exactly.
  2. When merging buckets to stay under 32 providers, add the merged remainder to an explicit 'other' key so the sum is preserved.
  3. Assert sum(values) === runtime_count client-side before POSTing.
  4. Make sure every runtime contributes to exactly one bucket, including unknown providers.

Example fix

// before
summary = topProviders(runtimes, 32); // dropped tail
payload = {runtime_count: runtimes.length, provider_summary: summary};

// after
summary = topProviders(runtimes, 31);
const counted = Object.values(summary).reduce((a, b) => a + b, 0);
summary.other = runtimes.length - counted; // preserve the partition
payload = {runtime_count: runtimes.length, provider_summary: summary};
Defensive patterns

Strategy: validation

Validate before calling

function assertSummaryPartitionsTotal(summary, runtimeCount) {
  const sum = Object.values(summary).reduce((a, b) => a + b, 0);
  if (sum !== runtimeCount) {
    throw new RangeError(`provider_summary sums to ${sum} but runtime_count is ${runtimeCount}`);
  }
}

Type guard

const summaryMatchesTotal = (summary, total) => Object.values(summary).reduce((a, b) => a + b, 0) === total;

Prevention

When it happens

Trigger: POST a success probe with runtime_count=10 but provider_summary {"openai":6,"anthropic":3} (sums to 9); dropping the smallest providers client-side to respect the 32-key cap without adjusting runtime_count; counting by provider from a different snapshot than the total.

Common situations: Truncating the summary for the cardinality cap (error 48) and forgetting to fold the remainder into an 'other' bucket; provider tally code skipping runtimes with unknown/empty provider; concurrent runtime registration between the two tally passes.

Related errors


AI-assisted analysis of multica-ai/multica@2c0912b6ec (2026-08-15). Data as JSON: /api/errors/8cd54ababd73c66b. Report an issue: GitHub.