grafana/k6 · error

max_vus: %w

Error message

max_vus: %w

What it means

Client.StartLocalExecution (internal/cloudapi/provisioning/api.go:206) converts req.MaxVUs from int64 to int32 via toInt32 because the cloud OpenAPI schema types max_vus as int32. The error means the value lies outside [-2147483648, 2147483647]. No real VU count reaches this range; the value is garbage, misparsed, or overflows from upstream arithmetic.

Source

Thrown at internal/cloudapi/provisioning/api.go:206

// safe retries. The caller provides options as pre-marshalled JSON.
func (c *Client) StartLocalExecution(
	ctx context.Context, loadTestID int64, req StartLocalExecutionRequest,
) (*StartLocalExecutionResponse, error) {
	// Generate idempotency key: 8 random bytes hex-encoded (16 chars).
	var key [8]byte
	if _, err := rand.Read(key[:]); err != nil {
		return nil, fmt.Errorf("generating idempotency key: %w", err)
	}

	// SDK adapter: unmarshal json.RawMessage → map[string]any.
	var opts map[string]any
	if err := json.Unmarshal(req.Options, &opts); err != nil {
		return nil, fmt.Errorf("unmarshalling options for SDK: %w", err)
	}

	maxVUs, err := toInt32(req.MaxVUs)
	if err != nil {
		return nil, fmt.Errorf("max_vus: %w", err)
	}
	totalDuration, err := toInt32(req.TotalDuration)
	if err != nil {
		return nil, fmt.Errorf("total_duration: %w", err)
	}

	sdkReq := k6cloud.NewStartLocalExecutionTestRequest(opts, maxVUs, totalDuration)

	if req.ArchiveSize > 0 {
		v, err := toInt32(req.ArchiveSize)
		if err != nil {
			return nil, fmt.Errorf("archive_size: %w", err)
		}
		sdkReq.SetArchiveSize(v)
	} else {
		sdkReq.SetArchiveSizeNil()
	}

View on GitHub (pinned to 93accf6570)

Solutions

  1. Inspect the resolved options (k6 inspect or debug log) and fix the absurd VU count
  2. Clamp or validate MaxVUs against a sane upper bound (cloud plans cap far below 2^31) before provisioning
  3. Find where the value is computed (env var, flag, options merging) and correct the unit/logic
  4. Treat this as a symptom of wrong input, not a cloud-side limit

Example fix

// before
req := provisioning.StartLocalExecutionRequest{MaxVUs: rawMaxVUs}

// after
const maxReasonableVUs = 1_000_000
if rawMaxVUs <= 0 || rawMaxVUs > maxReasonableVUs {
	return fmt.Errorf("invalid max VUs %d", rawMaxVUs)
}
req := provisioning.StartLocalExecutionRequest{MaxVUs: rawMaxVUs}
Defensive patterns

Strategy: validation

Validate before calling

const saneMaxVUs = 1 << 20
if req.MaxVUs <= 0 || req.MaxVUs > saneMaxVUs {
	return fmt.Errorf("max_vus %d out of sane range", req.MaxVUs)
}

Type guard

func fitsInt32(v int64) bool { return v >= math.MinInt32 && v <= math.MaxInt32 }

Try / catch

if err := client.StartLocalExecution(ctx, id, req); err != nil {
	if strings.HasPrefix(err.Error(), "max_vus:") {
		// fix the VU count at its source; do not retry as-is
	}
	return err
}

Prevention

When it happens

Trigger: options.MaxVUs computed from unvalidated input (e.g. an env var parsed with a typo like 99999999999), an integer overflow in caller-side summing of executor VUs, or a negative sentinel leaking into the field beyond int32 range.

Common situations: Scripts with absurd vus/max-vus settings; automation multiplying units; a corrupted config value passed through several layers without range checks.

Related errors


AI-assisted analysis of grafana/k6@93accf6570 (2026-08-15). Data as JSON: /api/errors/0919c4057fe57a3c. Report an issue: GitHub.