Fuzz findings

From bitwisecook/tcl-lsp · View interactive version

Fuzz findings is an AI agent skill from the GitHub repository bitwisecook/tcl-lsp. Drive the native differential fuzzer (rust/tcl-fuzz): run campaigns that compare any pair of backend engines (tclvm/tclsh, runtime/rust/tclsh, tclvm/runtime-rust), summarise the findings registry by category, and replay a seed to triage or confirm a fix. Use when working on fuzz findings, checking w

How to use this skill

Skill file

Fuzz Findings Management

The differential fuzzer lives in rust/tcl-fuzz. It generates Tcl programs

and runs each through a pair of engines, recording every divergence to a

findings registry. Three engines are available:

| Engine | What it is | Binary |

|---|---|---|

| tclvm | The native bytecode VM CLI | tcl-vm-cli's tclvm |

| tclsh | A reference C Tcl interpreter | tclsh9.0/tclsh on PATH |

| runtime-rust | runtime/rust's tree-walking interpreter | runtime/rust's run_script dev-tool example (cargo build --release --example run_script under runtime/rust; needs TCL_TOMMATH_DIR pointed at a libtommath source tree for expr/math to work — see "Building the runtime-rust engine" below) |

run --reference E1 --subject E2 pairs any two of these (default: tclsh

reference, tclvm subject). Findings are

keyed by their generating seed (so they replay exactly) and stored as a

JSON record (see rust/tcl-fuzz/src/findings.rs) plus the raw .tcl script

under the findings directory (default fuzz-findings/, override with

--findings DIR). A non-default pair is namespaced under

<findings>/<subject>-vs-<reference>/ so two pairs never collide on the same

seed; the default pair uses <findings>/ directly.

There is no separate "fixed/unfixed" state: the registry de-duplicates by seed

and categorises by the divergence kind. A finding is "fixed" when its seed no

longer reproduces — confirm that by replaying it (below).

Usage

Build once, then invoke the binary:

cargo run -q -p tcl-fuzz -- <command> [args...]
# or, after `cargo build -p tcl-fuzz`:
./target/debug/tcl-fuzz <command> [args...]

Global flags: --findings DIR (registry location), --timeout-ms MS

(per-script timeout), --tclvm PATH / --tclsh PATH / --runtime-rust PATH

(engine binaries; defaults are auto-located beside tcl-fuzz or on PATH),

and the two generator dials --malformed-expr-permille /

--word-shape-permille. Both dials are global rather than run-only because

replay has to generate a seed exactly as the recording campaign did.

Commands

| Command | Arguments | What it does |

|---|---|---|

| run | --iterations N [--seed S] [--verbose] [--reference E] [--subject E] [--compare-error-text] [--tcl-version X.Y] | Run a campaign over the pair; one release applies to every pinnable engine and an engine that cannot honour it stops the campaign |

| summary | [--reference E] [--subject E] [--tcl-version X.Y] | Print counts per release namespace. Without a release it includes unpinned and every tclX.Y registry; an explicit release selects only that registry |

| replay | SEED [--reference E] [--subject E] [--tcl-version X.Y] | Regenerate seed S, restoring its persisted release automatically. An explicit release selects that exact registry |

| wasm-check | --iterations N [--seed S] [--verbose] | WASM-runnability arm: compile each program to the eval-fallback WASM module and flag codegen panics / instantiation failures / traps |

| wasm-diff | --iterations N [--seed S] [--verbose] | WASM value-differential arm: compare compiled-WASM control flow (hosted by tcl-vm) against direct tcl-vm, isolating control-flow miscompiles |

| characterise | --iterations N [--seed S] [--verbose] [--compare-error-text] | Three-way campaign classifying tcl-vm and runtime/rust against C Tcl 9; agreement between the two Rust backends alone is never correctness |

| bpf-diff | --iterations N [--seed S] [--verbose] | eBPF arm: compare a generated BPF-Tcl socket filter's dialect contract against the real lowering, eBPF emitter, and userspace eBPF VM |

| linked-wasm-diff | --iterations N [--seed S] [--verbose] | Link a compiled user module against runtime/rust's WASM module and compare against C Tcl 9 |

Match the reference `tclsh`'s version, or read every finding twice

**A divergence is evidence of a bug only when both engines speak the same

version of Tcl.** A campaign against tclsh8.6 with a 9.0-era subject reports

deliberate language changes as findings. The usual culprits:

| Cause | Seeds | What differs |

|---|---|---|

| TIP 461 lt/gt/le/ge string-comparison operators (9.0+) | 90040, 90061, 90091, 90104, 90112 | 8.6 rejects expr {{a} lt {b}} as invalid bareword "lt" |

| TIP 521 isfinite()/isinf()/isnan() (9.0+) | 90119 | 8.6: invalid command name "tcl::mathfunc::isfinite" |

| Namespace-scope global fallback for relative variable names, removed in 9.0 (TIP 278) | 90022, 90188 | see the KCS note |

Every campaign prints both engines' releases before it starts and warns when

they differ; every finding records reference_version, subject_version and

version_skew. Check those before triaging.

To run version-matched against an older reference, pin the whole pair:

# runtime-rust and tclvm emulating 8.6
cargo run -q -p tcl-fuzz -- \
  run --subject runtime-rust --reference tclvm --tcl-version 8.6 \
  --iterations 200 --seed 90000

runtime-rust and tclvm receive the same --tcl-version argument. A fixed

release engine such as C tclsh is selected by its binary instead, then its

reported release is verified; no engine may silently ignore a pair pin.

--subject-tcl-version is an alias with the same pair-wide semantics. Pinned

findings live below tclX.Y/ and replay restores that line; the same seed at

8.6 and 9.0 is deliberately two separate records.

--compare-error-text (on run) additionally flags an ErrorTextMismatch

finding when both engines error but their stderr text differs — off by

default, since independent implementations legitimately word errors

differently (e.g. "wrong # args" phrasing); use it when hunting for an engine

reporting the wrong kind of error for a shared failure, not just "an error".

Building the `runtime-rust` engine

runtime/rust's expr/if/while/for/math commands are gated behind a

have_tommath cfg that only turns on when a libtommath C source tree is

found at build time ($TCL_TOMMATH_DIR, else tmp/tcl9.0.4/libtommath — see

runtime/rust/build.rs). Without it, run_script is missing most of the

generator's surface and a runtime-rust-paired campaign is dominated by

false "invalid command name" divergences that are a build gap, not a

runtime bug. Point TCL_TOMMATH_DIR at any libtommath ≥ 1.3.0 source

checkout (the version matters: 1.2.x's mp_expt_n is a deprecated wrapper

excluded by the build script's file filter; 1.3.0 defines it directly in

bn_mp_expt_n.c) before building:

# The Tcl 9.0.4 source tarball already ships libtommath 1.3.0 at
# tmp/tcl9.0.4/libtommath, so extracting it (which building a 9.0 oracle
# does anyway) is usually enough — check for that directory FIRST.
# Only if it is genuinely absent, a shallow tag checkout also works and
# needs no build of its own:
git clone --depth 1 --branch v1.3.0 \
  https://github.com/libtom/libtommath tmp/libtommath-1.3.0

# `runtime/rust` is a standalone crate, excluded from the top-level
# workspace — build it from its own directory so it keeps its own target
# dir (do not export the workspace's CARGO_TARGET_DIR into it).
cd runtime/rust && TCL_TOMMATH_DIR="$PWD/../../tmp/libtommath-1.3.0" \
  cargo build --release --example run_script

Verify with a quick smoke script (expr/if should both work, not error

with invalid command name) before trusting a campaign's findings.

Categories

A finding's category is the CODE0 that

produced it:

| Category | Meaning |

|---|---|

| stdout_mismatch | The two engines produced different stdout |

| status_mismatch | The two engines disagreed on error/success status |

| error_text_mismatch | Both engines errored, but their stderr text differed (only recorded with --compare-error-text) |

| timeout | The subject hung |

Typical workflows

Run a campaign and see what diverges (default pair: tclvm subject / tclsh reference)

cargo run -q -p tcl-fuzz -- run --iterations 5000 --verbose
cargo run -q -p tcl-fuzz -- summary

Run a campaign over a different backend pair

# runtime/rust vs tclsh (needs runtime-rust built with TCL_TOMMATH_DIR — see above)
cargo run -q -p tcl-fuzz -- run --subject runtime-rust --reference tclsh \
  --iterations 2000 --verbose
cargo run -q -p tcl-fuzz -- summary --subject runtime-rust --reference tclsh

# tclvm vs runtime/rust (both native implementations — isolates a tclvm/runtime-rust
# divergence from a "did either agree with tclsh" question)
cargo run -q -p tcl-fuzz -- run --subject tclvm --reference runtime-rust \
  --iterations 2000 --verbose

Hunt for wrong-kind-of-error divergences

cargo run -q -p tcl-fuzz -- run --iterations 5000 --compare-error-text

Triage a specific finding

cargo run -q -p tcl-fuzz -- replay 1772893252
# a non-default pair's finding needs the matching --reference/--subject:
cargo run -q -p tcl-fuzz -- replay 1772893252 --subject runtime-rust --reference tclsh

Confirm a fix resolved a finding

After changing the backend, rebuild and replay the seed; the engines should

now agree (no divergence printed):

cargo build -p tcl-vm
cargo run -q -p tcl-fuzz -- replay 1772893252

Finding JSON schema

Each finding is one JSON record (rust/tcl-fuzz/src/findings.rs):

{
  "seed": 1772822330,
  "category": "stdout_mismatch",
  "script": "…the generated Tcl…",
  "reference_stdout": "…reference engine's stdout…",
  "subject_stdout": "…subject engine's stdout…",
  "reference_errored": false,
  "subject_errored": false,
  "reference_stderr": "",
  "subject_stderr": "",
  "tcl_version": "9.0",
  "replay_metadata_version": 1,
  "reference_version": "9.0.4",
  "subject_version": "9.0.4",
  "version_skew": false
}

reference_version/subject_version are each engine's [info patchlevel],

probed once per campaign (null if the probe failed). version_skew is true

when the two engines emulate different release lines — treat every finding in

a skewed run as suspect until the version difference is ruled out.

replay_metadata_version: 1 proves the record was written with a complete

campaign configuration. Thus tcl_version: null is a legitimate newly

recorded unpinned campaign and replays unpinned; an older release-less record

missing the marker is refused rather than guessed at today's default. A valid

explicit tcl_version remains replay-safe even in a record written before the

marker. summary labels each namespace separately so release-specific records

never collide.

reference_stderr/subject_stderr are always captured when the engine ran

(independent of --compare-error-text), so a triager always has both

engines' error text to hand even for a stdout_mismatch/status_mismatch

finding.

$ARGUMENTS

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.