Skip to content

Give spored's hybrid-registry client a region (#899) - #902

Merged
scttfrdmn merged 3 commits into
mainfrom
fix/899
Oct 15, 2026
Merged

scttfrdmn merged 3 commits into
mainfrom
fix/899

Conversation

@scttfrdmn

Copy link
Copy Markdown
Contributor

Root cause

registry.NewPeerRegistry (pkg/registry/dynamodb.go) built its DynamoDB client with a bare config.LoadDefaultConfig(ctx). On an instance nothing ambient names a region: there's no AWS_REGION, no shared config, and the Go SDK only reads the region from IMDS if you pass WithEC2IMDSRegion. So endpoint resolution failed before any request was sent, and every Register, Heartbeat and Deregister failed with Missing Region. Every other spored client already pins identity.Region, which comes from the IMDS identity document (agent.go, fsx_mount.go, pool_worker.go).

Not MPI-specific. spored initialises the registry for any instance carrying spawn:job-array-id. buildJobArrayMemberConfig sets that tag on every --count job-array member, MPI or not. --mpi is just where it was noticed.

Which region

It's the instance's own region, not a fixed control-plane region. spawn-hybrid-registry is not one of the 21 tables in the infra account (docs/infra-account.md), and spored's credentials come from the instance role in the launching account. The table is created by spawn burst (registry.EnsureTable) in the CLI's account and region, and burst launches its instances into that same region from the same config.

Fix

  • NewPeerRegistry now pins identity.AWSRegion() and falls back to the ambient chain when that is empty.
  • New Identity.AWSRegion() treats the local provider's "local" placeholder (the default from LoadLocalConfig) as unset, so a client is never pointed at dynamodb.local.amazonaws.com.
  • The local provider's own DynamoDB client, used by DiscoverPeers, now uses the same region as registration. Before this, the two could hit different regions' tables.
  • spored run-queue (spawn launch --batch-queue) had the same bug in its S3 results uploader. It now uses config.WithEC2IMDSRegion(), which only kicks in when nothing else sets a region.

Tests

  • pkg/registry/region_test.go: with every ambient region source stripped (the instance's situation), the registry client's region is the instance's. The instance region also beats an ambient one, and ""/"local" fall back to ambient.
  • pkg/provider/region_test.go: Identity.AWSRegion is tested on the struct directly (rule 2). The local provider's DynamoDB client gets the configured region.
  • pkg/agent/queue_runner_region_test.go: a fake IMDSv2 server shows the queue runner taking its region from IMDS, and an explicit AWS_REGION still wins.

Each test was watched failing against a revert that compiles (false && region != "", a neutralised "local" check, a dropped WithEC2IMDSRegion), with go vet clean on the reverted tree.

make check: everything passes except TestGenerateWrapper_ChownFixesCrossUIDStickyUnlink_Docker, which needs a running Docker daemon that wasn't available locally. That's an environment problem unrelated to this change. All 9 nested modules pass.

Known follow-up (not in this PR)

With a region set, an ordinary spawn launch --count member will now reach DynamoDB and fail differently. spored-instance-role grants no DynamoDB actions, and the table only exists in an account where spawn burst has run. So the warning should change from Missing Region to an AccessDenied or ResourceNotFound error rather than disappear. Nothing reads the registry for non-hybrid arrays: EC2 peer discovery uses tags, and MPI peers come from the cohort Assembler. Limiting registration to hybrid members (local provider, or spawn:burst=true) would be a separate behaviour change.

Also still on the ambient-only chain, but not reached by any launch path in this repo: pkg/pipeline (NewStageDataHandler, GeneratePeerDiscoveryFile, downloadPipelineDefinitionFromS3) under spored run-pipeline-stage.

Fixes #899

@codecov

codecov Bot commented Oct 15, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 93.33333% with 1 line in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
pkg/agent/queue_runner.go 66.66% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

registry.NewPeerRegistry built its DynamoDB client from the ambient chain
alone. On an instance that chain names no region (no AWS_REGION, and the SDK
does not read IMDS unless asked), so every job-array member's Register failed
with "Missing Region". Pin it to identity.Region, as every other spored client
already does: `spawn burst` creates spawn-hybrid-registry in the region it
launches into, so the instance's region is where the table is. The infra
account holds no such table.

Identity.AWSRegion treats the local provider's "local" placeholder as unset, so
a local node without a configured region still uses the ambient chain; the
local provider's own DynamoDB client now uses the same region as registration.

`spored run-queue` had the same latent defect in its S3 results uploader; it
now falls back to the IMDS region via config.WithEC2IMDSRegion.
The fake IMDS server writes its identity document through a JSON encoder
instead of concatenating it into a raw ResponseWriter write, and the MPI
harness runs rank 0's block from a script file rather than bash -c.
@scttfrdmn
scttfrdmn merged commit e05f96b into main Oct 15, 2026
7 checks passed
@scttfrdmn
scttfrdmn deleted the fix/899 branch October 15, 2026 19:07
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.

spored on --mpi members: 'Failed to register with hybrid registry … DynamoDB PutItem … Missing Region'

1 participant