Skip to content

fix(spored): stop reporting CPU and stopped-time assumptions as measurements (#734, #735) - #746

Merged
scttfrdmn merged 1 commit into
mainfrom
fix/734-735-status-report
Oct 8, 2026
Merged

scttfrdmn merged 1 commit into
mainfrom
fix/734-735-status-report

Conversation

@scttfrdmn

Copy link
Copy Markdown
Contributor

Closes #734. Closes #735. Both are in spored status's report, and both are the
same defect in different clothes: a value that cannot be known rendered as a
value that is known.

#734 — CPU: 0.0% on an instance running at 100%

Three states collapsed into one float, two of them sentinels a caller could not
tell from data:

state returned
/proc/stat unreadable 100.0 "assume active"
no previous sample (first call) 100.0 "assume active"
zero-length sample interval 0.0 ← the broken one

The last returned the most reassuring possible value from a no-information
state, while both its siblings returned the most conservative one — and
getNetworkBytes does the same thing, returning its assume-active value on an
unreadable counter. So it was inconsistent with every neighbour.

spored status hits all of it in a single process: it reads CPU once via
IsIdle and again for the report, microseconds apart, against a function that
overwrites its own previous sample. Hence the reported pair — Not idle: CPU usage 100.00% beside CPU: 0.0%, same instance, same breath, neither a
measurement.

  • cpuUsage returns (value, measured); an unknown reading is the conservative
    100.0.
  • buildStatusReport samples once, after IsIdle, and reuses it. The
    ordering is now deliberate and commented, since IsIdle consumes a sample.
  • The table prints unknown (single sample; assuming active) rather than a
    number. For a one-shot spored status that is the common case, not an edge
    one — there is no prior sample to delta against.
  • JSON gains cpu_measured, so a dashboard cannot plot an assumption.
  • isIdle logs which kind of reading it had, so the two numbers in one status
    output can no longer look like a contradiction.

The part that outlives the display: that branch feeds the idle decision, so
the one place returning "0% busy" from no information was the one that could let
--idle-timeout stop a busy instance. The daemon's ticker spaces calls ≥1s
apart, so it was not reachable in practice — which makes it latent, not harmless.
One call site away from stopping a working box is not a property worth keeping,
and it is cheap to fix now.

#735 — boot time reported as stopped time

Elapsed: 22m 13s  (20m 0s compute · 2m 13s stopped)

on an instance that had never been stopped. stoppedTime was a residue —
elapsed-since-launch minus compute-since-spored-started — so it absorbed boot,
cloud-init and package installs, and asserted a specific, checkable fact from
arithmetic that cannot distinguish being stopped from never having started.

Boot time is now measured, not inferred: spored knows both the instance
launch time and its own start, so bootTime = sporedStart - launchTime is
directly computable. It is reported as its own term, which is worth having —
a slow boot is a real thing to notice. Stopped time appears only when there is
evidence of a stop: compute time carried over from a previous run through the tag
(HasPriorComputeTime), which is non-zero only after a genuine stop/start. A
first boot now shows (20m 0s compute · 2m 13s boot) and claims nothing it
cannot support.

A testability fix that was load-bearing

sysReadCPUTimes is now reached through a package var. It is build-tagged, and
the darwin implementation always returns errBadProcStat — so on the platform
most development happens on, every branch of the delta logic except the first was
unreachable
, and #734 could not be reproduced locally at all. The issue had to
record that as an open caveat; it no longer is.

Verification

revert fails
zero delta returns a measured 0.0 zero elapsed time reported 0% CPU — that is #734: the most reassuring possible value from a no-information state, and it is what feeds isIdle
stopped time as the raw residue StoppedSeconds = 3600 on an instance that was never stopped — that is boot time mislabelled (#735)
print an unmeasured sentinel as a reading an unmeasured sentinel was printed as a reading

Also asserted explicitly: a measured 0% stays distinguishable from an
unknown 0%, which is the entire point of the second return value — CPU: 0.0% meant both, and on the reported instance it meant the second while looking
like the first. And that compute+boot+stopped accounts for elapsed, so the
residue is split rather than partly discarded.

One of my own tests failed for its own reason first: the status fixture's agent
is constructed at test time, so compute rounds to zero and the pre-existing
computeTime > 0 guard suppresses the whole breakdown. That guard is defensible
and out of scope, so the test now sets the reported shape explicitly rather than
me changing production code to suit a fixture.

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

Remaining from the demo notes

#733 (spawn status performs a DNS registration write on every poll) and #736
(terminated and shutting-down instances invisible to lookup).

@codecov

codecov Bot commented Oct 8, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 72.50000% with 11 lines in your changes missing coverage. Please review.

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

📢 Thoughts on this report? Let us know!

…rements

Three states collapsed into one float, two of them sentinels a caller
could not distinguish from data:

  /proc/stat unreadable       -> 100.0  "assume active"
  no previous sample          -> 100.0  "assume active"
  zero-length sample interval ->   0.0  <- the broken one

The last returned the most REASSURING possible value from a
no-information state while both siblings returned the most conservative
one. `spored status` hits all of it in one process: it reads CPU once via
IsIdle and again for the report, microseconds apart, against a function
that overwrites its own previous sample. Hence `Not idle: CPU usage
100.00%` beside `CPU: 0.0%` — same instance, same breath, neither a
measurement.

- cpuUsage returns (value, measured). An unknown reading is the
  conservative 100%, consistently with its siblings and with
  getNetworkBytes.
- buildStatusReport samples ONCE, after IsIdle, and reuses it.
- The table prints "unknown (single sample; assuming active)" rather than
  a number; JSON gains cpu_measured so a consumer cannot plot an
  assumption.
- isIdle logs which kind of reading it had, so the two numbers in one
  status output can no longer look like a contradiction.

That branch also feeds the idle decision, so the one place returning "0%
busy" from no information was the one that could let --idle-timeout stop
a busy instance. The daemon's ticker spaces calls far enough apart that
it was not reachable in practice — but one call site away from stopping a
working box is not worth keeping.

a residue — elapsed-since-launch minus compute-since-spored-started — so
it absorbed boot, cloud-init and package installs and asserted
`2m 13s stopped` on an instance that was never stopped.

Boot time is now measured, not inferred: spored knows both the launch
time and its own start. It is reported as its own term, so a slow boot is
visible. Stopped time appears only with real evidence of a stop — compute
carried over from a prior run through the tag (HasPriorComputeTime) — so
a first boot shows "(20m 0s compute · 2m 13s boot)".

sysReadCPUTimes is now reached through a package var. It is build-tagged
and the darwin implementation always errors, so on the platform most
development happens on every branch of the delta logic except the first
was unreachable — #734 could not be reproduced locally at all before
this.

Gates confirmed to fail on revert: a measured 0.0 from a zero delta, the
raw residue as stopped time, and printing an unmeasured sentinel as a
reading.

One test of mine initially failed for its own reason: the status fixture's
agent is created at test time, so compute rounds to zero and the
pre-existing `computeTime > 0` guard suppresses the whole breakdown. That
guard is fine; the test now sets the reported shape explicitly.
@scttfrdmn
scttfrdmn force-pushed the fix/734-735-status-report branch from 8b33c3e to 0a2be04 Compare October 8, 2026 03:50
@scttfrdmn
scttfrdmn merged commit a614be0 into main Oct 8, 2026
7 checks passed
@scttfrdmn
scttfrdmn deleted the fix/734-735-status-report branch October 8, 2026 04:02
scttfrdmn added a commit that referenced this pull request Nov 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant