Skip to content

Benchmark harness and improvement loop, iterations 0–4 - #3

Merged
FMXExpress merged 9 commits into
mainfrom
bench-harness
Oct 31, 2026
Merged

FMXExpress merged 9 commits into
mainfrom
bench-harness

Conversation

@FMXExpress

Copy link
Copy Markdown
Owner

Adds a benchmark harness and the changes it led to. Every change was checked against held-out data; the rule throughout was that benign clients banned must stay at zero.

Harness

  • bench/gen_corpus.py generates synthetic labelled corpora for three site types (WordPress, static, web app), each split into dev and test. The benign traffic includes clients that trip cheap checks: API clients, link checkers, crawlers, monitors and the site owner. The attacks include clients built to dodge them: path variants, encodings, slow scanners, scans spread over a subnet, stealth scanners and prompt-injecting user agents.
  • bench/fetch_logarx.py downloads the LogarX/Zodiarc real labelled shop log at benchmark time and pins it by checksum. It is never committed.
  • bench/live.py measures wall-clock time to a ban while the daemon tails a live log.
  • bench/run.sh and bench/summarize.py produce the summary tables and JSON. --eval-json reports results per category, leaked requests and seconds to a ban.

Changes

  • The decider runs on a worker thread. The daemon keeps reading and hard-rule banning while the model thinks. In the live test, a scanner that arrived while the model was busy was banned after 2.1 s and 3 requests; before, it took 57.2 s and all 30 of its requests got through.
  • Faster local model.
    • llama.cpp is built with GGML_BACKEND_DL and the CPU variants, so the best instruction set is picked at run time.
    • jevban now uses every core (FPC reported only 1).
    • Prompts are compact, and pass verdicts are cached.
    • A prompt went from 26.7 s to 13.2 s. The micro benchmark went from 15 min 50 s to 2 min 26 s.
  • Behaviour rules: slow scanners (longretry/longtime), subnet heat (/24 and /64), path-scan (distinct 404s), a prompt-injection signature, and logged-in detection.
  • Safety:
    • One model verdict can no longer ban a client on its own (strike cap).
    • Only pass verdicts are reused.
    • A signed-in user's admin pages no longer count as probes.
    • Served paths only count as known-bad if they contain a dot.
  • Firewall: new ipset action. iptables, ipset and nftables were tested for real on IPv4 and IPv6. With 20k existing bans, ipset inserts 50 bans in 138 ms; iptables takes 419 ms.
  • nice is now applied with FpSetPriority, because FpNice fails on x86-64. jevban runs at BELOW_NORMAL priority on Windows.

Results (held-out test splits)

Benign banned Attackers banned, v1.0.0 rules Rules now Rules + Flash 9B
WordPress 0/73 24 44/51 47/51
Static 0/72 20 43/52 46/52
App 0/79 21 41/51 43/51
LogarX (real) 0/789 — 124/126 —

Prefilter throughput: about 29k lines/s on typical traffic and about 6k lines/s in a flood where every line is a new address, one core.

Known gaps (next iterations)

  • Stealth scanners are still 0/3 on every split. These are probes mixed in with real page views, on paths no list knows.
  • The model's batching adds latency. The median time to a ban goes from 3 s to 5 s. On the app split, 240 attack requests got through with the model against 233 with rules alone.

Unit tests: 125 checks, 0 failed. Per-iteration notes are in bench/results/*/README.md.


Generated by Claude Code

Iteration 0 of the benchmark/profile/improve/verify loop.

- bench/gen_corpus.py: labelled access logs for three site profiles
  (wordpress, static, app with an API and a real /admin), a dev split to tune
  on and a held-out test split to report on (different seeds and IP ranges),
  with a config describing each site. Benign traffic includes what trips
  cheap checks (API clients with script user agents, link checkers, SEO
  crawlers, monitors, the owner logging in); attacks include what dodges
  them (path variants, encodings, slow and distributed scanners, scanners
  hiding between page views, prompt-injection user agents). Word lists:
  samples of SecLists (MIT) in bench/wordlists.
- --eval: labels may carry a category (attack:wordlist, benign:api, ...);
  the report adds per-category clients banned and requests caught, attack
  requests that reached the server before each ban, seconds from first
  attack to ban, and wall time; --eval-json FILE writes it all as JSON.
- bench/run.sh: rules-only quality on all corpora plus prefilter throughput
  (seconds; MODEL= or PROVIDER= adds a decider on the test splits);
  bench/summarize.py makes the tables.

Baseline, rules only (bench/results/baseline-rules): 0 of 445 benign clients
banned; 37-46% of attackers banned per split; credential, stealth,
injection, slow and distributed attackers never banned. 15,700 lines/s
typical, 7,100 in a flood of new addresses.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01NPVFJFY41846T15QqxmGW2
…hmark pending)

Iteration 1: a model batch can take minutes on a CPU, and the daemon used to
stop reading the log meanwhile, so a fast scanner could finish its list
before a hard rule banned it. The live daemon now hands batches to a
TDeciderWorker thread and collects verdicts on each loop; tailing, hard
rules and unbans go on. Requests that arrive while a client's batch is out
get that batch's verdict. --test and --eval still decide inline, so replays
stay deterministic. The worker sets the FPU mask ggml needs (it is per
thread); clients with a batch out are not purged.

bench/live.py measures it: the daemon tails a log written in real time,
password guessers keep the decider busy, then an obvious scanner probes one
known-bad path a second; it reports seconds and requests to the scanner's
ban and the guessers' time to a verdict. tests/mock_jev.py takes
MOCK_DELAY=seconds per client to stand in for a slow model. The before/after
numbers are not in yet.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01NPVFJFY41846T15QqxmGW2
…k; served-path fix

- bench/results/iter1-live: with a decider busy for 60 s (password guessers),
  an obvious scanner was banned after 57.2 s and all 30 of its requests
  before (decider on the main loop), and after 2.1 s and 3 requests now
  (worker thread); model verdicts unchanged at ~64 s. bench/live.py raises
  timeout_ms so a slow decider is waited for.
- bench/fetch_logarx.py downloads the LogarX/Zodiarc labelled shop log (real
  Apache output of real tools, a label per line; no licence, so fetched at
  benchmark time and checksum-pinned, never committed) and converts it;
  bench/run.sh includes it when it can be fetched.
- A known-bad path answered with 2xx only counts (+3) when it looks like a
  file (has a dot: /phpinfo.php, /.env, /backup.zip). Plain routes that
  quickhits lists (/search, /download) are ordinary pages: on LogarX they
  were 242 benign requests against 66 attacks. LogarX, rules only: benign
  requests struck 2 -> 0; still 124 of 126 attackers and 0 of 789 benign
  clients banned.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01NPVFJFY41846T15QqxmGW2
…mpts; strikes need fresh verdicts

Iteration 2 (profile, then improve):
- Profile: 54 model calls for 8 clients on the micro benchmark (an uptime
  monitor re-judged every 5 minutes), prefill ~11 tokens/s, 260-730 tokens a
  prompt, much of it the client's user agent repeated on every line.
- llama.cpp is built with GGML_BACKEND_DL + GGML_CPU_ALL_VARIANTS (one CPU
  library per instruction set, the best picked at run time through
  ggml_backend_load_all_from_path): 19.1 s -> 13.2 s for a 250-token prompt
  on this AVX-512 machine (a native build: 11.8 s). Release and make llama.
- Every core for the model (3 -> 4 threads: 26.7 s -> 18.4 s); the daemon
  lowers its priority (nice = 10; below normal on Windows) so the web server
  keeps the CPU. setpriority, since FPC's FpNice fails on x86-64 Linux.
- A pass is reused for cache_pass_secs (1800) while the client shows no new
  signature and fewer new flagged requests than were judged (at least 3).
- Requests reach the decider as compact lines (time of day, request, status,
  size, referer; the client's user agent once in the state): 24% fewer
  tokens, for the local model and the hosted APIs.
- Only a pass is reused at all: a reused strike let one early verdict count
  as every strike (the micro benchmark's site owner, judged on its first two
  login requests at p=0.80, was banned on opening /wp-admin/). Strikes now
  need a fresh look; the owner's second look was p=0.69.
- JEVBAN_PROFILE=1 logs tokens and time per prompt; --eval reports them.
- bench/make_micro.py: a fixed 8-client model benchmark.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01NPVFJFY41846T15QqxmGW2
Iteration 3 (quality), from the misses the benchmark showed:
- Slow scanners (one probe per 15-40 minutes) never reached maxretry within
  findtime and their client state was forgotten in between: probes (score >=
  rules_min_score) are now remembered per address for longtime (86400 s), and
  longretry (5) of them ban.
- Scans spread over a subnet (16 addresses, 2 probes each): once subnet_retry
  (3) addresses of one /24 (IPv6 /64) have probed within findtime, the
  subnet is hot, and those addresses and any of its addresses that probes
  are banned. Only addresses that probed are banned, never the subnet.
- Path scans: scan_404 (8) different missing paths within scan_window (60 s)
  add +3 (path-scan): weak alone, it brings plugin probers and scanners of
  paths no list has to the decider with that context.
- Text written for an AI judge in a user agent, referer or URL ('ignore
  previous instructions', 'do not block', 'this client is legitimate', ...)
  is a hard rule (prompt-injection, weight 10).

Held-out test splits, rules only (bench/results/iter3): attackers banned
21 -> 41, 20 -> 43, 24 -> 44 of ~51; attack requests that reached the server
-21%; benign clients banned still 0 of 224. LogarX: 124 of 126 attackers and
0 of 789 benign clients banned, as before.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01NPVFJFY41846T15QqxmGW2
…es, benchmark

- action type = ipset: iptables with the bans in a hash set (jevban,
  jevban6) behind one rule. With iptables (1.8.10, nf_tables) adding 50 bans
  took 191 ms with no bans in place and 419 ms with 20,000; with ipset 162 and
  138 ms. Per packet, the iptables preset checks every rule in turn.
- The iptables, ipset and nftables presets were run for real (ban, unban on
  expiry, cleanup on stop) for an IPv4 and an IPv6 client.
- README: the behaviour rules (slow and distributed scanners, path scans,
  prompt injection) and a Benchmark section with the rules-only results on
  the held-out test splits and LogarX.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01NPVFJFY41846T15QqxmGW2
…an by itself

- A login POST answered with a redirect (301-303) marks the client signed in
  (WordPress answers a failed login with the form, 200, and a success with a
  302); after that its site-dependent WordPress and login tags (weight 3)
  stop counting. Hard rules still apply.
- One model verdict covers every request of its batch but counts as at most
  maxretry - 1 strikes unless it reaches instant_threshold: a ban needs at
  least two looks. The micro benchmark's site owner (p=0.80 on its first two
  login requests) can no longer be banned by that one look; the password
  guesser is banned after its second (one more request through).
- bench/results/iter2-micro: the micro benchmark before and after
  iterations 2-3: 15 min 50 s -> 2 min 26 s, 18 -> 7 model requests,
  attackers banned 3 -> 4 of 5, attack requests through 48 -> 31, benign
  clients banned 0 -> 0.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01NPVFJFY41846T15QqxmGW2
@FMXExpress
FMXExpress merged commit c1eb61d into main Oct 31, 2026
3 checks passed
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