Files
reims-vgpu/scripts/constant-fields/constant-fields.sh
T
Anees IqbalandClaude 24961caef6 ✨ constant-fields, the sweep that found the last two towers
`scripts/constant-fields/`, plus a section in `AGENTS.md` next to `dead-state`.
Tooling and docs only; no crate code.

`dead-state.sh` answers "does anything read this?". It cannot answer "does this
ever say anything?" — a counter with a live reader earns nothing if the branch
that would move it is never taken, and that is invisible in the source. Both
removals behind `930c6f0` and `f80f719` were found this way and neither was
reachable by reading code: `id_hits` looked like a per-page counter, and the four
`war_*` licence buckets looked like four quiet measurements.

The script parses every `key=value` field out of the always-on log and reports
those with exactly one distinct value. Two details that are load-bearing:

- **Bucket by emitting line family, not by field name.** `reason=` is constant on
  one family and varied on another; grouping by name alone cancels them and the
  constant one is never reported. The family is the token after the `OFF` marker.
- **Its own control** is that it re-finds `gva_write gpa_match=0` — the write-gate
  probe `d128fc1` deleted for exactly this reason. If a run stops reporting that
  on a pre-`d128fc1` log, the parser has drifted rather than the log having
  improved.

It reports 95 fields at the default threshold on the current 60 MB log, so this
is a backlog, not a one-off. The README records the triage rules, because most of
those 95 are legitimate: a standing alarm reading zero is working, and so is a
host capability constant like `frame_shift=12` or a probed device feature. It
also records the type-11 ladder's warning — 12/5/8/0 undriven against
31 916/1 694/705/150 driven — because an undriven boot is quiet enough to talk
someone into deleting a live rung.

The shape that actually convicts, and the reason the `war_*` cluster survived an
earlier session's review: **a bucket downstream of another bucket that is itself
always zero.** Four zeros read as four quiet measurements; the fifth zero
(`war_mapping`) showed the four were unreachable.

Verified: `scripts/constant-fields/constant-fields.sh` runs clean against
`/tmp/reims-vgpu-fail.log` and reproduces both findings plus its own control. No
crate code touched, so no test or clippy run was expected to change and none is
claimed.

Co-Authored-By: Claude <noreply@anthropic.com>
2026-08-01 14:11:15 +03:00

85 lines
3.0 KiB
Bash
Executable File

#!/usr/bin/env bash
#
# Report always-on log fields that only ever take ONE value.
#
# A `key=value` field that never varies across a whole log history is not a
# measurement. It is either structurally impossible (the branch that would move
# it returns before the line is emitted), or vestigial (it measures a mechanism
# that has since been deleted). Both are code to remove, and neither is visible
# from the source: the field looks like a live counter until you count it.
#
# See README.md for the triage rules and for what this deliberately does NOT
# report.
set -euo pipefail
LOG="${1:-/tmp/reims-vgpu-fail.log}"
MIN="${2:-200}"
if [[ ! -r "$LOG" ]]; then
echo "constant-fields: cannot read $LOG" >&2
echo "usage: $0 [logfile] [min-samples]" >&2
exit 1
fi
echo "[constant-fields] log=$LOG min-samples=$MIN"
echo
python3 - "$LOG" "$MIN" <<'PY'
import collections, re, sys
log, min_samples = sys.argv[1], int(sys.argv[2])
# Field name must start with a letter and be >=3 chars, so hex dumps and
# `t=<ms>` timestamps do not swamp the report. The lookbehind keeps `a=b` out of
# `foo.a=b` and of `x=y=z` tails.
field = re.compile(r'(?<![\w.])([a-z][a-z0-9_]{2,})=(\S+)')
values = collections.defaultdict(set)
counts = collections.Counter()
with open(log, errors='ignore') as fh:
for line in fh:
parts = line.split()
# Field names repeat across unrelated line families, so bucket by the
# emitting family (field 2, after the OFF/verbose marker). Without this
# a `reason=` that is constant on one line and varied on another cancels
# out and the constant one is never reported.
family = parts[1] if len(parts) > 1 else '?'
for key, value in field.findall(line):
slot = (family, key)
if len(values[slot]) < 6:
values[slot].add(value)
counts[slot] += 1
const = [
(n, fam, key, next(iter(values[(fam, key)])))
for (fam, key), n in counts.items()
if len(values[(fam, key)]) == 1 and n >= min_samples
]
const.sort(reverse=True)
if not const:
print(" none")
else:
print(f"{'samples':>8} {'family':<34} field=value")
for n, fam, key, val in const:
print(f"{n:8d} {fam:<34} {key}={val}")
print()
print(f"[constant-fields] {len(const)} single-valued fields at >={min_samples} samples")
PY
cat <<'NOTE'
[constant-fields] Triage before deleting. A field can be legitimately constant:
[constant-fields] - a standing alarm reading zero (it is doing its job)
[constant-fields] - a capability/geometry constant for this host (page shift,
[constant-fields] a cap's configured size, a device feature flag)
[constant-fields] - an arm the workload never reached (drive the guest harder
[constant-fields] before believing it, per the type-11 ladder's own note)
[constant-fields] What it is NOT: a bucket downstream of another bucket that is
[constant-fields] itself always zero, or a counterfactual for deleted code.
[constant-fields] Read the emitting code before cutting; the log only points.
NOTE