Skip to content

fix(highlighter): reseed fenced Markdown segments - #148

Merged
owainlewis merged 1 commit into
mainfrom
codex/146-segment-reseeding
Jul 28, 2026
Merged

fix(highlighter): reseed fenced Markdown segments#148
owainlewis merged 1 commit into
mainfrom
codex/146-segment-reseeding

Conversation

@owainlewis

Copy link
Copy Markdown
Owner

Summary

  • Reseed each bounded Rust/Markdown highlight segment from the lexical context active at that segment's first line.
  • Advance retained fence, quote-depth, and injected-Rust context through each segment while keeping every oversized line as a context barrier.
  • Add focused unquoted and block-quoted regressions with a retained fence opener, oversized middle line, visible Rust suffix, real closer, following Markdown heading, parser-request count, and retained-work bounds.
  • Record the scoped design and verification plan in docs/issues/146-plan.md.

Why

PR #144 retained Markdown fence context after a truncated line, but each post-barrier parser segment still started as a standalone Markdown document. Without a synthetic fence opener, visible Rust after the oversized line lost injected-language highlighting until a later window rebuild.

This change keeps the existing segmentation and checkpoint design. It gives each already-bounded segment the context Tree-sitter needs, then advances the same compact lexical state used by checkpoints before parsing the next segment.

Test plan

Verified on exact base 90f2823ded43d102650a8bce1e80e652fdb3740f and head 0ee87bb797539acef0dcb8afe56ea417d7d9db14:

  • cargo test highlighter::tests:: -- --nocapture: 46 passed.
  • cargo test performance:: -- --ignored --nocapture --test-threads=1: all 4 passed; deep highlighting completed in 1.281s initially and 25.104ms after edit.
  • cargo test --all-targets: 317 unit tests passed, 4 documented performance tests ignored and run separately, and all 5 signal cleanup tests passed.
  • cargo fmt --check.
  • git diff --check origin/main...HEAD.
  • cargo clippy --all-targets --all-features -- -D warnings.
  • cargo build --all-targets.
  • Applied the named improve workflow to clarify the segment-barrier invariant and preserve behavior.
  • Fresh independent review inspected the final tracked and untracked diff, ran focused and all-target tests, and approved with no important findings.

Risks

The fix deliberately does not remove or relax truncated-line barriers. Each existing parser segment receives only the bounded synthetic wrapper for its retained context, and parser call count remains one per segment. Window lines, per-line source prefixes, checkpoints, scanned work, and the #124 exact Rust wrapper cap keep their existing limits.

Real fence closers are scanned and parsed inside their segment, so following Markdown resumes on the next line. Block-quoted fences keep the retained quote depth. The separate #124 overflow branches and #142 overflow recovery policy are unchanged.

Related issue

Closes #146

@owainlewis
owainlewis merged commit 2c5f69d into main Jul 28, 2026
1 check passed
@owainlewis
owainlewis deleted the codex/146-segment-reseeding branch July 28, 2026 23:12

Copy link
Copy Markdown
Owner Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. 🎉

Reviewed commit: 2c5f69deb7

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Copy link
Copy Markdown
Owner Author

Merged-main verification complete.

Merge commit: 2c5f69deb75109501e4d682c259de616098b45dc

Main CI: https://github.com/owainlewis/cortex/actions/runs/30407212734

Rust checks passed in 1m45s, including the security workflow policy, formatting, Clippy, tests, and release build. Issue #146 is closed, and the original PR #144 review thread is replied to and resolved with the merged fix and focused regression evidence.

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.

[bug] Reseed fenced Markdown highlighting after truncated lines

1 participant