Skip to content

spored status shows the daemon's idle readings instead of a one-shot sample (#1090) - #1095

Merged
scttfrdmn merged 2 commits into
mainfrom
fix/1090
Oct 17, 2026
Merged

scttfrdmn merged 2 commits into
mainfrom
fix/1090

Conversation

@scttfrdmn

Copy link
Copy Markdown
Contributor

Fixes #1090.

Problem. Since #952 only the daemon's monitor loop samples the idle counters. spored status is a separate one-shot process with its own Agent, so its sample had no earlier one to delta against: CPU, network and disk always read unknown (single sample; assuming active), on every instance at every age. In the v0.131.1 idle test the daemon logged Not idle: Disk I/O 1204224 bytes every minute while status could show none of it.

Design. Mirrors the compute clock (#896):

  • pkg/agent/idlestate.go: IdleState (taken, idle, reason, CPU/network/disk readings with measured flags and why, last activity). The monitor loop's checkAndAct publishes each tick's evaluation via publishIdleState, right after evaluateIdle. The write is atomic (temp file and rename) and goes to /run/spored/idle-state.json (tmpfs). It is deliberately not fsynced: a per-minute disk write would itself count against idle (--idle-timeout never fires on an untouched default instance: system background I/O is 10-40x the 100 KB/min disk threshold #1093). Failures are logged once. The path is sysIdleStatePath: Linux only; Windows and other platforms return "", as for the compute clock. idleStatePath is a var so tests can use a temp dir.
  • IdleState.Fresh: taken within IdleStateFreshFor (150 s, two ticks plus margin), not zero, not in the future.
  • cmd/spored: buildStatusReport uses the daemon's fresh state for the readings, the idle decision and idle duration (from its last activity). Otherwise it falls back to the one-shot sample as before. daemonIdleState is the seam. The report gains IdleReading {source, age_seconds, reason} in the JSON output, and the table gains Idle check: with the daemon's verdict and its age, or daemon reading unavailable; one-shot sample.
  • spawn status passes spored's lines through (localizeSporedTimes only rewrites timestamps), and the new line carries no timestamp.

Verification.

  • New tests: TestCheckAndAct_PublishesTheIdleEvaluation, TestIdleState_Fresh, TestIdleState_RoundTrip, TestStatus_ShowsTheDaemonsIdleReadings (table and JSON), TestStatus_DaemonIdleDecisionDrivesTheIdleLine and TestStatus_LabelsTheOneShotFallback.
  • Each was watched failing against a compiling revert:
    • publish call removed → PublishesTheIdleEvaluation fails;
    • Fresh reduced to non-zero → Fresh fails;
    • daemon branch disabled (ok && false) → both daemon status tests fail;
    • one-shot label emptied → LabelsTheOneShotFallback fails.
  • pkg/agent, cmd/spored and the cmd status tests pass under bin/hermetic-exec.
  • go vet passes for linux, windows and darwin.
  • golangci-lint reports no findings in the changed lines.

@codecov

codecov Bot commented Oct 17, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 76.82927% with 19 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
pkg/agent/idlestate.go 72.09% 6 Missing and 6 partials ⚠️
cmd/spored/main.go 81.08% 6 Missing and 1 partial ⚠️

📢 Thoughts on this report? Let us know!

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 / spored status always show CPU, network and disk I/O as "unknown (single sample)"

1 participant