router-for-me/CLIProxyAPI · error

credential-in-flight.snapshot-interval must be positive

Error message

credential-in-flight.snapshot-interval must be positive

What it means

CredentialInFlightConfig.Durations() parses 'credential-in-flight.snapshot-interval' (a string duration like "2s") and rejects it when time.ParseDuration fails or the result is <= 0. This interval drives how often in-flight request observation snapshots are taken; a zero/negative/NaN-style value would stall observation.

Source

Thrown at internal/config/credential_in_flight.go:49

func DefaultCredentialInFlightConfig() CredentialInFlightConfig {
	return CredentialInFlightConfig{
		SnapshotInterval:   "2s",
		StaleAfter:         "10s",
		MaxPartBytes:       DefaultInFlightMaxPartBytes,
		MaxPartCount:       DefaultInFlightMaxPartCount,
		MaxRevisionBytes:   DefaultInFlightMaxRevisionBytes,
		MaxAggregateGroups: DefaultInFlightMaxAggregateGroups,
		MaxDetails:         DefaultInFlightMaxDetails,
		MaxStringBytes:     DefaultInFlightMaxStringBytes,
		StagingRetention:   "1m",
	}
}

// Durations parses and validates the in-flight observation durations.
func (c CredentialInFlightConfig) Durations() (time.Duration, time.Duration, time.Duration, error) {
	snapshotInterval, errSnapshot := time.ParseDuration(c.SnapshotInterval)
	if errSnapshot != nil || snapshotInterval <= 0 {
		return 0, 0, 0, fmt.Errorf("credential-in-flight.snapshot-interval must be positive")
	}
	staleAfter, errStale := time.ParseDuration(c.StaleAfter)
	if errStale != nil || staleAfter <= 0 || snapshotInterval > staleAfter/3 {
		return 0, 0, 0, fmt.Errorf("credential-in-flight.stale-after must be at least three snapshot intervals")
	}
	stagingRetention, errRetention := time.ParseDuration(c.StagingRetention)
	if errRetention != nil || stagingRetention <= 0 {
		return 0, 0, 0, fmt.Errorf("credential-in-flight.staging-retention must be positive")
	}
	return snapshotInterval, staleAfter, stagingRetention, nil
}

// Validate verifies the in-flight observation bounds.
func (c CredentialInFlightConfig) Validate() error {
	if _, _, _, errDurations := c.Durations(); errDurations != nil {
		return errDurations
	}
	if c.MaxPartBytes < 1024 || c.MaxPartCount <= 0 || c.MaxPartCount > DefaultInFlightMaxPartCount {

View on GitHub (pinned to 78f0c4079e)

Solutions

  1. Set snapshot-interval to a positive Go duration string, e.g. snapshot-interval: 2s (the documented default).
  2. Use exact Go duration syntax: number+unit with no space (ms, s, m).
  3. Ensure stale-after is at least 3x snapshot-interval to satisfy the sibling check.
  4. If you do not want in-flight observation, leave the whole credential-in-flight block commented out.

Example fix

# before (config.yaml)
credential-in-flight:
  snapshot-interval: 0s

# after
credential-in-flight:
  snapshot-interval: 2s
  stale-after: 10s
Defensive patterns

Strategy: validation

Validate before calling

// Go: pre-parse snapshot-interval the same way.
si, err := time.ParseDuration(cfg.CredentialInFlight.SnapshotInterval)
if err != nil || si <= 0 {
    return errors.New("credential-in-flight.snapshot-interval must be a positive Go duration")
}

Prevention

When it happens

Trigger: config.yaml with 'credential-in-flight:\n snapshot-interval: 0s', 'snapshot-interval: -2s', or an unparseable string like 'snapshot-interval: 2 sec' (Go duration syntax requires '2s'). An empty string also fails parsing.

Common situations: Using a space between number and unit; copying docs that write '2 seconds'; setting 0 to disable observation (not supported — remove the section instead); templating emitting an empty value.

Related errors


AI-assisted analysis of router-for-me/CLIProxyAPI@78f0c4079e (2026-08-15). Data as JSON: /api/errors/af7437f3c8f149a1. Report an issue: GitHub.