feat(heartbeat): write last-run.json at top of send-telemetry#148
Merged
ashishkurmi merged 3 commits intoJun 23, 2026
Merged
Conversation
Adds a local "I started" breadcrumb written to <install-dir>/last-run.json
as the first action of the send-telemetry path — before the enterprise
gate and before telemetry.Run acquires the singleton lock.
agent.error.log and scan-state.json only appear once a run gets far
enough to log a line or finish an upload. Several failure modes never
reach that point: a process killed mid-startup (e.g. the Windows
GUI-launcher teardown), a run that fails the enterprise gate, a lock it
can never acquire. The heartbeat records {written_at, pid, agent_version,
command, invocation_method, os} independent of all that, so:
- stale last-run.json -> the agent isn't being invoked (scheduler not
firing: battery policy, missing/broken task)
- fresh last-run.json + no server-side telemetry -> the agent runs but
dies/fails before upload
invocation_method reuses telemetry's scheduler-footprint detection, so a
scheduled fire is distinguishable from a manual run. The write is durable
against the abrupt termination it records: temp sibling, fsync, atomic
rename (mirrors internal/state.Save) — a kill leaves the previous or the
new file, never a truncated one. Best-effort: a write failure is logged
at debug and never affects the run.
ashishkurmi
approved these changes
Jun 23, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds a local "I started" breadcrumb written to /last-run.json as the first action of the send-telemetry path — before the enterprise gate and before telemetry.Run acquires the singleton lock.
agent.error.log and scan-state.json only appear once a run gets far enough to log a line or finish an upload. Several failure modes never reach that point: a process killed mid-startup (e.g. the Windows GUI-launcher teardown), a run that fails the enterprise gate, a lock it can never acquire. The heartbeat records {written_at, pid, agent_version, command, invocation_method, os} independent of all that, so:
invocation_method reuses telemetry's scheduler-footprint detection, so a scheduled fire is distinguishable from a manual run. The write is durable against the abrupt termination it records: temp sibling, fsync, atomic rename (mirrors internal/state.Save) — a kill leaves the previous or the new file, never a truncated one. Best-effort: a write failure is logged at debug and never affects the run.
What does this PR do?
Type of change
Testing
./stepsecurity-dev-machine-guard --verbose./stepsecurity-dev-machine-guard --json | python3 -m json.toolmake lintmake testRelated Issues