grafana/k6 · error

the startTime can't be negative

Error message

the startTime can't be negative

What it means

Emitted by BaseConfig.Validate (lib/executor/base_config.go:66-68) when a scenario's startTime is a negative duration. startTime (types.NullDuration) delays when the scenario begins relative to test start; negative values would mean starting before the test exists, so they are rejected. The check only fires when the value is non-zero, since the zero NullDuration default is skipped via the Valid/zero semantics of the surrounding code (negative values always have Duration < 0).

Source

Thrown at lib/executor/base_config.go:67

// Validate checks some basic things like present name, type, and a positive start time
func (bc BaseConfig) Validate() (result []error) {
	// Some just-in-case checks, since those things are likely checked in other places or
	// even assigned by us:
	if bc.Name == "" {
		result = append(result, errors.New("scenario name can't be empty"))
	}
	if !scenarioNameWhitelist.MatchString(bc.Name) {
		result = append(result, errors.New(scenarioNameErr))
	}
	if bc.Exec.Valid && bc.Exec.String == "" {
		result = append(result, errors.New("exec value cannot be empty"))
	}
	if bc.Type == "" {
		result = append(result, errors.New("missing or empty type field"))
	}
	// The actually reasonable checks:
	if bc.StartTime.Duration < 0 {
		result = append(result, errors.New("the startTime can't be negative"))
	}
	if bc.GracefulStop.Duration < 0 {
		result = append(result, errors.New("the gracefulStop timeout can't be negative"))
	}
	return result
}

// GetName returns the name of the scenario.
func (bc BaseConfig) GetName() string {
	return bc.Name
}

// GetType returns the executor's type as a string ID.
func (bc BaseConfig) GetType() string {
	return bc.Type
}

// GetStartTime returns the starting time, relative to the beginning of the

View on GitHub (pinned to 93accf6570)

Solutions

  1. Use a positive or zero startTime, e.g. startTime: '5s' to delay the scenario
  2. If the intent was to run immediately, remove the startTime property

Example fix

// before
export const options = {
  scenarios: { late: { executor: 'constant-vus', startTime: '-5s', vus: 2, duration: '1m' } },
};

// after
export const options = {
  scenarios: { late: { executor: 'constant-vus', startTime: '5s', vus: 2, duration: '1m' } },
};
Defensive patterns

Strategy: validation

Validate before calling

// JS: guard computed startTime values
const delay = Number(__ENV.SCENARIO_DELAY_S || 0);
if (delay < 0) throw new Error('scenario delay must be >= 0');
export const options = { scenarios: { late: { executor: 'constant-vus', startTime: `${delay}s`, vus: 1, duration: '1m' } } };

Prevention

When it happens

Trigger: Setting scenarios: { late: { executor: 'constant-vus', startTime: '-5s', ... } }, or unmarshaling a config/JSON where startTime parses to a negative duration (e.g. "-1m30s").

Common situations: Offsets computed from variables that go negative (e.g. startTime based on a computed delay), or a sign typo when hand-editing configs. Rare in practice because k6 duration parsing makes '-5s' an explicit choice.

Related errors


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