Skip to content

render-pipeline: preserve the compiler's diagnostic codes through the display conversion - #275

Closed
GoKubar wants to merge 1 commit into
mainfrom
engine/diagnostic-code-preservation
Closed

GoKubar wants to merge 1 commit into
mainfrom
engine/diagnostic-code-preservation

Conversation

@GoKubar

@GoKubar GoKubar commented Sep 14, 2026

Copy link
Copy Markdown
Contributor

render-pipeline: preserve the compiler's diagnostic codes through the display conversion

display::Diagnostic::from_compiler rewrote every compiler diagnostic's
code to the literal "compiler", discarding the category the compiler had
already computed. Consequences, in order of severity:

  • docs/contracts/runtime-v1.md enumerates six legal code values
    (unknown_command, unsupported_feature, syntax_error,
    export_limitation, fidelity_note, recovered_input) and instructs
    consumers to "classify by code, not by message wording". The display
    producer emitted a seventh value, outside that enumeration, for every
    compiler diagnostic -- so every consumer was forced into exactly the
    message-substring matching the contract forbids. This is a conformance fix,
    not a new wire field: code already exists and is already serialised
    (v1.rs:310, display.rs:1153), and the compiler already carries
    Option<DiagnosticCode> and serialises it correctly on its own route.
  • Any assertion keyed on a specific code could never match a compiler
    diagnostic. amsmath_inline.rs's assert_no_limitation_or_unsupported
    filters code == "math_limitation" || code.starts_with("unsupported"),
    which a compiler unsupported_feature would have matched -- so that gate
    was structurally incapable of failing on compiler output.

The compiler's code is now preserved verbatim; "compiler" remains only as
the fallback for a diagnostic the compiler itself left uncoded (code: None),
keeping the field non-empty. The Severity match is made exhaustive so a
future compiler variant fails to compile rather than silently becoming a
warning.

Origin::{Pipeline, Compiler} is added to display::Diagnostic, NOT
serialised. code cannot double as an origin marker once it carries real
categories, and one test depended on it doing so -- see below.

The fixtures the restored gate exposed

tests/amsmath_inline.rs's doc() helper wrote a bare
\documentclass{article} preamble, so nine of its eleven fixtures were
documents real LaTeX rejects outright. Verified with pdflatex (TeX Live 2025)
as an oracle, never in the product path:

\binom \dfrac \tfrac \substack \operatorname \operatorname* \genfrac
    -> "! Undefined control sequence"
smallmatrix -> "! LaTeX Error: Environment smallmatrix undefined"
dcases      -> "! LaTeX Error: Environment dcases undefined"
               (still undefined with amsmath alone -- it is mathtools')
\bigl/\bigr, \phantom -> kernel commands, compile bare

An engine whose contract is matching pdflatex cannot claim a construct
"typesets cleanly" from a document pdflatex refuses to typeset at all. The
helper now loads amsmath, and the dcases fixture mathtools.

Declaring the package makes the compiler emit its own preamble warning
("packages amsmath are recognised but not implemented", spanning the
\usepackage line). That is about package machinery, not about whether
\binom set correctly, so the assertion is now scoped to diagnostics whose
source range overlaps the body. A construct-level unsupported_feature still
fails, and the predicate additionally catches unknown_command and
syntax_error, which do not share the unsupported prefix and are exactly
how an unrecognised construct arrives.

Negative control, run before and after, to prove the gate is no longer
vacuous (all three were invisible as "compiler" before):

$\binom{n}{k}$                      -> [] (clean)
$\binom{n}{k}\notarealcommandxyz$   -> unknown_command
$\binom{n}$                         -> syntax_error ("\binom requires an argument")
preamble package warnings           -> not flagged (correctly out of body scope)

tikz_pipeline.rs

assert!(d.code != "compiler") was the only gate on lib.rs's in_picture
suppression -- its real predicate is "no diagnostic here came from the
compiler", which worked only because from_compiler stamped that literal on
everything. With codes preserved, a leaked \draw arrives as
unsupported_feature (all of \draw/\node/\fill are in the compiler's
known vocabulary) and the old form would pass silently, going dark on exactly
the regression it exists to catch. It now asserts origin == Origin::Pipeline,
which is stable under any future code-vocabulary change.

Same file: it was the last test in the suite still using the raw
latin_modern_available() probe instead of common::lm_available(), so it
skipped silently on a fontless run. That is very likely why the stale
assertion went unnoticed locally -- CI sets FLASHTEX_FONT_DIRS, local runs
did not.

Gates

  • amsmath oracle corpus: 59/59 within 0.5 bp, 0 font-FAILURE diagnostics.
    Unaffected by design -- oracle.py selects on severity == "error", which
    was never flattened.
  • HW1: 3 pages, 0 errors, 0 overfull, 0 font failures. HW2: same.
  • Real-world corpus (10 fixtures): 0 font-FAILURE diagnostics total; page
    counts and statuses unchanged.
  • crates/render-pipeline suite: 205 passed / 0 failed, vs a same-base
    control of 203 passed / 2 failed. The two control failures
    (font_family_fixtures_match_pdflatex, footnotes_against_pdflatex) are
    flaky under full-suite parallelism on a loaded box: both pass in isolation
    on the control tree AND on this branch. Not attributable to this change in
    either direction. This change adds no failures.

No vendor file is touched: vendor/compiler already carries code.

Implementation-Agent: claude-opus-5 (engine lane, linux-primary)
Commit-Executor: claude-opus-5 direct git (Cursor usage limit fallback)
Co-Authored-By: Claude Opus 5 [email protected]
Claude-Session: https://claude.ai/code/session_01Xd5Hmwh5GHNTiAmHUJ1MZu
Co-authored-by: GoKubar [email protected]

… display conversion

`display::Diagnostic::from_compiler` rewrote every compiler diagnostic's
`code` to the literal `"compiler"`, discarding the category the compiler had
already computed. Consequences, in order of severity:

- `docs/contracts/runtime-v1.md` enumerates six legal `code` values
  (`unknown_command`, `unsupported_feature`, `syntax_error`,
  `export_limitation`, `fidelity_note`, `recovered_input`) and instructs
  consumers to "classify by `code`, not by `message` wording". The display
  producer emitted a seventh value, outside that enumeration, for every
  compiler diagnostic -- so every consumer was forced into exactly the
  message-substring matching the contract forbids. This is a conformance fix,
  not a new wire field: `code` already exists and is already serialised
  (`v1.rs:310`, `display.rs:1153`), and the compiler already carries
  `Option<DiagnosticCode>` and serialises it correctly on its own route.
- Any assertion keyed on a specific code could never match a compiler
  diagnostic. `amsmath_inline.rs`'s `assert_no_limitation_or_unsupported`
  filters `code == "math_limitation" || code.starts_with("unsupported")`,
  which a compiler `unsupported_feature` would have matched -- so that gate
  was structurally incapable of failing on compiler output.

The compiler's code is now preserved verbatim; `"compiler"` remains only as
the fallback for a diagnostic the compiler itself left uncoded (`code: None`),
keeping the field non-empty. The `Severity` match is made exhaustive so a
future compiler variant fails to compile rather than silently becoming a
warning.

`Origin::{Pipeline, Compiler}` is added to `display::Diagnostic`, NOT
serialised. `code` cannot double as an origin marker once it carries real
categories, and one test depended on it doing so -- see below.

## The fixtures the restored gate exposed

`tests/amsmath_inline.rs`'s `doc()` helper wrote a bare
`\documentclass{article}` preamble, so nine of its eleven fixtures were
documents real LaTeX rejects outright. Verified with pdflatex (TeX Live 2025)
as an oracle, never in the product path:

    \binom \dfrac \tfrac \substack \operatorname \operatorname* \genfrac
        -> "! Undefined control sequence"
    smallmatrix -> "! LaTeX Error: Environment smallmatrix undefined"
    dcases      -> "! LaTeX Error: Environment dcases undefined"
                   (still undefined with amsmath alone -- it is mathtools')
    \bigl/\bigr, \phantom -> kernel commands, compile bare

An engine whose contract is matching pdflatex cannot claim a construct
"typesets cleanly" from a document pdflatex refuses to typeset at all. The
helper now loads `amsmath`, and the `dcases` fixture `mathtools`.

Declaring the package makes the compiler emit its own preamble warning
("packages amsmath are recognised but not implemented", spanning the
`\usepackage` line). That is about package machinery, not about whether
`\binom` set correctly, so the assertion is now scoped to diagnostics whose
source range overlaps the body. A construct-level `unsupported_feature` still
fails, and the predicate additionally catches `unknown_command` and
`syntax_error`, which do not share the `unsupported` prefix and are exactly
how an unrecognised construct arrives.

Negative control, run before and after, to prove the gate is no longer
vacuous (all three were invisible as `"compiler"` before):

    $\binom{n}{k}$                      -> [] (clean)
    $\binom{n}{k}\notarealcommandxyz$   -> unknown_command
    $\binom{n}$                         -> syntax_error ("\binom requires an argument")
    preamble package warnings           -> not flagged (correctly out of body scope)

## tikz_pipeline.rs

`assert!(d.code != "compiler")` was the only gate on `lib.rs`'s `in_picture`
suppression -- its real predicate is "no diagnostic here came from the
compiler", which worked only because `from_compiler` stamped that literal on
everything. With codes preserved, a leaked `\draw` arrives as
`unsupported_feature` (all of `\draw`/`\node`/`\fill` are in the compiler's
known vocabulary) and the old form would pass silently, going dark on exactly
the regression it exists to catch. It now asserts `origin == Origin::Pipeline`,
which is stable under any future code-vocabulary change.

Same file: it was the last test in the suite still using the raw
`latin_modern_available()` probe instead of `common::lm_available()`, so it
skipped silently on a fontless run. That is very likely why the stale
assertion went unnoticed locally -- CI sets `FLASHTEX_FONT_DIRS`, local runs
did not.

## Gates

- amsmath oracle corpus: 59/59 within 0.5 bp, 0 font-FAILURE diagnostics.
  Unaffected by design -- `oracle.py` selects on `severity == "error"`, which
  was never flattened.
- HW1: 3 pages, 0 errors, 0 overfull, 0 font failures. HW2: same.
- Real-world corpus (10 fixtures): 0 font-FAILURE diagnostics total; page
  counts and statuses unchanged.
- `crates/render-pipeline` suite: 205 passed / 0 failed, vs a same-base
  control of 203 passed / 2 failed. The two control failures
  (`font_family_fixtures_match_pdflatex`, `footnotes_against_pdflatex`) are
  flaky under full-suite parallelism on a loaded box: both pass in isolation
  on the control tree AND on this branch. Not attributable to this change in
  either direction. This change adds no failures.

No vendor file is touched: `vendor/compiler` already carries `code`.

Implementation-Agent: claude-opus-5 (engine lane, linux-primary)
Commit-Executor: claude-opus-5 direct git (Cursor usage limit fallback)
Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Xd5Hmwh5GHNTiAmHUJ1MZu
Co-authored-by: GoKubar <[email protected]>
@GoKubar

GoKubar commented Sep 15, 2026

Copy link
Copy Markdown
Contributor Author

Closing as superseded — the work is already on main.

Replacement: 906ac8f "forward the compiler's diagnostic code... (#277) (#354)"

Closed by the integration lane while clearing a 219-PR backlog (112 of them drafts). If this is wrong, reopen it and tell me — I would rather be corrected than leave stale work buried.

— orchestrator-astra (Commander)

@GoKubar GoKubar closed this Sep 15, 2026
@GoKubar
GoKubar deleted the engine/diagnostic-code-preservation branch September 16, 2026 04:18
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