Skip to content

feat: choose and show instance location in search and create - #456

Open
theFong wants to merge 3 commits into
mainfrom
codex/create-region-selection
Open

theFong wants to merge 3 commits into
mainfrom
codex/create-region-selection

Conversation

@theFong

@theFong theFong commented Aug 22, 2026 •

Copy link
Copy Markdown
Member

Summary

brev create never sent location/subLocation outside the launchable path, so plain creates always landed in the catalog default location. For n2d-standard-2, that default is asia-south1. Users had no way to change it, and nothing showed it before the instance existed. This PR fixes both:

  • brev create --location <loc> [--sub-location <zone>] sends the location on the create request. If the catalog says a type isn't available in that location, the type is skipped like any other unavailable type, so a fallback chain moves on to the next one. --location also replaces a launchable's location and zone.
  • Placement is visible before creating. --dry-run and the pre-create log show where each type will land: the requested location, or the catalog default.
  • brev search gets a LOCATION column, location/sub_location/available_locations in --json, and a --location filter. Piped tables keep TYPE and TARGET_DISK first, so brev search | brev create --stdin is unchanged.
  • brev search locations lists every location with its providers and GPU/CPU type counts; --type shows where one type can be created.
  • One catalog for location data. brev search gpu and create's auto-selection now read the same catalog as search cpu, search locations, and brev create validation. See Catalog consistency fix for why.

How locations work

Command What LOCATION means
brev search gpu|cpu The type's default location: where brev create puts it without --location
brev search gpu|cpu --location X Only types available in X; the column shows X, where brev create --location X will put it
brev search locations [--type T] Every location (or every location for T) with type counts
brev create --location X Types not available in X are skipped; the request carries location/subLocation

Locations come from the catalog, not live capacity, so a listed location can still fail at create time for lack of capacity. That failure is handled like any other create error.

Fixes #454

What it looks like

Discover locations

$ brev search locations
 LOCATION                 PROVIDERS        GPU_TYPES  CPU_TYPES
 af-south-1               aws                      6         28
 africa-south1            gcp                      0         60
 ...
 europe-west4             gcp                    122        120
 ...
 us-central1              gcp,nebius             130        126
 us-east-1                aws,lambda-labs         53        136
 ...
 us-west2                 gcp                      0        104
 ...
Found 111 locations

$ brev search locations --type n2d-standard-2
 LOCATION                 PROVIDERS  GPU_TYPES  CPU_TYPES
 africa-south1            gcp                0          1
 asia-east1               gcp                0          1
 ...
Found 40 locations

$ brev search locations --type nope
No locations match the specified filters

$ brev search locations --json        # excerpt
  { "location": "af-south-1", "providers": ["aws"], "gpu_types": 6, "cpu_types": 28 },

The counts match brev search gpu|cpu --location <loc>. On the live catalog: us-west2 0/104, us-east-1 53/136, us-central1 130/126, from both commands.

Find where a type lands

$ brev search cpu --provider gcp --min-vcpu 2 --sort price
 TYPE                   PROVIDER  LOCATION     VCPUS  RAM      ARCH    DISK       $/GB/MO  BOOT  FEATURES  $/HR
 n2d-highcpu-2          gcp       asia-south1      2  2 GB     x86_64  10GB-16TB  $0.16    7m    SP        $0.05
 n2d-standard-2         gcp       asia-south1      2  8 GB     x86_64  10GB-16TB  $0.16    7m    SP        $0.07
 n1-highcpu-2           gcp       us-central1      2  2 GB     x86_64  10GB-16TB  $0.15    7m    SP        $0.09
 ...

$ brev search cpu --location us-west2 --sort price
 TYPE              PROVIDER  LOCATION  VCPUS  RAM      ARCH    DISK       $/GB/MO  BOOT  FEATURES  $/HR
 n2d-highcpu-2     gcp       us-west2      2  2 GB     x86_64  10GB-16TB  $0.16    7m    SP        $0.05
 n1-standard-1     gcp       us-west2      1  4 GB     x86_64  10GB-16TB  $0.17    7m    SP        $0.06
 n2d-standard-2    gcp       us-west2      2  8 GB     x86_64  10GB-16TB  $0.16    7m    SP        $0.07
 ...

$ brev search --location us-east-1 --gpu-name L4
 TYPE          PROVIDER  LOCATION   GPU   COUNT  VRAM/GPU  TOTAL VRAM  CAPABILITY  DISK       $/GB/MO  BOOT  FEATURES  VCPUS  $/HR
 g6.xlarge     aws       us-east-1  L4        1  24 GB     24 GB       8.9         10GB-16TB  $0.12    7m    SRP           4  $0.97
 g6.2xlarge    aws       us-east-1  L4        1  24 GB     24 GB       8.9         10GB-16TB  $0.12    7m    SRP           8  $1.17
 ...

$ brev search cpu --json        # excerpt
  "type": "n2d-standard-2",
  ...
  "location": "asia-south1",
  "sub_location": "asia-south1-a",
  "available_locations": ["africa-south1", "asia-east1", ..., "us-west2", "us-west3", "us-west4"]

With --location, the LOCATION column (and JSON location) shows the requested location, because that's where brev create --location will put the instance. Location matching is exact; a non-matching location returns an empty list.

Preview placement before creating

$ brev create mybox --type n2d-standard-2 --dry-run
n2d-standard-2 (location: asia-south1/asia-south1-a)

$ brev create mybox --type n2d-standard-2 --location us-west2 --sub-location us-west2-a --dry-run
n2d-standard-2 (location: us-west2/us-west2-a)

$ brev create mybox --type m8g.medium,n2d-standard-2 --location us-west2 --dry-run
m8g.medium (not available in us-west2), n2d-standard-2 (location: us-west2)

$ brev search cpu --location us-west2 --sort price | head -4 | brev create mybox --stdin --location us-west2 --dry-run
n2d-highcpu-2 (10GB disk, location: us-west2), n1-standard-1 (10GB disk, location: us-west2), n2d-standard-2 (10GB disk, location: us-west2)

Errors

$ brev create mybox --type n2d-standard-2 --sub-location us-west2-a
--sub-location requires --location

$ brev create loc-e2e-454-neg --type n2d-standard-2 --location us-east-1      # real run; nothing was provisioned
Attempting to create 1 instance(s) with 1 parallel attempts
Instance types to try: n2d-standard-2 (not available in us-east-1)

Trying n2d-standard-2 for 1 instance(s)...
Skipping: instance type "n2d-standard-2" is not available in location "us-east-1"; available locations: africa-south1, asia-east1, ..., us-west1, us-west2, us-west3, us-west4

Type n2d-standard-2 had failures, trying next type...

Warning: Only created 0/1 instances
could only create 0/1 instances

End-to-end evidence (real instance, 2026-11-25)

This reproduces #454 with a binary built from this branch. The instance was deleted right after the checks.

1. Create

$ brev create loc-e2e-454 --type n2d-standard-2 --location us-west2 --sub-location us-west2-a --timeout 900
Attempting to create 1 instance(s) with 1 parallel attempts
Instance types to try: n2d-standard-2 (location: us-west2/us-west2-a)

Trying n2d-standard-2 for 1 instance(s)...
[Worker 1] Trying n2d-standard-2 for instance 'loc-e2e-454'...
[Worker 1] n2d-standard-2 Success! Created instance 'loc-e2e-454'

Waiting for instance(s) to be ready...
You can safely ctrl+c to exit
  6zzci9zex: Ready
loc-e2e-454

2. Control plane (GET /api/workspaces/6zzci9zex, location fields only)

.status = RUNNING
.instanceType = n2d-standard-2
.region = us-west2
.environment.provision.Directive.CreateInstanceRequest.location = us-west2
.environment.provision.Directive.CreateInstanceRequest.sub_location = us-west2-a
.environment.instance.location = us-west2
.environment.instance.sub_location = us-west2-a

3. On the VM (GCP metadata server)

$ brev exec loc-e2e-454 'curl -s -H "Metadata-Flavor: Google" http://metadata.google.internal/computeMetadata/v1/instance/zone; echo; curl -s -H "Metadata-Flavor: Google" http://metadata.google.internal/computeMetadata/v1/instance/machine-type'
projects/<project>/zones/us-west2-a
projects/<project>/machineTypes/n2d-standard-2

4. Cleanup: brev delete loc-e2e-454. The API went DELETING → STOPPED → 404, and brev ls no longer lists it.

Without --location, the same type still defaults to asia-south1/asia-south1-a, as the first dry-run above shows.

Catalog consistency fix

The public catalog returns a different region variant for some GPU types depending on whether CPU types are requested. On 2026-11-25, 166 of 350 GPU types had a different default location, sub-location, available locations, and storage in the GPU-only listing, and 54 of them had a different price. The results were deterministic across repeated calls, so this isn't live capacity.

brev create validates against the org catalog. For all 166 types, the org catalog matches the CPU-inclusive listing, never the GPU-only one, on both default location and price. Before this change:

  • brev search gpu showed default locations and prices that differ from what brev create uses. For example, n1-highmem-16:nvidia-tesla-p4:2 showed us-east4 at $2.719/hr, but creates use us-central1 at $2.576/hr.
  • brev search gpu --location us-west2 would list 51 GPU types that brev create --location us-west2 then rejects.

So brev search gpu and create's auto-selection now read the CPU-inclusive catalog and keep GPU types. User-visible effect: corrected default locations and prices for those GPU types. Three Nebius gpu-l40s-d.* types that the org catalog doesn't have, and that brev create already rejects as unrecognized, no longer appear. The server-side inconsistency in the GPU-only listing is worth fixing separately.

Design notes

  • Validation uses the catalog brev create already loads. No extra fetch. The org catalog has one row per type, and every row lists its available_locations: on 2026-11-25 it returned 556 rows for 556 distinct types, all with locations. So the existing GetCloudCredID lookup is unchanged and needs no region awareness. If a type isn't in the catalog (for example a private launchable type), or the catalog lists no locations for it, the server stays the source of truth.
  • Exact matching only. There's one flag name (--location, matching the API field), and the same matching rule in search and create.
  • uniqueInstanceType=true stays. Fetching the org catalog with uniqueInstanceType=false also returns one row per type, with identical locations, so de-duplication hides nothing.
  • brev search locations is built from that same catalog and the same NVIDIA filter as search gpu, so its counts and the --location filters can't disagree.
  • --dry-run --type X now makes one public catalog request to show placement.

Validation

  • go test -race -count=1 ./pkg/cmd/gpucreate ./pkg/cmd/gpusearch ./pkg/store
  • go test -count=1 ./...: all packages pass except e2etest/setup, which panics on a hardcoded /home/ubuntu/brev-cli path, as it does on main.
  • golangci-lint run ./... (v2.0.2, the version in tools/go.mod): 0 issues.
  • Mutation check: the new behavior was deliberately broken 29 different ways: request fields, launchable override, create-time validation, auto-select filtering, sub-location check, dry-run placement, search filtering, table column, JSON fields, the locations counts, sorting, filters, and placeholder, and which catalog each command reads. A test failed every time.
  • New tests:
  • Manual checks: the live public catalog, a read-only check of the authenticated org catalog, and the real create above.

Prior work

This replaces the earlier version of this PR (previous head 81c94d8e) with a smaller rewrite on current main. It builds on the region-flag work in #393 by @hakhandelwal11.

`brev create` never set location/subLocation outside the launchable path,
so every plain create landed in the catalog's default location (for
n2d-standard-2 that is asia-south1) with no way to change it or see it.

- create: add --location and --sub-location. Types whose catalog
  available_locations do not include the location are skipped like any
  other unavailable type in a fallback chain. --location overrides a
  launchable's location and its sub-location.
- create: dry-run and the pre-create log show where each type will land
  (requested location or catalog default).
- search: add a LOCATION column and location, sub_location and
  available_locations JSON fields; add --location to list types
  available in a location. Piped tables keep TYPE and TARGET_DISK first.

Fixes #454
@theFong
theFong force-pushed the codex/create-region-selection branch from 81c94d8 to 5e3479b Compare November 25, 2026 19:12
@theFong theFong changed the title feat: add region-aware instance search and creation feat: choose and show instance location in search and create Nov 25, 2026
@codecov

codecov Bot commented Nov 25, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 92.18107% with 19 lines in your changes missing coverage. Please review.
✅ Project coverage is 40.11%. Comparing base (6c85c4e) to head (2ac75af).
⚠️ Report is 18 commits behind head on main.

Files with missing lines Patch % Lines
pkg/cmd/gpucreate/gpucreate.go 89.69% 8 Missing and 2 partials ⚠️
pkg/cmd/gpusearch/locations.go 90.32% 6 Missing and 3 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #456      +/-   ##
==========================================
+ Coverage   33.51%   40.11%   +6.60%     
==========================================
  Files         153      137      -16     
  Lines       21654    20287    -1367     
==========================================
+ Hits         7257     8139     +882     
+ Misses      13624    11336    -2288     
- Partials      773      812      +39     
Flag Coverage Δ
Linux 40.11% <92.18%> (+6.60%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

theFong and others added 2 commits November 25, 2026 20:03
- 'brev search locations' lists every location with its providers and GPU
  and CPU type counts; --type shows where one type can be created, and
  --provider and --json work as in the other search commands. Counts match
  'brev search gpu|cpu --location'.
- 'brev search gpu' and create's auto-selection now read the CPU-inclusive
  public catalog and keep GPU types. The GPU-only listing returned a
  different region variant for 166 of 350 GPU types: a different default
  location and available locations than the org catalog 'brev create'
  validates against, and a different price for 54 of them. It also listed
  3 types the org catalog does not have.
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.

brev create cannot set region: location/subLocation exist in the request struct but are only populated via launchables

2 participants