Evaluation
This page is published from the ml repository. Edit on GitHub View source
A model is not shipped on its training loss. This page covers the three evaluations in
synthaea_ml/evaluation/: scenario replay (did the agent raise the
alerts a scenario expects), robustness (how far an attacker-style rewrite moves a known-bad
sample's score), and the lineage-gain measurement (does a feature block earn its place).
Scenario replay
A scenario in the scenarios repository is a script
plus a YAML sidecar listing the alerts it must raise, each with a technique, a rule, a
min_count and a tolerance (sidecar format).
scenario_replay.run_replay turns a sidecar and
the alerts.ndjson of a run against it into a ScenarioReplayResult:
load_expected_detectionsreads the sidecar withyaml.safe_load.name,expected_detectionsand all four keys of every entry are required; a missing key raisesKeyError.- Alert lines are counted by their
techniquestring. Blank and unparsable lines are skipped, sincealerts.ndjsonis an append-only log that may end on a torn line. - For each expected detection with a non-zero count, an observation is recorded with that count
and the expected
rule. Alerts carry no rule identifier, so the rule is copied, not observed; two expected entries with the same technique would share one count. compute_passed: every expected detection must be observed withmin_count <= count <= min_count + tolerance. An over-count fails, as an under-count does.
The result also records the sidecar's SHA-256, the time, and the environment
(platform.system(), platform.release(), platform.machine()). Techniques that fired but are
not expected are ignored.
run_replay does not run the scenario; it starts from an alerts.ndjson produced elsewhere.
Recording a replay
A replay validates the agent running a trained model, so it is recorded after training, not by
the trainers: deploy the model on a lab machine, run the scenario there (the rig's scenario
runner), bring its alerts.ndjson back, and run
synthaea-ml-record-replay. It reads the sidecar from the
scenarios sibling checkout, the directory the provenance gate checks against, and adds the
result to the record's scenario_replays. A rerun in the same environment (OS, kernel, arch)
replaces the replay it repeats; runs on other machines are kept beside it. A failed replay is
recorded too: the record states what the run showed, and the gate decides what ships. The
provenance gate re-verifies every recorded replay (registry.md).
Robustness
run_robustness_evaluation measures evasion cost: take
samples the model detects, rewrite them the way an attacker cheaply could, and see how many
escape. It produces one RobustnessCard per scenario.
Samples under test
- With an events source (
--robustness-eventson the trainers): every exec record in the file. The file may be the agent's wire format (flattened first) or a baseline. At tier T1, each exec'scorrelation_featuresis computed over the whole file as one window, filtered by(pid, process_generation). - Without one, or if it holds no exec record: one synthetic command line per expected detection
of the scenario, chosen by technique (a
curl ... | shfor T1071, abase64 -dpipeline for T1059, awgetto/tmpfor T1105, a generic one otherwise).
The sidecar must list at least one expected detection.
Mutators
Every mutator works on the raw record before canonicalization, returns a copy, runs at three intensities (light, medium, heavy), and draws from a seeded PRNG. Heavier must mean harder to detect, never easier.
| Tier | Mutators in use |
|---|---|
| T0 | PathSubstitutionMutator (/bin/ and /usr/bin/, /tmp/ and /var/tmp/, ...), ArgumentReorderMutator (argv[0] stays fixed) |
| T1 | The same command-line mutators. The parent is not in the T1 vector, so a lineage mutator could only report a flattering zero. |
| T2 | None yet; the evaluation raises NotImplementedError. |
Three more command-line mutators exist but are disabled: base64-encoding tokens, splitting tokens
with shell quotes and padding with comments are shell-level evasions, and the sensors capture argv
after the shell has parsed it, so they produce argv values that cannot occur. They belong in a
future mutator of sh -c payloads. The lineage mutators
(fake parent name, parent path moved to system directories, lineage removed) serve the lineage
measurement and its tests.
The PRNG is Knuth's 64-bit LCG, with the same
constants as the Rust robustness tests. The draws depend on the loop order (sample, then mutator,
then intensity), and each result records the PRNG state after its mutation, so a result can be
reproduced individually. A mutation that raises ValueError is skipped.
The card
For each mutation, both scores are recorded with their difference. A sample is detected when its score is at or below the threshold (default 0, the forest's decision boundary; the trainers and the site rarity floor pass each model's calibrated threshold), and a mutation escaped when the original was detected and the mutated score is above the threshold.
| Field | Meaning |
|---|---|
escape_rate | Escaped results over results whose original was detected |
median_score_degradation | Median of mutated - original over all results; positive moved toward benign |
worst_case_degradation | Largest such difference |
mutation_results | Every result: class, intensity, both scores, delta, threshold, escaped, PRNG state |
scenario_yaml_sha256, tested_at | Binding to the sidecar, and when it ran |
If no sample was detected before mutation, the evaluation raises ValueError: an escape rate on
nothing is undefined, and the usual cause is a benign file passed as the events source.
tests/test_robustness_snapshot.py pins a full card.
The provenance gate re-checks scenario_yaml_sha256 against the sidecar on disk, so a card
computed against a scenario that has since changed fails it (registry.md).
The gate
robustness_cli reads the cards of a version's
model_record.json:
synthaea-ml-robustness verify --model-dir registry/cmdline-iforest-linux/0.2.0 --check-regression
synthaea-ml-robustness report --model-dir registry/cmdline-iforest-linux/0.2.0 --output robustness.md
verify fails a scenario whose escape rate exceeds --max-escape-rate (default 0.15) or whose
median degradation exceeds --max-median-degradation (default 0.20). With --check-regression
it also compares each scenario with the same scenario in the previous version, and fails an
escape-rate increase above --max-regression-increase (default 0.05). The previous version is
the previous patch directory, else a version of the previous minor, else of the previous major; a
missing or unreadable one is a warning, not a failure. A record with no card does not pass. The
exit status is 0 on pass, 1 on failure.
report writes Markdown: per scenario, the three metrics and the first ten mutation results.
Lineage gain
t1_lineage_gain answers one question: does
adding the six lineage features to the T1 vector detect more at the same
false-positive budget? It is the measurement behind the T1 vector having no lineage block, and the
tool to re-run on better data.
- Benign: one or more behavior datasets (
events.jsonland manifest), reduced to distinct 23-feature vectors (T1 then lineage). At least 20 are required. - Malicious: a capture of a scenario run. Only the process tree of the runner counts: its
incarnation first seen within 30 s before
--start-ns, and every process first seen inside the window whose parent incarnation is already in the tree, excluding the runner itself. Background processes that ran during the window are not labeled malicious. The capture workloads write the three values torun.json. - Method: for each of
--seedssplits (default 20) of the benign vectors into 50% train, 25% calibration and 25% test, fitBEHAVIOR_FORESTwith that seed on 17 and on 23 columns, calibrate each to the trainer's FP budget, and measure the detection rate on the malicious vectors, the false-positive rate on the benign test rows, and the ROC AUC. - Output: a JSON report with the means and standard deviations per variant, the paired gain (23 minus 17) for AUC and detection, the number of seeds on which lineage is not worse, and the counts of distinct benign and malicious vectors.
synthaea-ml-t1-lineage-gain \
--benign-dataset <benign-dataset-dir> \
--malicious-capture <malicious-run>/events.jsonl \
--root-pid 4242 --start-ns 1762700000000000000 --end-ns 1762700300000000000 \
--output t1_lineage_gain.json
Report a gain with the vector counts next to it, and separately for scenarios whose parent is odd by name, odd by path, and ordinary: a lineage gain can only show where the parent is unusual. The report is not written into a model record.