Skip to content

fix: --command honours a custom --completion-file; queue files may omit queue_id (#1131) - #1164

Merged
scttfrdmn merged 1 commit into
mainfrom
fix/1131-completion-file
Oct 19, 2026
Merged

scttfrdmn merged 1 commit into
mainfrom
fix/1131-completion-file

Conversation

@scttfrdmn

@scttfrdmn scttfrdmn commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Two bugs from #1131.

1. --command ignored --completion-file, so --on-complete never fired (cost leak).
spored watches the path in --completion-file (LaunchConfig.CompletionFile). The --command wrapper in pkg/launcher/bootstrap.go wrote both of its completion records to a hardcoded /tmp/SPAWN_COMPLETE. That covers the failed-prerequisite write and the normal exit write. With a custom path, spored never saw completion and the instance billed until its TTL.

  • BootstrapConfig.CompletionFile is new. BuildLinuxBootstrap renders it into both write sites with security.ShellQuote. The default is still /tmp/SPAWN_COMPLETE.
  • The wrapper runs mkdir -p "$(dirname -- <path>)" || true before each write. Without it, a custom path in a directory that doesn't exist yet would fail the write under set -e, and the same leak would come back.
  • The CLI (buildUserData) and the headless launcher.Provision both pass config.CompletionFile.
  • /tmp/SPAWN_EXITCODE is unchanged. It isn't tied to the completion path, and spored doesn't watch it.

2. --batch-queue files had to set queue_id.
cmd/launch_batchqueue.go generated an ID "if not set". But queue.LoadConfig had already run ValidateQueue, which rejects an empty queue_id, so that branch never ran.

  • The new queue.LoadUserConfig generates the ID before validating. --batch-queue now uses it, and the dead branch is removed.
  • queue.LoadConfig stays strict on purpose. The on-instance runner reads the copy the CLI uploaded, which always has an ID. If the runner invented a different ID, it would diverge from the one the CLI used for S3 paths and tags.

Docs follow-up needed (spore-host repo, not changed here). The example in docs/guides/batch-queue.md already omits queue_id, so before this fix the documented example failed to load. Its field table has no queue_id row. Add one: queue_id: no, generated as queue-<timestamp> if omitted.

Gates (each watched failing against a revert that compiles)

  • pkg/launcher/bootstrap_completion_file_test.go
    • Finds every cat > <target> <<JSONEOF write by regex (fails if it finds none).
    • Asserts there are exactly 2 writes, and each targets exactly '<custom path>', never the default.
    • Checks the default case still writes '/tmp/SPAWN_COMPLETE'.
    • Quoting test: the path is <tmp>/new dir/it's $HOME done. It runs bash -n on the whole script, then runs the rendered mkdir and cat under bash and checks the record lands at exactly that path.
    • Reverts tried: body hardcoded back to /tmp/SPAWN_COMPLETE; ShellQuote dropped; builder ignores cfg. All fail.
  • cmd/launch_completion_file_test.go: buildUserData with CompletionFile: /data/done must emit cat > '/data/done' <<JSONEOF. Revert tried: CLI passes "". It fails, while the pkg tests pass.
  • pkg/queue/queue_optional_id_test.go: LoadUserConfig generates a queue-… ID and keeps an explicit one; LoadConfig still rejects a missing ID. Revert tried: if false && …. It fails.
  • cmd/launch_batchqueue_id_test.go: launchWithBatchQueue with an ID-less file stops at the --instance-type check, which comes after loading and before any AWS call. Revert tried: back to queue.LoadConfig. It fails with queue_id is required.

Not covered

Checks

  • make check: fmt, vet (all GOOS), hermetic short tests, nested and tidy all pass.
  • staticcheck: GOOS=linux staticcheck ./... is clean. On darwin, SA4023 in pkg/agent/sys_other.go is known noise.
  • check-build-tags fails with identical output on unmodified origin/main on this machine, so it's local-only.
  • api/public-surface.txt is regenerated (+BootstrapConfig.CompletionFile), with a CHANGELOG ### Added entry.
  • semgrep scan --config=auto --error . is clean.

Fixes #1131

…it queue_id (#1131)

The --command wrapper wrote its completion record to a hardcoded
/tmp/SPAWN_COMPLETE while spored watched --completion-file, so a custom
path never fired --on-complete. Render the configured path, shell-quoted,
into both write sites.

queue.LoadConfig rejected an empty queue_id before the CLI's generate-if-
missing branch could run. Add LoadUserConfig, which generates the ID before
validating, for --batch-queue files; LoadConfig stays strict for the runner.

Fixes #1131
@scttfrdmn
scttfrdmn force-pushed the fix/1131-completion-file branch from d31af7f to 2fda43b Compare October 19, 2026 04:56
@codecov

codecov Bot commented Oct 19, 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 35f26b3 into main Oct 19, 2026
8 checks passed
@scttfrdmn
scttfrdmn deleted the fix/1131-completion-file branch October 19, 2026 05:08
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.

--command with a custom --completion-file never triggers --on-complete

1 participant