Skip to content

fix(sizer): on a price tie prefer the smallest type that fits (#610) - #611

Merged
scttfrdmn merged 1 commit into
mainfrom
fix/610-size-tiebreak-smallest
Sep 25, 2026
Merged

scttfrdmn merged 1 commit into
mainfrom
fix/610-size-tiebreak-smallest

Conversation

@scttfrdmn

Copy link
Copy Markdown
Contributor

Summary

Fixes #610: a TaskSpec asking for 16 vCPUs in the hpc7g family was sized to hpc7g.16xlarge (64 vCPUs). Two changes — the tie-break, and documenting the escape hatch that already existed.

Root cause — not "prefers the largest", but lexicographic

taskproto.Size ranked by on-demand price and then tie-broke on the instance-type name:

// Tie-break deterministically by type name.
return matched[i].InstanceType < matched[j].InstanceType
$ printf '%s\n' hpc7g.4xlarge hpc7g.8xlarge hpc7g.16xlarge | sort
hpc7g.16xlarge
hpc7g.4xlarge
hpc7g.8xlarge

hpc7g.16xlarge won because '1' < '4'. On hpc7g every size is the same price (you rent the socket, not the cores), so the tie was reached legitimately and then resolved by a string comparison that has nothing to do with size.

Crucially this was not a bias toward the largest: on a family sized 2x/4x/8xlarge, the same comparison picks the smallest and looks entirely correct. That's why it survived — and it's why the regression test has to use a 1-prefixed double-digit size or it proves nothing.

The fix

Tie-break on vCPUs, then memory, then name (name kept last purely for determinism). Every candidate already satisfies the request, so on an equal rate the smallest is what the spec asked for and it minimises blast radius. On hpc7g the bill was unchanged, but the same tie-break would over-provision at cost on any family with genuinely equal-priced sizes.

resources.instance_type already existed — the real gap was documentation

The issue's second ask ("allow a spec to pin an exact instance type") has been implemented since #413: Size() honours resources.instance_type as its first action, short-circuiting candidate search and pricing entirely. But it was documented only in docs/pooled-task-execution-design.md and docs/workflow-adapter-protocol-rfc.md — nothing user-facing, not docs-gen/task.md, not --help. The reporter needed exactly this (sweeping three equal-spec hpc7g sizes, which cpu/memory_gib cannot distinguish) and reasonably concluded it didn't exist.

task run --help now documents the pin, the price-tie rule, and how resources.families differs from pinning. A capability described only in an internal design note is, in practice, missing.

Tests

  • TestSize_PriceTiePrefersSmallest — the hpc7g case; verified to fail against the previous comparator (tie went to "hpc7g.16xlarge" / VCPUs = 64, want 16) and pass after. It also asserts its own fixture still contains a 1-prefixed double-digit size, so it can't silently become vacuous.
  • TestSize_PriceTiePrefersLessMemoryWhenVCPUsEqual — the second rung.
  • TestSize_PriceTieFallsBackToNameWhenSameSize — equal price and size stays deterministic across repeated runs.
  • All pre-existing sizer tests unchanged and passing; gofmt/go vet ./.../go build ./... clean; make gen-docs run and docs-gen/task.md committed.

Expected release sizing: PATCH (behaviour fix + docs; no API change).

Fixes #610

Size() ranked by price and then tie-broke on the instance-type NAME, which is
lexicographic and therefore semantically arbitrary. On hpc7g — where every size
costs the same because you rent the socket rather than the cores —
'hpc7g.16xlarge' sorts before 'hpc7g.4xlarge' because '1' < '4', so a 16-vCPU
request was sized to a 64-vCPU instance. Note this was NOT a bias toward the
largest: on a 2x/4x/8xlarge family the same comparison picks the smallest and
looks correct, which is why it survived.

Tie-break is now vCPUs, then memory, then name (name retained last purely for
determinism). Every candidate already satisfies the request, so the smallest is
what the spec asked for and it minimises blast radius; on a family with genuinely
equal-priced sizes the old behaviour over-provisioned at cost.

Also documents resources.instance_type in 'task run --help': it has pinned an
exact type since #413 (short-circuiting candidate search and pricing) but was
described only in internal design docs, so the reporter concluded there was no
way to sweep three equal-spec hpc7g sizes.

The regression test uses hpc7g deliberately — a 2x/4x/8xlarge fixture would pass
under the old code too, making such a test vacuous — and was verified to fail
against the previous comparator before the fix landed.

Fixes #610
@codecov

codecov Bot commented Sep 25, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@scttfrdmn
scttfrdmn merged commit 927c86e into main Sep 25, 2026
7 checks passed
@scttfrdmn
scttfrdmn deleted the fix/610-size-tiebreak-smallest branch September 25, 2026 19:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant