Skip to content

Instruments carry their own conditions: a shared load gate, a shared PDF extractor, and the A/B reports ink beside pages - #805

Merged
tannevaled merged 6 commits into
mainfrom
instruments-carry-their-conditions
Nov 16, 2026
Merged

tannevaled merged 6 commits into
mainfrom
instruments-carry-their-conditions

Conversation

@tannevaled

Copy link
Copy Markdown
Contributor

Instruments carry their own conditions

Three things an instrument in this repository could not do, each of which had
already cost a measurement:

  1. refuse a busy machine by itself. The rule "never measure above a 1-minute
    load of ~8" was a human running uptime either side of a run and pasting the
    result into a pull request by hand — a dozen times in one day, and one run
    still went out at 8.46 with a caveat attached instead of being refused.
  2. tell a breaking change from a content one. gotex-abdiff counts pages.
    Pages cannot distinguish "the same text, broken differently" from "text that
    appeared or vanished", and the only code here that reads glyphs back out of a
    PDF lived inside gotex-linediff as package main, unreachable.
  3. be tested where it judges. Two defects in this branch were of that shape,
    and both were mine (below).

cmd/internal/loadguard

Shared by gotex-abdiff and gotex-refdiff rather than written twice.

  • both the 1-minute and the 5-minute average must be under 8. Reading only
    the first minute passed a run at 1-min 6.93 with a 5-min of 10.00.
  • ⛔ "I could not read the load" is not "the load is fine." Every path that
    cannot answer returns an error and the caller refuses. A guard that passes
    when blind converts an unmeasurable machine into a clean bill of health, and
    this fleet has paid for that shape before. Its test asserts that the zero value
    would pass the threshold, which is exactly why Check reads the error first.
  • -under-load '<why>' measures anyway and stamps the reason into the report,
    so a number taken deliberately on a busy machine says so wherever it is quoted.

Its first real firing came while writing this branch: it refused the end-to-end
control below at a 1-minute average of 23.75, before the flag was passed.

cmd/internal/pdfruns

gotex-linediff's PDF text extractor moves out whole — pdf.go, text.go,
font.go and the eleven tests that cover them (the text operators, the matrix
composition, the simple and composite widths, the UTF-16BE ToUnicode offset,
the subset tag, the page height). Still through go-pdfkit/reader: no qpdf,
no poppler, no MuPDF. What stays in gotex-linediff is what belongs to that
tool — grouping runs into lines, the leader pitch, -above, the report.

New, and the reason for the move: Glyphs(doc) (total, bad int) — the glyph
total over every page, with pages that failed to decode counted separately
rather than folded into the total as zero. An unreadable page is not an empty
one. Its test asserts an order (prose has more glyphs than one word), not a
magic number that would only record what the engine did the day it was written.

gotex-abdiff reports the ink

Σ|page deviation| 0 -> 0   (+0)
papers moved      0   (0 toward the reference, 0 away, 0 sideways)
Σ glyphs          1106 -> 1106   (+0)   ⚠ WITNESS, NOT A SCORE: the reference
                  file holds page counts only, so there is no ink to be near or far from
neither pagination nor ink moved on any paper: this change does not reach this corpus

A three-way verdict, because the two numbers answer different questions:

pages move, ink holds still a breaking change — the ink was re-dealt across pages, which is what a penalty, a measure or a glue change does
ink moves a content change — a macro that now expands, or output that got dropped. The xkeyval precedent: a package that stopped erroring, the same page count, text on the page that had not been there before, and a page-only A/B called it "nothing moved"
neither moves the change does not reach this corpus

⛔ The ink is a witness, not a score, and the line says so. The corpus
reference file carries page counts and nothing else, so "toward" and "away" are
undefined for ink: this says whether a change moved ink, never whether the ink
is right. A Σ with a signed delta printed beside two columns that are scored
against a reference gets read as a third score unless it disowns that reading
itself.

⛔ Pages that parse as pages but whose text does not decode are counted in their
own field and make the report refuse its own delta out loud: two incomplete
sums differ by an amount that looks exactly like ink that moved.

The two defects this branch introduced and took back

The load gate inside run(). run is gotex-refdiff's testable entry
point, and three tests call it directly — so their verdict became a function of
what else the machine happened to be doing: green at a 1-minute average of 4.6,
red at 14.44 with absent corpus: code=2 want 1, and not a line of code
different between the two. The "green on one pass, red on the next" class this
repository keeps paying for, introduced into a guard whose purpose is to keep a
measurement honest. main decides whether to measure; run decides how.

A verdict tested where it is worded, not where it is decided. The first ink
test hands reportInk an inkMoved of 3 and checks that it says CONTENT. Only
report knows whether 3 is the right number, and it derives it from
r.base.Glyphs != r.head.Glyphs — one word away from the r.base.Pages != r.head.Pages on the line above. Written against Pages by mistake the ink
column would say "ink held still" on every content change there is, and that test
would still pass, because it supplies the number it checks. report now prints
through an io.Writer and a second witness goes in through it with three papers
whose pages are identical and whose ink differs on two.

Witnesses

Each of the new rules has a witness on each side of its boundary, since a
stated rule is only as good as the case that catches it being too wide:

  • loadFlag — too narrow: an authorised override that is not read means the gate
    refuses a run the operator asked for. Too wide: -under-loading <reason> must
    not be taken as the override, or a measurement runs under a stamp nobody wrote.
    Turning the exact match into a prefix match turns that row red. Plus the control
    neither side gives: run's own -h listing must still mention -under-load,
    so the flag main reads is the flag run declares.
  • the ink verdict — a row per branch, each asserting the word the reader acts on
    and that the opposite word is absent. A branch chosen backwards would label
    every finding as its opposite, in a sentence a reader has no reason to doubt.
  • the undecodable-page warning has a control with nothing undecodable, so it
    cannot become furniture a reader learns to skip — including on the run where it
    is true.
  • three blank pages must measure 0 glyphs and 0 undecodable pages.
    Without the second half that zero passes just as well when nothing decoded at
    all; without the first the glyph count could be the page count under another
    name.
  • the report-level verdict has the control that matters: the same three papers
    with the ink equalised must flip the verdict away from CONTENT.

Measured

go test -count=1 ./cmd/... — 9 packages, 0 failures, uncached, at a 1-minute
load of 8.78, which is above the threshold and is the exact condition that
used to turn those three gotex-refdiff tests red.

End-to-end control, since every other figure here comes from hand-built structs:
a two-page document of real prose through the whole path — two worktrees, two
builds, measure, report — reports 1106 glyphs per side. Not zero: the ink is
read through the real pipeline and not only in tests. Both sides are the same
commit, so nothing may move, and nothing did.

⚠ That control ran with -under-load, and the banner carries the reason: at a
1-minute average of 11.07 it is not a measurement. Both sides are the same commit,
so no quantity is compared across revisions and the only reading taken is "is the
glyph total non-zero".

Not done

That the ink column detects a content change on real papers is untested end
to end. It needs two revisions whose output differs in ink; the next change that
produces one is its own witness.

Refs #675 — the plan is posted there and stays open: this lands the instruments,
not the fidelity work they serve.

🤖 Generated with Claude Code

tannevaled and others added 6 commits November 16, 2026 17:33
… and refuse a busy machine

Until now the load check was a HUMAN running `uptime` either side of every
gotex-abdiff and gotex-refdiff run and pasting the result into the pull request
by hand. That happened a dozen times in one day, and one run still went out at a
1-minute average of 8.46 — over this fleet's threshold — with a caveat attached
instead of being refused, and had to be repeated.

Both tools now call loadguard.Check before any compiling and print
loadguard.Banner above their result, so the conditions travel WITH the number
instead of living in the operator's memory:

	load 1-min 4.62 / 5-min 5.72 / 15-min 6.64  (under the 8 threshold on both …)
	base HEAD  aa209d3
	154 papers …

ONE IMPLEMENTATION, TWO CONSUMERS. It is a package under cmd/internal/ and not a
line copied into each main.go, because both tools produce numbers that go into
pull requests and both were worthless above a load their caller had to remember
to check.

⛔⛔ AND "I COULD NOT READ THE LOAD" IS NOT "THE LOAD IS FINE". Every path that
cannot answer returns an error and the caller refuses. A guard that passes when
blind is worse than no guard: it turns an unmeasurable machine into a clean bill
of health, which is the shape this fleet has already paid for — a scan that could
not read reported zero. The test asserts it: a failed parse returns the zero
Averages, the zero value PASSES the threshold comparison, and that is precisely
why Check consults the error first.

⚠ BOTH the 1-minute and the 5-minute average must be under the threshold. A
1-minute dip beneath a loaded 5-minute average is not a quiet machine; reading
only the first minute passed a run at 1-min 6.93 with a 5-min of 10.00 earlier in
this fleet's history. Tested as a table, including that exact pair.

⚠ WHY LOAD MATTERS AT ALL, since page counts are deterministic: it acts THROUGH
the per-paper timeout. gotex-refdiff's own doc says a compile that merely
exhausts -timeout "is marked timed-out and excluded on EITHER side … a slow
paper, or a loaded machine, moved the mean one way only."

-under-load '<why>' measures anyway and the reason is STAMPED into the banner, so
a reader sees the measurement was taken deliberately on a busy machine rather
than wondering.

⛔ AND IT TURNED A REPOSITORY GUARD RED, WHICH WAS RIGHT OF IT.
TestEveryCommandIsIgnoredAtTheRoot asserted that every DIRECTORY under cmd/ has a
/name line in .gitignore, because every command builds to a root binary of its
own name — "a command added without one is how the last binary got committed".
cmd/internal/ holds packages, not commands, and produces no binary, so demanding
a line would assert something false; adding "/internal" to .gitignore to quiet it
would ignore any internal directory at the root into the bargain. The invariant
is unchanged and is in the test's own name — every COMMAND is ignored — and only
the recognition moved, from "is a directory" to "declares package main".
MUTATED to prove the narrowing did not disarm it: a cmd/gotex-zzmutant holding
`package main` and no .gitignore line is named and refused. The test also gained
a control, because a premise that narrows can narrow to nothing: a run that
recognised no command at all now fails instead of passing in silence.

Co-Authored-By: Claude Opus 5 <[email protected]>
…e three tests depend on the ambient load

The gate landed one commit ago inside run(), the testable entry point. Three
tests call run directly, so their verdict became a function of what else the
machine happened to be doing: green at a 1-minute average of 4.6, red at 14.44
with `absent corpus: code=2 want 1`, and not a line of code different between
the two runs.

That is the "green on one pass, red on the next" class this repository keeps
paying for, and I had introduced it INTO a guard whose whole purpose is to keep
a measurement honest.

main now decides whether to measure; run decides how. Since main must decide
before run parses anything, loadFlag reads -under-load out of the raw arguments
-- deliberately recognising four spellings and nothing else, because run's own
FlagSet stays the authority on every argument a moment later.

The flag is still declared in run, so it is a known flag and shows in -h.

Witnesses, one on each side of loadFlag's boundary:
  - too narrow: an authorised override that is not read means the gate refuses
    a run the operator asked for, and the reason never reaches the report;
  - too wide: `-under-loading <reason>` must NOT be taken as the override, or a
    measurement runs on a busy machine under a stamp nobody wrote. Changing the
    exact match to a prefix match turns that row red.

And the control neither loop can give: run's -h listing must still mention
-under-load, so the flag main READS is the flag run DECLARES. The day those two
literals diverge, both loops still pass while the flag quietly stops working.

Verified uncached (-count=1) at a 1-minute load of 8.78 -- above the threshold,
which is the exact condition that used to turn those three tests red: 0
failures.

Co-Authored-By: Claude Opus 5 <[email protected]>
… the A/B can count ink, not only pages

gotex-abdiff answers "how many pages on each side". It cannot answer "is that
more ink, or the right ink" -- and that question cost a whole second protocol
earlier today, because the only code in this repository that reads glyphs back
out of a PDF lived inside gotex-linediff as package main and could not be
called from anywhere.

So it moves, unchanged, to cmd/internal/pdfruns: pdf.go, text.go, font.go and
the eleven tests that cover them -- the text operators, the matrix composition,
the simple and composite widths, the UTF-16BE ToUnicode offset, the subset tag,
the page height, and the two operators a reader forgets. They travel WITH the
code they test; what stays in gotex-linediff is what belongs to that tool
(grouping runs into lines, the leader pitch, -above, the report, formatting),
and ftoa came back there because no caller in pdfruns used it.

It reads through go-pdfkit/reader as before: no qpdf, no poppler, no MuPDF.

New in the package, and the reason for the move:

  Glyphs(doc) (total, bad int)

the glyph total over every page, with the pages that failed to decode counted
SEPARATELY rather than folded into the total as zero -- an unreadable page is
not an empty one, and a total that quietly absorbed it would make a broken
document look like a short one.

Its test asserts an ORDER, not a magic number: a paragraph of prose has more
glyphs than a single word, and a one-page control makes sure the count is over
ink and not over pages. A number baked in here would only record what the
engine did the day it was written.

Co-Authored-By: Claude Opus 5 <[email protected]>
…aking change from a content one

A page count cannot distinguish "the same text, broken differently" from "text
that appeared or vanished", and those are opposite findings:

  - pages move, ink holds still -- a BREAKING change: the ink was re-dealt
    across pages, which is what a penalty, a measure or a glue change does;
  - ink moves -- a CONTENT change: a macro that now expands, or output that got
    dropped. The precedent is xkeyval, where a package that stopped erroring
    produced the same page count with text on the page that had not been there
    before, and a page-only A/B called that "nothing moved";
  - neither moves -- the change does not reach this corpus.

Answering the second half used to mean a whole second protocol, because the
only code here that reads glyphs back out of a PDF was inside gotex-linediff as
package main. It is cmd/internal/pdfruns now, so pageCount becomes measure and
returns pages, glyphs and undecodable pages from ONE parse of the PDF.

What the report gains:

  Σ glyphs          50000 -> 51200   (+1200)   ⚠ WITNESS, NOT A SCORE: ...
  ink moved on 3 paper(s) with NO page moving at all: a CONTENT change ...
  ink moved on 3 paper(s):
    2405.20319      48120 ->   48344 glyphs   (+224)

⛔ The ink is a WITNESS, NOT A SCORE, and the line says so. The corpus reference
file carries page counts and nothing else, so "toward" and "away" are undefined
for ink: this says whether a change moved ink, never whether the ink is right. A
Σ with a signed delta printed beside two columns that ARE scored against a
reference gets read as a third score unless it disowns that reading itself.

⛔ Pages that parse as pages but whose text does not decode are counted in their
own field, never folded into the total as zero. When either side has one the
report refuses its own delta out loud: two incomplete sums differ by an amount
that looks exactly like ink that moved. An unreadable page is not an empty one.

Witnesses:

  - the three-way verdict gets a row per branch, each asserting the word the
    reader acts on AND that the opposite word is absent -- a branch chosen
    backwards would label every finding as its opposite, in a sentence a reader
    has no reason to doubt;
  - the undecodable-page warning has a control with nothing undecodable, so it
    cannot become furniture a reader learns to skip;
  - three BLANK pages must measure 0 glyphs AND 0 undecodable pages. Without the
    second half that zero passes just as well when nothing decoded at all, which
    is the blind-scan-reports-zero shape; and without the first half the glyph
    count could be the page count under another name.

reportInk takes an io.Writer, unlike the rest of this report, for exactly one
reason: a function that classifies belongs under a test, and one printing to
os.Stdout has none.

Co-Authored-By: Claude Opus 5 <[email protected]>
…re it is DECIDED and not where it is worded

The verdict test I had just written hands reportInk an inkMoved of 3 and checks
that it says "CONTENT". Only report knows whether 3 is the right number, and it
works it out from

	r.base.Glyphs != r.head.Glyphs

one word away from the r.base.Pages != r.head.Pages on the line above it.
Written against Pages by mistake, the ink column would say "ink held still" on
every content change there is -- and the verdict test would still pass, because
it supplies the number it is checking. A test of the wording is not a test of
the judgement.

So report prints through an io.Writer and a new witness goes in through it, with
three papers whose PAGE counts are identical and whose ink differs on two. It
reads the verdict out of the report's own text: "papers moved 0", "CONTENT",
"ink moved on 2 paper(s)", the two movers listed worst-first, and the paper that
did not move absent from that list. Changing Glyphs to Pages in report turns it
red.

And its control, which is the half that matters: the SAME three papers with the
ink equalised must flip the verdict away from CONTENT. Without it the test would
pass against a report that said CONTENT unconditionally.

The ink movers are now sorted worst-first too, like the page movers beside them;
unsorted, -top would have cut the list at whichever papers came first in the
corpus list rather than at the largest differences.

End-to-end control, since every figure above comes from hand-built structs. A
two-page document of real prose, compiled through the whole path -- two
worktrees, two builds, measure, report:

	base HEAD  ff5e6c5
	head HEAD  ff5e6c5
	Σ|page deviation| 0 -> 0   (+0)
	Σ glyphs          1106 -> 1106   (+0)
	neither pagination nor ink moved on any paper

1106 glyphs, not zero: the ink is being read through the real pipeline and not
only in tests. Both sides are the same commit, so nothing may move, and nothing
did.

⚠ Run with -under-load, and the reason is in the banner: at a 1-minute average of
11.07 this is not a measurement. Both sides are the same commit, so no quantity
is compared across revisions and the only reading taken is "is the glyph total
non-zero". The gate's own first real firing came in the same session, when it
refused this very command at 23.75 before I passed the flag.

Still untested end to end: that the ink column DETECTS a content change on real
papers. That needs two revisions whose output differs in ink, and the next change
that produces one is its own witness.

Co-Authored-By: Claude Opus 5 <[email protected]>
…the PDF extractor lives

Two user-visible changes in this branch had no entry in the table a reader
consults to choose an instrument:

  - gotex-abdiff reports Σ glyphs per side, and the row now carries what that
    distinguishes (pages moving with the ink still = breaking; ink moving =
    content, the xkeyval shape), that it is a WITNESS and not a score since the
    reference file holds page counts only, and that undecodable pages make the
    report disown its own glyph delta;
  - the load gate, which refuses both measuring tools above 8 on the 1-minute or
    the 5-minute average, refuses when it cannot READ the load, and stamps the
    reason of an -under-load override into the report.

And the gotex-linediff row says its PDF extractor now lives in
cmd/internal/pdfruns rather than inside that command -- which is the reason
gotex-abdiff can count ink at all instead of a second protocol being written to
answer the same question.

Co-Authored-By: Claude Opus 5 <[email protected]>
@tannevaled
tannevaled merged commit b019c2e into main Nov 16, 2026
26 of 27 checks passed
@tannevaled
tannevaled deleted the instruments-carry-their-conditions branch November 16, 2026 20:49
tannevaled added a commit that referenced this pull request Nov 16, 2026
…ws lane was blamed on (#806)

The windows-latest lane runs `go test -timeout 30m -race ./...` and the root
package came back `FAIL github.com/go-tex/engine 1800.560s` on #805, having
printed its coverage first: the suite nearly finished and then the alarm fired.
The same commit passed on the `push` event, so the lane sits exactly on the
bound, and the bound has already been raised twice (#156, #653).

The standing explanation -- recorded, and relayed to me by another session this
morning -- was that every test re-expands the whole LaTeX format through
LoadLaTeX, "which is exactly what TeX's .fmt files exist to avoid", with the
verdict "a third raise is not the fix; the per-test cost is".

The mechanism is real. The goroutine dump at the timeout is inside it:

	engine.(*Engine).define            engine.go:1202
	engine.(*Engine).assignLetMeaning  primitives.go:333
	engine.(*Engine).doLet             primitives.go:319
	engine.(*Engine).loadPrimitives.func5
	engine.(*Engine).execCS            engine.go:2353
	engine.(*Engine).mainLoop          engine.go:2113
	engine.(*Engine).LoadFormat        format.go:141
	engine.(*Engine).LoadLaTeX         latex.go:1942
	engine.TestTransformErrorBranches  transform_test.go:283

⛔ BUT THE SIZE IS NOT. This repository had NO benchmark at all, so the cost had
been argued about and never read. Measured with the two added here,
darwin/arm64, Apple M4 Max, GOMAXPROCS=1 and -parallel 1 so the suite and the
benchmark count ALIKE:

	suite, 2012 tests, serial        58.04 s
	BenchmarkLoadLaTeX                3.658 ms/op
	BenchmarkNewWithoutTheFormat      0.105 ms/op
	format expansion                  3.553 ms/op

2012 × 3.658 ms = 7.36 s = 12.7% of the suite, and that is an UPPER BOUND since
not every test calls LoadLaTeX. A format built once per package buys about an
eighth. Worth having; not the thirty minutes. 87% of the cost is somewhere else
and is still unlocated.

⚠ Two things I did NOT do, said plainly:

- the 58 s wants retaking on a quiet machine. The 1-minute load average was 4.95
  before that run and 28.02 after, so it may be inflated. The share argument
  survives either way -- the suite would have to be about 8 s serial for the
  format to dominate, and it is 20 s even with sixteen-way parallelism -- but the
  58 s should not be quoted as a baseline until it is retaken.
- the comparison is serial-to-serial on purpose. A serial sum of per-test costs
  held against a 16-way parallel wall clock is not a share, it is two different
  quantities, and that is the shape that lets two errors cancel.

⭐ The benchmark is the deliverable, not the number. Run it on each lane and
"windows is slow" becomes a ratio instead of a belief:

	go test -run '^$' -bench 'BenchmarkLoadLaTeX' -benchtime 10x .

Refs #799 -- the Windows lane decision it tracks is not taken here; this removes
one candidate from it.

Co-authored-by: Claude Opus 5 <[email protected]>
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.

1 participant