Skip to content

Count unparsed lines in their own slots in SCVS and ECVC - #448

Open
viktorbeck98 wants to merge 1 commit into
developmentfrom
fix/count-vec-unparsed-slot
Open

viktorbeck98 wants to merge 1 commit into
developmentfrom
fix/count-vec-unparsed-slot

Conversation

@viktorbeck98

@viktorbeck98 viktorbeck98 commented Nov 22, 2026 •

Copy link
Copy Markdown
Collaborator

Task

Follow-up to #439 (CountVectorDetector, SCVS). SCVS and ECVC counted unparsed lines into another event's slot, and into different slots from each other.

Description

count_events indexed its list with the eventID, so a line without a template (eventID -1) went through Python's negative indexing into the last slot built so far: the highest eventID seen earlier in the window, or event 0 when -1 came first. The result depended on the order of the lines. A line without a message field (eventID -2, NO_MESSAGE_EVENT_ID in the JSON parser) raised IndexError when no event above 0 preceded it in the window.

ECVC learned its vectors with count_events but counted at detection with events_vec, which put -1 into the last column of the learned matrix. So a window ECVC learned in training could look new at detection, and ECVC alerted on windows SCVS had learned.

This PR:

  • count_events gives each unparsed ID its own slot: slot 0 counts eventID -2, slot 1 eventID -1, slot e + 2 eventID e. An ID below -2 raises ValueError instead of folding silently.
  • ECVCOp.events_vec counts with count_events and pads to the matrix width, so ECVC counts a window at detection exactly as in training. Every ECVC alert is now an SCVS alert on the same windows and training data.
  • Docstrings and the SCVS/ECVC docs say how unparsed lines are counted.

Effect on data without unparsed lines: none. SCVS's keys stay consistent with each other. ECVC's vectors gain two leading zero columns, which leaves every distance, the sort order of the learned vectors, the validation split and the threshold unchanged.

Compatibility: count vectors saved by an earlier version use the old layout, without the two leading slots. Restored SCVS/ECVC state then matches no window counted with this version, so retrain after upgrading. test_pre_tracker_state.py pins this: the old ECVC fixture restores to the fresh count vectors without their two leading slots, with the same threshold.

Evidence: on BGL (time split, train fraction 0.1, window 10), 107,828 test windows were flagged by ECVC but not by SCVS, every one of them holding at least one eventID -1 line; at the other train fractions the same held. On datasets without unparsed lines the two detectors' alerts already nested. With this change, at train fraction 0.1, all 28,292 distinct test windows that SCVS learned are also learned by ECVC, so no ECVC-only alert remains.

How Has This Been Tested?

  • New tests, each failing before the change:
    • tests/test_utils/test_sequence_encoding.py::TestCountEvents: slot layout, an unparsed line is not another event, order independence, ValueError below -2.
    • tests/test_detectors/test_ecvc_detector.py::TestUnparsedLines: ECVC and SCVS never alert on a learned window that holds -1 or -2 lines; [3, -1] is not [3, 3]; on random streams with -1 (and with -2) every ECVC alert is an SCVS alert, for threshold methods mean and default (equal alert sets for default).
    • test_build_one_vec_counts_like_count_events.
  • Expected vectors in the existing count_events/build_count_vec/build_one_vec tests updated to the new layout.
  • test_ecvc_rebuilds_the_same_count_vectors became test_ecvc_rebuilds_the_old_count_vectors (see Compatibility).
  • uv run pytest -q --run-ignored: 1124 passed, 45 skipped, 0 failed.
  • prek run --files <changed files>: all hooks pass.

Checklist

  • This pull request targets the development branch.
  • I have successfully run prek locally.
  • I have added tests to cover my changes.
  • I have linked the issue ID in the task description.
  • I have reviewed my changes.

🤖 Generated with Claude Code


Run Proof
Open in [code]smith · Need help on this PR? Tag @codesmith-bot with what you need.

count_events indexed its list with the eventID, so a line without a
template (eventID -1) landed in the last slot built so far through
negative indexing, and a line without a message (-2) could raise
IndexError. ECVC also counted at detection with events_vec, which put
-1 into another column than training did, so ECVC alerted on windows
SCVS had learned.

count_events now uses slot 0 for -2, slot 1 for -1 and slot e+2 for
event e, and raises ValueError below -2. ECVCOp.events_vec counts with
count_events and pads to the matrix width, so every ECVC alert is an
SCVS alert on the same windows and training data. Count vectors saved
by an earlier version use the old layout: retrain after upgrading.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@viktorbeck98
viktorbeck98 requested a review from ipmach November 22, 2026 22:49

This branch has not been deployed

No deployments
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.

2 participants