Skip to content

fix(spored): make status read-only — it was registering DNS on every call (#733) - #748

Merged
scttfrdmn merged 1 commit into
mainfrom
fix/733-status-no-side-effects
Oct 8, 2026
Merged

scttfrdmn merged 1 commit into
mainfrom
fix/733-status-no-side-effects

Conversation

@scttfrdmn

Copy link
Copy Markdown
Contributor

Closes #733. The last of the ten issues from the 2026-10-07 demo run.

It was not an output nit

spored status constructs a full agent, and NewAgent registers DNS as part
of construction
: an HTTP POST that mutates a Route53 record, plus an EC2 tag
write via recordDNSStatus. So spawn status — a query — performed a
control-plane write on every invocation. Polling it in a loop is the normal
way to watch a job, and the demo guide instructs presenters to do exactly that,
so each demo run made several of those writes.

The reported symptom was spored's initialization lines leaking into the status
output, with Warning: Failed to register DNS: DNS API returned HTTP 403 above
the summary. Those lines were the symptom. The warning was only visible
because the write was failing — had it succeeded, nothing would have printed
and the behaviour would still have been wrong.

#540's fix was correct and could not have helped: separating stdout from stderr
does nothing about a side effect, and emitStatus was already careful about the
streams.

The fix

NewAgentForQuery builds the agent with no side effect:

skipped in query mode why it is a side effect
DNS registration HTTP POST mutating Route53, plus a tag write
EBS cost lookup writes spawn:ebs-hourly-cost
job-array registry registration writes, and starts a heartbeat goroutine
peer discovery an API call a query has no use for
plugin loading runs plugin resolution
initialization logging the visible symptom

State a query legitimately needs — dnsDomain, the notifier struct, the plugin
runtime — is still constructed, so the report can describe them.

Five non-daemon subcommands switch over: status, reload, config get,
config set, config list. The two mutating ones are deliberate: config set
performs its own intended write and should not also register DNS as a
side effect of setting a TTL.

One constructor with the side effects behind a flag, rather than the parallel
NewAgentForQuery the issue floated — a second constructor duplicating all that
setup would drift. The correct long-term shape is still splitting construction
from a Start/Activate the daemon calls; this is the narrow version of it.

Verification

revert fails
DNS registration ungated query mode built a DNS client, so the registration block ran — that is #733
registry + peer discovery ungated query mode discovered peers 1 time(s) + started a heartbeat goroutine
activation disabled for the daemon NewAgent no longer discovers peers — activation was disabled, not relocated

That third one is the one I most wanted. The cheap way to make this issue's
symptom go away is to stop registering DNS at all, which would break the feature
rather than relocate it — so the test asserts both directions.

My first version of the test hand-rolled a Provider and failed to compile
against the interface (missing CheckSpotInterruption). It now embeds the
package's existing stubProvider, so adding a method to Provider cannot break
it — the kind of thing that looks like tidiness and is actually the difference
between a test that survives and one that gets deleted.

gofmt, go vet ./..., go test -short ./... (all green), make check-docs,
changelog gate, semgrep scan --config=auto --error (0 findings).

On the shared fix with #741

You suggested #733 and #741 might share one fix, and I flagged it as unconfirmed.
Having now done both: they don't. #741's DNS registration shells out to ssh
from the controller and was fixed by gating it on SSH readiness and bounding
its retry; this one is in-process in spored and is fixed by not doing it at
all in query mode. Same API at the far end, genuinely different call paths. Both
are now closed, but separately.

Next for the guide

Once this merges and ships, the note you added to hide the 403 can come out — the
write it warns about no longer happens on the status path.

@codecov

codecov Bot commented Oct 8, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 50.00000% with 12 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
pkg/agent/agent.go 63.15% 2 Missing and 5 partials ⚠️
cmd/spored/main.go 0.00% 5 Missing ⚠️

📢 Thoughts on this report? Let us know!

…call

`spored status` constructed a full agent, and NewAgent registers DNS as
part of construction: an HTTP POST that mutates a Route53 record, plus an
EC2 tag write via recordDNSStatus. So `spawn status`, a query, performed
a control-plane WRITE on every invocation — and polling it in a loop (the
normal way to watch a job, and what the demo guide tells presenters to
do) meant one write per poll.

The reported symptom looked cosmetic: spored's init lines leaking into
the status output with "Warning: Failed to register DNS: DNS API returned
HTTP 403" above the summary. Those lines were the symptom. The warning
was only visible BECAUSE the write was failing — had it succeeded,
nothing would have printed and the behaviour would still be wrong.

NewAgentForQuery builds the agent with no side effect: no DNS
registration, no EBS cost lookup (a tag write), no job-array registry
registration, no heartbeat goroutine, no plugin loading, no init
logging. State a query legitimately needs — dnsDomain, the notifier
struct, the plugin runtime — is still constructed.

Five non-daemon subcommands switch to it: status, reload, config get,
config set, config list. The two mutating ones are included
deliberately: `config set` does its own intended write and should not
also register DNS.

One constructor with the side effects behind a flag, not a parallel
constructor that would drift. #540 was correct but could not have helped
here: separating stdout from stderr does nothing about a side effect.

Gates confirmed to fail on revert: DNS registration ungated, registry +
peer discovery ungated, and — importantly — activation disabled for the
DAEMON, which would "fix" #733 by breaking DNS registration entirely.
That third one is why the test asserts both directions.

My first version of the test hand-rolled a Provider and failed to
compile against the interface (missing CheckSpotInterruption). It now
embeds the package's existing stubProvider, so adding an interface
method cannot break it.
@scttfrdmn
scttfrdmn force-pushed the fix/733-status-no-side-effects branch from 2c715ab to 686c2ec Compare October 8, 2026 04:06
@scttfrdmn
scttfrdmn merged commit 45815b3 into main Oct 8, 2026
7 checks passed
@scttfrdmn
scttfrdmn deleted the fix/733-status-no-side-effects branch October 8, 2026 04:16
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.

spawn status performs a live DNS registration write (and re-runs agent init) on every invocation

1 participant