Skip to content

render-pipeline: refuse an over-limit compile_result without serialising it (perf C) - #651

Merged
GoKubar merged 1 commit into
mainfrom
agent/kabir-claude/v1-reply-size-gate
Sep 15, 2026
Merged

GoKubar merged 1 commit into
mainfrom
agent/kabir-claude/v1-reply-size-gate

Conversation

@GoKubar

@GoKubar GoKubar commented Sep 15, 2026

Copy link
Copy Markdown
Contributor

Phase 2, step C of the warm-repaint investigation (Phase 1 report: the 398-page warm keystroke spends ~34 ms building+serialising a 25 MB v1 envelope that is discarded against the 16 MB reply limit, replying failed with only its length).

What changes

  • V1Payload::envelope_len(id): the exact byte length write_envelope(id) would produce, computed by length arithmetic that mirrors the writer field for field (same escape rules, same jpt/ji milli-rounding) without allocating the line.
  • protocol::handle_line: when the item-count heuristic puts the reply limit in reach (approx > limit/4), the exact length is computed first; if it exceeds the limit the worker sends the refusal it always sent — with the same exact byte count in the message — and never serialises the envelope. A line that fits is written exactly as before, and the old post-write check remains as the last word (an underestimate could only cost the optimisation, never change a reply). Small replies skip both passes.

Output preservation

  • envelope_len_matches_write_envelope (new unit test): length == serialised length across every writer field shape — escapes, control chars, font hints, both item kinds, null sources, suggestions, non-finite/huge coordinates — plus the whole jpt milli-grid near zero and a pseudo-random sweep.
  • oversize_compile_result_refusal_names_the_exact_line_length (new e2e): the refused reply names exactly the byte count a permissive run's envelope actually has.
  • 67/67 byte-identical --v2 and --pdf vs main 18bbacf0: all 65 fixtures/ entry documents + the 398-page compiler: 3x faster large-document compile — shaping memo, glyph-table index, lent cleveref config (#65) #535 article with and without toc/pageref.
  • perf-bench (FT-070: engine performance harness, committed baseline and a >5% regression gate #206) full run vs the committed baseline: zero digest changes. The 152 flagged timings were a uniform +5–6% across every metric — including phases this change cannot execute (cold parse, PDF export) — at load 5.2 vs the baseline's 1.4; an interleaved base-vs-base control on the same box fails the same gate the same way (+14% on a cold phase, noise band 8.9%). Per the shared-box measurement guidance, those deltas are machine noise. An interleaved 5-case --pin run (base→C→base) flagged only cold phases with overlapping noise bands and no warm/v1 metric.
  • cargo test --release --no-run clean first; suite 454 passed / 0 failed (release); cargo build --release --locked clean.

Measured effect

xref_measure (450 sections / 398 pages), interleaved A/B/A/B: handle−render drops ~73–78 ms → 50–58 ms per warm edit (−20 ms: the 21 ms serialisation is gone; the 13 ms v1 fallback build and ~3 ms length pass remain). Render time untouched, cache counters identical.

Next (separate PRs, per plan): A — seed labels.pages/toc_pages across requests; B — stop cloning cached blocks into Laid.

🤖 Generated with Claude Code

https://claude.ai/code/session_01Xd5Hmwh5GHNTiAmHUJ1MZu

…ing it

On a 398-page document (#535's generated article) the worker built and
serialised a 25 MB v1 envelope on every warm keystroke, compared its length
to the 16 MB reply limit, and threw it away: ~34 ms per edit spent producing
a line whose only use was its length, before replying `failed`.

The refusal now comes first, the same shape as the display_list oversize
gate: `V1Payload::envelope_len` computes the exact byte length of the
envelope `write_envelope` would produce -- length arithmetic mirroring the
writer field for field, strings via the same escape rules, `jpt`/`ji`
milli-rounding reproduced -- without allocating the line. When that length
exceeds the reply limit the worker answers with the refusal it always sent,
carrying the same exact byte count, and never serialises the envelope. The
pre-check runs only when the item-count heuristic puts the limit in reach
(approx > limit/4), so small replies pay neither pass; a line that fits is
written exactly as before, and the old post-write check stays as the last
word, so an underestimate could only cost the optimisation, never change a
reply.

Output is unchanged by construction and by measurement:
- `envelope_len_matches_write_envelope` pins length == serialised length
  over every writer field shape (escapes, control characters, hints, both
  item kinds, null sources, suggestions, non-finite and huge coordinates)
  plus the whole jpt milli-grid near zero and a pseudo-random sweep.
- `oversize_compile_result_refusal_names_the_exact_line_length` (e2e) pins
  that the refused reply names exactly the byte count a permissive run's
  envelope actually has.
- 67/67 documents byte-identical `--v2` and `--pdf` against main 18bbacf
  (all 65 fixtures/ entry documents plus the 398-page #535 article with and
  without \tableofcontents+\pageref).
- perf-bench full run against the committed baseline: zero digest changes.
  The 152 flagged timings were uniform +5-6% across every metric including
  phases this change cannot execute (cold parse, PDF export), at load 5.2
  vs the baseline's 1.4, and an interleaved base-vs-base control run on the
  same box "fails" the same gate the same way (+14% on a cold phase, noise
  band 8.9%), so the deltas are machine noise, not the change. Suite: 454
  passed / 0 failed (release), `cargo test --release --no-run` clean first,
  `cargo build --release --locked` clean.

Measured effect (xref_measure, 450 sections / 398 pages, interleaved
A/B/A/B): handle_line minus render drops from ~73-78 ms to ~50-58 ms per
warm edit (the 21 ms serialisation is gone; the 13 ms v1 fallback build and
now ~3 ms exact length pass remain). Render time itself is untouched.

Implementation-Agent: Claude (Fable 5, render-perf lane, linux-primary)
Commit-Executor: Claude (Fable 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
@GoKubar
GoKubar merged commit d895e5e into main Sep 15, 2026
11 of 22 checks passed
GoKubar added a commit that referenced this pull request Sep 15, 2026
…ntegration queue)

- protocol.rs: #651's size-first envelope refusal kept whole; this
  branch's contribution grafted in — the refusal's capability echo also
  filters -only and -window, since nothing sibling-shaped was accepted.
- memsize.rs / memprofile.rs: this branch's window-aware versions are
  supersets of the #232 versions main landed; kept ours.
- typeset.rs: comment-only (derived-carets note on the math assembly).

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

Only conflict was docs/user/compiler.md (generated); resolved by
re-running crates/compiler/scripts/render_supported_latex.sh, never
hand-merged. apps/mac/scripts/sync-supported-latex.sh reports the
bundled copy current.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Xd5Hmwh5GHNTiAmHUJ1MZu
GoKubar added a commit that referenced this pull request Sep 15, 2026
@GoKubar
GoKubar deleted the agent/kabir-claude/v1-reply-size-gate branch September 16, 2026 04:17
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