Skip to content

backtest: run a rule over your own recent trail before you enable it #230

Open

Description

@blitzcrieg1

Why

A rule turned on blind either floods triage or stays quiet for the wrong reason. Before enabling a YAML rule, or changing a threshold, an operator should be able to see what it would have fired on in their own recent history.

agentmetry benchmark already replays a recorded corpus through the real engine (core/audit/detection/benchmark.py, run_detections). Running the same engine over the operator's own trail, for a window they choose, is a small step from that.

Shape

agentmetry backtest --days 30 [--rules-dir DIR] [--rule RULE_ID]
  • Read the trail (all segments, as verify --trail does) for the last N days.
  • Group by session and run run_detections over each session, with the built-in rules plus any rules from --rules-dir.
  • Report per rule: sessions it would fire on, the count by severity, and the three most recent example sessions with their ids, so agentmetry replay <id> can show each one.
  • Mark which of those findings the live trail already holds, so the output separates "new under this rule" from "already fired".
  • Read-only. It writes nothing to the trail, the live store or the disposition store.

Constraints

  • No frozen file changes. It calls the engine. It does not modify rules.py, traits.py, engine.py, mitre.py or the detection manifest, so the ruleset fingerprint does not move.
  • Large trails: stream the file rather than load it. The maintainer's own trail is over 56,000 lines.

Done when

  • agentmetry backtest --days 30 runs against a real trail and prints the per-rule report.
  • Tests cover a rule that fires, a rule that does not, and a window that excludes an older session.
  • The README CLI table lists it.

Activity

  1. added
    enhancement
    on Oct 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions