Skip to content

feat: tag everything calque creates spore-host:managed-by=calque (calque#227) - #233

Merged
scttfrdmn merged 1 commit into
mainfrom
feat/227-tags
Nov 16, 2026
Merged

scttfrdmn merged 1 commit into
mainfrom
feat/227-tags

Conversation

@scttfrdmn

@scttfrdmn scttfrdmn commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #227. Part of spore-host/spore-host#752 (Leave no trace). Builds on #231 (calque#226).

What changes

Everything calque creates gets the libs/tags v0.52.0 set (spore-host:managed-by=calque, spore-host:scope, spore-host:created, spore-host:schema) plus calque:managed=true. The tags are built in one place, internal/calquetags.

Resource Before After (scope)
SQS calque-pool-<model> untagged tagged at create, pool:<model>, + calque:pool-model; an existing queue is converged (ListQueueTags + TagQueue)
SQS calque-fleet-<run-id> untagged tagged at create, run:<id>, + calque:fleet-run, calque:run-id
SG calque-nfs-sg untagged TagSpecifications, vpc:<id>; an existing group gets CreateTags
Roles and profiles calque-real-run-<hash> / calque-pool-worker / calque-fleet-worker spawn's spawn:* only IAMRoleConfig.Tags on create, converged on every use with TagRole/TagInstanceProfile; bucket:<b> / pool-workers / fleet-workers
Baked AMI and snapshots calque:baked-* + the spore-host set, run:<id>
Instances (real/smoke/ramp/spawn-run/fleet/ami-bake) calque:* + the spore-host set, run:<id>
gpuprobe instance none spore-host set + calque:managed, calque:command=gpuprobe
Pool worker after pool scale calque:pool-model, calque:role only the full set, pool:<model>
S3 objects written from Go (artifacts, manifest, Dockerfile, results, summaries) untagged Tagging with managed-by, schema, scope, calque:run-id

managed-by on calque-launched instances is calque. calque terminates them, drains the fleet and deletes the pool, so it owns their lifecycle. spawn's TTL backstop keys on spawn:* and still applies. spawn v0.131.0's buildTags appends caller tags after its own and keeps the first of any repeated key. It writes no spore-host:* key, so calque's value survives. I checked this with a throwaway test against the v0.131.0 source: a caller spawn:managed=false is dropped, and a caller spore-host:managed-by=calque survives. If spawn#1652 adds its own spore-host:managed-by to the instance tags, it will win over calque's. That needs handling on the spawn side; see the comment on spawn#1652. For roles, calque's TagRole after create already corrects it.

Converge never moves an existing spore-host:created, so reuse doesn't reset cleanup's grace clock. A role, SG or queue from an older calque gets "now".

Queue expiry. Pool queues now set MessageRetentionPeriod=345600. That is SQS's default, which they already had. Any other value would make CreateQueue fail with QueueAlreadyExists on every existing pool. Retention expires messages, not queues. This PR corrects the fleet warning "12h retention will reap", the RunQueueName/CreateRunQueue comment and the DeleteQueue comment, which all claimed otherwise. The real deleter is calque#228.

New IAM actions

  • Caller: iam:TagRole, iam:TagInstanceProfile, s3:PutObjectTagging, sqs:TagQueue, sqs:ListQueueTags. ec2:CreateTags and iam:GetRole/iam:GetInstanceProfile were already needed.
  • Instance roles calque manages: s3:PutObjectTagging on the staging/results bucket (RealRunPolicy, WorkerPolicy, FleetWorkerPolicy).
  • A missing tagging permission never fails a run. calque creates or writes the resource untagged and prints a [tags] WARNING. S3 resends the write untagged once and then stops asking for tags. This matters for a pool worker still on an older grant. docs/guide/getting-started.md lists the actions.

Tests

  • internal/awstest: an in-process SDK seam. It answers at the end of Initialize, so a real client runs its own middleware, including tagtest's Detector. tagtest only sees real SDK clients, so it can't check calls made through an interface fake.
  • tagtest is wired into: CreatePoolQueue/CreateRunQueue; spawn v0.131.0's real CreateOrGetInstanceProfile (pool and real-run roles; CreateRole and CreateInstanceProfile must be tagged); EnsureNFSSecurityGroup; spawn's real CreateAMI (image and snapshot specs); UploadArtifacts/UploadDockerfile/WriteManifest/S3Sink; S3Results; warmd putJSON.
  • Converge paths are tested on an older untagged queue, role and SG, along with the AccessDenied fallbacks for SQS and S3. One allow-list entry, with its reason, covers the deliberate untagged SQS fallback.
  • Revert check: TestCreatePoolQueue_TaggedAtCreate and TestCreateRunQueue_TaggedAtCreate against main's queue.go fail with tagtest: SQS CreateQueue would create a resource without spore-host:managed-by=calque. Dropping the Tags: line from ensureWorkerProfile fails TestEnsureWorkerProfile_SpawnCreatesTheRoleTagged on both CreateRole and CreateInstanceProfile.

Not tagged yet

Objects the instance writes with aws s3 cp/sync aren't tagged: bootstrap logs, ami-bake markers, occupancy files and Volume commits. aws s3 cp can't tag. Follow-up: #234.

Not verified against AWS

None of this has been run against AWS; the tests use fakes only. Two things depend on SQS behaviour I could not check live:

  1. CreateQueue ignores tags when the queue already exists. I'm relying on the documented rule that only attributes must match, and the code has a fallback: it retries untagged on QueueAlreadyExists.
  2. Whether a tagged CreateQueue needs sqs:TagQueue, as documented.

Both are worth one live calque pool create against an existing pool before release.

Gates

gofmt -l . clean · go vet ./... · go test ./... (uv present, parse contract tests ran, 0 skips) · go test -race on changed packages · golangci-lint 0 issues (local v2.15.0; CI pins v2.12.2) · uvx ruff check . · semgrep on changed files: one finding, dangerous-exec-command at cmd/warmd/main.go (the occupancy sampler). It's on a line this PR doesn't touch, and it's identical on main.

libs v0.51.2 → v0.52.0 (now direct). spawn stays at v0.131.0.

…que#227)

Part of the leave-no-trace epic (spore-host/spore-host#752). calque's
cleanup (calque#228) can only remove what it can recognise, and the SQS
queues, calque-nfs-sg and the IAM roles carried no calque tag at all.

Every resource now gets the libs/tags v0.52.0 spore-host:* set plus
calque:managed=true, built in one place (internal/calquetags):

- SQS calque-pool-<model> / calque-fleet-<run-id>: tagged at create, plus
  calque:pool-model / calque:fleet-run. An existing queue is converged
  (ListQueueTags + TagQueue), since CreateQueue returns it untouched.
  Without sqs:TagQueue the queue is created untagged with a warning, as
  spawn's taskpool does.
- calque-nfs-sg: TagSpecifications at create; an existing group is
  converged with CreateTags.
- calque-real-run-<hash>, calque-pool-worker, calque-fleet-worker roles
  and profiles: IAMRoleConfig.Tags (spawn v0.131.0 applies them only on
  create), then converged on every use with TagRole/TagInstanceProfile.
  This also keeps managed-by=calque if spawn ever stamps its own.
- Baked AMIs and snapshots, and every instance calque launches (now
  including gpuprobe's and scaled-up pool workers, which had no or partial
  tags). managed-by is calque on these: calque owns their lifecycle;
  spawn's TTL backstop keys on spawn:* and is unchanged. spawn v0.131.0
  appends caller tags after its own, first key wins, and writes no
  spore-host:* key, so calque's value survives.
- S3 objects calque writes from Go, on both sides: PutObject Tagging with
  calque:run-id; the manifest carries run_id so warmd can tag its results
  and summary. The instance roles gain s3:PutObjectTagging; without it a
  write is resent untagged once with a warning, never failed.

Converge never moves an existing spore-host:created, so reuse doesn't
reset cleanup's grace clock.

Pool queues now state MessageRetentionPeriod=345600 (SQS's default, which
they already had; any other value would make CreateQueue fail on existing
pools). Retention expires messages, not queues: the fleet warning that
claimed "12h retention will reap" and the matching queue.go comments are
corrected.

Tests drive real SDK clients through a new in-process seam
(internal/awstest) with libs/tags/tagtest installed, including spawn's own
CreateOrGetInstanceProfile and CreateAMI. Reverting the queue or role
tagging makes them fail.
@scttfrdmn

Copy link
Copy Markdown
Contributor Author

LIVE check (dev 435415984226, us-east-1, 2026-11-16, throwaway queue created and deleted): a tagged CreateQueue on an existing untagged queue fails with QueueAlreadyExists: A queue already exists with the same name and a different value for tags. So SQS treats tags like attributes. The PR's untagged retry plus convergeQueueTags is the path every existing pool takes. It's also the path a re-create by this version takes: spore-host:created differs on each create, so the tags differ. The comment's "in case tags count too" is now confirmed; worth rewording in a follow-up.

@scttfrdmn
scttfrdmn marked this pull request as ready for review November 16, 2026 20:09
@scttfrdmn
scttfrdmn merged commit e498c68 into main Nov 16, 2026
7 checks passed
@scttfrdmn
scttfrdmn deleted the feat/227-tags branch November 16, 2026 20:10
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.

Tag everything calque creates (spore-host:managed-by=calque)

1 participant