SigNoz/signoz · error

offset and limit must be greater than 0

Error message

offset and limit must be greater than 0

What it means

QueryRuleStateHistory.Validate rejects negative Offset or Limit values for alerting rule state history pagination. The message text says 'greater than 0' but the code only forbids negative values; 0 is allowed.

Source

Thrown at pkg/query-service/model/alerting.go:164

	RelatedLogsLink   string `json:"relatedLogsLink"`
}

type QueryRuleStateHistory struct {
	Start   int64         `json:"start"`
	End     int64         `json:"end"`
	State   string        `json:"state"`
	Filters *v3.FilterSet `json:"filters"`
	Offset  int64         `json:"offset"`
	Limit   int64         `json:"limit"`
	Order   string        `json:"order"`
}

func (r *QueryRuleStateHistory) Validate() error {
	if r.Start == 0 || r.End == 0 {
		return fmt.Errorf("start and end are required")
	}
	if r.Offset < 0 || r.Limit < 0 {
		return fmt.Errorf("offset and limit must be greater than 0")
	}
	if r.Order != "asc" && r.Order != "desc" {
		return fmt.Errorf("order must be asc or desc")
	}
	return nil
}

type RuleStateHistoryContributor struct {
	Fingerprint       uint64       `json:"fingerprint" ch:"fingerprint"`
	Labels            LabelsString `json:"labels" ch:"labels"`
	Count             uint64       `json:"count" ch:"count"`
	RelatedTracesLink string       `json:"relatedTracesLink"`
	RelatedLogsLink   string       `json:"relatedLogsLink"`
}

type RuleStateTransition struct {
	RuleID         string     `json:"ruleID" ch:"rule_id"`
	State          AlertState `json:"state" ch:"state"`

View on GitHub (pinned to 5069bf80b0)

Solutions

  1. Clamp offset and limit to >= 0 before sending
  2. Fix client pagination arithmetic so offsets never go negative (use max(0, computed))
  3. Note 0 is valid; only negatives are rejected

Example fix

// before
GET /api/rules/<id>/state_history?offset=-20&start=..&end=..

// after
GET /api/rules/<id>/state_history?offset=0&start=..&end=..
Defensive patterns

Strategy: validation

Validate before calling

if r.Offset < 0 { r.Offset = 0 }
if r.Limit < 0 { r.Limit = 0 }

Type guard

func nonNegativePagination(offset, limit int64) bool { return offset >= 0 && limit >= 0 }

Prevention

When it happens

Trigger: Passing offset=-10 or limit=-1 (negative numbers) as query params to the rule state history endpoint, often via URL manipulation or int parsing of '-'.

Common situations: Manually edited URLs; client-side pagination math producing negative offsets at the first page; typo'd defaults.

Related errors


AI-assisted analysis of SigNoz/signoz@5069bf80b0 (2026-08-28). Data as JSON: /api/errors/7b807c0cdc4e6209. Report an issue: GitHub.