Skip to content

render-pipeline: adapt is linear again — index list/theorem nesting once, memoise setlength (18 s → 0.19 s warm edit on #535) - #623

Merged
GoKubar merged 2 commits into
mainfrom
agent/daniel-parent/adapter-quadratic
Sep 15, 2026
Merged

GoKubar merged 2 commits into
mainfrom
agent/daniel-parent/adapter-quadratic

Conversation

@d-q222

@d-q222 d-q222 commented Sep 15, 2026

Copy link
Copy Markdown
Contributor

What

adapter::adapt_cached was quadratic in document length (the finding in #613). This PR makes it linear, and the output is byte-identical. There are two commits:

  1. split_at_page_breaks: one forward pass per document (24a3d9d1).
    • Before, every block called in_theorem_environment and list_stack_at, which each rescan the source from byte 0. It also called setlist_calls (up to three times: list_seps_with, the nested list_seps and list_margins) and natbib_author_year, which each scan the whole source.
    • The new SourceIndex is built lazily, once per document per call. It records every \begin/\end with find_command's lexing, and stores:
      • the list stack after each list command;
      • whether a theorem-like environment is open after each named command;
      • the \setlist calls and the natbib flag.
    • A query at byte at is a partition_point over the marks.
    • list_seps_from, list_margins and list_end_adjust take the precomputed calls and stack. list_seps_with, list_stack_at and list_end_skip keep their signatures for the float code.
    • Why the snapshots give the same answers:
      • list_stack_at sees a command when pos + len(command) <= at, and it reads the name from the full source. A match cut off at at (for example \beginx) has no { after it, so it is skipped in both versions.
      • in_theorem_environment sees a name only when its closing } is before at. That byte never decreases in source order, so the matched commands are always a prefix.
    • in_theorem_environment stays as the reference. The unit test source_index_matches_prefix_scans compares the index with both prefix scans at every byte offset of edge-case sources. Those sources cover comments, \%, \\begin, \begin {x}, \begin[x]{theorem}, \beginning, unclosed names and braces, mismatched \ends, multibyte text, thebibliography options and enumitem keys.
  2. setlength, memoised per adapt call (ce286c98).
    • After step 1, 97% of the remaining adapt time was in TableLengths::read. Every tabular asks for four lengths, and each setlength call scanned the whole source with find_command: 770 ms at 450 sections.
    • The answer is a pure function of (source, name, size). It is now kept in the MacroDefsScope entry of the document, which already lives exactly as long as the adapt call, is keyed by the text's address and length, and indexes \newcommands the same way. Outside a scope, setlength scans as before.

Why

Warm edits to #535's 450-section article took about 18 s, and about 35–41 s with a table of contents, although parse, typeset and assemble took under 100 ms. #575's step-0 measurements (#613) could not show any incremental-render win until this was fixed.

Before / after

Machine: mac-m5pro-dq222, shared (load average 12–16 throughout). Release builds.

stages warm adapt time (#613's generator, --emit N; mean of the two warm runs out of 3):

sections pages adapt before (ms) adapt after (ms) speedup
150 136 2042.1 21.6 94×
300 267 7512.9 41.3 182×
450 398 16221.0 57.9 280×

After commit 1 only, the times were 99.0, 411.0 and 806.9 ms. That was still quadratic, which is why commit 2 exists.

xref_measure warm edit, render ms (median):

document edit render ms before render ms after speedup
535 no-label 18225.5 190.4 96×
535 renumber 18555.3 250.0 74×
535 move-label 17907.7 198.6 90×
535+toc+pageref no-label 36720.9 404.8 91×
535+toc+pageref renumber 40911.0 456.8 90×
535+toc+pageref move-label 38372.8 356.3 108×

The cold render of 535 now takes 338–368 ms, against about 18 s before.

Identity evidence

For each input, flashtex-render --tex <file> --v2 out.json --pdf out.pdf ran with the before and after binaries, from the file's own directory. The script compared the v2 display-list JSON, the PDF, stdout, stderr (with the output paths normalised) and the exit code byte for byte.

  • 1175 / 1175 identical, and each of them wrote a v2 display list. The inputs were:

  • 3 / 3 identical on extra stress documents written for this PR, because the corpus has few amsthm files:

    • 40 sections of nested theorem/lemma/remark/proof with nested itemize/enumerate/description and nosep/label=;
    • a comment holding \begin{lemma};
    • inline and centred tabulars, \setlength{\tabcolsep};
    • natbib authoryear and numbers bibliographies;
    • 60 × four-deep lists under \setlist{leftmargin=*}.

    They render as 27, 7 and 12 pages.

@GoKubar: you are the code owner of the theorem check (in_theorem_environment, 2945f61a) and the list model. This change is meant to preserve behaviour exactly. Please review the equivalence argument above and the byte-offset test. The per-offset function is kept as the test's oracle.

Overlap check

Test results

cargo test --release --no-fail-fast -- --test-threads=4   (crates/render-pipeline, all tests including the 16 *_oracle suites)
EXIT 0; 79 test result lines, 376 passed, 0 failed, 3 ignored (the pre-existing ignores)
test adapter::tests::source_index_matches_prefix_scans ... ok
test result: ok. 138 passed; 0 failed; 2 ignored; 0 measured; 0 filtered out; finished in 0.03s   (lib)
display-list identity: 1175 SAME, 0 DIFF (repository .tex corpus + 4 generated documents)
display-list identity: 3 SAME, 0 DIFF (theorem/list/tabular stress documents)

Not done

🤖 Generated with Claude Code

https://claude.ai/code/session_012c9XLkHjePPGBuarrmE2mz

…er block

What changed:
split_at_page_breaks asked list_stack_at, in_theorem_environment,
setlist_calls and natbib_author_year for every block, and each of them
scans the source from byte 0 (or all of it). SourceIndex does one forward
pass per document per call and answers the same questions from prefix
snapshots with a binary search. list_seps_from/list_margins/list_end_adjust
take the precomputed setlist calls and stacks. The old per-offset scans stay
as the reference: source_index_matches_prefix_scans compares them at every
byte offset of edge-case sources.

What was run:
cargo test --release --lib source_index_matches
test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 139 filtered out
stages doc450.tex (warm): adapt 16191.0 ms before, 791.1 ms after

Next step:
memoise setlength per adapt call (the remaining quadratic term: 4 whole-
source scans per tabular), then display-list identity over the corpus.

Implementation-Agent: claude-opus-5 subagent of daniel-parent
Commit-Executor: daniel-parent subagent
Claude-Session: https://claude.ai/code/session_012c9XLkHjePPGBuarrmE2mz
What changed:
Every tabular's TableLengths::read (and LongtableLengths::read) called
setlength four times, and each call scans the whole source for
\setlength. setlength now memoises its answer per (length, class size) in
the MacroDefsScope entry of the document, which already lives exactly as
long as the adapt call; outside a scope it scans as before.

What was run:
stages doc150/300/450.tex (warm): adapt 21.4 / 40.9 / 55.6 ms
(791.1 ms at 450 after the previous commit; 16191.0 ms on origin/main)

Next step:
display-list identity over every fixture and the 535 document; release suite.

Implementation-Agent: claude-opus-5 subagent of daniel-parent
Commit-Executor: daniel-parent subagent
Claude-Session: https://claude.ai/code/session_012c9XLkHjePPGBuarrmE2mz
d-q222 added a commit that referenced this pull request Sep 15, 2026
…table (#525 review, #623)

What changed:
- `length_at_checked` scanned the source before every table (a CmdScan of
  the prefix, plus a `group_open_between` rescan per assignment) for each
  of the four tabular lengths and the five longtable lengths. On a
  document with many tables that is quadratic or worse: 800 tables spent
  1.6 s in it. It is the same class of bug #623 fixed in
  `split_at_page_breaks`.
- Within an adapt call (`MacroDefsScope`) each length is now indexed once
  per document: `length_assignments` collects every `\setlength`/
  `\addtolength`/`\<name>=` and assigning macro invocation of the whole
  source once, `GroupTokens` lexes the group depth once (the tokens
  `group_open_between` counts, with the next-lower-depth token of each),
  and `LengthIndex` links each assignment to the last earlier one still in
  force at its end. A table binary-searches its byte offset and walks that
  chain past closed groups. The value and `unresolved` flag are folded in
  the same order as the scan, so the floats are bit-identical.
- Outside an adapt call, at a byte inside a control word, or for a document
  whose assignments do not form a chain (an assigning macro in another's
  argument, an assignment ending inside a comment), the old scan runs
  unchanged as `length_at_scan`.
- The indexes live in a new `lengths` field of `MacroDefsEntry`, placed
  before `index` so #623's `setlengths` field merges without conflict
  (`git merge-tree` of this commit with #623's head is clean).

What was run:
- `cargo test --release --lib -- table_length`: test result: ok. 5 passed; 0 failed
  - table_length_index_matches_the_prefix_scan: the indexed lookup equals
    the scan at every byte of 8 hand-written and 300 generated sources,
    for tabcolsep/arrayrulewidth/LTpre (both index and fallback paths hit).
  - table_lengths_scale_linearly_with_the_number_of_tables:
    before: 200 tables 41.2ms, 400 tables 242.7ms, 800 tables 1.637s (panicked: not linear)
    after:  200 tables 393µs, 400 tables 717µs, 800 tables 1.42ms
- flashtex-render end to end, generated doc, best of 3 (before -> after, v2 identical):
  200 tables 0.16s -> 0.08s; 400 tables 0.71s -> 0.22s; 800 tables 4.05s -> 0.73s
- v2 JSON + compile_result of all 128 tabular_corpus fixtures and 22
  fixtures/real-world documents, head 99defd5 vs this commit: `diff -rq` IDENTICAL (150/150)
- `oracle.py check`: TOTAL 128/128 (words 0.5 bp, rules 0.1 bp)
- `cargo test --release` (render-pipeline): exit 0, 79 test binaries, 383 passed; 0 failed; 3 ignored

Next step: merge #623 after #525 (or the reverse); the rest of the
remaining 800-table time is #623's `split_at_page_breaks` fix.

Implementation-Agent: claude-opus-5 subagent of daniel-parent
Commit-Executor: daniel-parent subagent
Claude-Session: https://claude.ai/code/session_012c9XLkHjePPGBuarrmE2mz
@d-q222

d-q222 commented Sep 15, 2026

Copy link
Copy Markdown
Contributor Author

daniel-parent (subagent): merge interaction with #525.

#525's length_at (tabular lengths with group scope) had the prefix-scan-per-table bug this PR describes. #525 commit 8e2ed58 makes it linear in #623's style:

  • The in-scope assignments are indexed once per adapt call.
  • Each table looks up its byte offset by binary search.

On a generated document with 800 tables, the unit test drops from 1.637 s to 1.42 ms. Output is byte-identical on 150 fixtures, and the tabular oracle passes 128/128.

Merging the two

🤖 Generated with Claude Code

https://claude.ai/code/session_012c9XLkHjePPGBuarrmE2mz

d-q222 added a commit that referenced this pull request Sep 15, 2026
…he source"

What changed:
- Reverts 71d8fbf (adapter list_stack_at / in_theorem_environment /
  setlist_calls indexing and its two timing tests). #623
  (agent/daniel-parent/adapter-quadratic, opened while this ran) makes
  the same scans linear with a per-document SourceIndex, verified
  byte-for-byte against the prefix scans, plus memoised \setlength. This
  PR leaves the adapter to #623 and lists the fuzz hangs it removes.

What was run:
- git revert (adapter.rs and tests/fuzz_regressions.rs return to their
  state before 71d8fbf)

Next step: none here; #623 carries the adapter fix.

Implementation-Agent: claude-opus-5 subagent of daniel-parent
Commit-Executor: daniel-parent subagent
Claude-Session: https://claude.ai/code/session_012c9XLkHjePPGBuarrmE2mz
@d-q222

d-q222 commented Sep 15, 2026

Copy link
Copy Markdown
Contributor Author

daniel-parent independent review (subagent)

Verdict: APPROVE

Environment: macOS (darwin), cargo build --release, CARGO_TARGET_DIR isolated per worktree, CARGO_BUILD_JOBS=4. PR head ce286c98 in /Users/dqi26/flashtex-wt/review-623 vs origin/main 36fe7ec3 in /Users/dqi26/flashtex-wt/review-623-mainbase.

  1. Byte identity, 30 real documents (v2 JSON) — PASS. Ran flashtex-render --tex <file> --v2 out.json (release binaries, invoked from each file's own directory per the PR's own methodology) on both branches for all 22 fixtures/real-world/* documents plus 8 tests/tex-corpus/cases/*/main.tex documents (30 total, the corpus the repo's own tools/real-world-corpus harness draws from). 30/30 byte-identical (cmp -s on every pair), 0 mismatches, 0 exit-code mismatches. Outputs were non-trivial (5–7 KB+ JSON, real "recovered, N pages" renders), not silent failures.

  2. SourceIndex nesting correctness — PASS, with a coverage-gap observation (non-blocking). The built-in source_index_matches_prefix_scans (adapter.rs:7408, new) checks every byte offset of 7 sources, but its theorem nesting is single-level (one theorem/proof pair, never a theorem-like env nested inside another) and its list nesting has no \setlist calls at differing depths. I wrote a throwaway #[test] (not committed, worktree only) with 3 levels of nested theorem-like environments (theorem > proof > lemma > corollary) and 3 levels of nested lists (itemize > enumerate > itemize) with \setlist calls at each depth, and checked SourceIndex::in_theorem/list_stack against in_theorem_environment/list_stack_at at every byte offset (149 offsets) — 0 mismatches. I also worked through the algorithm by hand: both the list-stack and theorem-open tracking are plain name-matched push/pop stacks over all \begin/\end pairs (theorem tracking keeps a generic open: Vec<&str> and a separate theorems_open counter gated on theorem_envs.contains(name)), which is correct for arbitrary nesting depth by construction, not just for the depths the shipped test happens to cover. I'd still suggest folding a 2–3 level nested case into the permanent test before/soon after merge, since the current one doesn't guard against a future regression in nesting-depth handling specifically. One more thing I chased down and ruled out: find_command's word-boundary check has a truncation illusion at exactly at == pos + len(command) for a command immediately followed by more alphabetic characters (e.g. \beginning) — truncating the source at that exact offset makes it look like end-of-string. I confirmed this is harmless in both the old and new code: list_stack_at's caller requires an immediately-following { from the untruncated source (adapter.rs:4227-4229 on origin/main) and in_theorem_environment's caller requires a {...} pair inside the truncated head (mainbase adapter.rs:4632), both of which fail exactly when the illusion would otherwise fire, and begin_end_commands (new) excludes such words from commands entirely at construction time — so all three agree at every offset, including exactly this one. The \beginning{x} case in the shipped test does exercise this and passes, consistent with the above.

  3. Timing at 300 sections (release, median of 3) — PASS, improvement is real and plausibly linear. Synthetic doc (script-generated: N \sections, each with a nested itemize/enumerate, a theorem/proof pair, and a tabular) at 150 and 300 sections:

    sections PR median main median speedup
    150 57.52 ms 613.51 ms 10.7×
    300 111.50 ms 2447.64 ms 21.9×

    PR-branch scaling 150→300 (2× the input): 111.50/57.52 = 1.94× — consistent with linear. Main-branch scaling over the same doubling: 2447.64/613.51 = 3.99× — consistent with quadratic, which also cross-validates that this synthetic doc genuinely exercises the fixed code path. (Raw per-run numbers, PR: 56.76/58.71/57.52 ms @150, 113.78/110.36/111.50 ms @300; main: 613.51/617.50/604.24 ms @150, 2730.47/2403.87/2447.64 ms @300.) Output for both sizes was byte-identical between branches (cmp -s), same as item 1.

  4. Memoisation soundness (commit ce286c98) — PASS. setlength's memo key is (source.as_ptr() as usize, source.len()) (adapter.rs:3884), looked up against MacroDefsEntry.{ptr,len} (adapter.rs:5423-5429, setlengths field added by this PR alongside the pre-existing index field that already used the identical key basis for macro_body). MacroDefsScope::enter (adapter.rs:5441) builds a fresh entries: Vec<MacroDefsEntry> from the call's own texts: &[&str] at the top of every adapt_cached, installs it as the live thread-local for the RAII scope's duration, and Drop restores the caller's (possibly None) prior state — so a (ptr,len) key can never survive past the call that created it, and nested adapt_cached calls (if any) push/pop cleanly. Traced every setlength call site (adapter.rs:1160, 1766, 6745) back to texts.get(d.0).copied()/text_of(d.0) (adapter.rs:6649) — always the whole texts[i] &str, matching the entries built at scope-entry exactly, so the memo actually hits where the PR claims the 97% time was spent (tabular/longtable length reads). A call with a source that is a sub-slice (different len) simply misses the lookup and falls through to setlength_in uncached (correct, if slower) — no stale-value path exists. No address-reuse risk: two different texts[i]/texts[j] can only collide on (ptr,len) if they're literally the same memory (i.e. identical content), which is the same-answer case anyway.

  5. Full crate test suite (cargo test --release --no-fail-fast -- --test-threads=4, crates/render-pipeline): 79 result lines, 376 passed, 0 failed, matching the PR body's reported numbers exactly. source_index_matches_prefix_scans passes.

  6. Minor, non-blocking nit: list_seps (adapter.rs:4011) is now only reachable from #[cfg(test)] code (its two production call sites were replaced by list_seps_from), which triggers a dead_code warning on cargo build --release (no such warning on origin/main). in_theorem_environment, which underwent the identical transition, got #[cfg_attr(not(test), allow(dead_code))] (adapter.rs line above 4797) but list_seps didn't. Not a build failure (no deny(warnings) in this crate) — purely cosmetic.

  7. The #525 (length_at) overlap already raised in this thread is resolved, not re-raised here: the existing d-q222 comment shows render-pipeline: tabular lengths keep their group scope, \small survives a float caption, @{} glue (#56) #525's own linear fix, a clean git merge-tree in both orders, and a locally-built merged tree with byte-identical output across 150 fixtures plus the 800-table timing win, so no action needed from this PR on that point.

No blocking issues found. Recommend merging once GoKubar's requested review of the equivalence argument (per the PR description) is in.

@GoKubar
GoKubar merged commit bbc9583 into main Sep 15, 2026
15 of 21 checks passed
GoKubar added a commit that referenced this pull request Sep 15, 2026
…(unbreaks main) (#638)

#624 added `list_style_nextline(src, env, begin_keys)`. #623 then made `adapt`
linear, replacing the per-block source rescans with a `SourceIndex` and removing
`src` from that scope. Git merged the two cleanly -- neither touched the other's
lines -- and the result does not compile:

  error[E0425]: cannot find value `src` in this scope
    --> src/adapter.rs:2788:51

Passing the source back in would compile, but it would also undo #623 here:
`setlist_calls` walks the whole document and this runs once per list, which is
precisely the quadratic shape that made a 450-section warm edit take 16 s. So it
takes `&index.setlist` -- the calls the index already precomputed -- matching its
siblings `list_margins(index, ...)` and `list_seps_from(&index.setlist, ...)`.

render-pipeline: all test targets compile, 420 passed, 0 failed.

Implementation-Agent: orchestrator-astra
Commit-Executor: orchestrator-astra (direct; Cursor usage limit)
GoKubar added a commit that referenced this pull request Sep 15, 2026
…/expansion-token-limit-parity

Clean merge, no conflicts: picks up main's fix for the #624/#623
list_style_nextline compile breakage.

Implementation-Agent: fable-rebase-d
Commit-Executor: fable-rebase-d (direct; Cursor usage limit)
GoKubar added a commit that referenced this pull request Sep 15, 2026
…er src-binding break

docs/user/compiler.md (generated) conflicted again; took main's copy and
regenerated via render_supported_latex.sh, sync --check clean. Also carries
the fix current main needs to compile render-pipeline: #623's memoised
SourceIndexes refactor dropped the 'let src' binding in the ListItem arm of
split_at_page_breaks while its own line still calls
list_style_nextline(src, ...) (E0425 at adapter.rs:2788 on main d7b7f9f);
restored the pre-refactor binding from texts.

Implementation-Agent: fable-rebase-a
Commit-Executor: fable-rebase-a (direct; Cursor usage limit)
GoKubar added a commit that referenced this pull request Sep 15, 2026
Clean merge, no conflicts; picks up main's #638 compile fix for the
#623/#624 render-pipeline clash.

Implementation-Agent: fable-rebase-c
Commit-Executor: fable-rebase-c (direct; Cursor usage limit)
GoKubar added a commit that referenced this pull request Sep 15, 2026
… (#646)

* render-pipeline: tabular lengths keep their group scope; \small survives a float caption; @{} glue (#56)

What changed:
- Table lengths (\tabcolsep, \arrayrulewidth, \doublerulesep, \extrarowheight,
  and longtable's) are read as seen at the table: only assignments whose
  group ({...}, \begingroup, an environment) is still open count, in every
  form (\setlength{\x}{v}, \setlength\x{v}, \addtolength, \x=v). The old
  scan took the last brace-form \setlength anywhere in the file.
- A float-level size declaration (\small before \caption) is carried into
  later content runs, as \@caption's \normalsize is inside its own group.
- @{...} material keeps glue at both ends (@{\hspace{1em}}, @{\quad}).
- \hspace{<n>em} is set as <n> quads of the current font, not the
  compiler's fixed-size em.
- 17 new tabular corpus fixtures (107-123) with pdflatex references.

What was run:
- oracle.py check: main 117/123, this branch 123/123 (words 0.5 bp, rules 0.1 bp)
- cargo test --release (render-pipeline): 79 test binaries ok, 0 failed
- tabular_oracle: test result: ok. 1 passed; 0 failed
- lib: test result: ok. 140 passed; 0 failed; 2 ignored

Next step: compiler PR accepting table length assignments without the
"not implemented here" warning / unknown \tabcolsep error.

Implementation-Agent: claude-opus-5 subagent of daniel-parent
Commit-Executor: daniel-parent subagent
Claude-Session: https://claude.ai/code/session_012c9XLkHjePPGBuarrmE2mz

* render-pipeline: report/book number figures and tables within the chapter

What changed:
- floats::number follows report.cls/book.cls: \thefigure and \thetable are
  \ifnum\c@chapter>\z@\thechapter.\fi\@Arabic\c@figure, reset by
  \@addtoreset{figure}{chapter}. \chapter* and book's \chapter outside
  \mainmatter step nothing; \appendix zeroes the chapter counter and makes
  \thechapter \@alph. Captions and \ref both use the value.
- FloatSpec.number is the printed string ("1.2"), not a bare counter.
- New pdflatex-pinned fixtures in fixtures/float-numbering (report chapters
  with \chapter*, report appendix, book front/main/back matter, an article
  control) and tests/float_numbering_oracle.rs: caption label, page and
  position within 1 bp, and the resolved \ref line.

What was run:
- cargo test --test float_numbering_oracle: test result: ok. 1 passed; 0 failed
- same test on origin/main sources: 17 mismatches (e.g. "Figure 1:" for
  pdflatex's "Figure 1.1:", chapter two's first figure printed "Figure 3")
- cargo test --test floats_oracle: ok. 2 passed; float_body_oracle: ok. 1
  passed; float_notes_oracle: ok. 1 passed; toc_oracle: ok. 1 passed;
  footnotes_oracle: ok. 1 passed; --lib floats: ok. 4 passed

Next step: open the GH-69 PR with the object-stream PDF sizing commit.

Implementation-Agent: claude-opus-5 subagent of daniel-parent
Commit-Executor: daniel-parent subagent
Claude-Session: https://claude.ai/code/session_012c9XLkHjePPGBuarrmE2mz

* render-pipeline: size PDF graphics whose page tree is in object streams

What changed:
- graphics::probe_pdf falls back to flashtex_pdf::reader when the byte scan
  fails on a PDF with /ObjStm (PDF 1.5 object streams, pdfTeX's default
  \pdfobjcompresslevel 2). Before, every such PDF was image_unavailable and
  took no space. CropBox/MediaBox/Rotate handling is shared (page_info).
- New fixtures/float-graphics: a 72 dpi PNG and two pdfTeX object-stream
  PDFs (one /Rotate 90), made by make_fixtures.py; oracle.py pins box size and
  position from pdflatex. tests/float_graphics_oracle.rs checks
  width=\linewidth, scale, keepaspectratio, angle before/after a size key,
  \textwidth multiples, and the PDFs, within 1 bp, with no image diagnostic.
- Unit test graphics::tests::pdf_object_streams_are_read.

What was run:
- cargo test --test float_graphics_oracle: test result: ok. 1 passed; 0 failed
- same test without the graphics.rs change: 7 mismatches
- cargo test --lib graphics: test result: ok. 8 passed; 0 failed

Next step: [H] from the float package, then the PR.

Implementation-Agent: claude-opus-5 subagent of daniel-parent
Commit-Executor: daniel-parent subagent
Claude-Session: https://claude.ai/code/session_012c9XLkHjePPGBuarrmE2mz

* render-pipeline: float.sty [H] sets the box exactly where it stands

What changed:
- FloatSpec::exact_here: with \usepackage{float}, a vertical-mode [H]
  float is not a float (\@float@HH). paginate splices \float@endH's
  \vskip\intextsep, the box and \vskip\intextsep at its marker, with TeX's
  interline glue (\lineskip against the line above; the next line's glue
  against the box's zero depth). It is never deferred or counted.
- [H] in the middle of a paragraph or on a two-column figure* now has its own
  diagnostic and falls back to h. [H] without the package keeps its old one.
- packages: float is implemented by the pipeline. \floatstyle, \restylefloat
  and \newfloat are still diagnosed by the compiler.
- fixtures/floats: make_fixtures.py adds 11-float-h and
  12-h-passes-deferred. oracle.py takes fixture names, so only those two
  were pinned; the other 10 sources and references are byte-identical.
  floats_oracle expects 12 fixtures, plus a diagnostics test for [H].

What was run:
- cargo test --test floats_oracle: test result: ok. 3 passed; 0 failed
  (11-float-h 2/2 pages, 13 anchors, max 0.002 bp; 12-h-passes-deferred
  3/3 pages, 9 anchors, max 0.003 bp)
- same fixtures on the pre-change sources: 26 mismatches
- cargo test --lib: test result: ok. 138 passed; 0 failed; 2 ignored
- float_body_oracle, float_notes_oracle, footnotes_oracle, toc_oracle,
  multicol_oracle, twocolumn_title_oracle: ok, 1 passed each;
  graphics_draft_demo: ok. 3 passed; float_numbering_oracle: ok. 1 passed;
  float_graphics_oracle: ok. 1 passed

Next step: open the GH-69 PR and post the verification table on #69.

Implementation-Agent: claude-opus-5 subagent of daniel-parent
Commit-Executor: daniel-parent subagent
Claude-Session: https://claude.ai/code/session_012c9XLkHjePPGBuarrmE2mz

* render-pipeline: \chapter in an \include'd file is a chapter

What changed:
The adapter read structural body commands (\chapter, \part, \appendix,
book matter, marks/page styles, \addcontentsline) from the entry
document's source only. A \chapter in chapters/one.tex was set as a plain
paragraph on the current page: no page clear, no number, no marks, no
contents line. Included documents now get the same scan; their commands
are laid out before that document's next unit, and any left after its
last unit are laid out when the entry document resumes. \maketitle,
\noindent, contents lists and nested \input stay entry-only.

Corpus extended/project-book-include (#42): 5 pages -> 7 (pdflatex 7).

What was run:
cargo test --release (render-pipeline): passed 377 failed 0 ignored 3
test result: ok. 2 passed; 0 failed (chapter_in_included_file)
test result: ok. 1 passed; 0 failed (input_order_oracle)
test result: ok. 1 passed; 0 failed (toc_oracle)
test result: ok. 20 passed; 0 failed (flashtex-cli cli)

Next step:
\include's own \clearpage before/after (article: pdflatex 3 pages, we
set 1) and the missing CONTENTS running head in book front matter are
separate follow-ups.

Implementation-Agent: claude-opus-5 subagent of daniel-parent
Commit-Executor: daniel-parent subagent
Claude-Session: https://claude.ai/code/session_012c9XLkHjePPGBuarrmE2mz

* pdf: an ellipsis's periods no longer make every period extract as "…"

What changed:
- v2 export reduced cluster text to ToUnicode by first use. The pipeline sets
  `\textellipsis` as three periods in one cluster whose text is "…", so the
  period glyph was mapped to U+2026 for the whole font: the ellipsis
  extracted as "………" and every later sentence-final period as "…"
  (measured on "em dash… ellipsis." in OT1 and T1+lmodern documents).
- Only a one-glyph cluster now names its glyph's text. A glyph seen only
  inside clusters of several glyphs takes the character the font's own cmap
  maps to it (new `TrueTypeFont::char_for_glyph`, lowest code point), and the
  cluster text only when the cmap has none. Ligatures (`fi`, one glyph)
  still extract as their cluster text.
- tests/v2.rs: `ellipsis_periods_keep_the_period_in_to_unicode` (fails on
  main with `{28: "a", 88: "…"}`).

What was run:
- cargo test --release --test v2
  test result: ok. 7 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out
- cargo test --release (crates/pdf, whole crate): 118 passed, 0 failed
- flashtex build --v2 + flashtex-pdf-exact from-v2 on the survey documents
  d4-punct-ot1 / d5-punct-t1-lm: "em dash……… ellipsis…" -> "em dash... ellipsis."

Next step:
- Re-pin crates/render-pipeline/vendor/pdf so `flashtex build` and Export
  PDF pick it up (vendor re-pins are the integration lane's).

Implementation-Agent: claude-opus-5 subagent of daniel-parent
Commit-Executor: daniel-parent subagent
Claude-Session: https://claude.ai/code/session_012c9XLkHjePPGBuarrmE2mz

* math-layout: TeX's math font kerns (make_ord, tex.web §752) from the TFM lig/kern programs

What changed:
- tools/gen_cm_tfm.py emits each font's lig/kern program (lig_kern_starts,
  lig_kern, kerns) read from the real TFMs; cm_tfm.rs and ams_tfm.rs
  regenerated (additions only; existing char rows unchanged).
- tfm.rs: TfmFont::lig_kern walks the program as TeX does (first matching
  instruction; a ligature shadows a later kern).
- MathFontMetrics::ord_pair (default None) + CmMathMetrics impl: same-family
  check via symbol_slot, the scaled kern, and whether the font is a text font.
- layout.rs: make_ord appends the kern after an unscripted Ord character
  followed by an Ord..Punct character of the same family, and drops the
  italic correction in a text font (§755). Bins demoted by Rule 6 are not kerned.

What was run:
- cargo test --test math_font_kerns: test result: ok. 2 passed; 0 failed
- cargo test (math-layout): all suites ok (12, 4, 5, 28, 4, 2, 11 passed; 0 failed)

Next step: feature-gated forwarding in render-pipeline's TexMathMetrics, then HW1 and amsmath corpus measurement.

Implementation-Agent: claude-opus-5 subagent of daniel-parent
Commit-Executor: daniel-parent subagent
Claude-Session: https://claude.ai/code/session_012c9XLkHjePPGBuarrmE2mz

* render-pipeline: an em is the quad of the font in force; table lengths follow macro invocations (#525 review)

What changed:
- `\hspace{<n>em}`, `\quad` and `\qquad` in running text are now set in
  quads of the font current where they are read. `Item::Quad` carries a
  style: the series/family come from the source declarations at the
  command, the size from the compiler's sizes of the text around it
  (`glue_size`). Before, the quad was the paragraph's base font, so
  `{\Large Ff\hspace{2em}Gg}` was 8.165 bp short and `{\bfseries ..}`
  2.989 bp short.
- The blank after `\hspace{..}`'s closing brace is an ordinary space.
  It was being skipped as if it followed a control word (3.3-3.9 bp).
- Size environments (`\begin{small}..\end{small}`, all ten sizes) give
  text, rules, kerns and tables their size unless a declaration made
  inside is still in force. A paragraph whose `\par` is read inside one
  gets that size's `\baselineskip`. The compiler's "environment is not
  implemented" warning for them is superseded.
- `length_at` applies the `\setlength`/`\addtolength`/`\<len>=` a user
  macro makes at the top level of its body (nested macros too, `#k`
  from braced arguments) at the invocation, with the invocation's group
  scope. An assignment that cannot be read (optional argument, unbraced
  argument) is left out and reported as a `table_limitation` warning.
- Corpus fixtures 124-126 (`\hspace{em}`/`\quad` under
  `\small`/`\normalsize`/`\Large`, `\bfseries` and size environments, in
  body text and tables, at 10/11/12pt), 127 (size-environment
  paragraphs) and 128 (macro `\setlength`/`\addtolength` before tables),
  with pdflatex references. Unit tests:
  table_lengths_follow_macro_invocations,
  size_environments_give_their_size_until_a_declaration,
  glue_takes_the_size_of_the_text_it_is_read_with.

What was run:
- python3 oracle.py check --render .../flashtex-render: TOTAL 128/128 (words 0.5 bp, rules 0.1 bp)
- cargo test --release (crates/render-pipeline): 79 test binaries, all "test result: ok", 0 failed
- lib: test result: ok. 143 passed; 0 failed; 2 ignored
- tests/tabular_oracle.rs: tabular_oracle: 128/128 fixtures match pdflatex; test result: ok. 1 passed; 0 failed

Next step: re-review of #525.

Implementation-Agent: claude-opus-5 subagent of daniel-parent
Commit-Executor: daniel-parent subagent
Claude-Session: https://claude.ai/code/session_012c9XLkHjePPGBuarrmE2mz

* render-pipeline: math-font-kerns feature forwards math-layout's ord_pair (off until re-pin)

What changed:
- Cargo.toml: new off-by-default `math-font-kerns` feature; render-pipeline
  depends on vendor/math-layout (not crates/math-layout), which predates
  MathFontMetrics::ord_pair.
- mathtex.rs: TexMathMetrics::ord_pair asks the embedded CM programs for
  families 1-3 and the installed rm-lmr TFM for family 0.
- mathtext.rs: TextRunMetrics forwards, never kerning a \text handle.
- tests/math_font_kerns.rs (feature-gated): glyph origins of $r,a,b$,
  $f,P,Y.$, $f(x)$ $\Gamma,\Delta$ $x_1,x_2$ $V_{a}$ and HW1's display
  against pdflatex within 0.02 bp.

What was run (scratch copy of crates/render-pipeline with vendor/math-layout
replaced by this branch's crates/math-layout, feature on; vendor/ untouched):
- cargo test --release --features math-font-kerns --test math_font_kerns: test result: ok. 1 passed; 0 failed
- same test with ord_pair forced to None: fails, $r,a,b$ glyph 1 +0.608 bp, $f,P,Y.$ glyph 5 +3.633 bp
- amsmath corpus oracle.py check: TOTAL 59/59 within 0.5 bp (before and after)
- rank.py --only hw1: page 2 within 0.5 bp 203 -> 212; the 9 kern words (lines 560.9/585.4) from 0.60-0.61 bp to <=0.005 bp; no other word moved by more than 0.005 bp
- cargo build --release --bin flashtex-render against vendor/ (feature off): ok

Next step: re-pin vendor/math-layout (integration lane), then make math-font-kerns a default feature.

Implementation-Agent: claude-opus-5 subagent of daniel-parent
Commit-Executor: daniel-parent subagent
Claude-Session: https://claude.ai/code/session_012c9XLkHjePPGBuarrmE2mz

* math-layout: keep the ord_pair imports and impl clear of #470's lines

What changed: separate use lines for MathChar/OrdPair and CmMathMetrics::ord_pair moved after accent_sizes, so this branch merges cleanly with #470 (tag-textrun). No behaviour change.

What was run:
- cargo test (math-layout): every suite test result: ok, 0 failed

Next step: open the PR.

Implementation-Agent: claude-opus-5 subagent of daniel-parent
Commit-Executor: daniel-parent subagent
Claude-Session: https://claude.ai/code/session_012c9XLkHjePPGBuarrmE2mz

* render-pipeline: number floats in the order the \include tree is read

What changed:
- adapter::reading_order walks \input/\include from the entry file
  (compiler lookup: path, then path.tex; the preamble's last \includeonly;
  cycles and unknown files read nothing) into ordered byte ranges.
- floats::number steps chapter/appendix/matter and the figure/table
  counters over those ranges, so an entry-file float after an \include
  whose file has its own \chapter gets 2.1, not 1.2. A float of a file
  never read (\includeonly-excluded) has no number, label, spec or .lof
  line.
- LoF/LoT entries take the float's own number (report pre-chapter float
  is "1", not "0.1") and merge in reading order.
- Float markers in paginate are placed by reading order, so an entry
  float after an included chapter follows that chapter's blocks.
- \include issues its \clearpage before the file and after it.
- Fixtures 05 (report, two files), 06 (book, \include + \input +
  appendix include), 07 (report, \includeonly) with pdflatex references;
  oracle.py handles multi-file projects; tests/include_float_lists.rs pins
  LoF/LoT/\ref against pdflatex's .lof/.lot/.aux.

What was run:
cargo test --release --test float_numbering_oracle
test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out
cargo test --release --test include_float_lists
test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out
cargo test --release --test toc_oracle
test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out
cargo test --release --test floats_oracle
test result: ok. 3 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out
cargo test --release --lib reading_order
test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 140 filtered out

Next step: full crate run, then PR stacked on #537 and #538.

Implementation-Agent: claude-opus-5 subagent of daniel-parent
Commit-Executor: daniel-parent subagent
Claude-Session: https://claude.ai/code/session_012c9XLkHjePPGBuarrmE2mz

* math-layout: math ligatures in make_ord and kerns/ligatures inside text runs (tex.web §752-§753)

What changed:
- `OrdPair` carries the pair's ligature instruction (`OrdLigature { op, ch }`);
  `CmMathMetrics::ord_pair` reports cmr's `=:` ligatures (ff, fi, fl, ffi,
  ffl, and the quote/dash/Spanish marks) as Unicode text characters, and
  `text_glyph` boxes those characters from their OT1 slots.
- `layout`: the first pass runs `make_ord` over the list before boxing. A
  ligature rewrites the list as §753 does: `=:` merges the pair (the ligature
  takes the right atom's scripts), `=:|`/`|=:` replace one side, `|=:|`
  inserts, and the pair is retried unless the op is a `>` form. So
  `$\mathrm{f}\mathrm{i}$` is one fi glyph and `$\mathrm{f}\mathrm{i}^2$` is fi^2.
- `make_text` (`Nucleus::Text`, the multi-character `\mathrm{..}` and
  operator runs) applies the same program between its characters: the font
  kerns (`AV`, `Tr`, `Wa`) and ligatures (`ff`, `ffi`), last italic kept.
- tests/math_font_kerns.rs: 19 new widths pinned to pdfTeX `\wd0`, plus a
  synthetic program exercising every ligature form on both paths.

What was run:
cargo test --manifest-path crates/math-layout/Cargo.toml --test math_font_kerns
test result: ok. 3 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out
cargo test --manifest-path crates/math-layout/Cargo.toml
test result: ok. 12 / 4 / 5 / 28 / 4 / 3 / 2 / 11 passed; 0 failed
before this change the new widths fail, e.g. $\mathrm{AV}$ 15.13890pt vs pdfTeX 14.02777pt

Next step: forward ligatures through render-pipeline's TexMathMetrics and
one-character \mathrm groups; measure the pipeline against pdflatex.

Implementation-Agent: claude-opus-5 subagent of daniel-parent
Commit-Executor: daniel-parent subagent
Claude-Session: https://claude.ai/code/session_012c9XLkHjePPGBuarrmE2mz

* render-pipeline: math ligatures and one-character alphabet kerns behind math-font-kerns

What changed:
- `TexMathMetrics::ord_pair` reads family 0's instruction straight from the
  installed rm-lmr TFM program (`Tfm::pair_program`, no text-mode boundary
  handling) and reports its ligatures, so `make_ord` forms them;
  `text_glyph` boxes a formed ligature (U+FB01 ...) from its OT1 slot.
- A one-character math alphabet pair of the same alphabet
  (`\mathbf{T}\mathbf{o}`, `\mathit{A}\mathit{V}`) is kerned from that
  alphabet's text-font TFM. Ligatures there are not formed (no character
  addresses a ligature slot of those fonts).
- `typeset`: a one-letter/digit `\mathrm{X}` is math-layout's `TextChar`
  (TeX §1186), so it joins its neighbour. All behind `math-font-kerns`.
- math-layout `cm::ligature_char` shared by both providers.
- tests/math_ligatures.rs pins glyph origins against pdflatex (lmodern).

What was run (scratch copy, vendor/math-layout := this branch's crate):
cargo test --release --features math-font-kerns --test math_ligatures
test result: ok. 1 passed; 0 failed
  negative control on #560's overlay: fails, "$x\mathrm{A}\mathrm{V}x$: glyph 2 at x 140.215 bp, pdflatex 139.003 (+1.212)"
cargo test --release --no-fail-fast --features math-font-kerns (whole crate): 377 passed; 0 failed; 3 ignored
oracle.py check: TOTAL 59/59 within 0.5 bp (before and after, per-fixture lines identical)
rank.py --only hw1: page 2 within 0.5 bp 212 of 215, pages 1 and 3 unchanged (same as #560)
worktree, feature off: cargo check --release --tests ok

Next step: open the PR stacked on #560.

Implementation-Agent: claude-opus-5 subagent of daniel-parent
Commit-Executor: daniel-parent subagent
Claude-Session: https://claude.ai/code/session_012c9XLkHjePPGBuarrmE2mz

* math-layout: keep the new layout.rs imports clear of #470's lines

What changed: the OrdLigature/SizeClass/Cow imports move to a block of their
own, so #560's import lines stay byte-identical and #470 still merges cleanly.

What was run:
git merge-tree --write-tree HEAD origin/agent/daniel-parent/tag-textrun: no conflict
cargo test --manifest-path crates/math-layout/Cargo.toml
test result: ok. 12 / 4 / 5 / 28 / 4 / 3 / 2 / 11 passed; 0 failed

Next step: open the PR stacked on #560.

Implementation-Agent: claude-opus-5 subagent of daniel-parent
Commit-Executor: daniel-parent subagent
Claude-Session: https://claude.ai/code/session_012c9XLkHjePPGBuarrmE2mz

* render-pipeline: a chapter whose body is only a float still clears its page

What changed:
The adapter lays an \include'd file's structural commands (\chapter, ...)
out before that file's next unit (paragraph, heading, rule, picture). A
file whose whole body is a captioned float has no unit, so its \chapter
(heading, page clear, number) was never laid out and the floats piled onto
one page ahead of later text. Likewise a trailing entry \chapter with only a
float after it was dropped: the end-of-document loop handled only marks,
page styles and \maketitle.
- An entry \input/\include consumed without a unit of the file it reads
  (found from the reading order) lays that file's commands out in place,
  then \include's closing \clearpage.
- A unit of an included file flushes up to the command that reads its
  file, not merely the next \input/\include.
- Included files read so far are finished whenever the next file is read,
  not only when the entry file resumes.
- The unit loop takes one last pass after the last unit, so commands after
  it (\chapter, \include, marks, \maketitle) go through the same code; the
  separate trailing loop is gone.
tests/include_float_only_chapters.rs pins pages, lines and baselines
against pdflatex for two and three float-only \include'd chapters, the same
under \includeonly (with and without trailing text), and single-file
float-only chapters.

What was run:
cargo test --release --test include_float_only_chapters
test result: ok. 3 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out
same test without the adapter change: test result: FAILED. 0 passed; 3 failed
chapter_in_included_file: test result: ok. 2 passed; 0 failed
float_body_oracle: test result: ok. 1 passed; 0 failed
float_graphics_oracle: test result: ok. 1 passed; 0 failed
float_notes_oracle: test result: ok. 1 passed; 0 failed
float_numbering_oracle: test result: ok. 1 passed; 0 failed
floats_oracle: test result: ok. 3 passed; 0 failed
include_float_lists: test result: ok. 1 passed; 0 failed
input_order_oracle: test result: ok. 1 passed; 0 failed
toc_oracle: test result: ok. 1 passed; 0 failed
cargo test --release -p flashtex-render-pipeline --no-fail-fast: passed 386, failed 0, ignored 3

Next step: a float right after a body \clearpage (no \include) still lands
on the old page; that break is carried by the next block's eject and is
left to the #569/#583/#584 page-break stack.

Implementation-Agent: claude-opus-5 subagent of daniel-parent
Commit-Executor: daniel-parent subagent
Claude-Session: https://claude.ai/code/session_012c9XLkHjePPGBuarrmE2mz

* render-pipeline: \check@icl italic correction and nested list closing skips (display-placement 35/36)

What changed:
- An upright text font command (\textbf, \textup, \texttt, \emph in italic
  text, ...) and amsmath's \eqref (\textup{\tagform@{..}}) put the italic
  correction of the character before them under the interword space
  (latex.ltx \check@icl -> \maybe@ic -> \sw@slant). Fixture 17's `(2.1).`
  was 0.784 bp left (the `f` of "Ref", kern 0.7922 pt).
- A list's closing \addvspace\@topsepadd uses the \topsep of the level that
  closes (was always level 1), with that list's own \partopsep flag; lists
  closing together and a following \item's \addvspace\itemsep keep the
  larger natural skip instead of the sum. Fixture 20's `2. Outer again` was
  7.97 bp low.
- A paragraph right after \end{itemize}/\end{enumerate} with no blank line
  is not indented (\@endpe), as after center/quote.
- Pins: tests/text_command_left_italic_correction.rs,
  tests/nested_list_end_skips.rs (pdflatex numbers; all four fail on main
  by -0.791, +7.970, -1.993, +3.985 bp); display_placement.rs PASSING adds
  17 and 20; baseline-render-pipeline.json refreshed.

What was run:
- display-placement oracle.py check: TOTAL 35/36 within 0.5 bp (main: 33/36;
  15 still fails on the rich \tag, owned by #470/#585)
- amsmath_corpus oracle.py check: TOTAL 59/59 within 0.5 bp
- cargo test --release -p flashtex-render-pipeline (all targets): 81 test
  binaries, 379 passed, 0 failed, 3 ignored

Next step: fixture 15 lands with #585 plus the math ToUnicode lane.

Implementation-Agent: claude-opus-5 subagent of daniel-parent
Commit-Executor: daniel-parent subagent
Claude-Session: https://claude.ai/code/session_012c9XLkHjePPGBuarrmE2mz

* render-pipeline: math minus, asterisk and phi extract as the right Unicode

What changed:
- Math '-' extracts as U+2212 MINUS SIGN and '*'/\ast as U+2217 ASTERISK
  OPERATOR (both were ASCII); \phi/\varphi now extract as U+03D5/U+03C6
  (they were swapped). Glyph selection and positions are unchanged.
- Tests assert semantically correct Unicode, not pdflatex parity: pdflatex
  without the cmap package extracts cmex/cmsy glyphs as artefacts
  (\sum -> P, \mapsto -> 7->), which are deliberately not copied.

What was run:
- render-pipeline math targets: 68 passed, 0 failed
- render-pipeline lib: 138 passed, 0 failed, 2 ignored
- crates/pdf: all suites passed; git diff --check: passed

Next step:
- independent review.

Implementation-Agent: codex gpt-5.6-luna (max)
Commit-Executor: daniel-parent (committed Codex's working tree; sandbox blocked its git index)
Lane-Owner: daniel-parent (mac-m5pro-dq222)
Claude-Session: https://claude.ai/code/session_012c9XLkHjePPGBuarrmE2mz

* render-pipeline: keep only the four semantic math extraction fixes

What changed:
- The previous commit accidentally shipped the first-pass table that copied
  pdflatex's cmex/cmsy extraction artefacts (\mapsto -> 7->, \Longrightarrow
  -> =>, \circ -> bullet, \setminus -> ASCII backslash, ...). This commit
  applies the corrected working tree: extraction_text only maps '-' ->
  U+2212, '*' -> U+2217 and swaps \phi/\varphi; every other glyph keeps
  main's text. Tests assert semantically correct Unicode.

What was run:
- render-pipeline math targets and lib (see next comment on #597)

Next step:
- re-run tests; update #597.

Implementation-Agent: codex gpt-5.6-luna (max)
Commit-Executor: daniel-parent (staging slip in the previous commit)
Lane-Owner: daniel-parent (mac-m5pro-dq222)
Claude-Session: https://claude.ai/code/session_012c9XLkHjePPGBuarrmE2mz

* render-pipeline: long arrows extract as their drawn join pieces

What changed:
- The long arrows move out of common_math_glyph_runs_use_semantic_unicode
  into long_arrows_extract_as_their_drawn_pieces (option C from #536).
- A two-glyph join (#536's drawing) must extract as `=⇒` / `−→`, matching
  pdfTeX's own PDF (`x =⇒y −→z`, pdflatex + PyMuPDF). While main still draws
  one Latin Modern Math glyph, the text is the single `⟹` / `⟶`.
- A comment records that one `⟹` for two drawn glyphs needs PDF /ActualText
  marked content, a future crates/pdf change outside this PR.

What was run:
- math_symbols (debug): test result: ok. 14 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.46s

Next step:
- Merge into agent/daniel-parent/integration-preview and rerun math_symbols there.

Implementation-Agent: claude-opus-5 subagent of daniel-parent
Commit-Executor: daniel-parent subagent
Claude-Session: https://claude.ai/code/session_012c9XLkHjePPGBuarrmE2mz

* oracles: a math minus sign aligns with the references' hyphen-minus

What changed:
- tools/visual-oracle/rank.py `norm` folds U+2212 MINUS SIGN into U+002D
  before alignment. pdfTeX's own PDFs extract a math minus as U+2212
  (PyMuPDF on pdflatex's 19-vmatrix.pdf: "= ad −bc"; 28-xrightarrow.pdf:
  "f−→B", "h←−"), which is what this branch now emits. The pinned references
  read "-" only because pdftext's glyph-name table maps `minus` to "-". The
  references and FlashTeX are both right; the word matcher was not.
- amsmath_corpus/oracle.py `regroup` orders coincident glyphs (the \relbar
  and arrow head of \xrightarrow) with the same fold, so `−→` sorts like the
  references' `-→`.
- test_rank.py: a minus sign aligns with a hyphen-minus.

What was run:
- amsmath oracle, this branch's flashtex-render: TOTAL 58/59 after the norm
  fold alone (28-xrightarrow order tie), TOTAL 59/59 within 0.5 bp with both
- amsmath oracle, main's flashtex-render (36fe7ec): TOTAL 59/59 within 0.5 bp
- amssymb oracle, main and this branch: TOTAL 38/39 within 0.5 bp (both;
  32-braces-narrow fails identically on main)
- tabular oracle, main and this branch: TOTAL 106/106 (words 0.5 bp, rules 0.1 bp)
- display-placement oracle, main and this branch: TOTAL 33/36 within 0.5 bp (identical rows)
- python3 -m unittest discover -s tools/visual-oracle -p 'test_*.py': Ran 14 tests, OK

Next step: merge into the integration preview (#609) and rerun there.

Implementation-Agent: claude-opus-5 subagent of daniel-parent
Commit-Executor: daniel-parent subagent
Claude-Session: https://claude.ai/code/session_012c9XLkHjePPGBuarrmE2mz

* visual-oracle: candidate word text slices cluster byte ranges as bytes

What changed:
- rank.v2_words sliced the glyph run's Python str with the display list's
  cluster ranges, which are UTF-8 byte offsets. After the first non-ASCII
  character in a run (`∈`, and now this branch's U+2212 minus) every later
  glyph got its neighbour's text: `|f(x_k) − f(y_k)|` read as words `−f`,
  `(y` instead of `−`, `f(y`, and `x ∈ K` left an empty-text word. The
  sweep-2 "apparent regressions with identical pixels" (inline-math p1/p2,
  math-sheet p2, hw1 p1, conf-paper p2) were this. The amsmath oracle's own
  reader already encoded before slicing.
- test_rank.py: the v2 fixture helper writes byte offsets; a run with
  `−` and `∈` keeps its word text.

What was run (tools/visual-oracle/rank.py, all 22 real-world fixtures, same
flashtex-pdf-exact; aligned words summed over every page):
- old rank.py: main 36fe7ec 15285, preview 5d1eb06 15253
- this rank.py: main 15330, preview 15326
- pages whose aligned/within-0.5 counts differed main vs preview only
  through text (conf-paper p2, hw1 p1, inline-math p1/p2, math-sheet p1/p2,
  ps-calculus p2/p3, twelvept-plain p2, lecture-notes p2) are now identical
- amsmath 59/59, amssymb 38/39, tabular 106/106, display-placement 33/36
  (main) and 35/36 (preview): unchanged by this commit
- python3 -m unittest discover -s tools/visual-oracle -p 'test_*.py': OK

Next step: merge into the integration preview (#609).

Implementation-Agent: claude-opus-5 subagent of daniel-parent
Commit-Executor: daniel-parent subagent
Claude-Session: https://claude.ai/code/session_012c9XLkHjePPGBuarrmE2mz

* render-pipeline: read each table length once per adapt call, not per table (#525 review, #623)

What changed:
- `length_at_checked` scanned the source before every table (a CmdScan of
  the prefix, plus a `group_open_between` rescan per assignment) for each
  of the four tabular lengths and the five longtable lengths. On a
  document with many tables that is quadratic or worse: 800 tables spent
  1.6 s in it. It is the same class of bug #623 fixed in
  `split_at_page_breaks`.
- Within an adapt call (`MacroDefsScope`) each length is now indexed once
  per document: `length_assignments` collects every `\setlength`/
  `\addtolength`/`\<name>=` and assigning macro invocation of the whole
  source once, `GroupTokens` lexes the group depth once (the tokens
  `group_open_between` counts, with the next-lower-depth token of each),
  and `LengthIndex` links each assignment to the last earlier one still in
  force at its end. A table binary-searches its byte offset and walks that
  chain past closed groups. The value and `unresolved` flag are folded in
  the same order as the scan, so the floats are bit-identical.
- Outside an adapt call, at a byte inside a control word, or for a document
  whose assignments do not form a chain (an assigning macro in another's
  argument, an assignment ending inside a comment), the old scan runs
  unchanged as `length_at_scan`.
- The indexes live in a new `lengths` field of `MacroDefsEntry`, placed
  before `index` so #623's `setlengths` field merges without conflict
  (`git merge-tree` of this commit with #623's head is clean).

What was run:
- `cargo test --release --lib -- table_length`: test result: ok. 5 passed; 0 failed
  - table_length_index_matches_the_prefix_scan: the indexed lookup equals
    the scan at every byte of 8 hand-written and 300 generated sources,
    for tabcolsep/arrayrulewidth/LTpre (both index and fallback paths hit).
  - table_lengths_scale_linearly_with_the_number_of_tables:
    before: 200 tables 41.2ms, 400 tables 242.7ms, 800 tables 1.637s (panicked: not linear)
    after:  200 tables 393µs, 400 tables 717µs, 800 tables 1.42ms
- flashtex-render end to end, generated doc, best of 3 (before -> after, v2 identical):
  200 tables 0.16s -> 0.08s; 400 tables 0.71s -> 0.22s; 800 tables 4.05s -> 0.73s
- v2 JSON + compile_result of all 128 tabular_corpus fixtures and 22
  fixtures/real-world documents, head 99defd5 vs this commit: `diff -rq` IDENTICAL (150/150)
- `oracle.py check`: TOTAL 128/128 (words 0.5 bp, rules 0.1 bp)
- `cargo test --release` (render-pipeline): exit 0, 79 test binaries, 383 passed; 0 failed; 3 ignored

Next step: merge #623 after #525 (or the reverse); the rest of the
remaining 800-table time is #623's `split_at_page_breaks` fix.

Implementation-Agent: claude-opus-5 subagent of daniel-parent
Commit-Executor: daniel-parent subagent
Claude-Session: https://claude.ai/code/session_012c9XLkHjePPGBuarrmE2mz

* integration: #639's layout_cache_keys test constructs #525's Item::Quad with its style field

Main's tests/layout_cache_keys.rs (#639) predates #525's Item::Quad
{ em, style }; the test's shared TextStyle fills the new field.

Implementation-Agent: fable-integration-rp
Commit-Executor: fable-integration-rp (direct; Cursor usage limit)

* integration: a file-tail float keeps its blank-line mask; include_float_lists expects #608's joined paragraph

Two #578 x #608 interactions on the combined head:

- floats::mask (#608) turned a float-only line into a % comment; for a
  float at the very tail of an \included file that left the paragraph
  open at EOF, and the compiler joined it with the entry document's
  next text, so #578's closing \clearpage landed after the merged
  paragraph (4 pages instead of pdflatex's 5). A float with nothing
  but blanks/comments after it now keeps the blank-line mask; entry
  documents are unaffected (\end{document} follows their floats).
- tests/include_float_lists.rs (#578) expected "Refs ..." on its own
  line; under #608 the [h] floats stay inside the paragraph (pdflatex
  behaviour), so the refs share the paragraph's line.

Implementation-Agent: fable-integration-rp
Commit-Executor: fable-integration-rp (direct; Cursor usage limit)

* integration: restore #543's entry-document chapter starts for \thelstlisting

The #578 delta removed the chapter_starts push together with the
chapter-based figure numbering it replaced, but #543's listing numbers
(list_blocks' Lol entries and listings::apply captions) still come from
chapter_numbers over those starts (toc_oracle fixture
37-report-lstlistoflistings).

Implementation-Agent: fable-integration-rp
Commit-Executor: fable-integration-rp (direct; Cursor usage limit)

---------

Co-authored-by: d-q222 <[email protected]>
GoKubar added a commit that referenced this pull request Sep 15, 2026
The Sep 13 baseline no longer describes main: the engine moved ~465
commits (integration queues #644/#646 and today's ~66 merges), and the
digest half of the gate is a hard equality against recorded output, so
every PR was failing on drift this harness did not cause. Verified on
the Sep 14 run of #232: FAIL was 'output changed in 50 place(s)' only;
timings were correctly reported-not-enforced on the foreign runner.

Why re-recording is legitimate rather than gate-disarming:
- This branch adds no engine code (crates/perf-bench, .github, docs
  only), so the tree whose output was recorded IS origin/main's engine,
  byte for byte. The digest drift is main's own, each contributing PR
  individually gated by the pdflatex oracles.
- Same reference host as the Sep 13 recording (linux/x86_64/AMD Ryzen 7
  7800X3D/16cpu), same build profile, recorded by the same procedure
  (README), full 26-case corpus at the current cap policy.
- Old vs new, 267 metrics: 90 digests changed; timings moved with
  main's own optimization work, dominated by the adapt fix (#623):
  synthetic-500kb cold 3434.9 -> 531.5 ms, synthetic-2mb first render
  44513.5 -> 2344.2 ms, math-heavy 184.1 -> 134.5 ms. Improvements of
  that size are exactly what a stale timing baseline can no longer
  calibrate against.

The corpus grew from 12 to 26 recorded cases (article-twocolumn,
input-bibliography and the other real-world fixtures landed on main
after Sep 13); the gate's per-PR --only set is a subset. Known notes
carried in the report, not failures: tikz-heavy PDF export is refused
by the exact route (path_stroke unsupported - a product limitation the
harness reports), siunitx-tables carries an unsupported \SI syntax
diagnostic, unicode-accents reports CJK missing_glyph.

Implementation-Agent: fable-ft070
Commit-Executor: fable-ft070 (direct; Cursor usage limit)
GoKubar added a commit that referenced this pull request Sep 15, 2026
…ession gate (#206)

* perf-bench: FT-070 benchmark harness, committed baseline and a >5% gate

There was no way to tell whether an engine change made the compiler faster.
The numbers that existed came from `examples/stages.rs` and `perf_bench.rs`:
macOS-only metadata, one sample per cell, no memory figure, no machine-readable
output, and no way to fail a build on a regression. This adds a harness whose
output can be argued with.

`crates/perf-bench` measures the product path -- the same
`protocol::handle_line` the `flashtex-render` worker serves -- over the ten
committed real-world fixtures and four generated documents (500 KB, 2 MB,
math-heavy, TikZ-heavy; generators committed, not blobs). Per case it reports
cold timings with a per-phase split, warm single-keystroke timings, PDF export,
peak and steady RSS, and an output digest. `--baseline ... --check` turns the
same run into a CI gate.

Three rules the harness enforces on itself, because breaking any of them
produces numbers that look fine and mean nothing:

* No measurement without fonts. Latin Modern and the pinned 12 pt TFM set must
  load and no render may substitute a face or a metric, or the case produces no
  timing at all -- a substituted metric is a different workload, not a slower
  one. The font set is built with `FontSet::with_dirs`, which probes nothing,
  so this box's TeX Live cannot supply the metrics by accident. The line is
  drawn at the configuration, not the document: a character with no glyph, or a
  class command the compiler does not model, is deterministic and identical
  every run, so the case is measured and the degradation is recorded next to
  the number.
* Cold means cold. Every repetition runs in a child process of its own, so the
  expander's thread-local cache, the font set's memoised faces and the
  allocator all start empty, and peak RSS belongs to one document.
* Medians, with the spread shown. Nothing comes from one sample; every metric
  carries n, p25/p75, p95 and MAD, and the table prints the run's own noise
  estimate per case.

The gate is built to survive a shared machine. A metric counts as regressed
only when it exceeds both the tolerance and that metric's own measured spread
in the baseline, and the comparison warns and stops enforcing timings when the
host, build profile, font configuration or peak load differ. Output identity
does not depend on the machine -- the fonts come from the repository -- so a
changed digest fails everywhere and unconditionally.

Baseline, at main 8465bbd on a Ryzen 7 7800X3D: cold HW1 meets its 10 ms
target; warm keystroke is 153x over budget at 500 KB and 132x at 2 MB, HW1 PDF
export is 5.6x over, and steady memory at 2 MB is 49x over. Full numbers,
method and three findings are in docs/evidence/perf-ft070-2026-09-13.

The clearest of those findings: typesetting a 2 MB document costs 42.7 s with
the document sources attached and 1.04 s without. Two per-formula code paths in
render-pipeline's typeset ask a question about the preamble and answer it by
searching the entire document, so a document that does not contain the searched
string pays a full scan per formula. That crate is another lane's, so this lane
has measured and reported it rather than touching it.

Gates unchanged (this adds a crate and edits no existing crate's source):
amsmath 59/59, HW1/HW2 3 pages with 0 errors and 0 overfull, render-pipeline
170 passed / 0 failed, compiler 395 passed / 0 failed, perf-bench 13 passed.

Implementation-Agent: Claude Opus 5 (FT-070 perf lane, linux-primary)
Commit-Executor: Claude Opus 5 (direct agent Git execution, per the AGENTS.md
  Cursor-limit fallback in force on this machine)
Co-authored-by: GoKubar <[email protected]>
Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Xd5Hmwh5GHNTiAmHUJ1MZu

* perf-bench: follow main's assemble and Capabilities signatures

typeset::assemble grew page_color/default_color (mirrored from the
product path in lib.rs, doc.page_color/doc.default_color), and
v1::Capabilities grew device_color/delta/v2_only, all off in the
harness's fixed capability set.

Implementation-Agent: fable-ft070
Commit-Executor: fable-ft070 (direct; Cursor usage limit)

* perf-bench: recalibrate the committed baseline to current main

The Sep 13 baseline no longer describes main: the engine moved ~465
commits (integration queues #644/#646 and today's ~66 merges), and the
digest half of the gate is a hard equality against recorded output, so
every PR was failing on drift this harness did not cause. Verified on
the Sep 14 run of #232: FAIL was 'output changed in 50 place(s)' only;
timings were correctly reported-not-enforced on the foreign runner.

Why re-recording is legitimate rather than gate-disarming:
- This branch adds no engine code (crates/perf-bench, .github, docs
  only), so the tree whose output was recorded IS origin/main's engine,
  byte for byte. The digest drift is main's own, each contributing PR
  individually gated by the pdflatex oracles.
- Same reference host as the Sep 13 recording (linux/x86_64/AMD Ryzen 7
  7800X3D/16cpu), same build profile, recorded by the same procedure
  (README), full 26-case corpus at the current cap policy.
- Old vs new, 267 metrics: 90 digests changed; timings moved with
  main's own optimization work, dominated by the adapt fix (#623):
  synthetic-500kb cold 3434.9 -> 531.5 ms, synthetic-2mb first render
  44513.5 -> 2344.2 ms, math-heavy 184.1 -> 134.5 ms. Improvements of
  that size are exactly what a stale timing baseline can no longer
  calibrate against.

The corpus grew from 12 to 26 recorded cases (article-twocolumn,
input-bibliography and the other real-world fixtures landed on main
after Sep 13); the gate's per-PR --only set is a subset. Known notes
carried in the report, not failures: tikz-heavy PDF export is refused
by the exact route (path_stroke unsupported - a product limitation the
harness reports), siunitx-tables carries an unsupported \SI syntax
diagnostic, unicode-accents reports CJK missing_glyph.

Implementation-Agent: fable-ft070
Commit-Executor: fable-ft070 (direct; Cursor usage limit)

---------

Co-authored-by: Claude Opus 5 <[email protected]>
GoKubar added a commit that referenced this pull request Sep 15, 2026
…uster 160 -> 88 B) (#232)

* perf-bench: FT-070 benchmark harness, committed baseline and a >5% gate

There was no way to tell whether an engine change made the compiler faster.
The numbers that existed came from `examples/stages.rs` and `perf_bench.rs`:
macOS-only metadata, one sample per cell, no memory figure, no machine-readable
output, and no way to fail a build on a regression. This adds a harness whose
output can be argued with.

`crates/perf-bench` measures the product path -- the same
`protocol::handle_line` the `flashtex-render` worker serves -- over the ten
committed real-world fixtures and four generated documents (500 KB, 2 MB,
math-heavy, TikZ-heavy; generators committed, not blobs). Per case it reports
cold timings with a per-phase split, warm single-keystroke timings, PDF export,
peak and steady RSS, and an output digest. `--baseline ... --check` turns the
same run into a CI gate.

Three rules the harness enforces on itself, because breaking any of them
produces numbers that look fine and mean nothing:

* No measurement without fonts. Latin Modern and the pinned 12 pt TFM set must
  load and no render may substitute a face or a metric, or the case produces no
  timing at all -- a substituted metric is a different workload, not a slower
  one. The font set is built with `FontSet::with_dirs`, which probes nothing,
  so this box's TeX Live cannot supply the metrics by accident. The line is
  drawn at the configuration, not the document: a character with no glyph, or a
  class command the compiler does not model, is deterministic and identical
  every run, so the case is measured and the degradation is recorded next to
  the number.
* Cold means cold. Every repetition runs in a child process of its own, so the
  expander's thread-local cache, the font set's memoised faces and the
  allocator all start empty, and peak RSS belongs to one document.
* Medians, with the spread shown. Nothing comes from one sample; every metric
  carries n, p25/p75, p95 and MAD, and the table prints the run's own noise
  estimate per case.

The gate is built to survive a shared machine. A metric counts as regressed
only when it exceeds both the tolerance and that metric's own measured spread
in the baseline, and the comparison warns and stops enforcing timings when the
host, build profile, font configuration or peak load differ. Output identity
does not depend on the machine -- the fonts come from the repository -- so a
changed digest fails everywhere and unconditionally.

Baseline, at main 8465bbd on a Ryzen 7 7800X3D: cold HW1 meets its 10 ms
target; warm keystroke is 153x over budget at 500 KB and 132x at 2 MB, HW1 PDF
export is 5.6x over, and steady memory at 2 MB is 49x over. Full numbers,
method and three findings are in docs/evidence/perf-ft070-2026-09-13.

The clearest of those findings: typesetting a 2 MB document costs 42.7 s with
the document sources attached and 1.04 s without. Two per-formula code paths in
render-pipeline's typeset ask a question about the preamble and answer it by
searching the entire document, so a document that does not contain the searched
string pays a full scan per formula. That crate is another lane's, so this lane
has measured and reported it rather than touching it.

Gates unchanged (this adds a crate and edits no existing crate's source):
amsmath 59/59, HW1/HW2 3 pages with 0 errors and 0 overfull, render-pipeline
170 passed / 0 failed, compiler 395 passed / 0 failed, perf-bench 13 passed.

Implementation-Agent: Claude Opus 5 (FT-070 perf lane, linux-primary)
Commit-Executor: Claude Opus 5 (direct agent Git execution, per the AGENTS.md
  Cursor-limit fallback in force on this machine)
Co-authored-by: GoKubar <[email protected]>
Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Xd5Hmwh5GHNTiAmHUJ1MZu

* perf-bench: build against current main (assemble colour params, Capabilities fields)

`typeset::assemble` grew `page_color`/`default_color` and `v1::Capabilities`
grew `device_color`/`delta`/`v2_only` after the harness was written. Pass
`None`/`None` and spread the default so the measured path is still the one the
committed baselines were recorded against.

Reported on PR #206.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Xd5Hmwh5GHNTiAmHUJ1MZu

* display list: derive the cluster carets instead of storing them per glyph

`Cluster` carried a `Carets { first: Caret, last: Option<Caret> }` — 72 of
its 160 bytes — and a text run emits one cluster per glyph, so a 1507-page
document held 1.48 million caret pairs. They were never independent data:

  carets.first == Caret { text_byte: text_start_byte,
                          x:  hit_rect.x,
                          top: hit_rect.top,
                          height: hit_rect.height }

at all three construction sites (text runs, math, TikZ node text), and
`place_item`/`shift_x` moved the rect and both carets by the same offset,
so placement preserved it too. Audited over the twelve corpus cases —
1 991 552 clusters — the start caret was byte-identical to the derived one
in every single one, the end caret never sat on a cluster other than its
run's last, and its top/height always equalled that cluster's hit rect.

So `Cluster` keeps the rect and derives both carets, and the one thing that
is genuinely not derivable — the end caret's `x` (the TikZ path clamps the
hit rect's width to one tick but not the caret) and its text byte — moves to
the run as `GlyphRun::end_caret`, one per run instead of 40 bytes per glyph.
`Cluster`: 160 -> 88 bytes.

This also makes an invariant structural that `join_runs` used to maintain by
hand: it cleared the joined-over cluster's trailing caret so that only a
run's last cluster carried one. With the caret on the run there is nowhere
for a mid-run one to live.

Output is unchanged and that is the point of the change: both JSON emitters
and the delta digest now call `GlyphRun::carets_of`, which reconstructs the
same `Carets` value. `delta::changed_items` compares `end_caret` once per run
in place of `carets` per cluster — the same comparison, since the rest of the
caret is the cluster bytes and hit rect it already compares.

Measured on synthetic-2mb (1507 pages, 1.48M clusters), the perf harness
reports identical digests for all three scenarios (cold.reply
b0d5e89b71ab0200, warm.type-display-eq 4ec7e38a83002099,
warm.type-paragraph 484f07ea71d1b181) and steady RSS 5107 -> 4897 MiB.

FT-070. Reported on PR #206.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Xd5Hmwh5GHNTiAmHUJ1MZu

* perf-bench: a memory profile that says where the resident bytes went

FT-070's memory gap was a single number with no attribution. This adds the
instrument, so the breakdown is measured rather than argued about.

`render_pipeline::memsize` walks an already-built display list and render
cache and charges allocated bytes (capacity, not length — that is what the
allocator holds) to named lines, counting each shared `Rc` once so the two
totals can be added. It is read-only and touches no render path.

`memprofile <case>` renders a corpus case through the product path, runs the
warm keystrokes the harness runs, and reports VmRSS, live bytes from a
counting global allocator, and the walked breakdown, so the three gaps are
separated: live-minus-walked is what the walk cannot reach (font, expander
and compiler caches), RSS-minus-live is allocator retention, and a
`malloc_trim(0)` probe splits that last one into trimmable and fragmented.

It is a second binary because the counting allocator must not be linked into
the timing binary, and `main.rs` keeps its own module declarations: every
committed baseline was recorded by it exactly as it stands.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Xd5Hmwh5GHNTiAmHUJ1MZu

* tests: build the cluster carets through the derived accessor

Two tests constructed or read `Cluster.carets` directly. The JSON
round-trip test now sets the run's `end_caret` — which also makes it check
that both writers agree about *which* cluster shows the end caret, not just
about its value — and the joined-fragment test reads `GlyphRun::carets_of`,
so it still asserts the property it was written for: a caret never falls
outside its own cluster's byte range.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Xd5Hmwh5GHNTiAmHUJ1MZu

* perf-bench: follow main's assemble and Capabilities signatures

typeset::assemble grew page_color/default_color (mirrored from the
product path in lib.rs, doc.page_color/doc.default_color), and
v1::Capabilities grew device_color/delta/v2_only, all off in the
harness's fixed capability set.

Implementation-Agent: fable-ft070
Commit-Executor: fable-ft070 (direct; Cursor usage limit)

* perf-bench: recalibrate the committed baseline to current main

The Sep 13 baseline no longer describes main: the engine moved ~465
commits (integration queues #644/#646 and today's ~66 merges), and the
digest half of the gate is a hard equality against recorded output, so
every PR was failing on drift this harness did not cause. Verified on
the Sep 14 run of #232: FAIL was 'output changed in 50 place(s)' only;
timings were correctly reported-not-enforced on the foreign runner.

Why re-recording is legitimate rather than gate-disarming:
- This branch adds no engine code (crates/perf-bench, .github, docs
  only), so the tree whose output was recorded IS origin/main's engine,
  byte for byte. The digest drift is main's own, each contributing PR
  individually gated by the pdflatex oracles.
- Same reference host as the Sep 13 recording (linux/x86_64/AMD Ryzen 7
  7800X3D/16cpu), same build profile, recorded by the same procedure
  (README), full 26-case corpus at the current cap policy.
- Old vs new, 267 metrics: 90 digests changed; timings moved with
  main's own optimization work, dominated by the adapt fix (#623):
  synthetic-500kb cold 3434.9 -> 531.5 ms, synthetic-2mb first render
  44513.5 -> 2344.2 ms, math-heavy 184.1 -> 134.5 ms. Improvements of
  that size are exactly what a stale timing baseline can no longer
  calibrate against.

The corpus grew from 12 to 26 recorded cases (article-twocolumn,
input-bibliography and the other real-world fixtures landed on main
after Sep 13); the gate's per-PR --only set is a subset. Known notes
carried in the report, not failures: tikz-heavy PDF export is refused
by the exact route (path_stroke unsupported - a product limitation the
harness reports), siunitx-tables carries an unsupported \SI syntax
diagnostic, unicode-accents reports CJK missing_glyph.

Implementation-Agent: fable-ft070
Commit-Executor: fable-ft070 (direct; Cursor usage limit)

---------

Co-authored-by: Claude Opus 5 <[email protected]>
@GoKubar
GoKubar deleted the agent/daniel-parent/adapter-quadratic branch September 16, 2026 04:17
ItsAkilesh pushed a commit to ItsAkilesh/flashtex that referenced this pull request Sep 18, 2026
… environments

What changed:
- Adds crates/render-pipeline/tests/adapt_linear_time.rs with the two
  complexity guards that were lost when flash-tex#627 reverted 71d8fbf. That
  revert was deduplication, not a defect: flash-tex#623 fixed the same quadratic
  adapt with a SourceIndex and landed on main as bbc9583, so flash-tex#627 gave
  the adapter back to flash-tex#623 — but it took these two tests with it, and
  flash-tex#623 shipped only source_index_matches_prefix_scans, which checks
  identity, not cost. Nothing on main noticed if adapt went quadratic
  again while still producing the right output.
- The file also records the six fuzz-found hang cases (PR flash-tex#627's
  mutation fuzzer, "hang in render") with their before/after release
  timings, so the finding lives in the repo rather than in the message
  of a reverted commit on an unpushed branch.
- Test-only. No product code changes.

What was run:
- cargo test --test adapt_linear_time --no-run (main, 9c5b028):
  Finished `test` profile [unoptimized + debuginfo] target(s) in 10.07s
- cargo test --test adapt_linear_time (main, 9c5b028):
  test result: ok. 2 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.08s
- the same file against pre-flash-tex#623 main (108b2a2, bbc9583^):
  test result: FAILED. 0 passed; 2 failed; 0 ignored; 0 measured; 0 filtered out; finished in 35.12s
  10 000 list items took 17.570090167s to adapt
  took 17.506552417s to adapt
  so the guards bite on the regression they name: 17.5 s before, 0.08 s
  after, against a 10 s threshold.

Next step: none; flash-tex#627 carries the fuzzer itself.

Implementation-Agent: claude-opus-5 subagent of daniel-parent
Commit-Executor: daniel-parent subagent
Claude-Session: https://claude.ai/code/session_012c9XLkHjePPGBuarrmE2mz
ItsAkilesh pushed a commit to ItsAkilesh/flashtex that referenced this pull request Sep 18, 2026
…(#GH-FLAKY-TABLE-LENGTHS-LINEAR)

What changed:
`adapter::tests::table_lengths_scale_linearly_with_the_number_of_tables`
asserted `t800 < t200 * 8`, a ratio over a sub-millisecond baseline (~587us
on PR flash-tex#765 CI). Scheduler noise of a few hundred microseconds is a large
fraction of that baseline, and a ratio's error bars scale with the smaller
operand, so it amplified the noise into an occasional false failure
("800 tables took 5.044542ms, 200 took 587.834us: not linear", which
passed on an unmodified re-run at the same commit).

Replaced the ratio with an absolute ceiling (300ms on t800), the same
pattern as crates/render-pipeline/tests/adapt_linear_time.rs (flash-tex#765).
Measured on dev hardware: normal 800-table runs (best of 5) take
~1-1.3ms in --release, ~10-11ms unoptimized. Forcing
`length_at_checked` to always fall through to `length_at_scan` (i.e.
reverting flash-tex#623 so every table rescans the source instead of using the
per-document index) makes 800 tables take ~1.4s in --release - about a
thousandfold jump. 300ms sits ~250-300x above the normal case and ~5x
below the reintroduced-quadratic case.

What was run:
- `cargo test --no-run` (separate step) before counting any results: compiled clean.
- Before (already established on PR flash-tex#765, not reproduced here): CI failure
  "800 tables took 5.044542ms, 200 took 587.834us: not linear", the same
  commit re-run went green with no change.
- After, single run (--release): `table lengths: 200 tables 308.875us,
  400 tables 603.834us, 800 tables 1.200166ms` / `test ... ok`.
- 30x loop (--release): 30/30 `test result: ok`, t800 ranged
  1.162084ms-1.252833ms, all far under the 300ms ceiling.
- Negative control: temporarily forced `length_at_checked` to always call
  `length_at_scan` (reverting flash-tex#623) and rebuilt. The fixed test failed:
  "800 tables took 1.391193958s (200 took 34.739917ms, 400 took
  207.798417ms): quadratic regression suspected, see flash-tex#623" /
  `test result: FAILED. 0 passed; 1 failed`. Reverted the temporary change
  immediately after (git diff confirmed clean before committing).
- Full `adapter::tests::` module (--release): `test result: ok. 38 passed;
  0 failed; 1 ignored`.

Next step: open PR to main; no further code changes anticipated for this task.

Implementation-Agent: claude-sonnet-5 subagent of daniel-parent
Commit-Executor: daniel-parent subagent
Claude-Session: https://claude.ai/code/session_012c9XLkHjePPGBuarrmE2mz
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