The in-sample check landed without any way to bound an evaluation, so every cell
was in-sample and every promotion path refused. Cutting the training bundles
earlier does not help: training spans the bundles, evaluation replays the whole
store with no lower bound, and the store keeps everything (retention 0), so
eval_first <= training_last always held.
replay --policy-eval gains --eval-after NS|auto (0 = unbounded). The bound is
applied where windows are ranked and where injected traces are planned, so the
periods partition only the out-of-sample span; auto derives it as the latest
training-range end over the loaded --eval-model files. Comparisons are written
without first + warm-up arithmetic so INT64_MAX timestamps cannot overflow. A
bound past the end of the store does not produce a silent empty cell: the cell
carries eval_error and promotion_gate refuses naming it.
Provenance also gets honest about width: training_last_ns is the last training
window's END (a window spans window_ns, so using its start left up to 60 s of
trained-on data looking disjoint), and the single-model path (model promote) now
uses the ranked span instead of the whole store, which had guaranteed a refusal.
Verified: R11c passes with 128 out-of-sample windows and a derived bound, and
unbounded returns to in-sample. Refuses an explicit bound later than all history.
Four findings from a four-lane audit made the promotion gate unable to support
its own claims.
In-sample evaluation: training walks the whole post-warm-up store and the gate
evaluates the same windows, with nothing checking provenance - replay.cpp itself
listed point_in_time_splits_and_overlap_not_assessed. Models now record the
window range they learned from (file format v2; v1 still loads as unknown) and a
content fingerprint, evaluation reports its own range plus in_sample, and
promotion_gate fails with the reason: an overlapping range, no recorded range,
or no digest. Unprovable provenance never counts as out-of-sample.
Degenerate baseline: with rarity-greedy on 0 hits, hits_per_cpu_second() returns
0.0, so ">= 1.5x rarity" reduced to "model hit something" and the recall check
was vacuous. A cell whose baseline scored no hits or spent no CPU now fails,
naming the budget refusals that starved it.
Stale models: cells keyed on a bare filename, so a later cycle that refused to
train left an older cycle's dist/gate models to be judged, and nothing bound a
verdict to the file it judged. Cells and reports carry the model digest, and
fleet gate sets refused (non-zero exit) for a cell without one or for a
(model, period) whose digests disagree across nodes instead of pooling them.
3 seeds are not generalization: they vary initialisation and the per-node
shuffle over identical windows. The procedure document now says so and states
what would test generalization (disjoint periods, models trained on an earlier
cut, out-of-sample ranges).
Tests: in-sample flagged, disjoint range not flagged, unprovable provenance
fails, 0-hit and 0-CPU baselines fail, mixed digests refused, legacy report
refused, range round-trip and fingerprint, v1 compatibility.
The pre-registered gate (docs/evaluation/stage4-promotion-gate.md) asks for the
criteria to hold on 3 non-overlapping periods x 3 training seeds; until now the
tool reported a single run and the operator recorded the rest. This produces
the 9 results for a fleet, with the criteria unchanged:
- replay --policy-eval --eval-model FILE (repeatable) --periods N: one pass
evaluates every model on every equal time slice of the ranked history; each
(model, period) cell simulates the model and rarity-greedy with their own
hourly budgets exactly as policy_eval does (policy_eval.cells). With one
model equal to --model and one period the cell equals the single-model
evaluation (test R11b); periods partition windows and positives.
- strawberry fleet gate DIR: pools the cells of every node report (windows,
positives, inspections, CPU-s, hits, refusals) per (model, period) and
applies learn::promotion_gate unchanged to each; passes only if all pass.
Malformed / cell-less reports are skipped and listed.
- Evaluation stays on the node (raw telemetry never leaves it): the central
cycle now also publishes all three seed models to dist/gate/; strawberry.gate
(sensors) evaluates them with the pre-registered evaluation traces; the
operator-run orch.strawberry_gate pushes the reports back and pools them;
evidence under central.work_dir/gate-<stamp>/. Nothing promotes.
- docs/evaluation/stage4-fleet-gate.md: the procedure (new dated document;
criteria and numbers unchanged).
Validated: test_fleet_gate (pooling sums, pooling reaching 10 positives
neither node has alone, one failing cell fails the fleet, malformed reports
skipped), R11b, Salt render checks (no models -> refusal; 3 models x 3
periods; orchestration pools), and scripts/fleet_e2e.sh end to end: 3 nodes ->
9 pooled cells with 28-50 positives each; the untrained synthetic models
correctly do not pass (exit code matches the verdict).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- fleet.cpp: HOST_NAME_MAX is Linux-only; use a 256-byte buffer (the
POSIX/RFC 1035 limit gethostname() truncates to).
- test_replay: two dangling pointers - victim(run(...)) returned a pointer
into a temporary report destroyed at the end of the statement. Passed on
Linux by allocator luck; failed deterministically on macOS for every seed.
- test_yara_scanner: a brace initializer with a comma inside assert() (the
macro splits it on macOS), and ::close needs <unistd.h> outside the
Linux-only block.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Reuse the global write->exec linkage (recent_writes) to attribute a detection to
its ROOT CAUSE. recent_writes now maps path -> {writer_node, writer_exe}; when a
window is late_detected (retro-hunt flags a binary after it ran) or detected
(YARA), set ReplayWindow.origin_node/origin_exe from whoever WROTE the flagged
binary -- usually an earlier node than the exec leaf that ran it. Surfaced in
window_json. Deterministic provenance walk (first writer wins); replay-level only,
no export-schema/record-type/enum change (R12/R13 intact), self_written_execs
unchanged. A learned ranking head over ambiguous origins is the follow-up (3.5d).
Test R10: a dropper writes /tmp/evil in one window, a separate process execs it
and is flagged late -> the window's origin_node is the dropper, not the exec leaf;
no in-set write -> empty origin; deterministic.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Reuse the existing resolver/sampler for opt-in aggregate training summaries. Reject incomplete or undecodable snapshots without usable partial reports, retain best-effort readers elsewhere, and document cooperative extent checks rather than atomic snapshot guarantees. Include command-table/help, JSON, fixture and corruption regressions; no model training or promotion.
The teacher-label join made a window a positive if it was detected
(replay.cpp), but it never applied the allowlist, so a window running a cleared
false positive (e.g. /usr/bin/ss) was labelled a teacher positive — poisoning
Stage 4 training. Negative labels were written to the stream but replay dropped
them.
- replay_store now collects negative labels into ReplayOptions.negative_labels
(it used to ignore any non-positive label).
- A window whose exec hash is negatively labelled is marked `suppressed`; the
example/policy-eval positive is gated on `!suppressed`, so such a window is
kept as a *negative* training example (useful signal) and never a positive,
even if a cleared rule "detected" it.
- DetectionPipeline seeds a negative label for every allowlisted sha256 at init,
so evidence stored before the allowlist (the historical ss storm) is covered
without waiting for a re-exec.
Test: a detected window with a stored negative label for its hash is a positive
before the label and a kept-negative after. Suite 51/51; analyzer + clang-tidy
clean on replay.cpp and detection_pipeline.cpp.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
A promoted model (promoted.sbm, written only by `model promote` after the
gate) can now request real inspections. Only two, both additive:
- memory_scan: through the daemon's memory-scan queue;
- deep_rescan: the root's image re-scanned on demand; new matches are
recorded as indicators of kind model_inspection (findings titled "YARA
match found by a deeper rescan the inspection model requested") and
positive labels.
watch_subtree has no mechanism and rescan_on_next_rules is the retro-hunt's
job, so both are masked out of acting decisions (kExecutableActions), and
replay's policy evaluation uses the same action set.
Guardrails:
- InspectionExecutor (bounded queue, one low-priority worker, submit()
never blocks); WorkClass::model_inspect lets the governor defer it, and
a deferred decision is dropped.
- Each action rechecks that the promoted model is still active at the
decision's generation (demoting or replacing it revokes queued work),
that the root's node id and raw image path still match (decisions carry
root_image, not the feature template), and skips protected processes.
A deep rescan discards its result if the process, image or rules changed
during the scan.
- An acting decision is durably written before it is dispatched; every
attempt becomes an inspection_outcome record (queued, scanned, skipped,
deferred, revoked, queue_full, failed).
- Source invariant R10: no file may couple learning types to the
exec-guard, OpenSnitch or policy APIs (daemon_app.cpp and main.cpp, the
wiring points, are reviewed by hand). Models never block, contain, kill
or create findings directly.
- Config model_act and model_lambda; status model block reports acting
stats; timings.model_inspection.
docs/evaluation/stage4-execution-gate.md amends the gate's method (not its
thresholds): executable action set, greedy promoted decisions, budgets as
estimated inspection seconds by scan profile.
Also: TerminalSafeBuf's destructor no longer lets an exception escape;
the health message clamps huge durations; replay timestamp overflow; the
Docker test build runs with -j2.
Tests: test_inspection_executor (every skip and execute path, revocation,
queue limits); shadow and replay acting cases; R10 fixture; fault injection
and invariant updates. Validation reported by the session that wrote it:
48/48 local, 46/46 Docker plus privileged live checks, 20 fuzz targets
(9.5M runs), three paired KPI runs without regressions (no acting model
was loaded, so active-inspection cost is not measured yet).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- replay --policy-eval: over ranked windows, simulates the model and
rarity-greedy (the same chooser, rarity score / 48 as the value), each
with its own hourly budget, and tallies the shadow decisions the daemon
logged. Hits are inspected "extra" positives: late labels or injected
evaluation traces on windows rules did not flag at exec time. Labels are
known after the fact, so every action's payoff is computable without
propensity weighting. Reports CPU-seconds, inspections, hits, recall,
hits per CPU-second and budget refusals.
- docs/evaluation/stage4-promotion-gate.md (pre-registered): at least 10
extra positives, model efficiency >= 1.5x rarity-greedy, model recall
not lower. promotion_gate() checks it.
- strawberry model promote [--inject FILE] [--warmup H] [--yes]: replays
with the shadow model, applies the gate and only then writes
promoted.sbm; asks for confirmation.
- learn/inspection.hpp: options, the greedy chooser and the
inspection_action record, shared by shadow mode and the evaluation.
- Fix: the hourly budget reset whenever a window closed with an earlier
timestamp than the hour's start (windows close roughly, not strictly,
in time order), letting spend exceed the budget; in both shadow mode
and the evaluation.
Tests: test_replay R11 (gate criteria; extra positives exclude rule-flagged
windows; spend within the budget; logged shadow decisions joined to their
windows); CLI translations.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- Replay builds each window's WindowSummary as it goes (exec depth and
locations, connections, writes, ptrace, module loads, scan outcomes,
surprisal) and can collect training examples: features, a label (a
detection or late label touched the window), time, root program and the
rarity score. Sampled to at most 50k: positives up to a fifth,
negatives by reservoir with at most 1% per root program.
--inject-train traces become positive examples and are not evaluated.
- learn/train: the value head (and hidden layers) learn P(teacher
positive) with a class-weighted log loss and Adam; positive-unlabeled
data, so unlabeled is "not known bad", documented. Split by time
(newest 20% tested); reports test loss, top-k hits and ROC AUC for the
model and for the rarity baseline. Refuses with fewer than 5 positives.
Deterministic for a seed. The policy head waits for shadow-mode
inspection outcomes.
- CLI: `strawberry model train [store_dir] [--inject-train FILE]
[--epochs N] [--seed N] [--out FILE] [--json]` writes the shadow model
(generation after the newest existing one, a note saying what it was
trained on); `strawberry model show [file]`; `strawberry replay --model
FILE` ranks windows (and evaluates injections) by the model's value.
Config model_dir (default /var/lib/strawberry/model).
- doctor: the model check loads promoted.sbm and shadow.sbm; an invalid
file is a problem (it is never used).
Tests: test_train (gradients against finite differences, skipping steps
that cross a ReLU kink; a planted pattern learned to high AUC; determinism;
refusal without labels; roc_auc); test_replay R10 (examples, labels,
per-program cap, training traces, model ranking); CLI and doctor cases.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Clang rejects "\x80evil" (the escape takes the 'e'); GCC accepted it and
the test used a different string than written.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The main source of teacher labels over time: rules improve daily, while
most malware runs once.
- The pipeline remembers every binary that ran (image_seen evidence
record: sha256, path, first/last seen, size; at most one write per hash
a day). Deleted and memfd images are skipped: nothing to find again.
- Each rules load computes a digest of the rule files and IOC hash lists
(paths after resolving symlinks, sizes, mtimes).
- RetroHunter (src/retro_hunt.cpp, own thread, idle priority, paced at
retro_hunt_pace_ms, deferred by the governor as WorkClass::retro_hunt)
re-scans when the digest differs from the last completed pass, most
recently seen first. Only paths that still hold the same content are
scanned (O_NOFOLLOW, regular files, hash compared); others count as
changed or missing. A completed pass is recorded (retro_hunt record) so
a restart does not repeat it; an interrupted one starts over.
- New matches (rules not recorded before for that hash, not allowlisted)
become indicators with scan_kind retro_hunt, a file/indicator graph
link, a positive label and a notification. Correlation turns them into
findings titled "YARA match on a binary that ran here (found after a
rules update)". Nothing is blocked or contained from here.
- Replay reads positive labels from the evidence stream and marks windows
that ran a binary labelled bad later (LATE in the CLI).
- Status: a retro_hunt block (API_CONTRACT.md); config: retro_hunt,
retro_hunt_pace_ms.
Tests: test_retro_hunt (remembered once; passes only on a digest change
and survive a restart; a clean-at-exec binary matching a new rule becomes
an indicator, label, finding and notification; a replaced binary is
counted as changed, never scanned as the old one; a stop abandons a pass
unrecorded); test_replay R9 (late labels, from a real store).
fuzz_evidence_records covers the new records.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- src/learn/trace.cpp: a small trace format (exec, connect, write,
ptrace, module with +offsets and process aliases) compiled to
telemetry records with pids above any pid_max and node ids that name
the trace and copy.
- --replay --inject FILE [--inject-copies N]: copies are spread evenly
over the ranked history (a first pass reads the time range), scored
but never learned from, and checked against alert budgets of 1, 3 and
10 per day: is the copy's best window above the (budget x days)-th best
real window? Ties count against. Injection leaves real windows and
their ranking unchanged.
- config/traces/standard.trace: the six plan traces (browser to curl|sh,
systemd user persistence, memfd loader, ptrace injection, download
then exec, python from a PDF viewer).
- docs/evaluation/stage3-rarity-preregistration.md: method and pass
thresholds, written before any run on host data.
Tests: test_trace (standard traces, error messages with line numbers,
records); test_replay R8 (every copy found, real ranking unchanged, a
novel chain caught at 10/day and a bare shell not). fuzz_trace_dsl.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
On the host, 586 of 303k records arrived more than 30 s late: exec records
of large images are written after their paced, deferrable scan. Replay is
offline, so holding 2 minutes of records costs nothing that matters.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
From the first replay of real host data (3.5 h, 266k records):
- A never-seen event scored higher the more the model had seen, so the
ranking favoured whatever happened last (the reinstall's systemctl
and generator runs). Each event is now capped at 16 bits (never
seen), and a window scores the sum of its three most surprising
distinct events.
- Warm-up: on a fresh history nearly everything is new. Windows in the
first 12 h are learned from but not ranked (--warmup H); detections
are always listed. The CLI says so when nothing is ranked yet.
- Windows with the same root program and top pattern are one line with
a count ("x40 similar").
- Counts: file writes split by persistence; events from processes
started before recording are reported as such, not as an error;
records more than 30 s out of order are counted as late.
tests/test_replay.cpp R7: warm-up, equal scores for a novel event early
and late, grouping, late-record counting.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Replay (src/learn/replay.cpp, strawberry --replay [dir] [--top N] [--json]):
reads the telemetry stream read-only, orders events by time (a 30 s
reorder buffer absorbs the writer's batching), joins behavior events to
the latest exec of their pid at that time (keeps PID reuse apart), builds
60 s windows (a root exec, its descendants and their behavior, at most 64
events), scores each exec, connection and persistence write with the
rarity model before observing it, and marks windows whose processes had
detections. Prints the most unusual windows with the tuples that made
them unusual. Deterministic. tests/test_replay.cpp: chain windows, PID
reuse, order insensitivity within the horizon, determinism, ranking,
detection marking, a real store round trip. fuzz_replay feeds arbitrary
record streams.
UTF-8: file names are bytes, and the fuzzer showed nlohmann's dump()
throwing on a path that is not UTF-8. The same applied to the daemon's
control replies (kill/suspend/quarantine name the exe path) and to the
OpenSnitch containment rule, so a binary with such a name could not be
contained, and json_escape wrote the raw bytes into status JSON. Now:
- every .dump() in src/ uses error_handler_t::replace (U+FFFD), enforced
by source invariant R9;
- json_escape writes invalid sequences as � (valid_utf8 and
utf8_sequence_length in json_util.hpp);
- containment refuses such a path with a clear error (a rule could never
match the real bytes); quarantine still blocks execution by hash.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>