multica-ai/multica · warning
invalid runtime counts
Error message
invalid runtime counts
What it means
Once a success probe carries all four count fields, validateClientUsageRuntime checks their arithmetic and range: runtime_count must be within 0..1000, online_count and offline_count must each be >= 0, and online_count + offline_count must equal runtime_count. This rejects internally inconsistent telemetry (counts that cannot describe the same set of runtimes) and caps the magnitude to keep the stored rows bounded.
Source
Thrown at server/internal/handler/client_usage.go:203
func validateClientUsageRuntime(probe clientUsageRuntimeProbe) (validatedRuntimeProbe, error) {
result := strings.ToLower(strings.TrimSpace(probe.ProbeResult))
if result != "success" && result != "error" {
return validatedRuntimeProbe{}, errors.New("runtime probe_result must be success or error")
}
validated := validatedRuntimeProbe{Result: pgtype.Text{String: result, Valid: true}}
if result == "error" {
if probe.RuntimeCount != nil || probe.ProviderSummary != nil || probe.OnlineCount != nil || probe.OfflineCount != nil {
return validatedRuntimeProbe{}, errors.New("failed runtime probes must not include counts")
}
return validated, nil
}
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")
}View on GitHub (pinned to 2c0912b6ec)
Solutions
- Compute all three counts from one consistent snapshot so online + offline == total by construction.
- Cap the report at 1000 runtimes (sample or batch) before sending.
- Assert the invariant client-side before the POST: online >= 0 && offline >= 0 && online + offline === runtime_count && runtime_count <= 1000.
- If totals drift because of concurrency, take a lock or copy the runtime list once and derive all counts from it.
Example fix
// before const online = runtimes.filter(r => r.online).length; const total = await recountRuntimes(); // second pass, may drift // after const snapshot = [...runtimes]; // one consistent snapshot const online = snapshot.filter(r => r.online).length; const offline = snapshot.length - online; const total = snapshot.length; // online + offline === total by construction
Defensive patterns
Strategy: validation
Validate before calling
function assertCountsConsistent(online, offline, total) {
if (!Number.isInteger(total) || total < 0 || total > 1000) throw new RangeError(`runtime_count ${total} out of [0,1000]`);
if (!Number.isInteger(online) || online < 0) throw new RangeError(`online_count ${online} invalid`);
if (!Number.isInteger(offline) || offline < 0) throw new RangeError(`offline_count ${offline} invalid`);
if (online + offline !== total) throw new RangeError(`online+offline (${online + offline}) != runtime_count (${total})`);
} Type guard
const countsAreConsistent = (o, f, t) => Number.isInteger(t) && t >= 0 && t <= 1000 && Number.isInteger(o) && o >= 0 && Number.isInteger(f) && f >= 0 && o + f === t;
Prevention
- Derive online/offline/total from a single copied snapshot of the runtime list.
- Run the invariant check right before the POST and drop the report (with a log) rather than sending a known-inconsistent one.
- If >1000 runtimes exist, sample or batch so total stays within the cap.
When it happens
Trigger: POST success probe with runtime_count=1500 (over cap); online_count=3, offline_count=4 but runtime_count=6 (3+4≠6); negative offline_count=-1. Any one condition triggers the shared 'invalid runtime counts' error.
Common situations: Race between probing and counting on the client (set changes between online/offline tally and total tally); client counting 'pending' runtimes in runtime_count but in neither online nor offline; integer overflow or unit confusion after a refactor; genuinely >1000 runtimes needing a batched report.
Related errors
- runtime provider counts do not match runtime_count
- runtime probe_result must be success or error
- failed runtime probes must not include counts
- successful runtime probes require all counts
- too many runtime providers
AI-assisted analysis of multica-ai/multica@2c0912b6ec (2026-08-15).
Data as JSON: /api/errors/72b99c82074ebff3.
Report an issue: GitHub.