Skip to content

fix(heartbeat): degrade when the chain fails to verify or a configured anchor goes stale - #518

Merged
blitzcrieg1 merged 4 commits into
masterfrom
fix/318-heartbeat-chain-anchor-staleness
Nov 28, 2026
Merged

blitzcrieg1 merged 4 commits into
masterfrom
fix/318-heartbeat-chain-anchor-staleness

Conversation

@blitzcrieg1

Copy link
Copy Markdown
Owner

Closes #318.

What

The heartbeat already attested the trail head and Merkle root, but stayed success while the local chain was broken or an operator's external anchor commitment had quietly stopped. Two new definite facts now degrade the beat:

Chain verification. Each beat runs verify_trail_tail over the newest 200 records: they must link, each hash must recompute, and the file must still end where the sidecar says the writer stopped. A full genesis walk is agentmetry verify's job; the tail is where appends, crashed writes and tail deletions land, at a cost bounded by the window and not by trail age. Broken chain degrades with LOCAL CHAIN FAILED TO VERIFY: <message> as the loudest degrade reason. A machine with no trail yet attests chain_verified: null, not a degrade: a fresh install and a tampered one must not read identically.

Anchor staleness. Only a log configured via AGENTMETRY_ANCHOR_LOG is checked: the sibling default sits on the same disk an attacker would rewrite, and a machine that never anchored should not degrade forever. The newest checkpoint applicable to this trail older than AGENTMETRY_ANCHOR_STALE_MINUTES (default 1440, 0 disables the age check) degrades the beat; a configured log with no readable checkpoint for this trail degrades as silent. Checkpoints naming a different trail are skipped rather than scored, the same cry-wolf rule verify_anchors already follows.

The Sigma rule agentmetry_recorder_degraded matches any degraded beat, so both new causes flow into existing customer detections; its description and field list now name them.

Why it is shaped this way

  • degraded stays a definite claim: only failures that say the record or the commitment are impaired set it, never an unconfigured or absent anchor.
  • The anchor facts carry a path only when the operator configured one, which is the same standard policy_rejected already meets (locations an admin chose, never developer content).

Evidence

  • pytest tests/test_heartbeat.py: 27 passed (10 new: healthy chain attests verified; tampered record degrades with the failure message; no trail is not a tamper alarm; fresh anchor stays green; stale anchor degrades; configured-but-silent log degrades; another trail's checkpoints are not scored; sibling default is not the beat's business; the limit is configurable and 0 disables)
  • pytest tests/test_trail_anchor.py tests/test_trail_chain.py tests/test_coverage_observed.py tests/test_supply_chain_boundaries.py tests -k sigma: all pass
  • python -m agentmetry.cli benchmark: 119 cases, 21 rules, 63 firings, 0 missed, 0 false positives (detection untouched)
  • ruff check agentmetry tests: clean

blitzcrieg1 and others added 4 commits November 27, 2026 23:20
…d anchor goes stale (#318)

The beat already carried the trail head and Merkle root, but said success
while the chain was broken or the external commitment had quietly stopped.

- chain facts: verify_trail_tail over the newest 200 records each beat,
  bounded so the cost does not grow with trail age. Broken chain degrades
  with the failure message in the reason, loudest of the degrade causes.
  No trail yet attests chain_verified=null, not a degrade: a fresh machine
  and a tampered one must not read identically.
- anchor facts: only for a log configured via AGENTMETRY_ANCHOR_LOG, since
  the sibling default sits on the same disk an attacker would rewrite and a
  machine that never anchored should not degrade forever. Newest applicable
  checkpoint older than AGENTMETRY_ANCHOR_STALE_MINUTES (default 1440,
  0 disables) degrades; a configured log with no readable checkpoint for
  this trail degrades as silent. Checkpoints naming another trail are not
  scored, per the cry-wolf rule from verify_anchors.
- Sigma: agentmetry_recorder_degraded matches any degraded beat, so the
  new causes flow into it; its description and field list now name them.

pytest tests/test_heartbeat.py: 26 passed (10 new). Benchmark unchanged:
119 cases, 21 rules, 63 firings, 0 missed, 0 false positives. Ruff clean.

Generated by Mistral Vibe.
Co-Authored-By: Mistral Vibe <[email protected]>
…r tests

Generated by Mistral Vibe.
Co-Authored-By: Mistral Vibe <[email protected]>
@blitzcrieg1
blitzcrieg1 merged commit 104e306 into master Nov 28, 2026
10 checks passed
This was referenced Nov 28, 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

Development

Successfully merging this pull request may close these issues.

heartbeat: degrade when a configured anchor goes stale or the local chain fails to verify

1 participant