garm icon indicating copy to clipboard operation
garm copied to clipboard

scale_set_instances.generation is never set, so --outdated rotation matches every runner after a generation bump

Open wintrover opened this issue 1 month ago • 1 comments

Summary

scale_set_instances.generation is never populated on instance creation, so it stays 0 forever. Since ListScaleSetInstances(outdatedOnly=true) selects instances.generation < scale_sets.generation, after the scale set's generation is bumped even once, every instance — including ones created after the bump — is classified as outdated. The outdatedOnly filter therefore stops distinguishing stale runners from current ones.

Where

params/params.go:424-429 documents the intended semantics:

// Generation is the pool generation at the time of creating this instance.
Generation uint64 `json:"generation"`

But database/sql/scaleset_instances.go:52 builds the instance without it:

newInstance := Instance{
	ScaleSetFkID:      &scaleSet.ID,
	ScaleSet:          scaleSet,
	Name:              param.Name,
	Status:            param.Status,
	RunnerStatus:      param.RunnerStatus,
	OSType:            param.OSType,
	OSArch:            param.OSArch,
	CallbackURL:       param.CallbackURL,
	MetadataURL:       param.MetadataURL,
	GitHubRunnerGroup: param.GitHubRunnerGroup,
	JitConfiguration:  secret,
	AgentID:           param.AgentID,
}   // <- no Generation

database/sql/scalesets.go:414 is what bumps the parent:

updates["generation"] = scaleSet.Generation + 1

incrementGeneration is set by os_arch (:343), os_type (:350), image (:356), flavor (:369), provider_name? (:374), extra_specs (:396), runner_bootstrap_timeout? (:401), etc.

And the filter in database/sql/scaleset_instances.go:77-78:

if outdatedOnly {
	q = q.Where("instances.generation < (SELECT scale_sets.generation FROM scale_sets WHERE scale_sets.id = instances.scale_set_fk_id)")
}

So the comparison is 0 < N for every instance when N >= 1.

Reproduction (observed, not theoretical)

GARM running against an OpenStack external provider, custom scale set (max_runners: 8, runner_bootstrap_timeout: 6).

  1. Scale set starts at generation: 0.
  2. Update a generation-bumping field, e.g. extra_specs: garm-cli scaleset update 2 --extra-specs '{"disable_updates":true,"extra_packages":[...]}'
  3. garm-cli scaleset show 2 --format json → "generation": 1
  4. Let GARM create brand-new ephemeral instances, then inspect them:
{"name":"garm-yuq2e3ci7zfy","generation":0,"created_at":"2026-10-27T08:17:34Z"}
{"name":"garm-hw58q4p1czl5","generation":0,"created_at":"2026-10-27T08:17:54Z"}

Instances created after the bump still report generation: 0, i.e. they satisfy 0 < 1.

  1. Consequently outdatedOnly returns every runner:
garm-cli scaleset runner list 2 --format json | jq -r '.[]|[.name,.generation]|@tsv'
# garm-yuq2e3ci7zfy	0
# garm-hw58q4p1czl5	0

Impact

  • garm-cli scaleset runner rotate <scaleset-id> --outdated cannot express "rotate only runners from before the update". It selects all runners, so it behaves as an undifferentiated rotation.
  • Operators who bump extra_specs/image/os_* and then rotate --outdated to drain pre-update runners will also churn freshly created, correctly-configured runners — including ones already running jobs. That is the opposite of the documented purpose.
  • Anyone auditing "how many runners are stale" via the outdatedOnly query parameter gets a permanently wrong answer.

Expected

CreateInstance should persist the parent's current generation:

newInstance := Instance{
	...
	AgentID:    param.AgentID,
	Generation: scaleSet.Generation,
}

(and/or listInstancesBatched should join the parent generation rather than reading a stored column). After the fix, instances created after a bump must report the bumped generation, and outdatedOnly must return only instances whose generation is strictly less than the parent's.

Notes

  • Versions observed: garm daemon from main, garm-cli v0.2.1.
  • This is separate from cloudbase/garm#931 (CLI job list unmarshal error).
  • No generation column default/backfill was observed — existing rows also read 0.

wintrover avatar Oct 27 '26 08:10 wintrover

@gabriel-samfira I opened #945 for this. Could you please review it when you have a moment? Thank you!

RyoKusnadi avatar Nov 06 '26 02:11 RyoKusnadi